From a312e5a9b9638b2bcbb0d1a51d760e0e042c5188 Mon Sep 17 00:00:00 2001 From: souhaiebtar Date: Sat, 22 Jan 2022 12:33:33 +0000 Subject: [PATCH 01/17] fix wrong function name in `helpers.bash` when i tried to install, i got a message `_bash-it-pluralize-component` command not found; after checking `utilities.bash` the correct function name was `_bash-it-component-pluralize` --- lib/helpers.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 01211079..eaaa63cd 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -814,7 +814,7 @@ _disable-thing () _bash-it-clean-component-cache "${file_type}" if [ "$file_entity" = "all" ]; then - printf '%s\n' "$file_entity $(_bash-it-pluralize-component "$file_type") disabled." + printf '%s\n' "$file_entity $(_bash-it-component-pluralize "$file_type") disabled." else printf '%s\n' "$file_entity disabled." fi From e7818dbacacbc1b138ee6a7e1248000d3dff8a30 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 2 Feb 2022 11:53:00 -0800 Subject: [PATCH 02/17] lib/helpers: handle unbound positional parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alsö, don't `pushd`/`popd` when restarting shell. --- lib/helpers.bash | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 86850a05..873db9a6 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -255,10 +255,10 @@ function _bash-it_update_migrate_and_restart() { _about 'Checks out the wanted version, pops directory and restart. Does not return (because of the restart!)' _param '1: Which branch to checkout to' _param '2: Which type of version we are using' - if git checkout "$1" &> /dev/null; then + if git checkout "${1?}" &> /dev/null; then echo "Bash-it successfully updated." echo "" - echo "Migrating your installation to the latest $2 version now..." + echo "Migrating your installation to the latest ${2:-} version now..." _bash-it-migrate echo "" echo "All done, enjoy!" @@ -300,7 +300,7 @@ function _bash-it-update-() { BASH_IT_DEVELOPMENT_BRANCH="master" fi # Defaults to stable update - if [[ -z "$1" || "$1" == "stable" ]]; then + if [[ -z "${1:-}" || "$1" == "stable" ]]; then version="stable" TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2> /dev/null) @@ -577,10 +577,10 @@ _bash-it-profile-load-parse-profile() { break fi # Do not actually modify config on dry run - [[ -z $2 ]] || continue + [[ -z "${2:-}" ]] || continue # Actually enable the component $enable_func "$component" - done < "$1" + done < "${1?}" # Make sure to propagate the error [[ -z $bad ]] @@ -602,7 +602,7 @@ _bash-it-profile-rm() { about 'Removes a profile from the "profiles" directory' _group 'lib' - local name="$1" + local name="${1:-}" if [[ -z $name ]]; then echo -e "${echo_orange?}Please specify profile name to remove...${echo_reset_color?}" return 1 @@ -628,7 +628,7 @@ _bash-it-profile-load() { _about 'loads a configuration from the "profiles" directory' _group 'lib' - local name="$1" + local name="${1:-}" if [[ -z $name ]]; then echo -e "${echo_orange?}Please specify profile name to load, not changing configuration...${echo_reset_color?}" return 1 @@ -659,19 +659,15 @@ function _bash-it-restart() { _about 'restarts the shell in order to fully reload it' _group 'lib' - local saved_pwd="${PWD}" init_file="${BASH_IT_BASHRC:-${HOME?}/.bashrc}" - - exec "${0/-/}" --rcfile <(echo "source \"${init_file}\"; cd \"$saved_pwd\"") + exec "${0#-}" --rcfile "${BASH_IT_BASHRC:-${HOME?}/.bashrc}" } function _bash-it-reload() { - _about 'reloads a profile file' + _about 'reloads the shell initialization file' _group 'lib' - pushd "${BASH_IT?}" > /dev/null || return # shellcheck disable=SC1090 source "${BASH_IT_BASHRC:-${HOME?}/.bashrc}" - popd > /dev/null || return } function _bash-it-describe() { @@ -728,7 +724,7 @@ function _disable-plugin() { _example '$ disable-plugin rvm' _group 'lib' - _disable-thing "plugins" "plugin" "$1" + _disable-thing "plugins" "plugin" "${1?}" _on-disable-callback "$1" } @@ -738,7 +734,7 @@ function _disable-alias() { _example '$ disable-alias git' _group 'lib' - _disable-thing "aliases" "alias" "$1" + _disable-thing "aliases" "alias" "${1?}" } function _disable-completion() { @@ -747,7 +743,7 @@ function _disable-completion() { _example '$ disable-completion git' _group 'lib' - _disable-thing "completion" "completion" "$1" + _disable-thing "completion" "completion" "${1?}" } function _disable-thing() { @@ -808,7 +804,7 @@ function _enable-plugin() { _example '$ enable-plugin rvm' _group 'lib' - _enable-thing "plugins" "plugin" "$1" "$BASH_IT_LOAD_PRIORITY_PLUGIN" + _enable-thing "plugins" "plugin" "${1?}" "$BASH_IT_LOAD_PRIORITY_PLUGIN" } function _enable-plugins() { @@ -822,7 +818,7 @@ function _enable-alias() { _example '$ enable-alias git' _group 'lib' - _enable-thing "aliases" "alias" "$1" "$BASH_IT_LOAD_PRIORITY_ALIAS" + _enable-thing "aliases" "alias" "${1?}" "$BASH_IT_LOAD_PRIORITY_ALIAS" } function _enable-aliases() { @@ -836,7 +832,7 @@ function _enable-completion() { _example '$ enable-completion git' _group 'lib' - _enable-thing "completion" "completion" "$1" "$BASH_IT_LOAD_PRIORITY_COMPLETION" + _enable-thing "completion" "completion" "${1?}" "$BASH_IT_LOAD_PRIORITY_COMPLETION" } function _enable-thing() { @@ -909,7 +905,7 @@ function _help-aliases() { _example '$ alias-help' _example '$ alias-help git' - if [[ -n "$1" ]]; then + if [[ -n "${1:-}" ]]; then case "$1" in custom) alias_path='custom.aliases.bash' From 31751624c0066da51501f7fc4b91cde953428e9d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 2 Feb 2022 11:59:36 -0800 Subject: [PATCH 03/17] lib/helpers: cleanup `_bash-it-profile-load-parse-profile()` a bit --- lib/helpers.bash | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 873db9a6..2f1f7a02 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -560,20 +560,20 @@ _bash-it-profile-load-parse-profile() { _example '$ _bash-it-profile-load-parse-profile "profile.bash_it" "dry"' local -i num=0 - local line + local line enable_func subdirectory component to_enable bad while read -r -a line; do ((++num)) # Ignore comments and empty lines [[ -z "${line[*]}" || "${line[*]}" =~ ^#.* ]] && continue - local enable_func="_enable-${line[0]}" - local subdirectory=${line[0]} - local component=${line[1]} + enable_func="_enable-${line[0]}" + subdirectory=${line[0]} + component=${line[1]} - local to_enable=("${BASH_IT}/$subdirectory/available/$component.${subdirectory%s}"*.bash) + to_enable=("${BASH_IT}/$subdirectory/available/$component.${subdirectory%s}"*.bash) # Ignore botched lines if [[ ! -e "${to_enable[0]}" ]]; then echo -e "${echo_orange?}Bad line(#$num) in profile, aborting load...${line[*]}${echo_reset_color?}" - local bad="bad line" + bad="bad line" break fi # Do not actually modify config on dry run @@ -583,7 +583,7 @@ _bash-it-profile-load-parse-profile() { done < "${1?}" # Make sure to propagate the error - [[ -z $bad ]] + [[ -z ${bad:-} ]] } _bash-it-profile-list() { From 35ecc260c24f745d035b481f1714d3bbc4b4136c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 17 Feb 2022 20:46:28 -0800 Subject: [PATCH 04/17] lib/helpers: handle unbound parameters --- lib/helpers.bash | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 2f1f7a02..8186165d 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -542,7 +542,7 @@ function _bash-it-profile-save() { fi done done - if [[ -z "$something_exists" ]]; then + if [[ -z "${something_exists:-}" ]]; then echo "It seems like no configuration was enabled.." echo "Make sure to double check that this is the wanted behavior." fi @@ -705,7 +705,9 @@ function _on-disable-callback() { _group 'lib' local callback="${1}_on_disable" - _command_exists "$callback" && "$callback" + if _command_exists "$callback"; then + "$callback" + fi } function _disable-all() { @@ -725,7 +727,7 @@ function _disable-plugin() { _group 'lib' _disable-thing "plugins" "plugin" "${1?}" - _on-disable-callback "$1" + _on-disable-callback "${1?}" } function _disable-alias() { @@ -777,7 +779,7 @@ function _disable-thing() { # Either one will be matched by this glob for plugin in "${BASH_IT}/enabled"/[[:digit:]][[:digit:]][[:digit:]]"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash" "${BASH_IT}/$subdirectory/enabled/"{[[:digit:]][[:digit:]][[:digit:]]"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash","${file_entity}.${suffix}.bash"}; do if [[ -e "${plugin}" ]]; then - rm "${plugin}" + rm -f "${plugin}" plugin= break fi @@ -790,7 +792,7 @@ function _disable-thing() { _bash-it-clean-component-cache "${file_type}" - if [[ "$file_entity" = "all" ]]; then + if [[ "$file_entity" == "all" ]]; then _bash-it-component-pluralize "$file_type" file_type printf '%s\n' "$file_entity ${file_type} disabled." else From ddf75f17ac0d8fba5c96f8d1a172a95bb8f56394 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 2 Feb 2022 12:39:53 -0800 Subject: [PATCH 05/17] lib/search: fix variable scope --- lib/search.bash | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/search.bash b/lib/search.bash index 2da8f005..4b7f5cdd 100644 --- a/lib/search.bash +++ b/lib/search.bash @@ -266,9 +266,11 @@ function _bash-it-search-result() { shift local color_component color_enable color_disable color_off - local color_sep=':' line - + local match_color compatible_action suffix opposite_suffix + local color_sep=':' line match matched temp + local -i modified=0 enabled=0 len local -a matches=() + # Discard any empty arguments while IFS='' read -r line; do [[ -n "${line}" ]] && matches+=("$line") @@ -290,18 +292,13 @@ function _bash-it-search-result() { color_off='' fi - local match - local -i modified=0 - if [[ "${#matches[@]}" -gt 0 ]]; then printf "${color_component}%13s${color_sep}${color_off} " "${component}" for match in "${matches[@]}"; do - local -i enabled=0 + enabled=0 _bash-it-component-item-is-enabled "${component}" "${match}" && enabled=1 - local match_color compatible_action suffix opposite_suffix - if ((enabled)); then match_color="${color_enable}" suffix="${suffix_enable}" @@ -314,8 +311,8 @@ function _bash-it-search-result() { compatible_action="enable" fi - local matched="${match}${suffix}" - local -i len="${#matched}" + matched="${match}${suffix}" + len="${#matched}" printf '%b' "${match_color}${matched}" # print current state if [[ "${action}" == "${compatible_action}" ]]; then @@ -327,7 +324,7 @@ function _bash-it-search-result() { modified=1 # shellcheck disable=SC2034 # no idea if `$result` is ever used result=$("${action_func}" "${match}") - local temp="color_${compatible_action}" + temp="color_${compatible_action}" match_color="${!temp}" _bash-it-rewind "${len}" printf '%b' "${match_color}${match}${opposite_suffix}" From 95353f1a98239e9526b40b62620911df5037ee56 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 11 Feb 2022 22:19:37 -0800 Subject: [PATCH 06/17] lib/helpers: the last remnants of the `$OSTYPE` have been swept away - Figure out which `sed` we have by checking, not guessing. --- lib/helpers.bash | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 8186165d..896062f0 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -8,16 +8,19 @@ : "${BASH_IT_LOAD_PRIORITY_COMPLETION:=350}" BASH_IT_LOAD_PRIORITY_SEPARATOR="---" -# Handle the different ways of running `sed` without generating a backup file based on OS -# - GNU sed (Linux) uses `-i` -# - BSD sed (macOS) uses `-i ''` +# Handle the different ways of running `sed` without generating a backup file based on provenance: +# - GNU sed (Linux) uses `-i''` +# - BSD sed (FreeBSD/macOS/Solaris/PlayStation) uses `-i ''` # To use this in Bash-it for inline replacements with `sed`, use the following syntax: # sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file -BASH_IT_SED_I_PARAMETERS=('-i') # shellcheck disable=SC2034 # expected for this case -case "$OSTYPE" in - 'darwin'*) BASH_IT_SED_I_PARAMETERS=('-i' '') ;; -esac +if sed --version > /dev/null 2>&1; then + # GNU sed accepts "long" options + BASH_IT_SED_I_PARAMETERS=('-i') +else + # BSD sed errors on invalid option `-` + BASH_IT_SED_I_PARAMETERS=('-i' '') +fi function _command_exists() { _about 'checks for existence of a command' From 2cea663a4a51f20599dccf7e1ff9e8c2473584ec Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 2 Feb 2022 12:54:00 -0800 Subject: [PATCH 07/17] lib/theme: handle undefined parameter --- themes/githelpers.theme.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index ba089392..5ef18e9a 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -134,7 +134,7 @@ function _git-remote-info { elif [[ ${same_branch_name} != "true" ]]; then remote_info="${VCS_STATUS_REMOTE_BRANCH}" fi - if [[ -n "${remote_info}" ]];then + if [[ -n "${remote_info:-}" ]];then # no support for gone remote branches in gitstatusd local branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" echo "${branch_prefix}${remote_info}" @@ -155,7 +155,7 @@ function _git-remote-info { elif [[ ${same_branch_name} != "true" ]]; then remote_info="\$(_git-upstream-branch)" fi - if [[ -n "${remote_info}" ]];then + if [[ -n "${remote_info:-}" ]];then local branch_prefix if _git-upstream-branch-gone; then branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}" From 150f73ee50e70a0f9d101818d604a0a76c28a83f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 17 Feb 2022 20:40:36 -0800 Subject: [PATCH 08/17] bash-it update: show change log once --- lib/helpers.bash | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 896062f0..be320564 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -278,7 +278,7 @@ function _bash-it-update-() { _param '1: What kind of update to do (stable|dev)' _group 'lib' - local silent word DIFF version TARGET revision status revert log_color num_of_lines description i RESP + local silent word DIFF version TARGET revision status revert log_color RESP for word in "$@"; do if [[ "${word}" == "--silent" || "${word}" == "-s" ]]; then silent=true @@ -334,15 +334,7 @@ function _bash-it-update-() { log_color="%Cred" fi - for i in $(git rev-list --merges --first-parent "${revision}"); do - num_of_lines=$(git log -1 --format=%B "$i" | awk '!/^[[:space:]]*$/ {++i} END{print i}') - if [[ "$num_of_lines" -eq 1 ]]; then - description="%s" - else - description="%b" - fi - git log --format="${log_color}%h: $description (%an)" -1 "$i" - done + git log --format="${log_color}%h: %s (%an)" "${revision}" echo "" if [[ -n "${silent}" ]]; then From fbd842b2ea44eb0bbcb915f6947da377cc31cc51 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 14 Feb 2022 15:29:55 -0800 Subject: [PATCH 09/17] lib/helpers: fix extraneous quotes from `_bash-it-grep()` --- lib/utilities.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 63734a0f..28c7c318 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -63,7 +63,7 @@ function _bash-it-array-dedup() { # Outputs a full path of the grep found on the filesystem function _bash-it-grep() { : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" - printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}" + printf "%s" "${BASH_IT_GREP:-/usr/bin/grep}" } # Runs `grep` with extended regular expressions From ffcf8f1c946db2a1ff7ad554fef95de90a0a35ac Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 18 Feb 2022 00:10:20 -0800 Subject: [PATCH 10/17] lib/utilities: >| --- lib/utilities.bash | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 28c7c318..6e65fe8f 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -122,18 +122,16 @@ function _bash-it-component-pluralize() { } function _bash-it-clean-component-cache() { - local component="$1" + local component="${1:-}" local cache - local -a BASH_IT_COMPONENTS=(aliases plugins completions) + local -a components=('aliases' 'plugins' 'completions') if [[ -z "${component}" ]]; then - for component in "${BASH_IT_COMPONENTS[@]}"; do + for component in "${components[@]}"; do _bash-it-clean-component-cache "${component}" done else _bash-it-component-cache-file "${component}" cache - if [[ -f "${cache}" ]]; then - rm -f "${cache}" - fi + : >| "${cache:?}" fi } From 72829ca21d0340a7458be1dc32249c4a613f8063 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 18 Feb 2022 00:08:04 -0800 Subject: [PATCH 11/17] lib/utilities: `_bash-it-component-item-is-enabled()` - required arguments --- lib/utilities.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 6e65fe8f..60f15131 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -168,11 +168,11 @@ function _bash-it-component-list-disabled() { function _bash-it-component-item-is-enabled() { local component_type item_name each_file - if [[ -f "${1}" ]]; then + if [[ -f "${1?}" ]]; then item_name="$(_bash-it-get-component-name-from-path "${1}")" component_type="$(_bash-it-get-component-type-from-path "${1}")" else - component_type="${1}" item_name="${2}" + component_type="${1}" item_name="${2?}" fi for each_file in "${BASH_IT}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash" \ From 625785375960e5d0c212fd984ac2e562c02d0872 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 18 Feb 2022 02:55:54 -0800 Subject: [PATCH 12/17] lib/utilities: use `$XDG_CACHE_HOME` properly We should fall back to the default location, not use an entirely different one. --- lib/utilities.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 60f15131..180d66f0 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -91,7 +91,7 @@ function _bash-it-component-help() { function _bash-it-component-cache-file() { local _component_to_cache _file_path _result="${2:-${FUNCNAME[0]//-/_}}" _bash-it-component-pluralize "${1?${FUNCNAME[0]}: component name required}" _component_to_cache - _file_path="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${_component_to_cache?}" + _file_path="${XDG_CACHE_HOME:-${HOME?}/.cache}/bash/${_component_to_cache?}" [[ -f "${_file_path}" ]] || mkdir -p "${_file_path%/*}" printf -v "${_result?}" '%s' "${_file_path}" } From fe48deda2da4dd10c591d3bf2cc42b61cbe625c5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 18 Feb 2022 00:22:20 -0800 Subject: [PATCH 13/17] lib: rename `_bash-it-clean-component-cache()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …to `_bash-it-component-cache-clean()` --- lib/helpers.bash | 4 ++-- lib/search.bash | 4 ++-- lib/utilities.bash | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index be320564..8430459a 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -785,7 +785,7 @@ function _disable-thing() { fi fi - _bash-it-clean-component-cache "${file_type}" + _bash-it-component-cache-clean "${file_type}" if [[ "$file_entity" == "all" ]]; then _bash-it-component-pluralize "$file_type" file_type @@ -884,7 +884,7 @@ function _enable-thing() { ln -s "../$subdirectory/available/$to_enable" "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" fi - _bash-it-clean-component-cache "${file_type}" + _bash-it-component-cache-clean "${file_type}" printf '%s\n' "$file_entity enabled with priority $use_load_priority." } diff --git a/lib/search.bash b/lib/search.bash index 4b7f5cdd..7073f879 100644 --- a/lib/search.bash +++ b/lib/search.bash @@ -70,7 +70,7 @@ function _bash-it-search() { return 0 ;; '-r' | '--refresh') - _bash-it-clean-component-cache + _bash-it-component-cache-clean ;; '-c' | '--no-color') BASH_IT_SEARCH_USE_COLOR=false @@ -333,7 +333,7 @@ function _bash-it-search-result() { printf '%b' "${color_off} " done - ((modified)) && _bash-it-clean-component-cache "${component}" + ((modified)) && _bash-it-component-cache-clean "${component}" printf "\n" fi } diff --git a/lib/utilities.bash b/lib/utilities.bash index 180d66f0..d576c8e4 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -121,13 +121,13 @@ function _bash-it-component-pluralize() { printf -v "${_result?}" '%s' "${_component_to_plural}" } -function _bash-it-clean-component-cache() { +function _bash-it-component-cache-clean() { local component="${1:-}" local cache local -a components=('aliases' 'plugins' 'completions') if [[ -z "${component}" ]]; then for component in "${components[@]}"; do - _bash-it-clean-component-cache "${component}" + _bash-it-component-cache-clean "${component}" done else _bash-it-component-cache-file "${component}" cache From 5957d189ea9e7b6f41662dc271d69f7f9f4d3072 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 18 Feb 2022 02:40:05 -0800 Subject: [PATCH 14/17] lib/utilities: `_bash-it-component-item-is-enabled()` - Use normal `if`/`then` --- lib/utilities.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index d576c8e4..8ea6b98c 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -178,8 +178,12 @@ function _bash-it-component-item-is-enabled() { for each_file in "${BASH_IT}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash" \ "${BASH_IT}/${component_type}"*/"enabled/${item_name}.${component_type}"*."bash" \ "${BASH_IT}/${component_type}"*/"enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash"; do - [[ -f "${each_file}" ]] && return + if [[ -f "${each_file}" ]]; then + return 0 + fi done + + return 1 } # Checks if a given item is disabled for a particular component/file-type. From 47bbc73744a32617b62af3dbac40447bb556c30a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 23 Feb 2022 16:54:21 -0800 Subject: [PATCH 15/17] lib/helpers: `_bash-it-find-in-ancestor()` Use new `composure.sh` feature to avoid `cite()`. --- lib/helpers.bash | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 8430459a..c0ce2eb3 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -1015,14 +1015,14 @@ function pathmunge() { # a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]` # without any external dependencies. Let the shell do what it's good at. function _bash-it-find-in-ancestor() ( - about 'searches parents of the current directory for any of the specified file names' - group 'helpers' - param '*: names of files or folders to search for' - returns '0: prints path of closest matching ancestor directory to stdout' - returns '1: no match found' - returns '2: improper usage of shell builtin' # uncommon - example '_bash-it-find-in-ancestor .git .hg' - example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile' + : _about 'searches parents of the current directory for any of the specified file names' + : _group 'helpers' + : _param '*: names of files or folders to search for' + : _returns '0: prints path of closest matching ancestor directory to stdout' + : _returns '1: no match found' + : _returns '2: improper usage of shell builtin' # uncommon + : _example '_bash-it-find-in-ancestor .git .hg' + : _example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile' local kin # To keep things simple, we do not search the root dir. From 604f9b0baa7a854c958c6911c7b5cf705de9c601 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 24 Feb 2022 11:08:02 -0800 Subject: [PATCH 16/17] Remove executable bit. --- .editorconfig | 0 .gitignore | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 .editorconfig mode change 100755 => 100644 .gitignore diff --git a/.editorconfig b/.editorconfig old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 From 789ede9ef3d6ea906334381760f4b561e57cb1ed Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 20 Feb 2022 13:26:55 -0800 Subject: [PATCH 17/17] plugin/battery: fix tests --- test/plugins/battery.plugin.bats | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index f06fa008..51ef93e9 100755 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -196,12 +196,11 @@ function setup_upower { percent="$1" BAT0="/org/freedesktop/UPower/devices/battery_BAT$RANDOM" - function upower { case $1 in '-e'|'--enumerate') - echo "$BAT0" - echo "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" + # don't just `echo` twice because `grep` will close the pipe after matching the first line... + echo "$BAT0"$'\n'"/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" ;; '-i'|'--show-info') if [[ $2 == "$BAT0" ]]