|
11 | 11 | : "${BASH_IT_LOG_LEVEL_TRACE:=7}"
|
12 | 12 | readonly "${!BASH_IT_LOG_LEVEL_@}"
|
13 | 13 |
|
| 14 | +function _bash-it-log-prefix-by-path() { |
| 15 | + local component_path="${1?${FUNCNAME[0]}: path specification required}" |
| 16 | + local without_extension component_directory |
| 17 | + local component_filename component_type component_name |
| 18 | + |
| 19 | + # get the directory, if any |
| 20 | + component_directory="${component_path%/*}" |
| 21 | + # drop the directory, if any |
| 22 | + component_filename="${component_path##*/}" |
| 23 | + # strip the file extension |
| 24 | + without_extension="${component_filename%.bash}" |
| 25 | + # strip before the last dot |
| 26 | + component_type="${without_extension##*.}" |
| 27 | + # strip component type, but try not to strip other words |
| 28 | + # - aliases, completions, plugins, themes |
| 29 | + component_name="${without_extension%.[acpt][hlo][eimu]*[ens]}" |
| 30 | + # Finally, strip load priority prefix |
| 31 | + component_name="${component_name##[[:digit:]][[:digit:]][[:digit:]]"${BASH_IT_LOAD_PRIORITY_SEPARATOR:----}"}" |
| 32 | + |
| 33 | + # best-guess for files without a type |
| 34 | + if [[ "${component_type:-${component_name}}" == "${component_name}" ]]; then |
| 35 | + if [[ "${component_directory}" == *'vendor'* ]]; then |
| 36 | + component_type='vendor' |
| 37 | + else |
| 38 | + component_type="${component_directory##*/}" |
| 39 | + fi |
| 40 | + fi |
| 41 | + |
| 42 | + # shellcheck disable=SC2034 |
| 43 | + BASH_IT_LOG_PREFIX="${component_type:-lib}: $component_name" |
| 44 | +} |
| 45 | + |
14 | 46 | function _has_colors() {
|
15 | 47 | # Check that stdout is a terminal, and that it has at least 8 colors.
|
16 | 48 | [[ -t 1 && "${_bash_it_available_colors:=$(tput colors 2> /dev/null)}" -ge 8 ]]
|
|
0 commit comments