From a312e5a9b9638b2bcbb0d1a51d760e0e042c5188 Mon Sep 17 00:00:00 2001 From: souhaiebtar Date: Sat, 22 Jan 2022 12:33:33 +0000 Subject: [PATCH 001/239] 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 01211079a1..eaaa63cd78 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 b87f3067b595bd0db448654e9b85e38cfd881a99 Mon Sep 17 00:00:00 2001 From: Nariyasu Heseri Date: Sat, 29 Jan 2022 03:17:50 +0900 Subject: [PATCH 002/239] plugin/battery: bug fix When `upower --enumerate | grep -i BAT` returns multiple lines of results (which are file paths), the added quotation (from commit 3cb5f3f7e66345a329cae8ad112f1ecbedc60dab) concatenates them all to provide an invalid path. Thus to make the plugin work as before the commit, take only the first line of the results. --- plugins/available/battery.plugin.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index dc18167c77..8b1a4e0879 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -3,7 +3,7 @@ about-plugin 'display info about your battery charge level' function ac_adapter_connected() { if _command_exists upower; then - upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'charging\|fully-charged' + upower -i "$(upower -e | grep -i BAT | head -n 1)" | grep 'state' | grep -q 'charging\|fully-charged' elif _command_exists acpi; then acpi -a | grep -q "on-line" elif _command_exists pmset; then @@ -17,7 +17,7 @@ function ac_adapter_connected() { function ac_adapter_disconnected() { if _command_exists upower; then - upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'discharging' + upower -i "$(upower -e | grep -i BAT | head -n 1)" | grep 'state' | grep -q 'discharging' elif _command_exists acpi; then acpi -a | grep -q "off-line" elif _command_exists pmset; then @@ -36,7 +36,7 @@ function battery_percentage() { local command_output="no" if _command_exists upower; then - command_output=$(upower --show-info "$(upower --enumerate | grep -i BAT)" | grep percentage | grep -o "[0-9]\+" | head -1) + command_output=$(upower --show-info "$(upower --enumerate | grep -i BAT | head -n 1)" | grep percentage | grep -o "[0-9]\+" | head -1) elif _command_exists acpi; then command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}') elif _command_exists pmset; then From c794f4f0e76dcac4e15bf8269c0da9b9670e6247 Mon Sep 17 00:00:00 2001 From: Nariyasu Heseri Date: Sat, 29 Jan 2022 15:50:36 +0900 Subject: [PATCH 003/239] plugin/battery: use `--max-count` of `grep` instead of `head` --- plugins/available/battery.plugin.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index 8b1a4e0879..d86a1f08a0 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -3,7 +3,7 @@ about-plugin 'display info about your battery charge level' function ac_adapter_connected() { if _command_exists upower; then - upower -i "$(upower -e | grep -i BAT | head -n 1)" | grep 'state' | grep -q 'charging\|fully-charged' + upower -i "$(upower -e | grep --max-count=1 -i BAT)" | grep 'state' | grep -q 'charging\|fully-charged' elif _command_exists acpi; then acpi -a | grep -q "on-line" elif _command_exists pmset; then @@ -17,7 +17,7 @@ function ac_adapter_connected() { function ac_adapter_disconnected() { if _command_exists upower; then - upower -i "$(upower -e | grep -i BAT | head -n 1)" | grep 'state' | grep -q 'discharging' + upower -i "$(upower -e | grep --max-count=1 -i BAT)" | grep 'state' | grep -q 'discharging' elif _command_exists acpi; then acpi -a | grep -q "off-line" elif _command_exists pmset; then @@ -36,7 +36,7 @@ function battery_percentage() { local command_output="no" if _command_exists upower; then - command_output=$(upower --show-info "$(upower --enumerate | grep -i BAT | head -n 1)" | grep percentage | grep -o "[0-9]\+" | head -1) + command_output=$(upower --show-info "$(upower --enumerate | grep --max-count=1 -i BAT)" | grep percentage | grep -o "[0-9]\+" | head -1) elif _command_exists acpi; then command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}') elif _command_exists pmset; then From b0f23d8e98ee8048561693c3508bd72608e812e6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 09:43:23 -0800 Subject: [PATCH 004/239] completion/alias: eliminate use of `eval` --- .../available/alias-completion.plugin.bash | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index eb368d933c..0ce2820ee9 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -1,26 +1,18 @@ # shellcheck shell=bash +about-plugin 'Automatic completion of aliases' # Load after the other completions to understand what needs to be completed -# BASH_IT_LOAD_PRIORITY: 365 +# BASH_IT_LOAD_PRIORITY: 800 -cite about-plugin -about-plugin 'Automatic completion of aliases' # References: # http://superuser.com/a/437508/119764 # http://stackoverflow.com/a/1793178/1228454 -# This needs to be a plugin so it gets executed after the completions and the aliases have been defined. -# Bash-it loads its components in the order -# 1) Aliases -# 2) Completions -# 3) Plugins -# 4) Custom scripts - # Automatically add completion for all aliases to commands having completion functions -function alias_completion { +function alias_completion() { local namespace="alias_completion" local tmp_file completion_loader alias_name alias_tokens line completions - local alias_arg_words new_completion compl_func compl_wrapper + local alias_arg_words new_completion compl_func compl_wrapper alias_defn # parse function based completion definitions, where capture group 2 => function and 3 => trigger local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)' @@ -28,9 +20,13 @@ function alias_completion { local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'" # create array of function completion triggers, keeping multi-word triggers together - eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" + IFS=$'\n' read -d '' -ra completions < <(complete -p) ((${#completions[@]} == 0)) && return 0 + completions=("${completions[@]##complete -* * -}") # strip all but last option plus trigger(s) + completions=("${completions[@]#complete -}") # strip last option and arg, leaving only trigger(s) + completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s) + # create temporary file for wrapper functions and completions tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1 @@ -40,13 +36,16 @@ function alias_completion { # some aliases do have backslashes that needs to be interpreted # shellcheck disable=SC2162 while read line; do - eval "alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error - # shellcheck disable=SC2154 # see `eval` above - alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }" + line="${line#alias }" + alias_name="${line%%=*}" + alias_defn="${line#*=}" # alias definition + alias_cmd="${alias_defn%%[[:space:]]*}" # first word of alias + alias_cmd="${alias_cmd:1}" # lose opening quotation mark + alias_args="${alias_defn#*[[:space:]]}" # everything after first word + alias_args="${alias_args:0:-1}" # lose ending quotation mark # skip aliases to pipes, boolean control structures and other command lists - # (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters) - eval "alias_arg_words=($alias_args)" 2> /dev/null || continue + [[ "${alias_args}" =~ [\|\&\;\)\(\n] ]] && continue # avoid expanding wildcards read -a alias_arg_words <<< "$alias_args" @@ -54,7 +53,7 @@ function alias_completion { if ! _bash-it-array-contains-element "$alias_cmd" "${completions[@]}"; then if [[ -n "$completion_loader" ]]; then # force loading of completions for the aliased command - eval "$completion_loader $alias_cmd" + "${completion_loader:?}" "${alias_cmd}" # 124 means completion loader was successful [[ $? -eq 124 ]] || continue completions+=("$alias_cmd") @@ -97,7 +96,7 @@ function alias_completion { new_completion="${new_completion% *} $alias_name" echo "$new_completion" >> "$tmp_file" fi - done < <(alias -p | sed -Ene "s/$alias_regex/\2 '\3' '\4'/p") + done < <(alias -p) # shellcheck source=/dev/null source "$tmp_file" && command rm -f "$tmp_file" } From d214621d39b4f2079b4bbcad4a516d19d0a3962d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 10:14:27 -0800 Subject: [PATCH 005/239] completion/alias: `shfmt` && `shellcheck` --- plugins/available/alias-completion.plugin.bash | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index 0ce2820ee9..a1d1cb898a 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -3,7 +3,6 @@ about-plugin 'Automatic completion of aliases' # Load after the other completions to understand what needs to be completed # BASH_IT_LOAD_PRIORITY: 800 - # References: # http://superuser.com/a/437508/119764 # http://stackoverflow.com/a/1793178/1228454 @@ -11,21 +10,16 @@ about-plugin 'Automatic completion of aliases' # Automatically add completion for all aliases to commands having completion functions function alias_completion() { local namespace="alias_completion" - local tmp_file completion_loader alias_name alias_tokens line completions + local tmp_file completion_loader alias_name line completions local alias_arg_words new_completion compl_func compl_wrapper alias_defn - # parse function based completion definitions, where capture group 2 => function and 3 => trigger - local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)' - # parse alias definitions, where capture group 1 => trigger, 2 => command, 3 => command arguments - local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'" - # create array of function completion triggers, keeping multi-word triggers together IFS=$'\n' read -d '' -ra completions < <(complete -p) ((${#completions[@]} == 0)) && return 0 completions=("${completions[@]##complete -* * -}") # strip all but last option plus trigger(s) - completions=("${completions[@]#complete -}") # strip last option and arg, leaving only trigger(s) - completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s) + completions=("${completions[@]#complete -}") # strip anything missed + completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s) # create temporary file for wrapper functions and completions tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1 @@ -38,11 +32,11 @@ function alias_completion() { while read line; do line="${line#alias }" alias_name="${line%%=*}" - alias_defn="${line#*=}" # alias definition + alias_defn="${line#*=}" # alias definition alias_cmd="${alias_defn%%[[:space:]]*}" # first word of alias - alias_cmd="${alias_cmd:1}" # lose opening quotation mark + alias_cmd="${alias_cmd:1}" # lose opening quotation mark alias_args="${alias_defn#*[[:space:]]}" # everything after first word - alias_args="${alias_args:0:-1}" # lose ending quotation mark + alias_args="${alias_args%\'}" # lose ending quotation mark # skip aliases to pipes, boolean control structures and other command lists [[ "${alias_args}" =~ [\|\&\;\)\(\n] ]] && continue From 7fcad6ed0d9427e51b94cc721a846666cef8ea82 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 15 Jan 2022 00:01:25 -0800 Subject: [PATCH 006/239] completion/alias: rename There is no reason for this to be in the `plugins` directory, it just needs to have a load priority sufficiently high that it runs after any aliases are defined. --- .../available/aliases.completion.bash | 0 profiles/default.bash_it | 2 +- .../aliases.completion.bats} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename plugins/available/alias-completion.plugin.bash => completion/available/aliases.completion.bash (100%) rename test/{plugins/alias-completion.plugin.bats => completion/aliases.completion.bats} (100%) diff --git a/plugins/available/alias-completion.plugin.bash b/completion/available/aliases.completion.bash similarity index 100% rename from plugins/available/alias-completion.plugin.bash rename to completion/available/aliases.completion.bash diff --git a/profiles/default.bash_it b/profiles/default.bash_it index 5e4f4631d5..9a55f6c7de 100644 --- a/profiles/default.bash_it +++ b/profiles/default.bash_it @@ -1,10 +1,10 @@ # This is the default profile of Bash-it # plugins -plugins alias-completion plugins base # completion +completion aliases completion bash-it completion system diff --git a/test/plugins/alias-completion.plugin.bats b/test/completion/aliases.completion.bats similarity index 100% rename from test/plugins/alias-completion.plugin.bats rename to test/completion/aliases.completion.bats From b0862899d7cbd8cbfcc9465e09f1aa9b004470e0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 10:23:02 -0800 Subject: [PATCH 007/239] completion/alias: fix tests --- test/completion/aliases.completion.bats | 7 ++++--- test/fixtures/bash_it/profiles/test-bad-component.bash_it | 2 +- test/fixtures/bash_it/profiles/test-bad-type.bash_it | 4 ++-- test/install/install.bats | 2 +- test/lib/helpers.bats | 6 +++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/test/completion/aliases.completion.bats b/test/completion/aliases.completion.bats index 20d13cf2e2..813a7bbd7a 100644 --- a/test/completion/aliases.completion.bats +++ b/test/completion/aliases.completion.bats @@ -3,25 +3,26 @@ load ../test_helper load ../test_helper_libs +# Load something, anything... load ../../completion/available/capistrano.completion @test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" { alias gtest="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative" - load ../../plugins/available/alias-completion.plugin + run load ../../completion/available/aliases.completion assert_success } @test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" { alias gtest='git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative' - load ../../plugins/available/alias-completion.plugin + run load ../../completion/available/aliases.completion assert_success } @test "alias-completion: See that having aliased rm command does not output unnecessary output" { alias rm='rm -v' - load ../../plugins/available/alias-completion.plugin + run load ../../completion/available/aliases.completion refute_output } diff --git a/test/fixtures/bash_it/profiles/test-bad-component.bash_it b/test/fixtures/bash_it/profiles/test-bad-component.bash_it index 8640265cf2..068c4b63b6 100644 --- a/test/fixtures/bash_it/profiles/test-bad-component.bash_it +++ b/test/fixtures/bash_it/profiles/test-bad-component.bash_it @@ -1,8 +1,8 @@ # plugins -plugins alias-completion plugins base # completion +completion aliases completion bash-it completion system diff --git a/test/fixtures/bash_it/profiles/test-bad-type.bash_it b/test/fixtures/bash_it/profiles/test-bad-type.bash_it index ed2d23732f..102c52eade 100644 --- a/test/fixtures/bash_it/profiles/test-bad-type.bash_it +++ b/test/fixtures/bash_it/profiles/test-bad-type.bash_it @@ -1,10 +1,10 @@ # plugins -plugins alias-completion plugins base # Bad type -pluugins alias-completion +compleetion aliases # completion +completion aliases completion bash-it completion system diff --git a/test/install/install.bats b/test/install/install.bats index 262bf4f0a7..b3aee5a7a6 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -29,7 +29,7 @@ function local_setup { assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" + assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" } diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index bd339d0419..8c340c58f8 100755 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -296,7 +296,7 @@ function local_setup { assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" + assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" } @@ -356,7 +356,7 @@ function local_setup { run _bash-it-profile-load "test" assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" + assert_link_not_exist "$BASH_IT/enabled/800---aliases.completion.bash" assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash" } @@ -384,7 +384,7 @@ function local_setup { @test "helpers: profile load corrupted profile file: bad subdirectory" { run _bash-it-profile-load "test-bad-type" - assert_line -n 1 -p "Bad line(#5) in profile, aborting load..." + assert_line -n 1 -p "Bad line(#4) in profile, aborting load..." } @test "helpers: profile rm sanity" { From 880488ec9a0de18714351b7f6284838c9d2185f5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 26 Jan 2022 10:14:54 -0800 Subject: [PATCH 008/239] completion/alias: add stub file - put a loader to remove the symlink at `enabled/***---alias-completion.plugin.bash`. --- plugins/available/alias-completion.plugin.bash | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 plugins/available/alias-completion.plugin.bash diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash new file mode 100644 index 0000000000..84c59a1e7f --- /dev/null +++ b/plugins/available/alias-completion.plugin.bash @@ -0,0 +1,5 @@ +# shellcheck shell=bash +# stub for renamed file + +_enable-completion aliases && _disable-plugin alias-completion +source "${BASH_IT?}/completion/aliases.completion.bash" From cade0a1e7a40c929907a9b2c50ca68458a6bd9e5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 1 Feb 2022 10:15:35 -0800 Subject: [PATCH 009/239] plugin/battery: split `upower` to two variables --- plugins/available/battery.plugin.bash | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index d86a1f08a0..1f758e0cb5 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -2,8 +2,10 @@ about-plugin 'display info about your battery charge level' function ac_adapter_connected() { + local batteries if _command_exists upower; then - upower -i "$(upower -e | grep --max-count=1 -i BAT)" | grep 'state' | grep -q 'charging\|fully-charged' + batteries="$(upower -e | grep --max-count=1 -i BAT)" + upower -i "${batteries}" | grep 'state' | grep -q 'charging\|fully-charged' elif _command_exists acpi; then acpi -a | grep -q "on-line" elif _command_exists pmset; then @@ -16,8 +18,10 @@ function ac_adapter_connected() { } function ac_adapter_disconnected() { + local batteries if _command_exists upower; then - upower -i "$(upower -e | grep --max-count=1 -i BAT)" | grep 'state' | grep -q 'discharging' + batteries="$(upower -e | grep --max-count=1 -i BAT)" + upower -i "${batteries}" | grep 'state' | grep -q 'discharging' elif _command_exists acpi; then acpi -a | grep -q "off-line" elif _command_exists pmset; then @@ -33,16 +37,17 @@ function battery_percentage() { about 'displays battery charge as a percentage of full (100%)' group 'battery' - local command_output="no" + local command_output batteries if _command_exists upower; then - command_output=$(upower --show-info "$(upower --enumerate | grep --max-count=1 -i BAT)" | grep percentage | grep -o "[0-9]\+" | head -1) + batteries="$(upower --enumerate | grep --max-count=1 -i BAT)" + command_output="$(upower --show-info "${batteries:-}" | grep percentage | grep -o '[0-9]\+' | head -1)" elif _command_exists acpi; then command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}') elif _command_exists pmset; then - command_output=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -1) + command_output=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o '[0-9]\+' | head -1) elif _command_exists ioreg; then - command_output=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o "[0-9]\+" | head -1) + command_output=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o '[0-9]\+' | head -1) elif _command_exists WMIC; then command_output=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1) else From 23f7916a4d38d162007a94015d2bb6abd5b0d855 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 1 Feb 2022 10:15:54 -0800 Subject: [PATCH 010/239] test/battery: add multiple-battery edge case --- test/plugins/battery.plugin.bats | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) mode change 100644 => 100755 test/plugins/battery.plugin.bats diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats old mode 100644 new mode 100755 index eac6d02150..7ca962d94b --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -193,11 +193,19 @@ function setup_acpi { # Creates a `upower` function that simulates output like the real `upower` command. # The passed in parameter is used for the remaining battery percentage. function setup_upower { - percent="$1" - - function upower { - printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" - } + percent="$1" + + function upower { + case $1 in + '-e'|'--enumerate') + echo "/org/freedesktop/UPower/devices/battery_BAT0" + echo "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" + ;; + '-i'|'--show-info') + printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" + ;; + esac + } } @test 'plugins battery: battery-percentage with upower, 100%' { From 302bae9c5fb75665d8fefa001cfe101db4947ad9 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 13:53:54 -0800 Subject: [PATCH 011/239] test/battery: require matching battery identifier --- test/plugins/battery.plugin.bats | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 7ca962d94b..f06fa0086e 100755 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -194,15 +194,22 @@ function setup_acpi { # The passed in parameter is used for the remaining battery percentage. function setup_upower { percent="$1" + BAT0="/org/freedesktop/UPower/devices/battery_BAT$RANDOM" + function upower { case $1 in '-e'|'--enumerate') - echo "/org/freedesktop/UPower/devices/battery_BAT0" + echo "$BAT0" echo "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" ;; '-i'|'--show-info') - printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" + if [[ $2 == "$BAT0" ]] + then + printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" + else + false + fi ;; esac } From 43df0fe130f00444b836a24f0670a6d5df50ba0e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 22:46:58 -0800 Subject: [PATCH 012/239] completion/aliases: rename init function Use the callback naming convention for the init function, for later use. --- completion/available/aliases.completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/completion/available/aliases.completion.bash b/completion/available/aliases.completion.bash index a1d1cb898a..bdcaf9173c 100644 --- a/completion/available/aliases.completion.bash +++ b/completion/available/aliases.completion.bash @@ -1,6 +1,6 @@ # shellcheck shell=bash about-plugin 'Automatic completion of aliases' -# Load after the other completions to understand what needs to be completed +# Load after all aliases and completions to understand what needs to be completed # BASH_IT_LOAD_PRIORITY: 800 # References: @@ -8,7 +8,7 @@ about-plugin 'Automatic completion of aliases' # http://stackoverflow.com/a/1793178/1228454 # Automatically add completion for all aliases to commands having completion functions -function alias_completion() { +function _bash-it-component-completion-callback-on-init-aliases() { local namespace="alias_completion" local tmp_file completion_loader alias_name line completions local alias_arg_words new_completion compl_func compl_wrapper alias_defn @@ -95,4 +95,4 @@ function alias_completion() { source "$tmp_file" && command rm -f "$tmp_file" } -alias_completion +_bash-it-component-completion-callback-on-init-aliases From a4e41badf18042e1d9779eb991495d0304748c5f Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Mon, 7 Feb 2022 10:43:23 +1000 Subject: [PATCH 013/239] Refresh bug report: - use issue forms --- .github/ISSUE_TEMPLATE/bug_report.md | 46 --------------- .github/ISSUE_TEMPLATE/bug_report.yml | 80 +++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 46 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index b501d941ca..0000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -name: Bug report -about: Create a bug report to help us improve -title: '' -labels: bug:general -assignees: '' - ---- - - - -## Expected Behavior - - -## Current Behavior - - -## Possible Solution - - -## Context - - - -## Steps to Reproduce - - -1. -2. -3. -4. - -## Your Environment - -* Bash-it version used: -* List of enabled plugins, themes and aliases (use ``bash-it show (plugins/themes/aliases)``): -* ``bash-it doctor`` output: -* Bash version: -* Operating System and version: - -## Your Bash Config File - - -```bash - # Your bash config file should be here -``` diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000000..fb1bbcdf43 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,80 @@ +name: πŸ› Bug report +title: "[Bug]: " +description: Create a bug report to help us improve +labels: "bug:general" +body: + - type: textarea + attributes: + label: Expected behavior + description: Tell us what should happen. + validations: + required: true + - type: textarea + attributes: + label: Current behavior + description: Tell us what happens instead of the expected behavior. + validations: + required: true + - type: textarea + attributes: + label: Possible solution + description: Tell us how it could be fixed at your glance. + validations: + required: false + - type: textarea + attributes: + label: Context + description: > + How has this issue affected you? What are you trying to accomplish? + Providing context helps us come up with a solution that is most useful in the real world. + validations: + required: false + - type: textarea + attributes: + label: Steps to reproduce + description: > + Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant. + validations: + required: true + - type: input + attributes: + label: Bash-it version + placeholder: "How to get: bash-it version" + validations: + required: true + - type: input + attributes: + label: List of enabled plugins, themes and aliases + placeholder: "How to get: bash-it show plugins|themes|aliases (it is not a pipe)" + validations: + required: true + - type: input + attributes: + label: Bash version + placeholder: "How to get: bash --version" + validations: + required: true + - type: input + attributes: + label: Operating system and version + placeholder: "How to get: neofetch (or another command)" + validations: + required: true + - type: textarea + attributes: + label: "bash-it doctor output" + value: | + ``` + # Smth here + ``` + validations: + required: false + - type: textarea + attributes: + label: Your ~/.bashrc + value: | + ```bash + # Smth here + ``` + validations: + required: true From eb91f4ec691cf131280e6678261f6df97570ff03 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Mon, 7 Feb 2022 10:47:42 +1000 Subject: [PATCH 014/239] Refresh feature request: - use issue forms --- .github/ISSUE_TEMPLATE/feature_request.md | 23 ----------------- .github/ISSUE_TEMPLATE/feature_request.yml | 30 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 23 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index b1fabfbab8..0000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: feature request -assignees: '' - ---- - - - -## Expected Behavior - - -## Current Behavior - - -## Possible Solution - - -## Context - - diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000000..28bb4410b1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,30 @@ +name: πŸ’‘ Feature request +title: "[Feature]: " +description: Suggest an idea for this project +labels: "feature request" +body: + - type: textarea + attributes: + label: Expected behavior + description: Tell us how your feature should work. + validations: + required: true + - type: textarea + attributes: + label: Current behavior + description: Explain the difference your feature will have from current behavior. + validations: + required: true + - type: textarea + attributes: + label: Possible solution + description: Tell us how it could be fixed at your glance. + validations: + required: false + - type: textarea + attributes: + label: Context + description: > + How has this issue affected you? What are you trying to accomplish? + Providing context helps us come up with a solution that is most useful in the real world. + From dfe681d223e89d84c62713e567014021abe12d9b Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Mon, 7 Feb 2022 10:51:40 +1000 Subject: [PATCH 015/239] Add config for issue forms --- .github/ISSUE_TEMPLATE/config.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000..f33f8a3fd8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Libera chat + url: https://web.libera.chat/?channel=#bash-it + about: You can ask and answer questions here From 0d346b204fb424f2c1dcbeb3a8169131deb41e3b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 29 Jan 2022 22:13:50 -0800 Subject: [PATCH 016/239] main: Glob for *.bash properly when path contains spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `shfmt`, `shellcheck` - Clean up legacy/compatibility code to simpler control flow - Move theme stuff down to where themes are handled - Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsΓΆ fixes users having any not-enabled themes under their custom dir. - Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.) - Place `composure.sh` init all in one place - remove 10-years-deprecated backwards compatibility: Deprecated in `b59ee658f78ec6ff8c6c2754216e0322b7fe18e2` dated 2011-10-29. --- bash_it.sh | 133 ++++++++++++++++++++--------------------------------- 1 file changed, 51 insertions(+), 82 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index 03fd0bf5ec..b47b9f63e1 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -1,145 +1,114 @@ #!/usr/bin/env bash +# shellcheck source-path=SCRIPTDIR/lib source-path=SCRIPTDIR/scripts +# shellcheck disable=SC2034 +# # Initialize Bash It BASH_IT_LOG_PREFIX="core: main: " - -# Only set $BASH_IT if it's not already set -if [ -z "${BASH_IT:-}" ]; then - # Setting $BASH to maintain backwards compatibility - export BASH_IT=$BASH - BASH="$(bash -c 'echo $BASH')" - export BASH - BASH_IT_OLD_BASH_SETUP=true -fi +: "${BASH_IT:=${BASH_SOURCE%/*}}" +: "${BASH_IT_CUSTOM:=${BASH_IT}/custom}" +: "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM}/themes"}" +: "${BASH_IT_BASHRC:=${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}}" # Load composure first, so we support function metadata -# shellcheck disable=SC1090 -source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh +# shellcheck source-path=SCRIPTDIR/vendor/github.com/erichs/composure +source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +# support 'plumbing' metadata +cite _about _param _example _group _author _version +cite about-alias about-plugin about-completion -# Declare our end-of-main finishing hook -declare -a _bash_it_library_finalize_hook +# Declare our end-of-main finishing hook, but don't use `declare`/`typeset` +_bash_it_library_finalize_hook=() # We need to load logging module early in order to be able to log -# shellcheck source-path=SCRIPTDIR/lib source "${BASH_IT}/lib/log.bash" -# We can only log it now -[ -z "${BASH_IT_OLD_BASH_SETUP:-}" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!" - -# For backwards compatibility, look in old BASH_THEME location -if [ -z "${BASH_IT_THEME:-}" ]; then - _log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!" - export BASH_IT_THEME="${BASH_THEME:-}" - unset BASH_THEME -fi - -# support 'plumbing' metadata -cite _about _param _example _group _author _version -cite about-alias about-plugin about-completion - # libraries, but skip appearance (themes) for now _log_debug "Loading libraries(except appearance)..." -LIB="${BASH_IT}/lib/*.bash" APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" -for _bash_it_config_file in $LIB; do - if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then - filename=${_bash_it_config_file##*/} - filename=${filename%.bash} - BASH_IT_LOG_PREFIX="lib: ${filename}: " - _log_debug "Loading library file..." - # shellcheck disable=SC1090 - source "$_bash_it_config_file" - fi +for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do + [[ "$_bash_it_main_file_lib" == "$APPEARANCE_LIB" ]] && continue + filename="${_bash_it_main_file_lib##*/}" + filename="${filename%.bash}" + BASH_IT_LOG_PREFIX="lib: ${filename}: " + _log_debug "Loading library file..." + # shellcheck disable=SC1090 + source "$_bash_it_main_file_lib" + BASH_IT_LOG_PREFIX="core: main: " done -BASH_IT_LOG_PREFIX="core: main: " -# Load the global "enabled" directory -# "family" param is empty so that files get sources in glob order -# shellcheck source=./scripts/reloader.bash -source "${BASH_IT}/scripts/reloader.bash" - -# Load enabled aliases, completion, plugins -for file_type in "aliases" "plugins" "completion"; do - # shellcheck source=./scripts/reloader.bash - source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type" +# Load the global "enabled" directory, then enabled aliases, completion, plugins +# "file_type" param is empty so that files get sourced in glob order +for file_type in "" "aliases" "plugins" "completion"; do + BASH_IT_LOG_PREFIX="core: reloader: " + source "${BASH_IT}/scripts/reloader.bash" "${file_type:+skip}" "$file_type" + BASH_IT_LOG_PREFIX="core: main: " done # Load theme, if a theme was set -if [[ -n "${BASH_IT_THEME}" ]]; then - _log_debug "Loading \"${BASH_IT_THEME}\" theme..." +# shellcheck source-path=SCRIPTDIR/themes +if [[ -n "${BASH_IT_THEME:-}" ]]; then + _log_debug "Loading theme '${BASH_IT_THEME}'." BASH_IT_LOG_PREFIX="themes: githelpers: " - # shellcheck source=./themes/githelpers.theme.bash source "${BASH_IT}/themes/githelpers.theme.bash" BASH_IT_LOG_PREFIX="themes: p4helpers: " - # shellcheck source=./themes/p4helpers.theme.bash source "${BASH_IT}/themes/p4helpers.theme.bash" BASH_IT_LOG_PREFIX="themes: command_duration: " - # shellcheck source=./themes/command_duration.theme.bash source "${BASH_IT}/themes/command_duration.theme.bash" BASH_IT_LOG_PREFIX="themes: base: " - # shellcheck source=./themes/base.theme.bash source "${BASH_IT}/themes/base.theme.bash" BASH_IT_LOG_PREFIX="lib: appearance: " # appearance (themes) now, after all dependencies - # shellcheck source=./lib/appearance.bash + # shellcheck source=SCRIPTDIR/lib/appearance.bash source "$APPEARANCE_LIB" + BASH_IT_LOG_PREFIX="core: main: " fi -BASH_IT_LOG_PREFIX="core: main: " _log_debug "Loading custom aliases, completion, plugins..." for file_type in "aliases" "completion" "plugins"; do - if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then + if [[ -s "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]]; then BASH_IT_LOG_PREFIX="${file_type}: custom: " _log_debug "Loading component..." # shellcheck disable=SC1090 source "${BASH_IT}/${file_type}/custom.${file_type}.bash" fi + BASH_IT_LOG_PREFIX="core: main: " done # Custom -BASH_IT_LOG_PREFIX="core: main: " _log_debug "Loading general custom files..." -CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash" -for _bash_it_config_file in $CUSTOM; do - if [ -e "${_bash_it_config_file}" ]; then - filename=$(basename "${_bash_it_config_file}") - filename=${filename%*.bash} - # shellcheck disable=SC2034 +for _bash_it_main_file_custom in "${BASH_IT_CUSTOM}"/*.bash "${BASH_IT_CUSTOM}"/*/*.bash; do + if [[ -s "${_bash_it_main_file_custom}" ]]; then + filename="${_bash_it_main_file_custom##*/}" + filename="${filename%*.bash}" BASH_IT_LOG_PREFIX="custom: $filename: " _log_debug "Loading custom file..." # shellcheck disable=SC1090 - source "$_bash_it_config_file" + source "$_bash_it_main_file_custom" fi + BASH_IT_LOG_PREFIX="core: main: " done -unset _bash_it_config_file if [[ -n "${PROMPT:-}" ]]; then - export PS1="\[""$PROMPT""\]" + PS1="${PROMPT}" fi # Adding Support for other OSes -PREVIEW="less" - -if [ -s /usr/bin/gloobus-preview ]; then +if _command_exists gloobus-preview; then PREVIEW="gloobus-preview" -elif [ -s /Applications/Preview.app ]; then - # shellcheck disable=SC2034 +elif [[ -d /Applications/Preview.app ]]; then PREVIEW="/Applications/Preview.app" +else + PREVIEW="less" fi # BASH_IT_RELOAD_LEGACY is set. -if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then - case $OSTYPE in - darwin*) - alias reload='source ~/.bash_profile' - ;; - *) - alias reload='source ~/.bashrc' - ;; - esac +if [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]] && ! _command_exists reload; then + # shellcheck disable=SC2139 + alias reload="builtin source '${BASH_IT_BASHRC?}'" fi for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`. done -unset "${!_bash_it_library_finalize_@}" +unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}" filename file_type From bc95eceb10db21859c847a6ca77eb99611409918 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 16 Oct 2021 14:49:43 -0700 Subject: [PATCH 017/239] main: adopt `_bash-it-log-prefix-by-path()` --- bash_it.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index b47b9f63e1..b890f02166 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -27,9 +27,7 @@ _log_debug "Loading libraries(except appearance)..." APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do [[ "$_bash_it_main_file_lib" == "$APPEARANCE_LIB" ]] && continue - filename="${_bash_it_main_file_lib##*/}" - filename="${filename%.bash}" - BASH_IT_LOG_PREFIX="lib: ${filename}: " + _bash-it-log-prefix-by-path "${_bash_it_main_file_lib}" _log_debug "Loading library file..." # shellcheck disable=SC1090 source "$_bash_it_main_file_lib" @@ -66,11 +64,13 @@ fi _log_debug "Loading custom aliases, completion, plugins..." for file_type in "aliases" "completion" "plugins"; do - if [[ -s "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]]; then - BASH_IT_LOG_PREFIX="${file_type}: custom: " + _bash_it_main_file_custom="${BASH_IT}/${file_type}/custom.${file_type}.bash" + if [[ -s "${_bash_it_main_file_custom}" ]]; then + _bash-it-log-prefix-by-path "${_bash_it_main_file_custom}" _log_debug "Loading component..." + # shellcheck source-path=SCRIPTDIR/aliases source-path=SCRIPTDIR/completions source-path=SCRIPTDIR/plugins # shellcheck disable=SC1090 - source "${BASH_IT}/${file_type}/custom.${file_type}.bash" + source "${_bash_it_main_file_custom}" fi BASH_IT_LOG_PREFIX="core: main: " done @@ -79,9 +79,7 @@ done _log_debug "Loading general custom files..." for _bash_it_main_file_custom in "${BASH_IT_CUSTOM}"/*.bash "${BASH_IT_CUSTOM}"/*/*.bash; do if [[ -s "${_bash_it_main_file_custom}" ]]; then - filename="${_bash_it_main_file_custom##*/}" - filename="${filename%*.bash}" - BASH_IT_LOG_PREFIX="custom: $filename: " + _bash-it-log-prefix-by-path "${_bash_it_main_file_custom}" _log_debug "Loading custom file..." # shellcheck disable=SC1090 source "$_bash_it_main_file_custom" @@ -111,4 +109,4 @@ fi for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`. done -unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}" filename file_type +unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}" file_type From 1480cdfa340a92da331acd94f855c6de9e2d7f99 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 26 Jan 2022 14:21:47 -0800 Subject: [PATCH 018/239] completion/system: correctly load version when not linked - Load the correct version of `bash-completion` even when not "linked". --- completion/available/system.completion.bash | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index af7ea70dc0..bb1d14eb27 100644 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -14,31 +14,24 @@ else __bash_it_restore_nounset=false fi +# shellcheck disable=SC1090 disable=SC1091 if [[ -r "${BASH_COMPLETION:-}" ]]; then - # shellcheck disable=SC1090 source "${BASH_COMPLETION}" - elif [[ -r /etc/bash_completion ]]; then - # shellcheck disable=SC1091 source /etc/bash_completion - # Some distribution makes use of a profile.d script to import completion. elif [[ -r /etc/profile.d/bash_completion.sh ]]; then - # shellcheck disable=SC1091 source /etc/profile.d/bash_completion.sh - elif _bash_it_homebrew_check; then - : "${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d}" - + : "${BASH_COMPLETION_COMPAT_DIR:=${BASH_IT_HOMEBREW_PREFIX}/etc/bash_completion.d}" case "${BASH_VERSION}" in 1* | 2* | 3.0* | 3.1*) _log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?" ;; 3.2* | 4.0* | 4.1*) # Import version 1.x of bash-completion, if installed. - BASH_COMPLETION="$BASH_IT_HOMEBREW_PREFIX/opt/bash-completion@1/etc/bash_completion" + BASH_COMPLETION="${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@1/etc/bash_completion" if [[ -r "$BASH_COMPLETION" ]]; then - # shellcheck disable=SC1090 source "$BASH_COMPLETION" else unset BASH_COMPLETION @@ -46,9 +39,8 @@ elif _bash_it_homebrew_check; then ;; 4.2* | 5* | *) # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path - if [[ -r "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then - # shellcheck disable=SC1091 - source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" + if [[ -r "${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@2/etc/profile.d/bash_completion.sh" ]]; then + source "${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@2/etc/profile.d/bash_completion.sh" fi ;; esac From d6555f369a067470451760f42e40ec7d7abd0acb Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 29 Jan 2022 23:16:40 -0800 Subject: [PATCH 019/239] lib/preview: refactor into a function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows future use like `bash-it preview`. AlsΓΆ, allows to use `$BASH_PREVIEW` to specify a particular theme to preview instead of just doing all of them. --- clean_files.txt | 1 + lib/preview.bash | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8f9c173a29..49e51abc08 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -85,6 +85,7 @@ lib/colors.bash lib/helpers.bash lib/log.bash lib/preexec.bash +lib/preview.bash lib/search.bash lib/utilities.bash diff --git a/lib/preview.bash b/lib/preview.bash index 418839cd2d..60659df553 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -1,19 +1,30 @@ -if [[ "${BASH_PREVIEW:-}" ]]; -then - unset BASH_PREVIEW #Prevent infinite looping - echo " +# shellcheck shell=bash +# +# Displays the prompt from each _Bash It_ theme. - Previewing Bash-it Themes +function _bash-it-preview() { + local BASH_IT_THEME BASH_IT_LOG_LEVEL + local themes theme - " + printf '\n\n\t%s\n\n' "Previewing Bash-it Themes" - THEMES="$BASH_IT/themes/*/*.theme.bash" - for theme in $THEMES - do - BASH_IT_THEME=${theme%.theme.bash} - BASH_IT_THEME=${BASH_IT_THEME##*/} - echo " - $BASH_IT_THEME" - echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i - done + if [[ -n "${1:-}" && -s "${BASH_IT?}/themes/${1}/${1}.theme.bash" ]]; then + themes=("${1}") + else + themes=("${BASH_IT?}/themes"/*/*.theme.bash) + fi + + # shellcheck disable=SC2034 + for theme in "${themes[@]}"; do + BASH_IT_THEME="${theme%.theme.bash}" + BASH_IT_THEME="${BASH_IT_THEME##*/}" + BASH_IT_LOG_LEVEL=0 + + bash --init-file "${BASH_IT_BASHRC:-${BASH_IT?}/bash_it.sh}" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"' + done +} + +if [[ -n "${BASH_PREVIEW:-}" ]]; then + _bash-it-preview "${BASH_PREVIEW}" "$@" + unset BASH_PREVIEW #Prevent infinite looping fi From a9a40a3cad024add8fbbace487e4005389674dff Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 25 Jan 2022 12:57:23 -0800 Subject: [PATCH 020/239] lib/helpers: add `preview` to `bash-it` spaghetti --- completion/available/bash-it.completion.bash | 4 ++-- docs/themes.rst | 2 +- lib/helpers.bash | 8 +++++++- test/completion/bash-it.completion.bats | 12 ++++++------ 4 files changed, 16 insertions(+), 10 deletions(-) mode change 100644 => 100755 completion/available/bash-it.completion.bash diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash old mode 100644 new mode 100755 index 1f83d5c8b7..aa00a06e72 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -13,7 +13,7 @@ function _bash-it() { prev="${COMP_WORDS[COMP_CWORD - 1]}" verb="${COMP_WORDS[1]}" file_type="${COMP_WORDS[2]:-}" - candidates=('disable' 'enable' 'help' 'migrate' 'reload' 'restart' 'profile' 'doctor' 'search' 'show' 'update' 'version') + candidates=('disable' 'enable' 'help' 'migrate' 'reload' 'restart' 'preview' 'profile' 'doctor' 'search' 'show' 'update' 'version') case "${verb}" in show) candidates=('aliases' 'completions' 'plugins') @@ -58,7 +58,7 @@ function _bash-it() { fi _compreply_candidates ;; - migrate | reload | restart | search | version) ;; + migrate | reload | restart | preview | search | version) ;; enable | disable) if [[ "${verb}" == "enable" ]]; then suffix="disabled" diff --git a/docs/themes.rst b/docs/themes.rst index 5b79638927..8cfbeb2346 100644 --- a/docs/themes.rst +++ b/docs/themes.rst @@ -22,7 +22,7 @@ Examples: # Disable theming export BASH_IT_THEME="" -You can easily preview the themes in your own shell using ``BASH_PREVIEW=true bash-it reload``. +You can easily preview the themes in your own shell using ``bash-it preview``. If you've created your own custom prompts, we'd love it if you shared them with everyone else! Just submit a Pull Request. You can see theme screenshots on `wiki/Themes `_. diff --git a/lib/helpers.bash b/lib/helpers.bash index 66cdec74f2..4728541a65 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -98,7 +98,7 @@ alias reload_plugins="$(_make_reload_alias plugin plugins)" function bash-it() { about 'Bash-it help and maintenance' - param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] ' + param '1: verb [one of: help | show | enable | disable | migrate | update | search | preview | version | reload | restart | doctor ] ' param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)' param '3: specific component [optional]' example '$ bash-it show plugins' @@ -108,6 +108,8 @@ function bash-it() { example '$ bash-it migrate' example '$ bash-it update' example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]' + example '$ bash-it preview' + example '$ bash-it preview essential' example '$ bash-it version' example '$ bash-it reload' example '$ bash-it restart' @@ -142,6 +144,10 @@ function bash-it() { _bash-it-search "$component" "$@" return ;; + preview) + _bash-it-preview "$component" "$@" + return + ;; update) func="_bash-it-update-$component" ;; diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index f23361850e..087a926d13 100755 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -81,32 +81,32 @@ function __check_completion () { @test "completion bash-it: show options" { run __check_completion 'bash-it ' - assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" + assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash-ti - show options" { run __check_completion 'bash-ti ' - assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" + assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: shit - show options" { run __check_completion 'shit ' - assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" + assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bashit - show options" { run __check_completion 'bashit ' - assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" + assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: batshit - show options" { run __check_completion 'batshit ' - assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" + assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash_it - show options" { run __check_completion 'bash_it ' - assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" + assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: profile - show options" { From 00e3955dd38bd7db49c20fc6cb8c48faabc016c5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 25 Jan 2022 12:58:22 -0800 Subject: [PATCH 021/239] lib/preview: add full completion --- completion/available/bash-it.completion.bash | 6 +++++- lib/preview.bash | 22 ++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) mode change 100755 => 100644 completion/available/bash-it.completion.bash diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash old mode 100755 new mode 100644 index aa00a06e72..2259e37b17 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -58,7 +58,11 @@ function _bash-it() { fi _compreply_candidates ;; - migrate | reload | restart | preview | search | version) ;; + migrate | reload | restart | search | version) ;; + preview) + _bash-it-preview # completes itself + return 0 + ;; enable | disable) if [[ "${verb}" == "enable" ]]; then suffix="disabled" diff --git a/lib/preview.bash b/lib/preview.bash index 60659df553..96fafae7ab 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -4,22 +4,26 @@ function _bash-it-preview() { local BASH_IT_THEME BASH_IT_LOG_LEVEL - local themes theme + local themes IFS=$'\n' cur - printf '\n\n\t%s\n\n' "Previewing Bash-it Themes" - - if [[ -n "${1:-}" && -s "${BASH_IT?}/themes/${1}/${1}.theme.bash" ]]; then - themes=("${1}") + if [[ $# -gt '0' ]]; then + themes=("$@") else themes=("${BASH_IT?}/themes"/*/*.theme.bash) + themes=("${themes[@]##*/}") + themes=("${themes[@]%.theme.bash}") + fi + + if [[ ${COMP_CWORD:-} -gt '0' ]]; then + cur="${COMP_WORDS[COMP_CWORD]}" + read -d '' -ra COMPREPLY < <(compgen -W "all${IFS}${themes[*]}" -- "${cur}") + return fi + printf '\n\n\t%s\n\n' "Previewing Bash-it Themes" # shellcheck disable=SC2034 - for theme in "${themes[@]}"; do - BASH_IT_THEME="${theme%.theme.bash}" - BASH_IT_THEME="${BASH_IT_THEME##*/}" + for BASH_IT_THEME in "${themes[@]}"; do BASH_IT_LOG_LEVEL=0 - bash --init-file "${BASH_IT_BASHRC:-${BASH_IT?}/bash_it.sh}" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"' done } From 2b8928f2bd505189ea46724ceaf27373a9b4a6ec Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 8 Feb 2022 14:27:48 +0530 Subject: [PATCH 022/239] Make the ls color available for macos --- aliases/available/general.aliases.bash | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 3c29928d10..e0a2d6172f 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -1,13 +1,18 @@ cite about-alias about-alias 'general aliases' -if ls --color -d . &> /dev/null -then - alias ls="ls --color=auto" -elif ls -G -d . &> /dev/null -then - alias ls='ls -G' # Compact view, show colors -fi +# color support for darwin and non-darwin os +# special thanks https://stackoverflow.com/a/27776822/10362396 +case "$(uname -s)" in + + Darwin) + alias ls='ls -G' + ;; + + *) + alias ls='ls --color=auto' + ;; +esac # List directory contents alias sl=ls From 70dbda053b5d0f0eee87c4515018e0f0f53f3a57 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 8 Feb 2022 14:49:43 +0530 Subject: [PATCH 023/239] Remove redundant aliases for clear screen --- aliases/available/general.aliases.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 3c29928d10..01e45e4b92 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -37,7 +37,6 @@ then fi alias c='clear' -alias k='clear' alias cls='clear' alias edit="$EDITOR" From 8052911861883c9e3d1187529a72b72921f27746 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 27 Dec 2021 14:16:58 -0800 Subject: [PATCH 024/239] plugin/history: don't use `export` ...so the plugin is friendly to variables already marked read-only. --- plugins/available/history.plugin.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/available/history.plugin.bash b/plugins/available/history.plugin.bash index be253e4a53..4c8cdabaf6 100644 --- a/plugins/available/history.plugin.bash +++ b/plugins/available/history.plugin.bash @@ -5,11 +5,11 @@ about-plugin 'improve history handling with sane defaults' # variable when the shell exits, rather than overwriting the file. shopt -s histappend -# erase duplicates; alternative option: export HISTCONTROL=ignoredups -export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups} +# erase duplicates; alternative option: HISTCONTROL=ignoredups +: "${HISTCONTROL:=ignorespace:erasedups}" # resize history to 100x the default (500) -export HISTSIZE=${HISTSIZE:-50000} +: "${HISTSIZE:=50000}" # Flush history to disk after each command. export PROMPT_COMMAND="history -a;${PROMPT_COMMAND}" From 267a721ac607ea85fd262a0b4b490254854bab69 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 27 Dec 2021 14:21:44 -0800 Subject: [PATCH 025/239] plugin/history-eternal: Use `readonly` instead of `export` ...and hide errors relating to setting already-readonly variables. `plugin/history-eternal` does not need to force loading after `plugin/history` because both plugins will play nicely with read-only variables, and since we're overwritting and marking read-only then the intended result survives no matter which loads first. plugin/history-eternal: require Bash v4.3+ Unlimited history is only possible in _Bash_ version 4.3 and up --- plugins/available/history-eternal.plugin.bash | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/available/history-eternal.plugin.bash b/plugins/available/history-eternal.plugin.bash index a18283d31f..829868df4a 100644 --- a/plugins/available/history-eternal.plugin.bash +++ b/plugins/available/history-eternal.plugin.bash @@ -1,20 +1,22 @@ # shellcheck shell=bash about-plugin 'eternal bash history' -# Load after the history plugin -# BASH_IT_LOAD_PRIORITY: 375 +if [[ ${BASH_VERSINFO[0]} -lt 4 ]] || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then + _log_warning "Bash version 4.3 introduced the 'unlimited' history size capability." + return 1 +fi # Modify history sizes before changing location to avoid unintentionally # truncating the history file early. # "Numeric values less than zero result in every command being saved on the history list (there is no limit)" -export HISTSIZE=-1 +readonly HISTSIZE=-1 2> /dev/null || true # "Non-numeric values and numeric values less than zero inhibit truncation" -export HISTFILESIZE='unlimited' +readonly HISTFILESIZE='unlimited' 2> /dev/null || true # Use a custom history file location so history is not truncated # if the environment ever loses this "eternal" configuration. HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash" [[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}" -export HISTFILE="${HISTDIR?}/history" +readonly HISTFILE="${HISTDIR?}/history" 2> /dev/null || true From f6119567e835b2048ca7ac015663381151e45b8e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 27 Dec 2021 16:38:46 -0800 Subject: [PATCH 026/239] plugin/history*search: no need to load after `plugin/history` There's no need for these plugins to load after `plugin/history`. None of the history plugins depend upon each other loading before, after, or at all. --- plugins/available/history-search.plugin.bash | 3 --- plugins/available/history-substring-search.plugin.bash | 3 --- 2 files changed, 6 deletions(-) diff --git a/plugins/available/history-search.plugin.bash b/plugins/available/history-search.plugin.bash index 341ce2af27..969419934c 100644 --- a/plugins/available/history-search.plugin.bash +++ b/plugins/available/history-search.plugin.bash @@ -1,9 +1,6 @@ # shellcheck shell=bash about-plugin 'search history using the prefix already entered' -# Load after the history plugin -# BASH_IT_LOAD_PRIORITY: 375 - # enter a few characters and press UpArrow/DownArrow # to search backwards/forwards through the history if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then diff --git a/plugins/available/history-substring-search.plugin.bash b/plugins/available/history-substring-search.plugin.bash index 586ceb50b0..dde3272083 100644 --- a/plugins/available/history-substring-search.plugin.bash +++ b/plugins/available/history-substring-search.plugin.bash @@ -1,9 +1,6 @@ # shellcheck shell=bash about-plugin 'search history using the substring already entered' -# Load after the history plugin -# BASH_IT_LOAD_PRIORITY: 375 - # enter a few characters and press UpArrow/DownArrow # to search backwards/forwards through the history if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then From 5d5858058ec61abefcfb122f90bd0eee3d8276f5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 24 Jan 2022 21:37:04 -0800 Subject: [PATCH 027/239] lib/history: new functions `_bash-it-history-auto-*()` Two new functions `_bash-it-history-auto-save()` and `_bash-it-history-auto-load()`, which append new history to disk and load new history from disk, respectively. See bash-it/bash-it#1595 for discussion. --- clean_files.txt | 1 + lib/history.bash | 49 +++++++++++++++++++++++++++ plugins/available/history.plugin.bash | 9 +++-- themes/base.theme.bash | 5 +-- 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 lib/history.bash diff --git a/clean_files.txt b/clean_files.txt index 8f9c173a29..70b1175cb1 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -83,6 +83,7 @@ completion/available/wpscan.completion.bash # libraries lib/colors.bash lib/helpers.bash +lib/history.bash lib/log.bash lib/preexec.bash lib/search.bash diff --git a/lib/history.bash b/lib/history.bash new file mode 100644 index 0000000000..7bdbbd5ef0 --- /dev/null +++ b/lib/history.bash @@ -0,0 +1,49 @@ +# shellcheck shell=bash +# +# Functions for working with Bash's command history. + +function _bash-it-history-init() { + safe_append_preexec '_bash-it-history-auto-save' + safe_append_prompt_command '_bash-it-history-auto-load' +} + +function _bash-it-history-auto-save() { + case $HISTCONTROL in + *'noauto'* | *'autoload'*) + : # Do nothing, as configured. + ;; + *'auto'*) + # Append new history from this session to the $HISTFILE + history -a + ;; + *) + # Append *only* if shell option `histappend` has been enabled. + shopt -q histappend && history -a && return + ;; + esac +} + +function _bash-it-history-auto-load() { + case $HISTCONTROL in + *'noauto'*) + : # Do nothing, as configured. + ;; + *'autosave'*) + # Append new history from this session to the $HISTFILE + history -a + ;; + *'autoloadnew'*) + # Read new entries from $HISTFILE + history -n + ;; + *'auto'*) + # Blank in-memory history, then read entire $HISTFILE fresh from disk. + history -a && history -c && history -r + ;; + *) + : # Do nothing, default. + ;; + esac +} + +_bash_it_library_finalize_hook+=('_bash-it-history-init') diff --git a/plugins/available/history.plugin.bash b/plugins/available/history.plugin.bash index 4c8cdabaf6..d9e930c389 100644 --- a/plugins/available/history.plugin.bash +++ b/plugins/available/history.plugin.bash @@ -5,15 +5,14 @@ about-plugin 'improve history handling with sane defaults' # variable when the shell exits, rather than overwriting the file. shopt -s histappend -# erase duplicates; alternative option: HISTCONTROL=ignoredups -: "${HISTCONTROL:=ignorespace:erasedups}" +# 'ignorespace': don't save command lines which begin with a space to history +# 'erasedups' (alternative 'ignoredups'): don't save duplicates to history +# 'autoshare': automatically share history between multiple running shells +: "${HISTCONTROL:=ignorespace:erasedups:autoshare}" # resize history to 100x the default (500) : "${HISTSIZE:=50000}" -# Flush history to disk after each command. -export PROMPT_COMMAND="history -a;${PROMPT_COMMAND}" - function top-history() { about 'print the name and count of the most commonly run tools' diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a7e999617b..d7479b3fc0 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -584,6 +584,7 @@ function aws_profile { } function _save-and-reload-history() { - local autosave=${1:-0} - [[ $autosave -eq 1 ]] && history -a && history -c && history -r + local autosave="${1:-${HISTORY_AUTOSAVE:-0}}" + [[ ${autosave} -eq 1 ]] && local HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autoshare" + _bash-it-history-auto-save && _bash-it-history-auto-load } From 146107926e6d428699d8718068172d340f3e717e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 13:59:50 -0800 Subject: [PATCH 028/239] main: variable name cleanup --- bash_it.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index b890f02166..78d19b8761 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -35,10 +35,10 @@ for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do done # Load the global "enabled" directory, then enabled aliases, completion, plugins -# "file_type" param is empty so that files get sourced in glob order -for file_type in "" "aliases" "plugins" "completion"; do +# "_bash_it_main_file_type" param is empty so that files get sourced in glob order +for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do BASH_IT_LOG_PREFIX="core: reloader: " - source "${BASH_IT}/scripts/reloader.bash" "${file_type:+skip}" "$file_type" + source "${BASH_IT}/scripts/reloader.bash" "${_bash_it_main_file_type:+skip}" "$_bash_it_main_file_type" BASH_IT_LOG_PREFIX="core: main: " done @@ -63,12 +63,11 @@ if [[ -n "${BASH_IT_THEME:-}" ]]; then fi _log_debug "Loading custom aliases, completion, plugins..." -for file_type in "aliases" "completion" "plugins"; do - _bash_it_main_file_custom="${BASH_IT}/${file_type}/custom.${file_type}.bash" +for _bash_it_main_file_type in "aliases" "completion" "plugins"; do + _bash_it_main_file_custom="${BASH_IT}/${_bash_it_main_file_type}/custom.${_bash_it_main_file_type}.bash" if [[ -s "${_bash_it_main_file_custom}" ]]; then _bash-it-log-prefix-by-path "${_bash_it_main_file_custom}" _log_debug "Loading component..." - # shellcheck source-path=SCRIPTDIR/aliases source-path=SCRIPTDIR/completions source-path=SCRIPTDIR/plugins # shellcheck disable=SC1090 source "${_bash_it_main_file_custom}" fi @@ -109,4 +108,4 @@ fi for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`. done -unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}" file_type +unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}" From 98889b208c629c2411bca8bab5d8483b65540fec Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Fri, 11 Feb 2022 09:56:10 +0200 Subject: [PATCH 029/239] Tilde expanstion won't work once it is a quoted string, expanding in advance. --- plugins/available/dirs.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index f61680caad..34468fa061 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -59,7 +59,7 @@ function dirs-help() { # Add bookmarking functionality # Usage: -: "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-~/.local/state}/bash_it/dirs}" +: "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-${HOME}/.local/state}/bash_it/dirs}" if [[ -f "${BASH_IT_DIRS_BKS?}" ]]; then # shellcheck disable=SC1090 source "${BASH_IT_DIRS_BKS?}" From 1afbe3115877faeb1394cca662a8fdad8fff02f4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 17 Jan 2022 14:27:06 -0800 Subject: [PATCH 030/239] theme/powerline.base: lint, clean, defaults - Local some variables, - install reasonable defaults, based on `theme/powerline-plain` which doens't use the special font, - Use `\D{fmt}` instead of `$(date +fmt)`. --- themes/powerline/powerline.base.bash | 190 ++++++++++++++------------- 1 file changed, 98 insertions(+), 92 deletions(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 84469e877f..5a7b1782b5 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -1,6 +1,7 @@ # shellcheck shell=bash # shellcheck disable=SC2034 # Expected behavior for themes. +#To set color for foreground and background function set_color() { local fg='' bg='' if [[ "${1:-}" != "-" ]]; then @@ -13,38 +14,38 @@ function set_color() { echo -e "\[\033[${fg}${bg}m\]" } +#Customising User Info Segment function __powerline_user_info_prompt() { - local user_info="" - local color=${USER_INFO_THEME_PROMPT_COLOR} + local user_info="${SHORT_USER:-${USER}}" + local color=${USER_INFO_THEME_PROMPT_COLOR-${POWERLINE_USER_INFO_COLOR-"32"}} - if [[ "${THEME_CHECK_SUDO}" = true ]]; then - sudo -vn 1> /dev/null 2>&1 && color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + if [[ "${THEME_CHECK_SUDO:-false}" == true ]]; then + if sudo -vn 2> /dev/null; then + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO-${POWERLINE_USER_INFO_COLOR_SUDO-"202"}} + fi fi - case "${POWERLINE_PROMPT_USER_INFO_MODE}" in + case "${POWERLINE_PROMPT_USER_INFO_MODE:-}" in "sudo") - if [[ "${color}" = "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then + if [[ "${color}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO-${POWERLINE_USER_INFO_COLOR_SUDO-"202"}}" ]]; then user_info="!" fi ;; *) - local user=${SHORT_USER:-${USER}} - if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then - user_info="${USER_INFO_SSH_CHAR}${user}" - else - user_info="${user}" + if [[ -n "${SSH_CLIENT:-}" ]] || [[ -n "${SSH_CONNECTION:-}" ]]; then + user_info="${USER_INFO_SSH_CHAR-${POWERLINE_USER_INFO_SSH_CHAR-"⌁ "}}${user_info}" fi ;; esac - [[ -n "${user_info}" ]] && echo "${user_info}|${color}" + echo "${user_info}|${color}" } function __powerline_terraform_prompt() { local terraform_workspace="" - if [ -d .terraform ]; then + if [[ -d .terraform ]]; then terraform_workspace="$(terraform_workspace_prompt)" - [[ -n "${terraform_workspace}" ]] && echo "${TERRAFORM_CHAR}${terraform_workspace}|${TERRAFORM_THEME_PROMPT_COLOR}" + [[ -n "${terraform_workspace}" ]] && echo "${TERRAFORM_CHAR-${POWERLINE_TERRAFORM_CHAR-"❲t❳ "}}${terraform_workspace}|${TERRAFORM_THEME_PROMPT_COLOR-${POWERLINE_TERRAFORM_COLOR-"161"}}" fi } @@ -52,18 +53,19 @@ function __powerline_gcloud_prompt() { local active_gcloud_account="" active_gcloud_account="$(active_gcloud_account_prompt)" - [[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR}" + [[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR-${POWERLINE_GCLOUD_CHAR-"❲G❳ "}}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR-${POWERLINE_GCLOUD_COLOR-"161"}}" } function __powerline_node_prompt() { local node_version="" node_version="$(node_version_prompt)" - [[ -n "${node_version}" ]] && echo "${NODE_CHAR}${node_version}|${NODE_THEME_PROMPT_COLOR}" + [[ -n "${node_version}" ]] && echo "${NODE_CHAR-${POWERLINE_NODE_CHAR-="❲n❳ "}}${node_version}|${NODE_THEME_PROMPT_COLOR-${POWERLINE_NODE_COLOR-"22"}}" } +#Customising Ruby Prompt function __powerline_ruby_prompt() { - local ruby_version="" + local ruby_version if _command_exists rvm; then ruby_version="$(rvm_version_prompt)" @@ -71,7 +73,9 @@ function __powerline_ruby_prompt() { ruby_version=$(rbenv_version_prompt) fi - [[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}" + if [[ -n "${ruby_version:-}" ]]; then + echo "${RUBY_CHAR-${POWERLINE_RUBY_CHAR-"πŸ’Ž "}}${ruby_version}|${RUBY_THEME_PROMPT_COLOR-${POWERLINE_RUBY_COLOR-"161"}}" + fi } function __powerline_k8s_context_prompt() { @@ -81,7 +85,7 @@ function __powerline_k8s_context_prompt() { kubernetes_context="$(k8s_context_prompt)" fi - [[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}" + [[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR-${POWERLINE_KUBERNETES_CONTEXT_CHAR-"⎈ "}}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_CONTEXT_COLOR-"26"}}" } function __powerline_k8s_namespace_prompt() { @@ -91,57 +95,61 @@ function __powerline_k8s_namespace_prompt() { kubernetes_namespace="$(k8s_namespace_prompt)" fi - [[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR}" + [[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR-${POWERLINE_KUBERNETES_NAMESPACE_CHAR-"⎈ "}}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_NAMESPACE_COLOR-"60"}}" } +#Customising Python (venv) Prompt function __powerline_python_venv_prompt() { local python_venv="" if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then python_venv="${CONDA_DEFAULT_ENV}" - PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR} + local PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR-${POWERLINE_CONDA_PYTHON_VENV_CHAR-"β“” "}} elif [[ -n "${VIRTUAL_ENV:-}" ]]; then python_venv="${VIRTUAL_ENV##*/}" fi - [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}" + [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR-${POWERLINE_PYTHON_VENV_CHAR-"β“” "}}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR-${POWERLINE_PYTHON_VENV_COLOR-"35"}}" } +#Customising SCM(GIT) Prompt function __powerline_scm_prompt() { local color="" local scm_prompt="" scm_prompt_vars - if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then - if [[ "${SCM_DIRTY}" -eq 3 ]]; then - color=${SCM_THEME_PROMPT_STAGED_COLOR} - elif [[ "${SCM_DIRTY}" -eq 2 ]]; then - color=${SCM_THEME_PROMPT_UNSTAGED_COLOR} - elif [[ "${SCM_DIRTY}" -eq 1 ]]; then - color=${SCM_THEME_PROMPT_DIRTY_COLOR} + if [[ "${SCM_NONE_CHAR?}" != "${SCM_CHAR?}" ]]; then + if [[ "${SCM_DIRTY?}" -eq 3 ]]; then + color=${SCM_THEME_PROMPT_STAGED_COLOR-${POWERLINE_SCM_STAGED_COLOR-"30"}} + elif [[ "${SCM_DIRTY?}" -eq 2 ]]; then + color=${SCM_THEME_PROMPT_UNSTAGED_COLOR-${POWERLINE_SCM_UNSTAGED_COLOR-"92"}} + elif [[ "${SCM_DIRTY?}" -eq 1 ]]; then + color=${SCM_THEME_PROMPT_DIRTY_COLOR-${POWERLINE_SCM_DIRTY_COLOR-"88"}} + elif [[ "${SCM_DIRTY?}" -eq 0 ]]; then + color=${SCM_THEME_PROMPT_CLEAN_COLOR-${POWERLINE_SCM_CLEAN_COLOR-"25"}} else - color=${SCM_THEME_PROMPT_CLEAN_COLOR} + color=${SCM_THEME_PROMPT_COLOR-${POWERLINE_SCM_CLEAN_COLOR-"25"}} fi - if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - elif [[ "${SCM_P4_CHAR}" == "${SCM_CHAR}" ]]; then - scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - elif [[ "${SCM_HG_CHAR}" == "${SCM_CHAR}" ]]; then - scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - elif [[ "${SCM_SVN_CHAR}" == "${SCM_CHAR}" ]]; then - scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + if [[ "${SCM_GIT_CHAR?}" == "${SCM_CHAR?}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" + elif [[ "${SCM_P4_CHAR?}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" + elif [[ "${SCM_HG_CHAR?}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" + elif [[ "${SCM_SVN_CHAR?}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" fi - echo "${scm_prompt?}|${color}" + echo "${scm_prompt}|${color}" fi } function __powerline_cwd_prompt() { - echo "\w|${CWD_THEME_PROMPT_COLOR}" + echo "\w|${CWD_THEME_PROMPT_COLOR-240}" } function __powerline_hostname_prompt() { - echo "${SHORT_HOSTNAME:-$(hostname -s)}|${HOST_THEME_PROMPT_COLOR}" + echo "\h|${HOST_THEME_PROMPT_COLOR-"0"}" } function __powerline_wd_prompt() { @@ -149,7 +157,7 @@ function __powerline_wd_prompt() { } function __powerline_clock_prompt() { - echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}" + echo "\D{${THEME_CLOCK_FORMAT-"%H:%M:%S"}}|${CLOCK_THEME_PROMPT_COLOR-"240"}" } function __powerline_battery_prompt() { @@ -160,149 +168,147 @@ function __powerline_battery_prompt() { true else if [[ "$((10#${battery_status}))" -le 5 ]]; then - color="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" + color="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR-"160"}" elif [[ "$((10#${battery_status}))" -le 25 ]]; then - color="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" + color="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR-"208"}" else - color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" + color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR-"70"}" fi - ac_adapter_connected && battery_status="${BATTERY_AC_CHAR}${battery_status}" + ac_adapter_connected && battery_status="${BATTERY_AC_CHAR-"+ "}${battery_status}" echo "${battery_status}%|${color}" fi } function __powerline_in_vim_prompt() { - if [[ -n "$VIMRUNTIME" ]]; then - echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}" + if [[ -n "${VIMRUNTIME:-}" ]]; then + echo "${IN_VIM_THEME_PROMPT_TEXT-"vim"}|${IN_VIM_THEME_PROMPT_COLOR-"245"}" fi } function __powerline_aws_profile_prompt() { - if [[ -n "${AWS_PROFILE}" ]]; then - echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}" + if [[ -n "${AWS_PROFILE:-}" ]]; then + echo "${AWS_PROFILE_CHAR-${POWERLINE_AWS_PROFILE_CHAR-"❲aws❳ "}}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR-${POWERLINE_AWS_PROFILE_COLOR-"208"}}" fi } function __powerline_in_toolbox_prompt() { - if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then - echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}" + if [[ -f /run/.containerenv ]] && [[ -f /run/.toolboxenv ]]; then + echo "${IN_TOOLBOX_THEME_PROMPT_TEXT-"β¬’ "}|${IN_TOOLBOX_THEME_PROMPT_COLOR-"125"}" fi } function __powerline_shlvl_prompt() { if [[ "${SHLVL}" -gt 1 ]]; then - local prompt="${SHLVL_THEME_PROMPT_CHAR}" + local prompt="${SHLVL_THEME_PROMPT_CHAR-"Β§"}" local level=$((SHLVL - 1)) - echo "${prompt}${level}|${SHLVL_THEME_PROMPT_COLOR}" + echo "${prompt}${level}|${SHLVL_THEME_PROMPT_COLOR-${HOST_THEME_PROMPT_COLOR-"0"}}" fi } function __powerline_dirstack_prompt() { if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then local depth=$((${#DIRSTACK[@]} - 1)) - local prompt="${DIRSTACK_THEME_PROMPT_CHAR}" + local prompt="${DIRSTACK_THEME_PROMPT_CHAR-${POWERLINE_DIRSTACK_CHAR-"←"}}" if [[ "${depth}" -ge 2 ]]; then prompt+="${depth}" fi - echo "${prompt}|${DIRSTACK_THEME_PROMPT_COLOR}" + echo "${prompt}|${DIRSTACK_THEME_PROMPT_COLOR-${POWERLINE_DIRSTACK_COLOR-${CWD_THEME_PROMPT_COLOR-${POWERLINE_CWD_COLOR-"240"}}}}" fi } function __powerline_history_number_prompt() { - echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR}" + echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_HISTORY_NUMBER_CHAR-"#"}}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_HISTORY_NUMBER_COLOR-"0"}}" } function __powerline_command_number_prompt() { - echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}" + echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_COMMAND_NUMBER_CHAR-"#"}}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_COMMAND_NUMBER_COLOR-"0"}}" } function __powerline_duration_prompt() { local duration duration=$(_command_duration) - [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}" + [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR?}" } function __powerline_left_segment() { - local params + local -a params IFS="|" read -ra params <<< "${1}" local pad_before_segment=" " - if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then - if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -ne 0 ]]; then + #for seperator character + if [[ "${SEGMENTS_AT_LEFT?}" -eq 0 ]]; then + if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-0}" -ne 0 ]]; then pad_before_segment="" fi else - if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -ne 0 ]]; then + if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR:-0}" -ne 0 ]]; then pad_before_segment="" fi # Since the previous segment wasn't the last segment, add padding, if needed # - if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then - LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal?}" + if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-0}" -eq 0 ]]; then + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal?}" fi - if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]}" ]]; then - LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}")${POWERLINE_LEFT_SEPARATOR_SOFT}${normal?}" + if [[ "${LAST_SEGMENT_COLOR?}" -eq "${params[1]:-}" ]]; then + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_SEPARATOR_SOFT:- }${normal?}" else - LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR}" "${params[1]}")${POWERLINE_LEFT_SEPARATOR}${normal?}" + LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR?}" "${params[1]:-}")${POWERLINE_LEFT_SEPARATOR:- }${normal?}" fi fi - LEFT_PROMPT+="$(set_color - "${params[1]}")${pad_before_segment}${params[0]}${normal}" - LAST_SEGMENT_COLOR=${params[1]} + #change here to cahnge fg color + LEFT_PROMPT+="$(set_color - "${params[1]:-}")${pad_before_segment}${params[0]}${normal?}" + #seperator char color == current bg + LAST_SEGMENT_COLOR="${params[1]:-}" ((SEGMENTS_AT_LEFT += 1)) } function __powerline_left_last_segment_padding() { - LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal?}" + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal?}" } function __powerline_last_status_prompt() { - [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}" + [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR-"52"}" } function __powerline_prompt_command() { local last_status="$?" ## always the first - local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color + local info prompt_color segment - LEFT_PROMPT="" - SEGMENTS_AT_LEFT=0 - LAST_SEGMENT_COLOR="" + local LEFT_PROMPT="" + local SEGMENTS_AT_LEFT=0 + local LAST_SEGMENT_COLOR="" _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" - if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then - LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR}" "${PROMPT_DISTRO_LOGO_COLORBG}")${PROMPT_DISTRO_LOGO}$(set_color - -)" + if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO:-}" ]]; then + LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR?}" "${PROMPT_DISTRO_LOGO_COLORBG?}")${PROMPT_DISTRO_LOGO?}$(set_color - -)" fi ## left prompt ## - for segment in $POWERLINE_PROMPT; do - info="$(__powerline_"${segment}"_prompt)" + for segment in ${POWERLINE_PROMPT-"user_info" "scm" "python_venv" "ruby" "node" "cwd"}; do + info="$("__powerline_${segment}_prompt")" [[ -n "${info}" ]] && __powerline_left_segment "${info}" done [[ "${last_status}" -ne 0 ]] && __powerline_left_segment "$(__powerline_last_status_prompt "${last_status}")" - if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-}" -eq 0 ]]; then + if [[ -n "${LEFT_PROMPT:-}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-0}" -eq 0 ]]; then __powerline_left_last_segment_padding fi # By default we try to match the prompt to the adjacent segment's background color, # but when part of the prompt exists within that segment, we instead match the foreground color. - prompt_color="$(set_color "${LAST_SEGMENT_COLOR}" -)" - if [[ -n "${LEFT_PROMPT}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" ]]; then - LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" + prompt_color="$(set_color "${LAST_SEGMENT_COLOR?}" -)" + if [[ -n "${LEFT_PROMPT:-}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR:-}" ]]; then + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" prompt_color="${normal?}" fi - [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="${prompt_color}${separator_char}${normal?}" + [[ -n "${LEFT_PROMPT:-}" ]] && LEFT_PROMPT+="${prompt_color}${POWERLINE_PROMPT_CHAR-\\$}${normal?}" - if [[ "${POWERLINE_COMPACT_PROMPT:-}" -eq 0 ]]; then + if [[ "${POWERLINE_COMPACT_PROMPT:-0}" -eq 0 ]]; then LEFT_PROMPT+=" " fi - PS1="${LEFT_PROMPT}" - - ## cleanup ## - unset LAST_SEGMENT_COLOR \ - LEFT_PROMPT \ - SEGMENTS_AT_LEFT + PS1="${LEFT_PROMPT?}" } From c697ada0a5a83709ea32597a080a946fe96a569e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 12 Feb 2022 21:22:47 -0800 Subject: [PATCH 031/239] theme/powerline-base: allow `$POWERLINE_PROMPT` as array --- themes/powerline/powerline.base.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 5a7b1782b5..8c1f1c6bc6 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -286,7 +286,8 @@ function __powerline_prompt_command() { fi ## left prompt ## - for segment in ${POWERLINE_PROMPT-"user_info" "scm" "python_venv" "ruby" "node" "cwd"}; do + # shellcheck disable=SC2068 # intended behavior + for segment in ${POWERLINE_PROMPT[@]-"user_info" "scm" "python_venv" "ruby" "node" "cwd"}; do info="$("__powerline_${segment}_prompt")" [[ -n "${info}" ]] && __powerline_left_segment "${info}" done From ee779c8bb74b06885a682a4a5338505bfab09d1a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 10 Feb 2022 21:16:25 -0800 Subject: [PATCH 032/239] theme/powerline base: //echo/printf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AlsΓΆ: - Use `\u` instead of `${SHORT_USER:-${USER?}}`. - Use `if`/`then` properly. - Lose some whitespace from prompt characters; that's what padding is for. TODO: - prompt character prefix/suffix support - use variables rather than subshells... --- themes/powerline/powerline.base.bash | 96 +++++++++++++++++----------- 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 8c1f1c6bc6..45e5efb661 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -9,14 +9,16 @@ function set_color() { fi if [[ "${2:-}" != "-" ]]; then bg="48;5;${2}" - [[ -n "${fg}" ]] && bg=";${bg}" + if [[ -n "${fg}" ]]; then + bg=";${bg}" + fi fi - echo -e "\[\033[${fg}${bg}m\]" + printf '\[\\e[%s%sm\]' "${fg}" "${bg}" } #Customising User Info Segment function __powerline_user_info_prompt() { - local user_info="${SHORT_USER:-${USER}}" + local user_info='\u' local color=${USER_INFO_THEME_PROMPT_COLOR-${POWERLINE_USER_INFO_COLOR-"32"}} if [[ "${THEME_CHECK_SUDO:-false}" == true ]]; then @@ -32,12 +34,12 @@ function __powerline_user_info_prompt() { fi ;; *) - if [[ -n "${SSH_CLIENT:-}" ]] || [[ -n "${SSH_CONNECTION:-}" ]]; then - user_info="${USER_INFO_SSH_CHAR-${POWERLINE_USER_INFO_SSH_CHAR-"⌁ "}}${user_info}" + if [[ -n "${SSH_CLIENT:-}" || -n "${SSH_CONNECTION:-}" ]]; then + user_info="${USER_INFO_SSH_CHAR-${POWERLINE_USER_INFO_SSH_CHAR-"⌁"}}${user_info}" fi ;; esac - echo "${user_info}|${color}" + printf '%s|%s' "${user_info}" "${color}" } function __powerline_terraform_prompt() { @@ -45,7 +47,9 @@ function __powerline_terraform_prompt() { if [[ -d .terraform ]]; then terraform_workspace="$(terraform_workspace_prompt)" - [[ -n "${terraform_workspace}" ]] && echo "${TERRAFORM_CHAR-${POWERLINE_TERRAFORM_CHAR-"❲t❳ "}}${terraform_workspace}|${TERRAFORM_THEME_PROMPT_COLOR-${POWERLINE_TERRAFORM_COLOR-"161"}}" + if [[ -n "${terraform_workspace}" ]]; then + printf '%s%s|%s' "${TERRAFORM_CHAR-${POWERLINE_TERRAFORM_CHAR-"❲t❳"}}" "${terraform_workspace}" "${TERRAFORM_THEME_PROMPT_COLOR-${POWERLINE_TERRAFORM_COLOR-"161"}}" + fi fi } @@ -53,14 +57,18 @@ function __powerline_gcloud_prompt() { local active_gcloud_account="" active_gcloud_account="$(active_gcloud_account_prompt)" - [[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR-${POWERLINE_GCLOUD_CHAR-"❲G❳ "}}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR-${POWERLINE_GCLOUD_COLOR-"161"}}" + if [[ -n "${active_gcloud_account}" ]]; then + printf '%s%s|%s' "${GCLOUD_CHAR-${POWERLINE_GCLOUD_CHAR-"❲G❳"}}" "${active_gcloud_account}" "${GCLOUD_THEME_PROMPT_COLOR-${POWERLINE_GCLOUD_COLOR-"161"}}" + fi } function __powerline_node_prompt() { local node_version="" node_version="$(node_version_prompt)" - [[ -n "${node_version}" ]] && echo "${NODE_CHAR-${POWERLINE_NODE_CHAR-="❲n❳ "}}${node_version}|${NODE_THEME_PROMPT_COLOR-${POWERLINE_NODE_COLOR-"22"}}" + if [[ -n "${node_version}" ]]; then + printf '%s%s|%s' "${NODE_CHAR-${POWERLINE_NODE_CHAR-="❲n❳"}}" "${node_version}" "${NODE_THEME_PROMPT_COLOR-${POWERLINE_NODE_COLOR-"22"}}" + fi } #Customising Ruby Prompt @@ -74,7 +82,7 @@ function __powerline_ruby_prompt() { fi if [[ -n "${ruby_version:-}" ]]; then - echo "${RUBY_CHAR-${POWERLINE_RUBY_CHAR-"πŸ’Ž "}}${ruby_version}|${RUBY_THEME_PROMPT_COLOR-${POWERLINE_RUBY_COLOR-"161"}}" + printf '%s%s|%s' "${RUBY_CHAR-${POWERLINE_RUBY_CHAR-"πŸ’Ž"}}" "${ruby_version}" "${RUBY_THEME_PROMPT_COLOR-${POWERLINE_RUBY_COLOR-"161"}}" fi } @@ -85,7 +93,9 @@ function __powerline_k8s_context_prompt() { kubernetes_context="$(k8s_context_prompt)" fi - [[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR-${POWERLINE_KUBERNETES_CONTEXT_CHAR-"⎈ "}}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_CONTEXT_COLOR-"26"}}" + if [[ -n "${kubernetes_context}" ]]; then + printf '%s%s|%s' "${KUBERNETES_CONTEXT_THEME_CHAR-${POWERLINE_KUBERNETES_CONTEXT_CHAR-"⎈"}}" "${kubernetes_context}" "${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_CONTEXT_COLOR-"26"}}" + fi } function __powerline_k8s_namespace_prompt() { @@ -95,7 +105,9 @@ function __powerline_k8s_namespace_prompt() { kubernetes_namespace="$(k8s_namespace_prompt)" fi - [[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR-${POWERLINE_KUBERNETES_NAMESPACE_CHAR-"⎈ "}}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_NAMESPACE_COLOR-"60"}}" + if [[ -n "${kubernetes_namespace}" ]]; then + printf '%s%s|%s' "${KUBERNETES_NAMESPACE_THEME_CHAR-${POWERLINE_KUBERNETES_NAMESPACE_CHAR-"⎈"}}" "${kubernetes_namespace}" "${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_NAMESPACE_COLOR-"60"}}" + fi } #Customising Python (venv) Prompt @@ -104,12 +116,14 @@ function __powerline_python_venv_prompt() { if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then python_venv="${CONDA_DEFAULT_ENV}" - local PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR-${POWERLINE_CONDA_PYTHON_VENV_CHAR-"β“” "}} + local PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR-${POWERLINE_CONDA_PYTHON_VENV_CHAR-"β“”"}} elif [[ -n "${VIRTUAL_ENV:-}" ]]; then python_venv="${VIRTUAL_ENV##*/}" fi - [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR-${POWERLINE_PYTHON_VENV_CHAR-"β“” "}}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR-${POWERLINE_PYTHON_VENV_COLOR-"35"}}" + if [[ -n "${python_venv}" ]]; then + printf '%s%s|%s' "${PYTHON_VENV_CHAR-${POWERLINE_PYTHON_VENV_CHAR-"β“”"}}" "${python_venv}" "${PYTHON_VENV_THEME_PROMPT_COLOR-${POWERLINE_PYTHON_VENV_COLOR-"35"}}" + fi } #Customising SCM(GIT) Prompt @@ -140,24 +154,24 @@ function __powerline_scm_prompt() { elif [[ "${SCM_SVN_CHAR?}" == "${SCM_CHAR}" ]]; then scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" fi - echo "${scm_prompt}|${color}" + printf '%s|%s' "${scm_prompt}" "${color}" fi } function __powerline_cwd_prompt() { - echo "\w|${CWD_THEME_PROMPT_COLOR-240}" + printf '%s|%s' "\w" "${CWD_THEME_PROMPT_COLOR-"240"}" } function __powerline_hostname_prompt() { - echo "\h|${HOST_THEME_PROMPT_COLOR-"0"}" + printf '%s|%s' "\h" "${HOST_THEME_PROMPT_COLOR-"0"}" } function __powerline_wd_prompt() { - echo "\W|${CWD_THEME_PROMPT_COLOR}" + printf '%s|%s' "\W" "${CWD_THEME_PROMPT_COLOR-"240"}" } function __powerline_clock_prompt() { - echo "\D{${THEME_CLOCK_FORMAT-"%H:%M:%S"}}|${CLOCK_THEME_PROMPT_COLOR-"240"}" + printf '%s|%s' "\D{${THEME_CLOCK_FORMAT-"%H:%M:%S"}}" "${CLOCK_THEME_PROMPT_COLOR-"240"}" } function __powerline_battery_prompt() { @@ -174,26 +188,28 @@ function __powerline_battery_prompt() { else color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR-"70"}" fi - ac_adapter_connected && battery_status="${BATTERY_AC_CHAR-"+ "}${battery_status}" - echo "${battery_status}%|${color}" + if ac_adapter_connected; then + battery_status="${BATTERY_AC_CHAR-"+"}${battery_status}" + fi + printf '%s|%s' "${battery_status}%" "${color}" fi } function __powerline_in_vim_prompt() { if [[ -n "${VIMRUNTIME:-}" ]]; then - echo "${IN_VIM_THEME_PROMPT_TEXT-"vim"}|${IN_VIM_THEME_PROMPT_COLOR-"245"}" + printf '%s|%s' "${IN_VIM_THEME_PROMPT_TEXT-"vim"}" "${IN_VIM_THEME_PROMPT_COLOR-"245"}" fi } function __powerline_aws_profile_prompt() { if [[ -n "${AWS_PROFILE:-}" ]]; then - echo "${AWS_PROFILE_CHAR-${POWERLINE_AWS_PROFILE_CHAR-"❲aws❳ "}}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR-${POWERLINE_AWS_PROFILE_COLOR-"208"}}" + printf '%s%s|%s' "${AWS_PROFILE_CHAR-${POWERLINE_AWS_PROFILE_CHAR-"❲aws❳"}}" "${AWS_PROFILE}" "${AWS_PROFILE_PROMPT_COLOR-${POWERLINE_AWS_PROFILE_COLOR-"208"}}" fi } function __powerline_in_toolbox_prompt() { - if [[ -f /run/.containerenv ]] && [[ -f /run/.toolboxenv ]]; then - echo "${IN_TOOLBOX_THEME_PROMPT_TEXT-"β¬’ "}|${IN_TOOLBOX_THEME_PROMPT_COLOR-"125"}" + if [[ -f /run/.containerenv && -f /run/.toolboxenv ]]; then + printf '%s|%s' "${IN_TOOLBOX_THEME_PROMPT_TEXT-"β¬’"}" "${IN_TOOLBOX_THEME_PROMPT_COLOR-"125"}" fi } @@ -201,7 +217,7 @@ function __powerline_shlvl_prompt() { if [[ "${SHLVL}" -gt 1 ]]; then local prompt="${SHLVL_THEME_PROMPT_CHAR-"Β§"}" local level=$((SHLVL - 1)) - echo "${prompt}${level}|${SHLVL_THEME_PROMPT_COLOR-${HOST_THEME_PROMPT_COLOR-"0"}}" + printf '%s|%s' "${prompt}${level}" "${SHLVL_THEME_PROMPT_COLOR-${HOST_THEME_PROMPT_COLOR-"0"}}" fi } @@ -212,22 +228,24 @@ function __powerline_dirstack_prompt() { if [[ "${depth}" -ge 2 ]]; then prompt+="${depth}" fi - echo "${prompt}|${DIRSTACK_THEME_PROMPT_COLOR-${POWERLINE_DIRSTACK_COLOR-${CWD_THEME_PROMPT_COLOR-${POWERLINE_CWD_COLOR-"240"}}}}" + printf '%s|%s' "${prompt}" "${DIRSTACK_THEME_PROMPT_COLOR-${POWERLINE_DIRSTACK_COLOR-${CWD_THEME_PROMPT_COLOR-${POWERLINE_CWD_COLOR-"240"}}}}" fi } function __powerline_history_number_prompt() { - echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_HISTORY_NUMBER_CHAR-"#"}}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_HISTORY_NUMBER_COLOR-"0"}}" + printf '%s%s|%s' "${HISTORY_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_HISTORY_NUMBER_CHAR-"#"}}" '\!' "${HISTORY_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_HISTORY_NUMBER_COLOR-"0"}}" } function __powerline_command_number_prompt() { - echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_COMMAND_NUMBER_CHAR-"#"}}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_COMMAND_NUMBER_COLOR-"0"}}" + printf '%s%s|%s' "${COMMAND_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_COMMAND_NUMBER_CHAR-"#"}}" '\#' "${COMMAND_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_COMMAND_NUMBER_COLOR-"0"}}" } function __powerline_duration_prompt() { local duration duration=$(_command_duration) - [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR?}" + if [[ -n "$duration" ]]; then + printf '%s|%s' "${duration}" "${COMMAND_DURATION_PROMPT_COLOR?}" + fi } function __powerline_left_segment() { @@ -268,7 +286,9 @@ function __powerline_left_last_segment_padding() { } function __powerline_last_status_prompt() { - [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR-"52"}" + if [[ "${1?}" -ne 0 ]]; then + printf '%s|%s' "${1}" "${LAST_STATUS_THEME_PROMPT_COLOR-"52"}" + fi } function __powerline_prompt_command() { @@ -289,23 +309,27 @@ function __powerline_prompt_command() { # shellcheck disable=SC2068 # intended behavior for segment in ${POWERLINE_PROMPT[@]-"user_info" "scm" "python_venv" "ruby" "node" "cwd"}; do info="$("__powerline_${segment}_prompt")" - [[ -n "${info}" ]] && __powerline_left_segment "${info}" + if [[ -n "${info}" ]]; then + __powerline_left_segment "${info}" + fi done - [[ "${last_status}" -ne 0 ]] && __powerline_left_segment "$(__powerline_last_status_prompt "${last_status}")" + if [[ "${last_status}" -ne 0 ]]; then + __powerline_left_segment "$(__powerline_last_status_prompt "${last_status}")" + fi - if [[ -n "${LEFT_PROMPT:-}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-0}" -eq 0 ]]; then + if [[ -n "${LEFT_PROMPT:-}" && "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-0}" -eq 0 ]]; then __powerline_left_last_segment_padding fi # By default we try to match the prompt to the adjacent segment's background color, # but when part of the prompt exists within that segment, we instead match the foreground color. prompt_color="$(set_color "${LAST_SEGMENT_COLOR?}" -)" - if [[ -n "${LEFT_PROMPT:-}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR:-}" ]]; then + if [[ -n "${LEFT_PROMPT:-}" && -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR:-}" ]]; then LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" prompt_color="${normal?}" fi - [[ -n "${LEFT_PROMPT:-}" ]] && LEFT_PROMPT+="${prompt_color}${POWERLINE_PROMPT_CHAR-\\$}${normal?}" + LEFT_PROMPT+="${prompt_color}${POWERLINE_PROMPT_CHAR-\\$}${normal?}" if [[ "${POWERLINE_COMPACT_PROMPT:-0}" -eq 0 ]]; then LEFT_PROMPT+=" " From 5ef4b0f8985c52bd4efb9a508b58bb976946b58b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 12 Feb 2022 21:45:54 -0800 Subject: [PATCH 033/239] theme/powerline-base: clean up `user_info` segment --- themes/powerline/powerline.base.bash | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 45e5efb661..2a40a0dbfb 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -24,21 +24,15 @@ function __powerline_user_info_prompt() { if [[ "${THEME_CHECK_SUDO:-false}" == true ]]; then if sudo -vn 2> /dev/null; then color=${USER_INFO_THEME_PROMPT_COLOR_SUDO-${POWERLINE_USER_INFO_COLOR_SUDO-"202"}} + if [[ "${POWERLINE_PROMPT_USER_INFO_MODE:-}" == "sudo" ]]; then + user_info="!" + fi fi fi - case "${POWERLINE_PROMPT_USER_INFO_MODE:-}" in - "sudo") - if [[ "${color}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO-${POWERLINE_USER_INFO_COLOR_SUDO-"202"}}" ]]; then - user_info="!" - fi - ;; - *) - if [[ -n "${SSH_CLIENT:-}" || -n "${SSH_CONNECTION:-}" ]]; then - user_info="${USER_INFO_SSH_CHAR-${POWERLINE_USER_INFO_SSH_CHAR-"⌁"}}${user_info}" - fi - ;; - esac + if [[ -n "${SSH_CLIENT:-}" || -n "${SSH_CONNECTION:-}" ]]; then + user_info="${USER_INFO_SSH_CHAR-${POWERLINE_USER_INFO_SSH_CHAR-"⌁"}}${user_info}" + fi printf '%s|%s' "${user_info}" "${color}" } From b16d7efcf5777ba386a6cc121f72790690dfe089 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 12 Feb 2022 22:45:44 -0800 Subject: [PATCH 034/239] theme/powerline-base: harmonize with -multiline a bit --- themes/powerline/powerline.base.bash | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 2a40a0dbfb..e7ae8ede7f 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -249,22 +249,22 @@ function __powerline_left_segment() { #for seperator character if [[ "${SEGMENTS_AT_LEFT?}" -eq 0 ]]; then - if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-0}" -ne 0 ]]; then + if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -ne 0 ]]; then pad_before_segment="" fi else - if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR:-0}" -ne 0 ]]; then + if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR:-${POWERLINE_COMPACT:-0}}" -ne 0 ]]; then pad_before_segment="" fi # Since the previous segment wasn't the last segment, add padding, if needed # - if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-0}" -eq 0 ]]; then + if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal?}" fi if [[ "${LAST_SEGMENT_COLOR?}" -eq "${params[1]:-}" ]]; then - LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_SEPARATOR_SOFT:- }${normal?}" + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_SEPARATOR_SOFT- }${normal?}" else - LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR?}" "${params[1]:-}")${POWERLINE_LEFT_SEPARATOR:- }${normal?}" + LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR?}" "${params[1]:-}")${POWERLINE_LEFT_SEPARATOR- }${normal?}" fi fi @@ -287,7 +287,8 @@ function __powerline_last_status_prompt() { function __powerline_prompt_command() { local last_status="$?" ## always the first - local info prompt_color segment + local beginning_of_line='\[\e[G\]' + local info prompt_color segment prompt local LEFT_PROMPT="" local SEGMENTS_AT_LEFT=0 @@ -312,22 +313,22 @@ function __powerline_prompt_command() { __powerline_left_segment "$(__powerline_last_status_prompt "${last_status}")" fi - if [[ -n "${LEFT_PROMPT:-}" && "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-0}" -eq 0 ]]; then + if [[ -n "${LEFT_PROMPT:-}" && "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then __powerline_left_last_segment_padding fi # By default we try to match the prompt to the adjacent segment's background color, # but when part of the prompt exists within that segment, we instead match the foreground color. prompt_color="$(set_color "${LAST_SEGMENT_COLOR?}" -)" - if [[ -n "${LEFT_PROMPT:-}" && -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR:-}" ]]; then - LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" + if [[ -n "${LEFT_PROMPT:-}" && -n "${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR:-}" ]]; then + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR}" prompt_color="${normal?}" fi - LEFT_PROMPT+="${prompt_color}${POWERLINE_PROMPT_CHAR-\\$}${normal?}" - if [[ "${POWERLINE_COMPACT_PROMPT:-0}" -eq 0 ]]; then - LEFT_PROMPT+=" " + prompt="${prompt_color}${PROMPT_CHAR-${POWERLINE_PROMPT_CHAR-\\$}}${normal?}" + if [[ "${POWERLINE_COMPACT_PROMPT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then + prompt+=" " fi - PS1="${LEFT_PROMPT?}" + PS1="${beginning_of_line}${normal?}${LEFT_PROMPT}${prompt}" } From 9fc004b43395e1a408d572a385ac9f6a8b325f5b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 17 Jan 2022 12:15:01 -0800 Subject: [PATCH 035/239] theme/powerline: cleanup --- themes/powerline/powerline.theme.bash | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 49b397aa1d..e2cdc58cad 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -1,20 +1,19 @@ # shellcheck shell=bash # shellcheck disable=SC2034 # Expected behavior for themes. - -# shellcheck source=../../themes/powerline/powerline.base.bash -. "$BASH_IT/themes/powerline/powerline.base.bash" +# shellcheck source-path=SCRIPTDIR/../powerline +source "${BASH_IT?}/themes/powerline/powerline.base.bash" PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:="ξ‚°"} -POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:="ξ‚°"} -POWERLINE_LEFT_SEPARATOR_SOFT=${POWERLINE_LEFT_SEPARATOR_SOFT:="ξ‚±"} -POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR=${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR:=""} +: "${POWERLINE_LEFT_SEPARATOR:="ξ‚°"}" +: "${POWERLINE_LEFT_SEPARATOR_SOFT:="ξ‚±"}" +: "${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR:=""}" -POWERLINE_COMPACT=${POWERLINE_COMPACT:=0} -POWERLINE_COMPACT_BEFORE_SEPARATOR=${POWERLINE_COMPACT_BEFORE_SEPARATOR:=${POWERLINE_COMPACT}} -POWERLINE_COMPACT_AFTER_SEPARATOR=${POWERLINE_COMPACT_AFTER_SEPARATOR:=${POWERLINE_COMPACT}} -POWERLINE_COMPACT_BEFOR_FIRST_SEGMENT=${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:=${POWERLINE_COMPACT}} -POWERLINE_COMPACT_AFTER_LAST_SEGMENT=${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${POWERLINE_COMPACT}} -POWERLINE_COMPACT_PROMPT=${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}} +: "${POWERLINE_COMPACT:=0}" +: "${POWERLINE_COMPACT_BEFORE_SEPARATOR:=${POWERLINE_COMPACT}}" +: "${POWERLINE_COMPACT_AFTER_SEPARATOR:=${POWERLINE_COMPACT}}" +: "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:=${POWERLINE_COMPACT}}" +: "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${POWERLINE_COMPACT}}" +: "${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}}" USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:="ξ‚’ "} USER_INFO_THEME_PROMPT_COLOR=${POWERLINE_USER_INFO_COLOR:=32} @@ -65,12 +64,12 @@ LAST_STATUS_THEME_PROMPT_COLOR=${POWERLINE_LAST_STATUS_COLOR:=52} CLOCK_THEME_PROMPT_COLOR=${POWERLINE_CLOCK_COLOR:=240} -BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚑"} +: "${BATTERY_AC_CHAR:="⚑"}" BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=${POWERLINE_BATTERY_GOOD_COLOR:=70} BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=${POWERLINE_BATTERY_LOW_COLOR:=208} BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=${POWERLINE_BATTERY_CRITICAL_COLOR:=160} -THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} +: "${THEME_CLOCK_FORMAT:="%H:%M:%S"}" IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} @@ -97,6 +96,6 @@ GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129} -POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"} +: "${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"}" safe_append_prompt_command __powerline_prompt_command From 363827a3b5e27b389e0d835d7876dd1f3bde25eb Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 21 Jan 2022 21:33:53 -0800 Subject: [PATCH 036/239] theme/pure: cleanup Use `\$` to let _Bash_ choose the mark, move `PS1=` outside the `case` statement. #TODO: last command status? --- themes/pure/pure.theme.bash | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash index ba83a232da..4dd59e02ca 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -14,17 +14,12 @@ SCM_HG_CHAR="${bold_red?}☿${normal?}" VIRTUALENV_THEME_PROMPT_PREFIX="(" VIRTUALENV_THEME_PROMPT_SUFFIX=")" -### TODO: openSUSE has already colors enabled, check if those differs from stock -# LS colors, made with http://geoff.greer.fm/lscolors/ -# export LSCOLORS="Gxfxcxdxbxegedabagacad" -# export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' - function pure_prompt() { local ps_host="${bold_blue?}\h${normal?}" local ps_user="${green?}\u${normal?}" - local ps_user_mark="${green?} $ ${normal?}" + local ps_user_mark="${green?} \$ ${normal?}" local ps_root="${red?}\u${red?}" - local ps_root_mark="${red?} # ${normal?}" + local ps_root_mark="${red?} \$ ${normal?}" local ps_path="${yellow?}\w${normal?}" local virtualenv_prompt scm_prompt virtualenv_prompt="$(virtualenv_prompt)" @@ -32,12 +27,11 @@ function pure_prompt() { # make it work case "${EUID:-$UID}" in 0) - PS1="${virtualenv_prompt}${ps_root}@${ps_host}${scm_prompt}:${ps_path}${ps_root_mark}" - ;; - *) - PS1="${virtualenv_prompt}${ps_user}@${ps_host}${scm_prompt}:${ps_path}${ps_user_mark}" + ps_user_mark="${ps_root_mark}" + ps_user="${ps_root}" ;; esac + PS1="${virtualenv_prompt}${ps_user}@${ps_host}${scm_prompt}:${ps_path}${ps_user_mark}" } safe_append_prompt_command pure_prompt From 7c2c2a5525557cbfee98e73de921fd7f7e6811a1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 12:44:18 -0800 Subject: [PATCH 037/239] aliases: run `shfmt` on the whole folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My apologies to future `git blame` hunters β™₯ --- aliases/available/apt.aliases.bash | 6 +- aliases/available/curl.aliases.bash | 24 ++-- aliases/available/docker.aliases.bash | 42 +++--- aliases/available/emacs.aliases.bash | 22 +-- aliases/available/fuck.aliases.bash | 4 +- aliases/available/general.aliases.bash | 41 +++--- aliases/available/kubectl.aliases.bash | 29 ++-- aliases/available/osx.aliases.bash | 4 +- aliases/available/pyrocms.aliases.bash | 178 ++++++++++++------------ aliases/available/rails.aliases.bash | 4 +- aliases/available/systemd.aliases.bash | 34 ++--- aliases/available/textmate.aliases.bash | 10 +- aliases/available/uuidgen.aliases.bash | 10 +- clean_files.txt | 7 +- 14 files changed, 200 insertions(+), 215 deletions(-) diff --git a/aliases/available/apt.aliases.bash b/aliases/available/apt.aliases.bash index b7ef274c81..1d43ffac66 100644 --- a/aliases/available/apt.aliases.bash +++ b/aliases/available/apt.aliases.bash @@ -6,10 +6,8 @@ cite 'about-alias' about-alias 'Apt and dpkg aliases for Ubuntu and Debian distros.' # set apt aliases -function _set_pkg_aliases() -{ - if _command_exists apt - then +function _set_pkg_aliases() { + if _command_exists apt; then alias apts='apt-cache search' alias aptshow='apt-cache show' alias aptinst='sudo apt-get install -V' diff --git a/aliases/available/curl.aliases.bash b/aliases/available/curl.aliases.bash index a6b2b344ed..a1a6d221cd 100644 --- a/aliases/available/curl.aliases.bash +++ b/aliases/available/curl.aliases.bash @@ -4,20 +4,18 @@ cite 'about-alias' about-alias 'Curl aliases for convenience.' # set apt aliases -function _set_pkg_aliases() -{ - if _command_exists curl - then +function _set_pkg_aliases() { + if _command_exists curl; then # follow redirects - alias cl='curl -L' - # follow redirects, download as original name - alias clo='curl -L -O' - # follow redirects, download as original name, continue - alias cloc='curl -L -C - -O' - # follow redirects, download as original name, continue, retry 5 times - alias clocr='curl -L -C - -O --retry 5' - # follow redirects, fetch banner - alias clb='curl -L -I' + alias cl='curl -L' + # follow redirects, download as original name + alias clo='curl -L -O' + # follow redirects, download as original name, continue + alias cloc='curl -L -C - -O' + # follow redirects, download as original name, continue, retry 5 times + alias clocr='curl -L -C - -O --retry 5' + # follow redirects, fetch banner + alias clb='curl -L -I' # see only response headers from a get request alias clhead='curl -D - -so /dev/null' fi diff --git a/aliases/available/docker.aliases.bash b/aliases/available/docker.aliases.bash index 9f005aa7ba..c1b344ce14 100644 --- a/aliases/available/docker.aliases.bash +++ b/aliases/available/docker.aliases.bash @@ -2,31 +2,31 @@ cite 'about-alias' about-alias 'docker abbreviations' alias dk='docker' -alias dklc='docker ps -l' # List last Docker container -alias dklcid='docker ps -l -q' # List last Docker container ID -alias dklcip='docker inspect -f "{{.NetworkSettings.IPAddress}}" $(docker ps -l -q)' # Get IP of last Docker container -alias dkps='docker ps' # List running Docker containers -alias dkpsa='docker ps -a' # List all Docker containers -alias dki='docker images' # List Docker images -alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers +alias dklc='docker ps -l' # List last Docker container +alias dklcid='docker ps -l -q' # List last Docker container ID +alias dklcip='docker inspect -f "{{.NetworkSettings.IPAddress}}" $(docker ps -l -q)' # Get IP of last Docker container +alias dkps='docker ps' # List running Docker containers +alias dkpsa='docker ps -a' # List all Docker containers +alias dki='docker images' # List Docker images +alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers case $OSTYPE in - darwin*|*bsd*|*BSD*) - alias dkrmui='docker images -q -f dangling=true | xargs docker rmi' # Delete all untagged Docker images - ;; - *) - alias dkrmui='docker images -q -f dangling=true | xargs -r docker rmi' # Delete all untagged Docker images - ;; + darwin* | *bsd* | *BSD*) + alias dkrmui='docker images -q -f dangling=true | xargs docker rmi' # Delete all untagged Docker images + ;; + *) + alias dkrmui='docker images -q -f dangling=true | xargs -r docker rmi' # Delete all untagged Docker images + ;; esac -if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then -# Function aliases from docker plugin: - alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container - alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers - alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image - alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments - alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz - alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID +if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2> /dev/null | head -1)" ]; then + # Function aliases from docker plugin: + alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container + alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers + alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image + alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments + alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz + alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID fi alias dkelc='docker exec -it $(dklcid) bash --login' # Enter last container (works with Docker 1.3 and above) alias dkrmflast='docker rm -f $(dklcid)' diff --git a/aliases/available/emacs.aliases.bash b/aliases/available/emacs.aliases.bash index f8e1259b80..78554e0ab4 100644 --- a/aliases/available/emacs.aliases.bash +++ b/aliases/available/emacs.aliases.bash @@ -2,15 +2,15 @@ cite 'about-alias' about-alias 'emacs editor' case $OSTYPE in - linux*) - alias em='emacs' - alias en='emacs -nw' - alias e='emacsclient -n' - alias et='emacsclient -t' - alias ed='emacs --daemon' - alias E='SUDO_EDITOR=emacsclient sudo -e' - ;; - darwin*) - alias em='open -a emacs' - ;; + linux*) + alias em='emacs' + alias en='emacs -nw' + alias e='emacsclient -n' + alias et='emacsclient -t' + alias ed='emacs --daemon' + alias E='SUDO_EDITOR=emacsclient sudo -e' + ;; + darwin*) + alias em='open -a emacs' + ;; esac diff --git a/aliases/available/fuck.aliases.bash b/aliases/available/fuck.aliases.bash index 495ea851a3..6a67a2e908 100644 --- a/aliases/available/fuck.aliases.bash +++ b/aliases/available/fuck.aliases.bash @@ -2,8 +2,8 @@ cite 'about-alias' about-alias 'fuck/please to retry last command with sudo' # Play nicely with 'thefuck' plugin -if ! _command_exists fuck ; then - alias fuck='sudo $(fc -ln -1)' +if ! _command_exists fuck; then + alias fuck='sudo $(fc -ln -1)' fi alias please=fuck alias plz=please diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 3c29928d10..f03ccb1c11 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -1,17 +1,15 @@ cite about-alias about-alias 'general aliases' -if ls --color -d . &> /dev/null -then - alias ls="ls --color=auto" -elif ls -G -d . &> /dev/null -then - alias ls='ls -G' # Compact view, show colors +if ls --color -d . &> /dev/null; then + alias ls="ls --color=auto" +elif ls -G -d . &> /dev/null; then + alias ls='ls -G' # Compact view, show colors fi # List directory contents alias sl=ls -alias la='ls -AF' # Compact view, show hidden +alias la='ls -AF' # Compact view, show hidden alias ll='ls -al' alias l='ls -a' alias l1='ls -1' @@ -26,14 +24,12 @@ alias vbpf="vim ~/.bash_profile" # colored grep # Need to check an existing file for a pattern that will be found to ensure # that the check works when on an OS that supports the color option -if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null -then - alias grep='grep --color=auto' +if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null; then + alias grep='grep --color=auto' fi -if _command_exists gshuf -then - alias shuf=gshuf +if _command_exists gshuf; then + alias shuf=gshuf fi alias c='clear' @@ -66,9 +62,8 @@ alias -- -='cd -' # Go back alias h='history' # Tree -if ! _command_exists tree -then - alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" +if ! _command_exists tree; then + alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" fi # Directory @@ -84,13 +79,13 @@ alias snano="sudo nano" # Display whatever file is regular file or folder catt() { - for i in "$@"; do - if [ -d "$i" ]; then - ls "$i" - else - cat "$i" - fi - done + for i in "$@"; do + if [ -d "$i" ]; then + ls "$i" + else + cat "$i" + fi + done } # The Bash-it aliases were moved to the `bash-it.aliases.bash` file. The intent of this diff --git a/aliases/available/kubectl.aliases.bash b/aliases/available/kubectl.aliases.bash index 440a9041f0..5343ef7f5d 100644 --- a/aliases/available/kubectl.aliases.bash +++ b/aliases/available/kubectl.aliases.bash @@ -5,21 +5,20 @@ cite 'about-alias' about-alias 'kubectl aliases' -function _set_pkg_aliases() -{ - if _command_exists kubectl; then - alias kc='kubectl' - alias kcgp='kubectl get pods' - alias kcgd='kubectl get deployments' - alias kcgn='kubectl get nodes' - alias kcdp='kubectl describe pod' - alias kcdd='kubectl describe deployment' - alias kcdn='kubectl describe node' - alias kcgpan='kubectl get pods --all-namespaces' - alias kcgdan='kubectl get deployments --all-namespaces' - # launches a disposable netshoot pod in the k8s cluster - alias kcnetshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash' - fi +function _set_pkg_aliases() { + if _command_exists kubectl; then + alias kc='kubectl' + alias kcgp='kubectl get pods' + alias kcgd='kubectl get deployments' + alias kcgn='kubectl get nodes' + alias kcdp='kubectl describe pod' + alias kcdd='kubectl describe deployment' + alias kcdn='kubectl describe node' + alias kcgpan='kubectl get pods --all-namespaces' + alias kcgdan='kubectl get deployments --all-namespaces' + # launches a disposable netshoot pod in the k8s cluster + alias kcnetshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash' + fi } _set_pkg_aliases diff --git a/aliases/available/osx.aliases.bash b/aliases/available/osx.aliases.bash index 5e30bc7c20..0217fe81c9 100644 --- a/aliases/available/osx.aliases.bash +++ b/aliases/available/osx.aliases.bash @@ -20,8 +20,8 @@ alias skype='open -a Skype' alias mou='open -a Mou' alias subl='open -a Sublime\ Text' -if [ -s /usr/bin/firefox ] ; then - unalias firefox +if [ -s /usr/bin/firefox ]; then + unalias firefox fi # Requires growlnotify, which can be found in the Growl DMG under "Extras" diff --git a/aliases/available/pyrocms.aliases.bash b/aliases/available/pyrocms.aliases.bash index d19dff9149..8ab76b61cf 100644 --- a/aliases/available/pyrocms.aliases.bash +++ b/aliases/available/pyrocms.aliases.bash @@ -7,146 +7,146 @@ about-alias 'pyrocms abbreviations' ### # general -alias a:cl="php artisan clear-compiled" # Remove the compiled class file -alias a:d="php artisan down" # Put the application into maintenance mode -alias a:e="php artisan env" # Display the current framework environment -alias a:h="php artisan help" # Displays help for a command -alias a:i="php artisan install" # Install the Streams Platform. -alias a:ls="php artisan list" # Lists commands -alias a:mg="php artisan migrate" # Run the database migrations -alias a:op="php artisan optimize" # Optimize the framework for better performance (deprecated) -alias a:pr="php artisan preset" # Swap the front-end scaffolding for the application -alias a:s="php artisan serve" # Serve the application on the PHP development server -alias a:u="php artisan up" # Bring the application out of maintenance mode +alias a:cl="php artisan clear-compiled" # Remove the compiled class file +alias a:d="php artisan down" # Put the application into maintenance mode +alias a:e="php artisan env" # Display the current framework environment +alias a:h="php artisan help" # Displays help for a command +alias a:i="php artisan install" # Install the Streams Platform. +alias a:ls="php artisan list" # Lists commands +alias a:mg="php artisan migrate" # Run the database migrations +alias a:op="php artisan optimize" # Optimize the framework for better performance (deprecated) +alias a:pr="php artisan preset" # Swap the front-end scaffolding for the application +alias a:s="php artisan serve" # Serve the application on the PHP development server +alias a:u="php artisan up" # Bring the application out of maintenance mode # addon -alias a:ad:i="php artisan addon:install" # Install an addon. -alias a:ad:p="php artisan addon:publish" # Publish an the configuration and translations for an addon. -alias a:ad:r="php artisan addon:reinstall" # Reinstall an addon. -alias a:ad:u="php artisan addon:uninstall" # Uninstall an addon. +alias a:ad:i="php artisan addon:install" # Install an addon. +alias a:ad:p="php artisan addon:publish" # Publish an the configuration and translations for an addon. +alias a:ad:r="php artisan addon:reinstall" # Reinstall an addon. +alias a:ad:u="php artisan addon:uninstall" # Uninstall an addon. # app -alias a:ap:n="php artisan app:name" # Set the application namespace -alias a:ap:p="php artisan app:publish" # Publish general application override files. +alias a:ap:n="php artisan app:name" # Set the application namespace +alias a:ap:p="php artisan app:publish" # Publish general application override files. # assets -alias a:as:cl="php artisan assets:clear" # Clear compiled public assets. +alias a:as:cl="php artisan assets:clear" # Clear compiled public assets. # auth -alias a:au:clrs="php artisan auth:clear-resets" # Flush expired password reset tokens +alias a:au:clrs="php artisan auth:clear-resets" # Flush expired password reset tokens # cache -alias a:ca:cl="php artisan cache:clear" # Flush the application cache -alias a:ca:f="php artisan cache:forget" # Remove an item from the cache -alias a:ca:t="php artisan cache:table" # Create a migration for the cache database table +alias a:ca:cl="php artisan cache:clear" # Flush the application cache +alias a:ca:f="php artisan cache:forget" # Remove an item from the cache +alias a:ca:t="php artisan cache:table" # Create a migration for the cache database table # config -alias a:co:ca="php artisan config:cache" # Create a cache file for faster configuration loading -alias a:co:cl="php artisan config:clear" # Remove the configuration cache file +alias a:co:ca="php artisan config:cache" # Create a cache file for faster configuration loading +alias a:co:cl="php artisan config:clear" # Remove the configuration cache file # db -alias a:db:s="php artisan db:seed" # Seed the database with records +alias a:db:s="php artisan db:seed" # Seed the database with records # env -alias a:en:s="php artisan env:set" # Set an environmental value. +alias a:en:s="php artisan env:set" # Set an environmental value. # event -alias a:ev:g="php artisan event:generate" # Generate the missing events and listeners based on registration +alias a:ev:g="php artisan event:generate" # Generate the missing events and listeners based on registration # extension -alias a:ex:i="php artisan extension:install" # Install a extension. -alias a:ex:r="php artisan extension:reinstall" # Reinstall a extension. -alias a:ex:u="php artisan extension:uninstall" # Uninstall a extension. +alias a:ex:i="php artisan extension:install" # Install a extension. +alias a:ex:r="php artisan extension:reinstall" # Reinstall a extension. +alias a:ex:u="php artisan extension:uninstall" # Uninstall a extension. # files -alias a:fi:cl="php artisan files:clean" # Clean missing files from the files table. +alias a:fi:cl="php artisan files:clean" # Clean missing files from the files table. # key -alias a:ke:g="php artisan key:generate" # Set the application key +alias a:ke:g="php artisan key:generate" # Set the application key # make -alias a:mk:ad="php artisan make:addon" # Create a new addon. -alias a:mk:au="php artisan make:auth" # Scaffold basic login and registration views and routes -alias a:mk:cm="php artisan make:command" # Create a new Artisan command -alias a:mk:ct="php artisan make:controller" # Create a new controller class -alias a:mk:ev="php artisan make:event" # Create a new event class -alias a:mk:fa="php artisan make:factory" # Create a new model factory -alias a:mk:j="php artisan make:job" # Create a new job class -alias a:mk:li="php artisan make:listener" # Create a new event listener class -alias a:mk:ma="php artisan make:mail" # Create a new email class -alias a:mk:mw="php artisan make:middleware" # Create a new middleware class -alias a:mk:mg="php artisan make:migration" # Create a new migration file -alias a:mk:md="php artisan make:model" # Create a new Eloquent model class -alias a:mk:no="php artisan make:notification" # Create a new notification class -alias a:mk:po="php artisan make:policy" # Create a new policy class -alias a:mk:pr="php artisan make:provider" # Create a new service provider class -alias a:mk:rq="php artisan make:request" # Create a new form request class -alias a:mk:rs="php artisan make:resource" # Create a new resource -alias a:mk:rl="php artisan make:rule" # Create a new validation rule -alias a:mk:sd="php artisan make:seeder" # Create a new seeder class -alias a:mk:st="php artisan make:stream" # Make a streams entity namespace. -alias a:mk:ts="php artisan make:test" # Create a new test class +alias a:mk:ad="php artisan make:addon" # Create a new addon. +alias a:mk:au="php artisan make:auth" # Scaffold basic login and registration views and routes +alias a:mk:cm="php artisan make:command" # Create a new Artisan command +alias a:mk:ct="php artisan make:controller" # Create a new controller class +alias a:mk:ev="php artisan make:event" # Create a new event class +alias a:mk:fa="php artisan make:factory" # Create a new model factory +alias a:mk:j="php artisan make:job" # Create a new job class +alias a:mk:li="php artisan make:listener" # Create a new event listener class +alias a:mk:ma="php artisan make:mail" # Create a new email class +alias a:mk:mw="php artisan make:middleware" # Create a new middleware class +alias a:mk:mg="php artisan make:migration" # Create a new migration file +alias a:mk:md="php artisan make:model" # Create a new Eloquent model class +alias a:mk:no="php artisan make:notification" # Create a new notification class +alias a:mk:po="php artisan make:policy" # Create a new policy class +alias a:mk:pr="php artisan make:provider" # Create a new service provider class +alias a:mk:rq="php artisan make:request" # Create a new form request class +alias a:mk:rs="php artisan make:resource" # Create a new resource +alias a:mk:rl="php artisan make:rule" # Create a new validation rule +alias a:mk:sd="php artisan make:seeder" # Create a new seeder class +alias a:mk:st="php artisan make:stream" # Make a streams entity namespace. +alias a:mk:ts="php artisan make:test" # Create a new test class # migrate -alias a:mg:fr="php artisan migrate:fresh" # Drop all tables and re-run all migrations -alias a:mg:i="php artisan migrate:install" # Create the migration repository -alias a:mg:rf="php artisan migrate:refresh" # Reset and re-run all migrations -alias a:mg:rs="php artisan migrate:reset" # Rollback all database migrations -alias a:mg:rl="php artisan migrate:rollback" # Rollback the last database migration -alias a:mg:st="php artisan migrate:status" # Show the status of each migration +alias a:mg:fr="php artisan migrate:fresh" # Drop all tables and re-run all migrations +alias a:mg:i="php artisan migrate:install" # Create the migration repository +alias a:mg:rf="php artisan migrate:refresh" # Reset and re-run all migrations +alias a:mg:rs="php artisan migrate:reset" # Rollback all database migrations +alias a:mg:rl="php artisan migrate:rollback" # Rollback the last database migration +alias a:mg:st="php artisan migrate:status" # Show the status of each migration # module -alias a:mo:i="php artisan module:install" # Install a module. -alias a:mo:r="php artisan module:reinstall" # Reinstall a module. -alias a:mo:u="php artisan module:uninstall" # Uninstall a module. +alias a:mo:i="php artisan module:install" # Install a module. +alias a:mo:r="php artisan module:reinstall" # Reinstall a module. +alias a:mo:u="php artisan module:uninstall" # Uninstall a module. # notifications -alias a:no:tb="php artisan notifications:table" # Create a migration for the notifications table +alias a:no:tb="php artisan notifications:table" # Create a migration for the notifications table # package -alias a:pk:d="php artisan package:discover" # Rebuild the cached package manifest +alias a:pk:d="php artisan package:discover" # Rebuild the cached package manifest # queue -alias a:qu:fa="php artisan queue:failed" # List all of the failed queue jobs -alias a:qu:ft="php artisan queue:failed-table" # Create a migration for the failed queue jobs database table -alias a:qu:fl="php artisan queue:flush" # Flush all of the failed queue jobs -alias a:qu:fg="php artisan queue:forget" # Delete a failed queue job -alias a:qu:li="php artisan queue:listen" # Listen to a given queue -alias a:qu:rs="php artisan queue:restart" # Restart queue worker daemons after their current job -alias a:qu:rt="php artisan queue:retry" # Retry a failed queue job -alias a:qu:tb="php artisan queue:table" # Create a migration for the queue jobs database table -alias a:qu:w="php artisan queue:work" # Start processing jobs on the queue as a daemon +alias a:qu:fa="php artisan queue:failed" # List all of the failed queue jobs +alias a:qu:ft="php artisan queue:failed-table" # Create a migration for the failed queue jobs database table +alias a:qu:fl="php artisan queue:flush" # Flush all of the failed queue jobs +alias a:qu:fg="php artisan queue:forget" # Delete a failed queue job +alias a:qu:li="php artisan queue:listen" # Listen to a given queue +alias a:qu:rs="php artisan queue:restart" # Restart queue worker daemons after their current job +alias a:qu:rt="php artisan queue:retry" # Retry a failed queue job +alias a:qu:tb="php artisan queue:table" # Create a migration for the queue jobs database table +alias a:qu:w="php artisan queue:work" # Start processing jobs on the queue as a daemon # route -alias a:ro:ca="php artisan route:cache" # Create a route cache file for faster route registration -alias a:ro:cl="php artisan route:clear" # Remove the route cache file -alias a:ro:ls="php artisan route:list" # List all registered routes +alias a:ro:ca="php artisan route:cache" # Create a route cache file for faster route registration +alias a:ro:cl="php artisan route:clear" # Remove the route cache file +alias a:ro:ls="php artisan route:list" # List all registered routes # schedule -alias a:sc:r="php artisan schedule:run" # Run the scheduled commands +alias a:sc:r="php artisan schedule:run" # Run the scheduled commands # scout -alias a:su:fl="php artisan scout:flush" # Flush all of the model's records from the index -alias a:su:im="php artisan scout:import" # Import the given model into the search index +alias a:su:fl="php artisan scout:flush" # Flush all of the model's records from the index +alias a:su:im="php artisan scout:import" # Import the given model into the search index # session -alias a:se:tb="php artisan session:table" # Create a migration for the session database table +alias a:se:tb="php artisan session:table" # Create a migration for the session database table # storage -alias a:sg:l="php artisan storage:link" # Create a symbolic link from "public/storage" to "storage/app/public" +alias a:sg:l="php artisan storage:link" # Create a symbolic link from "public/storage" to "storage/app/public" # streams -alias a:st:cl="php artisan streams:cleanup" # Cleanup streams entry models. -alias a:st:co="php artisan streams:compile" # Compile streams entry models. -alias a:st:d="php artisan streams:destroy" # Destroy a namespace. -alias a:st:p="php artisan streams:publish" # Publish configuration and translations for streams. -alias a:st:r="php artisan streams:refresh" # Refresh streams generated components. +alias a:st:cl="php artisan streams:cleanup" # Cleanup streams entry models. +alias a:st:co="php artisan streams:compile" # Compile streams entry models. +alias a:st:d="php artisan streams:destroy" # Destroy a namespace. +alias a:st:p="php artisan streams:publish" # Publish configuration and translations for streams. +alias a:st:r="php artisan streams:refresh" # Refresh streams generated components. # tntsearch -alias a:tn:im="php artisan tntsearch:import" # Import the given model into the search index +alias a:tn:im="php artisan tntsearch:import" # Import the given model into the search index # vendor -alias a:ve:p="php artisan vendor:publish" # Publish any publishable assets from vendor packages +alias a:ve:p="php artisan vendor:publish" # Publish any publishable assets from vendor packages # view -alias a:vi:cl="php artisan view:clear" # Clear all compiled view files +alias a:vi:cl="php artisan view:clear" # Clear all compiled view files diff --git a/aliases/available/rails.aliases.bash b/aliases/available/rails.aliases.bash index c776660eeb..b63f9a4b1a 100644 --- a/aliases/available/rails.aliases.bash +++ b/aliases/available/rails.aliases.bash @@ -14,9 +14,9 @@ alias rd='rails destroy' alias dbm='rake db:migrate' alias ss='script/server' -alias ts="thin start" # thin server +alias ts="thin start" # thin server alias sc='script/console' alias restartapp='touch tmp/restart.txt' -alias restart='touch tmp/restart.txt' # restart passenger +alias restart='touch tmp/restart.txt' # restart passenger alias devlog='tail -f log/development.log' alias taild='tail -f log/development.log' # tail dev log diff --git a/aliases/available/systemd.aliases.bash b/aliases/available/systemd.aliases.bash index 19b0eae624..8a82ff96e1 100644 --- a/aliases/available/systemd.aliases.bash +++ b/aliases/available/systemd.aliases.bash @@ -2,21 +2,21 @@ cite 'about-alias' about-alias 'systemd service' case $OSTYPE in - linux*) -# Improve aliases by bringing the common root `sc|scd` + `sre` for action + `u` for user - alias sc='systemctl' - alias scu='systemctl --user' - alias scdr='systemctl daemon-reload' - alias scdru='systemctl --user daemon-reload' - alias scr='systemctl restart' - alias scru='systemctl --user restart' - alias sce='systemctl stop' - alias sceu='systemctl --user stop' - alias scs='systemctl start' - alias scsu='systemctl --user start' -# Keeping previous aliases for a non-breaking change. - alias scue='sceu' - alias scus='scsu' - alias scur='scdru' - ;; + linux*) + # Improve aliases by bringing the common root `sc|scd` + `sre` for action + `u` for user + alias sc='systemctl' + alias scu='systemctl --user' + alias scdr='systemctl daemon-reload' + alias scdru='systemctl --user daemon-reload' + alias scr='systemctl restart' + alias scru='systemctl --user restart' + alias sce='systemctl stop' + alias sceu='systemctl --user stop' + alias scs='systemctl start' + alias scsu='systemctl --user start' + # Keeping previous aliases for a non-breaking change. + alias scue='sceu' + alias scus='scsu' + alias scur='scdru' + ;; esac diff --git a/aliases/available/textmate.aliases.bash b/aliases/available/textmate.aliases.bash index f0f69e4389..ca88eebf33 100644 --- a/aliases/available/textmate.aliases.bash +++ b/aliases/available/textmate.aliases.bash @@ -2,9 +2,9 @@ cite 'about-alias' about-alias 'textmate abbreviations' case $OSTYPE in - darwin*) - # Textmate - alias e='mate . &' - alias et='mate app config db lib public script test spec config.ru Gemfile Rakefile README &' - ;; + darwin*) + # Textmate + alias e='mate . &' + alias et='mate app config db lib public script test spec config.ru Gemfile Rakefile README &' + ;; esac diff --git a/aliases/available/uuidgen.aliases.bash b/aliases/available/uuidgen.aliases.bash index aada05fba0..08478dbdfa 100644 --- a/aliases/available/uuidgen.aliases.bash +++ b/aliases/available/uuidgen.aliases.bash @@ -2,10 +2,10 @@ cite 'uuid-alias' about-alias 'uuidgen aliases' if _command_exists uuid; then # Linux - alias uuidu="uuid | tr '[:lower:]' '[:upper:]'" - alias uuidl=uuid + alias uuidu="uuid | tr '[:lower:]' '[:upper:]'" + alias uuidl=uuid elif _command_exists uuidgen; then # macOS/BSD - alias uuidu="uuidgen" - alias uuid="uuidgen | tr '[:upper:]' '[:lower:]'" # because upper case is like YELLING - alias uuidl=uuid + alias uuidu="uuidgen" + alias uuid="uuidgen | tr '[:upper:]' '[:lower:]'" # because upper case is like YELLING + alias uuidl=uuid fi diff --git a/clean_files.txt b/clean_files.txt index 6ef4d247ff..54180c19fd 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -16,6 +16,7 @@ # root directories # +aliases/ docs/ hooks/ scripts/ @@ -28,12 +29,6 @@ clean_files.txt install.sh lint_clean_files.sh -# aliases -# -aliases/available/dnf.aliases.bash -aliases/available/git.aliases.bash -aliases/available/vim.aliases.bash - # completions # completion/available/apm.completion.bash From 5748aa20a7bda68a4627caa08480f19a2c1fde1e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 12:49:48 -0800 Subject: [PATCH 038/239] alias/docker: `shellcheck` --- aliases/available/docker.aliases.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aliases/available/docker.aliases.bash b/aliases/available/docker.aliases.bash index c1b344ce14..1c49207f49 100644 --- a/aliases/available/docker.aliases.bash +++ b/aliases/available/docker.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'docker abbreviations' alias dk='docker' @@ -19,7 +19,7 @@ case $OSTYPE in ;; esac -if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2> /dev/null | head -1)" ]; then +if _bash-it-component-item-is-enabled plugin docker; then # Function aliases from docker plugin: alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers From 11aa32387ed4045b22f9f0e552904668a44d8013 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 12:56:16 -0800 Subject: [PATCH 039/239] alias/general: `shellcheck` --- aliases/available/general.aliases.bash | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index f03ccb1c11..fddd6a734d 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -1,10 +1,9 @@ -cite about-alias +# shellcheck shell=bash about-alias 'general aliases' -if ls --color -d . &> /dev/null; then +if command ls --color -d . &> /dev/null; then alias ls="ls --color=auto" -elif ls -G -d . &> /dev/null; then - alias ls='ls -G' # Compact view, show colors + # BSD `ls` doesn't need an argument (`-G`) when `$CLICOLOR` is set. fi # List directory contents @@ -18,13 +17,13 @@ alias lf='ls -F' alias _="sudo" # Shortcuts to edit startup files -alias vbrc="vim ~/.bashrc" -alias vbpf="vim ~/.bash_profile" +alias vbrc="${VISUAL:-vim} ~/.bashrc" +alias vbpf="${VISUAL:-vim} ~/.bash_profile" # colored grep # Need to check an existing file for a pattern that will be found to ensure # that the check works when on an OS that supports the color option -if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null; then +if command grep --color=auto "a" "${BASH_IT?}"/*.md &> /dev/null; then alias grep='grep --color=auto' fi @@ -36,12 +35,12 @@ alias c='clear' alias k='clear' alias cls='clear' -alias edit="$EDITOR" -alias pager="$PAGER" +alias edit='${EDITOR:-${ALTERNATE_EDITOR?}}' +alias pager='${PAGER:=less}' alias q='exit' -alias irc="${IRC_CLIENT:=irc}" +alias irc='${IRC_CLIENT:=irc}' # Language aliases alias rb='ruby' @@ -74,13 +73,13 @@ alias rd='rmdir' alias xt="extract" # sudo editors -alias svim="sudo vim" +alias svim="sudo ${VISUAL:-vim}" alias snano="sudo nano" # Display whatever file is regular file or folder -catt() { +function catt() { for i in "$@"; do - if [ -d "$i" ]; then + if [[ -d "$i" ]]; then ls "$i" else cat "$i" @@ -94,5 +93,5 @@ catt() { # aliases and enable just the ones for Bash-it explicitly: # bash-it disable alias general # bash-it enable alias bash-it -# shellcheck source=./bash-it.aliases.bash +# shellcheck source-path=SCRIPTDIR source "$BASH_IT/aliases/available/bash-it.aliases.bash" From 826916be4ffdcb84bb73ca9f3067ea5e51ad24a5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 12:58:47 -0800 Subject: [PATCH 040/239] alias/homesick: `shellcheck` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AlsΓΆ, remove impossible alias. If someone wants it, they can write the function, but since aliases literally don't work this way it seems obvious that nobody has ever used it. --- aliases/available/homesick.aliases.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aliases/available/homesick.aliases.bash b/aliases/available/homesick.aliases.bash index 548efc3b38..00101eedb2 100644 --- a/aliases/available/homesick.aliases.bash +++ b/aliases/available/homesick.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'homesick aliases' # Aliases @@ -19,6 +19,5 @@ alias sikpsh="homesick push dotfiles" alias sikrc="homesick rc dotfiles" alias sikpth="homesick show_path dotfiles" alias sikst="homesick status dotfiles" -alias siktrk="homesick track $1 dotfiles" alias sikulnk="homesick unlink dotfiles" alias sikv="homesick version" From ea6cb6afec7ea07118dc1f2616ed3f2824abeb68 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 13:00:10 -0800 Subject: [PATCH 041/239] alias/laravel: `shellcheck` --- aliases/available/laravel.aliases.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aliases/available/laravel.aliases.bash b/aliases/available/laravel.aliases.bash index 75a51a01b8..50a9749f91 100644 --- a/aliases/available/laravel.aliases.bash +++ b/aliases/available/laravel.aliases.bash @@ -1,9 +1,9 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'laravel artisan abbreviations' # A list of useful laravel aliases -alias laravel="${HOME}/.composer/vendor/bin/laravel" +alias laravel='${HOME?}/.composer/vendor/bin/laravel' # asset alias a:apub='php artisan asset:publish' From 8d30275b8a53745dbcb26a797e81cbd84ab06705 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 13:01:44 -0800 Subject: [PATCH 042/239] alias/msys2: `shellcheck` --- aliases/available/msys2.aliases.bash | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/aliases/available/msys2.aliases.bash b/aliases/available/msys2.aliases.bash index 000ea4bc91..da41cc82a3 100644 --- a/aliases/available/msys2.aliases.bash +++ b/aliases/available/msys2.aliases.bash @@ -1,6 +1,4 @@ -#!/bin/bash - -cite 'about-alias' +# shellcheck shell=bash about-alias 'MSYS2 aliases' LS_COMMON="-hG" @@ -9,7 +7,7 @@ LS_COMMON="$LS_COMMON -I NTUSER.DAT\* -I ntuser.dat\*" # alias # setup the main ls alias if we've established common args -test -n "$LS_COMMON" && alias ls="command ls $LS_COMMON" +alias ls='command ls ${LS_COMMON:-}' alias ll="ls -l" alias la="ls -a" alias lal="ll -a" From 665d9e96a85320b7bf7ebdf756445e86277085b3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 13:05:49 -0800 Subject: [PATCH 043/239] alias/osx: `shellcheck` --- aliases/available/osx.aliases.bash | 39 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/aliases/available/osx.aliases.bash b/aliases/available/osx.aliases.bash index 0217fe81c9..e99bcae6b3 100644 --- a/aliases/available/osx.aliases.bash +++ b/aliases/available/osx.aliases.bash @@ -1,26 +1,26 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'osx-specific aliases' # Desktop Programs -alias fireworks="open -a '/Applications/Adobe Fireworks CS3/Adobe Fireworks CS3.app'" -alias photoshop="open -a '/Applications/Adobe Photoshop CS3/Adobe Photoshop.app'" -alias preview="open -a '$PREVIEW'" -alias xcode="open -a '/Applications/XCode.app'" -alias filemerge="open -a '/Developer/Applications/Utilities/FileMerge.app'" -alias safari="open -a safari" -alias firefox="open -a firefox" -alias chrome="open -a google\ chrome" -alias chromium="open -a chromium" -alias dashcode="open -a dashcode" +alias fireworks='open -a "/Applications/Adobe Fireworks CS3/Adobe Fireworks CS3.app"' +alias photoshop='open -a "/Applications/Adobe Photoshop CS3/Adobe Photoshop.app"' +alias preview='open -a "${PREVIEW?}"' +alias xcode='open -a "/Applications/XCode.app"' +alias filemerge='open -a "/Developer/Applications/Utilities/FileMerge.app"' +alias safari='open -a safari' +alias firefox='open -a firefox' +alias chrome='open -a "Google Chrome"' +alias chromium='open -a chromium' +alias dashcode='open -a dashcode' alias f='open -a Finder ' alias fh='open -a Finder .' alias textedit='open -a TextEdit' alias hex='open -a "Hex Fiend"' alias skype='open -a Skype' alias mou='open -a Mou' -alias subl='open -a Sublime\ Text' +alias subl='open -a "Sublime Text"' -if [ -s /usr/bin/firefox ]; then +if [[ -s /usr/bin/firefox ]]; then unalias firefox fi @@ -37,19 +37,20 @@ alias whotunes='lsof -r 2 -n -P -F n -c iTunes -a -i TCP@`hostname`:3689' alias flush='dscacheutil -flushcache' # Show/hide hidden files (for Mac OS X Mavericks) -alias showhidden="defaults write com.apple.finder AppleShowAllFiles TRUE" -alias hidehidden="defaults write com.apple.finder AppleShowAllFiles FALSE" +alias showhidden='defaults write com.apple.finder AppleShowAllFiles TRUE' +alias hidehidden='defaults write com.apple.finder AppleShowAllFiles FALSE' # From http://apple.stackexchange.com/questions/110343/copy-last-command-in-terminal -alias copyLastCmd='fc -ln -1 | awk '\''{$1=$1}1'\'' ORS='\'''\'' | pbcopy' +# shellcheck disable=SC2142 # The quoting confuses `shellcheck`... +alias copyLastCmd="fc -ln -1 | awk '{\$1=\$1}1' ORS='' | pbcopy" # Use Finder's Quick Look on a file (^C or space to close) alias ql='qlmanage -p 2>/dev/null' # Mute/Unmute the system volume. Plays nice with all other volume settings. -alias mute="osascript -e 'set volume output muted true'" -alias unmute="osascript -e 'set volume output muted false'" +alias mute='osascript -e "set volume output muted true"' +alias unmute='osascript -e "set volume output muted false"' # Pin to the tail of long commands for an audible alert after long processes ## curl http://downloads.com/hugefile.zip; lmk -alias lmk="say 'Process complete.'" +alias lmk='say "Process complete."' From 604e5c5040451b099665d30e3055874a36904dfb Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 13:06:39 -0800 Subject: [PATCH 044/239] alias/todo.txt-cli: `shellcheck` --- aliases/available/todo.txt-cli.aliases.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aliases/available/todo.txt-cli.aliases.bash b/aliases/available/todo.txt-cli.aliases.bash index 5bf35d0d77..359321a4b0 100644 --- a/aliases/available/todo.txt-cli.aliases.bash +++ b/aliases/available/todo.txt-cli.aliases.bash @@ -1,8 +1,8 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'todo.txt-cli abbreviations' -alias tls="$TODO ls" -alias ta="$TODO a" -alias trm="$TODO rm" -alias tdo="$TODO do" -alias tpri="$TODO pri" +alias tls='"${TODO?}" ls' +alias ta='"${TODO?}" a' +alias trm='"${TODO?}" rm' +alias tdo='"${TODO?}" do' +alias tpri='"${TODO?}" pri' From 27bfc966ac7a84e5a50d131e0a9c80c35a2e8bca Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 16 Jan 2022 13:15:16 -0800 Subject: [PATCH 045/239] aliases: add shellcheck headers --- aliases/available/ag.aliases.bash | 2 +- aliases/available/ansible.aliases.bash | 2 +- aliases/available/atom.aliases.bash | 2 +- aliases/available/bash-it.aliases.bash | 2 +- aliases/available/bolt.aliases.bash | 2 +- aliases/available/bundler.aliases.bash | 2 +- aliases/available/clipboard.aliases.bash | 1 - aliases/available/composer.aliases.bash | 2 +- aliases/available/curl.aliases.bash | 4 +--- aliases/available/dnf.aliases.bash | 1 - aliases/available/docker-compose.aliases.bash | 2 +- aliases/available/emacs.aliases.bash | 2 +- aliases/available/fuck.aliases.bash | 2 +- aliases/available/git.aliases.bash | 1 - aliases/available/gitsvn.aliases.bash | 2 +- aliases/available/heroku.aliases.bash | 2 +- aliases/available/hg.aliases.bash | 2 +- aliases/available/homebrew-cask.aliases.bash | 6 ++---- aliases/available/homebrew.aliases.bash | 6 ++---- aliases/available/jitsu.aliases.bash | 2 +- aliases/available/kubectl.aliases.bash | 6 +----- aliases/available/maven.aliases.bash | 2 +- aliases/available/node.aliases.bash | 2 +- aliases/available/npm.aliases.bash | 2 +- aliases/available/phoenix.aliases.bash | 2 +- aliases/available/puppet.aliases.bash | 2 +- aliases/available/pyrocms.aliases.bash | 2 +- aliases/available/rails.aliases.bash | 2 +- aliases/available/svn.aliases.bash | 2 +- aliases/available/systemd.aliases.bash | 2 +- aliases/available/terraform.aliases.bash | 6 ++---- aliases/available/terragrunt.aliases.bash | 6 ++---- aliases/available/textmate.aliases.bash | 2 +- aliases/available/tmux.aliases.bash | 2 +- aliases/available/uuidgen.aliases.bash | 2 +- aliases/available/vagrant.aliases.bash | 2 +- aliases/available/vault.aliases.bash | 2 +- aliases/available/vim.aliases.bash | 1 - aliases/available/yarn.aliases.bash | 2 +- 39 files changed, 39 insertions(+), 57 deletions(-) diff --git a/aliases/available/ag.aliases.bash b/aliases/available/ag.aliases.bash index e3157f9433..7f9af7dad5 100644 --- a/aliases/available/ag.aliases.bash +++ b/aliases/available/ag.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'the silver searcher (ag) aliases' ## Summary for args to less: diff --git a/aliases/available/ansible.aliases.bash b/aliases/available/ansible.aliases.bash index 1c53a88e3f..04c5d2801a 100644 --- a/aliases/available/ansible.aliases.bash +++ b/aliases/available/ansible.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'ansible abbreviations' alias ans=ansible diff --git a/aliases/available/atom.aliases.bash b/aliases/available/atom.aliases.bash index 8d70cffaa5..6868e2cc2e 100644 --- a/aliases/available/atom.aliases.bash +++ b/aliases/available/atom.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'Atom.io editor abbreviations' alias a='atom' diff --git a/aliases/available/bash-it.aliases.bash b/aliases/available/bash-it.aliases.bash index d2975667a0..1f16638b0a 100644 --- a/aliases/available/bash-it.aliases.bash +++ b/aliases/available/bash-it.aliases.bash @@ -1,4 +1,4 @@ -cite about-alias +# shellcheck shell=bash about-alias 'Aliases for the bash-it command (these aliases are automatically included with the "general" aliases)' # Common misspellings of bash-it diff --git a/aliases/available/bolt.aliases.bash b/aliases/available/bolt.aliases.bash index 8490f71031..556dd7fe00 100644 --- a/aliases/available/bolt.aliases.bash +++ b/aliases/available/bolt.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'puppet bolt aliases' # Aliases diff --git a/aliases/available/bundler.aliases.bash b/aliases/available/bundler.aliases.bash index fc20f4ff9d..1eb0086245 100644 --- a/aliases/available/bundler.aliases.bash +++ b/aliases/available/bundler.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'ruby bundler' # Bundler Commands diff --git a/aliases/available/clipboard.aliases.bash b/aliases/available/clipboard.aliases.bash index 4c7e6f5bdf..2a5c3e8c98 100644 --- a/aliases/available/clipboard.aliases.bash +++ b/aliases/available/clipboard.aliases.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite 'about-alias' about-alias 'xclip shortcuts' alias pbcopy="xclip -selection clipboard" diff --git a/aliases/available/composer.aliases.bash b/aliases/available/composer.aliases.bash index 5ccb2e2463..85401abb82 100644 --- a/aliases/available/composer.aliases.bash +++ b/aliases/available/composer.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'common composer abbreviations' # Aliases diff --git a/aliases/available/curl.aliases.bash b/aliases/available/curl.aliases.bash index a1a6d221cd..a270e416d2 100644 --- a/aliases/available/curl.aliases.bash +++ b/aliases/available/curl.aliases.bash @@ -1,6 +1,4 @@ -#!/bin/bash - -cite 'about-alias' +# shellcheck shell=bash about-alias 'Curl aliases for convenience.' # set apt aliases diff --git a/aliases/available/dnf.aliases.bash b/aliases/available/dnf.aliases.bash index 9d9f02673a..25007c23c7 100644 --- a/aliases/available/dnf.aliases.bash +++ b/aliases/available/dnf.aliases.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite 'about-alias' about-alias 'dnf aliases for fedora 22+ distros' alias dnfl="dnf list" # List packages diff --git a/aliases/available/docker-compose.aliases.bash b/aliases/available/docker-compose.aliases.bash index 3583be8fef..a2f637c006 100644 --- a/aliases/available/docker-compose.aliases.bash +++ b/aliases/available/docker-compose.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'docker-compose abbreviations' alias dco="docker-compose" diff --git a/aliases/available/emacs.aliases.bash b/aliases/available/emacs.aliases.bash index 78554e0ab4..a4e4111ada 100644 --- a/aliases/available/emacs.aliases.bash +++ b/aliases/available/emacs.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'emacs editor' case $OSTYPE in diff --git a/aliases/available/fuck.aliases.bash b/aliases/available/fuck.aliases.bash index 6a67a2e908..4cfa52d81b 100644 --- a/aliases/available/fuck.aliases.bash +++ b/aliases/available/fuck.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'fuck/please to retry last command with sudo' # Play nicely with 'thefuck' plugin diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index a63faa47ef..507037e1d0 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite 'about-alias' about-alias 'common git abbreviations' alias g='git' diff --git a/aliases/available/gitsvn.aliases.bash b/aliases/available/gitsvn.aliases.bash index feb608beef..3c578445a7 100644 --- a/aliases/available/gitsvn.aliases.bash +++ b/aliases/available/gitsvn.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'common git-svn abbreviations' # Aliases diff --git a/aliases/available/heroku.aliases.bash b/aliases/available/heroku.aliases.bash index a749d4247d..4c82259438 100644 --- a/aliases/available/heroku.aliases.bash +++ b/aliases/available/heroku.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'heroku task abbreviations' # heroku diff --git a/aliases/available/hg.aliases.bash b/aliases/available/hg.aliases.bash index eea819ff8a..d9101a03c4 100644 --- a/aliases/available/hg.aliases.bash +++ b/aliases/available/hg.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'mercurial abbreviations' alias hs='hg status' diff --git a/aliases/available/homebrew-cask.aliases.bash b/aliases/available/homebrew-cask.aliases.bash index 57d8161c9e..43d206d4a9 100644 --- a/aliases/available/homebrew-cask.aliases.bash +++ b/aliases/available/homebrew-cask.aliases.bash @@ -1,7 +1,5 @@ -# Some aliases for Homebrew Cask - -cite 'about-alias' -about-alias 'homebrew-cask abbreviations' +# shellcheck shell=bash +about-alias 'Some aliases for Homebrew Cask' alias bcin='brew cask install' alias bcrm='brew cask uninstall' diff --git a/aliases/available/homebrew.aliases.bash b/aliases/available/homebrew.aliases.bash index 15907518c3..f35a38d382 100644 --- a/aliases/available/homebrew.aliases.bash +++ b/aliases/available/homebrew.aliases.bash @@ -1,7 +1,5 @@ -# Some aliases for Homebrew - -cite 'about-alias' -about-alias 'homebrew abbreviations' +# shellcheck shell=bash +about-alias 'Some aliases for Homebrew' alias bup='brew update && brew upgrade' alias bout='brew outdated' diff --git a/aliases/available/jitsu.aliases.bash b/aliases/available/jitsu.aliases.bash index 91e96849d0..f056e74989 100644 --- a/aliases/available/jitsu.aliases.bash +++ b/aliases/available/jitsu.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'jitsu task abbreviations' # jitsu diff --git a/aliases/available/kubectl.aliases.bash b/aliases/available/kubectl.aliases.bash index 5343ef7f5d..aaca4ca259 100644 --- a/aliases/available/kubectl.aliases.bash +++ b/aliases/available/kubectl.aliases.bash @@ -1,8 +1,4 @@ -#!/bin/bash -# -# -binaryanomaly - -cite 'about-alias' +# shellcheck shell=bash about-alias 'kubectl aliases' function _set_pkg_aliases() { diff --git a/aliases/available/maven.aliases.bash b/aliases/available/maven.aliases.bash index f8a44a1c9a..737826eb47 100644 --- a/aliases/available/maven.aliases.bash +++ b/aliases/available/maven.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'maven abbreviations' alias mci='mvn clean install' diff --git a/aliases/available/node.aliases.bash b/aliases/available/node.aliases.bash index a1408f263d..a9e29743b4 100644 --- a/aliases/available/node.aliases.bash +++ b/aliases/available/node.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'the Node.js environment aliases' # alias to setup nodejs development environment diff --git a/aliases/available/npm.aliases.bash b/aliases/available/npm.aliases.bash index bd742d5d15..27cf5c9f6a 100644 --- a/aliases/available/npm.aliases.bash +++ b/aliases/available/npm.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'common npm abbreviations' # Aliases diff --git a/aliases/available/phoenix.aliases.bash b/aliases/available/phoenix.aliases.bash index 64728a2ee9..08cef4f406 100644 --- a/aliases/available/phoenix.aliases.bash +++ b/aliases/available/phoenix.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'phoenix abbreviations' # Phoenix Commands diff --git a/aliases/available/puppet.aliases.bash b/aliases/available/puppet.aliases.bash index 15b6992354..c92d13b1f7 100644 --- a/aliases/available/puppet.aliases.bash +++ b/aliases/available/puppet.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'puppet aliases' # Aliases diff --git a/aliases/available/pyrocms.aliases.bash b/aliases/available/pyrocms.aliases.bash index 8ab76b61cf..77865a23a3 100644 --- a/aliases/available/pyrocms.aliases.bash +++ b/aliases/available/pyrocms.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'pyrocms abbreviations' ### diff --git a/aliases/available/rails.aliases.bash b/aliases/available/rails.aliases.bash index b63f9a4b1a..4de4faff30 100644 --- a/aliases/available/rails.aliases.bash +++ b/aliases/available/rails.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'rails abbreviations' # Rails Commands diff --git a/aliases/available/svn.aliases.bash b/aliases/available/svn.aliases.bash index 3d6d263e09..4d3de464c3 100644 --- a/aliases/available/svn.aliases.bash +++ b/aliases/available/svn.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'common svn abbreviations' # Aliases diff --git a/aliases/available/systemd.aliases.bash b/aliases/available/systemd.aliases.bash index 8a82ff96e1..57351ae0b4 100644 --- a/aliases/available/systemd.aliases.bash +++ b/aliases/available/systemd.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'systemd service' case $OSTYPE in diff --git a/aliases/available/terraform.aliases.bash b/aliases/available/terraform.aliases.bash index 09380868d3..baa9b0c7ce 100644 --- a/aliases/available/terraform.aliases.bash +++ b/aliases/available/terraform.aliases.bash @@ -1,7 +1,5 @@ -# Aliases for Terraform and Terragrunt - -cite 'about-alias' -about-alias 'Terraform abbreviations' +# shellcheck shell=bash +about-alias 'Aliases for Terraform and Terragrunt' alias tf='terraform' alias tfv='terraform validate' diff --git a/aliases/available/terragrunt.aliases.bash b/aliases/available/terragrunt.aliases.bash index 9395b35134..94892901f3 100644 --- a/aliases/available/terragrunt.aliases.bash +++ b/aliases/available/terragrunt.aliases.bash @@ -1,7 +1,5 @@ -# Aliases for Terraform and Terragrunt - -cite 'about-alias' -about-alias 'Terragrunt abbreviations' +# shellcheck shell=bash +about-alias 'Aliases for Terraform and Terragrunt' alias tg='terragrunt' alias tgv='terragrunt validate' diff --git a/aliases/available/textmate.aliases.bash b/aliases/available/textmate.aliases.bash index ca88eebf33..e53eed1a1a 100644 --- a/aliases/available/textmate.aliases.bash +++ b/aliases/available/textmate.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'textmate abbreviations' case $OSTYPE in diff --git a/aliases/available/tmux.aliases.bash b/aliases/available/tmux.aliases.bash index 1b07f14952..192db5b589 100644 --- a/aliases/available/tmux.aliases.bash +++ b/aliases/available/tmux.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'Tmux terminal multiplexer' alias txl='tmux ls' diff --git a/aliases/available/uuidgen.aliases.bash b/aliases/available/uuidgen.aliases.bash index 08478dbdfa..45c368204f 100644 --- a/aliases/available/uuidgen.aliases.bash +++ b/aliases/available/uuidgen.aliases.bash @@ -1,4 +1,4 @@ -cite 'uuid-alias' +# shellcheck shell=bash about-alias 'uuidgen aliases' if _command_exists uuid; then # Linux diff --git a/aliases/available/vagrant.aliases.bash b/aliases/available/vagrant.aliases.bash index d479fb2b13..a949cbb3d2 100644 --- a/aliases/available/vagrant.aliases.bash +++ b/aliases/available/vagrant.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'vagrant aliases' # Aliases diff --git a/aliases/available/vault.aliases.bash b/aliases/available/vault.aliases.bash index d2ad8e74b7..4d083fb609 100644 --- a/aliases/available/vault.aliases.bash +++ b/aliases/available/vault.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'vault aliases' # Aliases diff --git a/aliases/available/vim.aliases.bash b/aliases/available/vim.aliases.bash index b426d27004..f80687640b 100644 --- a/aliases/available/vim.aliases.bash +++ b/aliases/available/vim.aliases.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite 'about-alias' about-alias 'vim abbreviations' _command_exists vim || return diff --git a/aliases/available/yarn.aliases.bash b/aliases/available/yarn.aliases.bash index b50535b9f6..a2fb6d0dc5 100644 --- a/aliases/available/yarn.aliases.bash +++ b/aliases/available/yarn.aliases.bash @@ -1,4 +1,4 @@ -cite 'about-alias' +# shellcheck shell=bash about-alias 'yarn package manager aliases' # Aliases From 12a734cb49183ee26fa246b8c502aee62d660f4a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 14:29:51 -0800 Subject: [PATCH 046/239] aliases/general: use single quotes as much as possible --- aliases/available/general.aliases.bash | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index fddd6a734d..08affb7927 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -2,7 +2,7 @@ about-alias 'general aliases' if command ls --color -d . &> /dev/null; then - alias ls="ls --color=auto" + alias ls='ls --color=auto' # BSD `ls` doesn't need an argument (`-G`) when `$CLICOLOR` is set. fi @@ -14,11 +14,11 @@ alias l='ls -a' alias l1='ls -1' alias lf='ls -F' -alias _="sudo" +alias _='sudo' # Shortcuts to edit startup files -alias vbrc="${VISUAL:-vim} ~/.bashrc" -alias vbpf="${VISUAL:-vim} ~/.bash_profile" +alias vbrc='${VISUAL:-vim} ~/.bashrc' +alias vbpf='${VISUAL:-vim} ~/.bash_profile' # colored grep # Need to check an existing file for a pattern that will be found to ensure @@ -70,11 +70,11 @@ alias md='mkdir -p' alias rd='rmdir' # Shorten extract -alias xt="extract" +alias xt='extract' # sudo editors -alias svim="sudo ${VISUAL:-vim}" -alias snano="sudo nano" +alias svim='sudo ${VISUAL:-vim}' +alias snano='sudo nano' # Display whatever file is regular file or folder function catt() { From c982a881a2d824c31a9079bb1929345fe82e9117 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 14 Feb 2022 16:00:15 -0800 Subject: [PATCH 047/239] completion/aliases: typo --- plugins/available/alias-completion.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index 84c59a1e7f..d23779f798 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -2,4 +2,4 @@ # stub for renamed file _enable-completion aliases && _disable-plugin alias-completion -source "${BASH_IT?}/completion/aliases.completion.bash" +source "${BASH_IT?}/completion/available/aliases.completion.bash" From 4ba11dbaa2f8872a0d94b68cf5bd7f30ce3fa390 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 22:48:19 -0800 Subject: [PATCH 048/239] completion/aliases: redirection, quote MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AlsΓΆ, some aliases are returned by `alias -p` with `alias -- xxxxx`...which confuses the function, so handle it specially. --- completion/available/aliases.completion.bash | 38 +++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/completion/available/aliases.completion.bash b/completion/available/aliases.completion.bash index bdcaf9173c..f9cc1ed181 100644 --- a/completion/available/aliases.completion.bash +++ b/completion/available/aliases.completion.bash @@ -10,7 +10,7 @@ about-plugin 'Automatic completion of aliases' # Automatically add completion for all aliases to commands having completion functions function _bash-it-component-completion-callback-on-init-aliases() { local namespace="alias_completion" - local tmp_file completion_loader alias_name line completions + local tmp_file completion_loader alias_name line completions chars local alias_arg_words new_completion compl_func compl_wrapper alias_defn # create array of function completion triggers, keeping multi-word triggers together @@ -20,28 +20,42 @@ function _bash-it-component-completion-callback-on-init-aliases() { completions=("${completions[@]##complete -* * -}") # strip all but last option plus trigger(s) completions=("${completions[@]#complete -}") # strip anything missed completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s) + completions=("${completions[@]#? }") # strip anything missed + #TODO: this will fail on some completions... # create temporary file for wrapper functions and completions tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1 - completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')" + IFS=$'\n' read -r completion_loader < <(complete -p -D 2> /dev/null) + if [[ "${completion_loader#complete }" =~ '-F'[[:space:]]([[:alnum:]_]+)[[:space:]] ]]; then + completion_loader="${BASH_REMATCH[1]}" + else + completion_loader="" + fi # read in " '' ''" lines from defined aliases # some aliases do have backslashes that needs to be interpreted # shellcheck disable=SC2162 while read line; do + line="${line#alias -- }" line="${line#alias }" alias_name="${line%%=*}" - alias_defn="${line#*=}" # alias definition + alias_defn="${line#*=\'}" # alias definition + alias_defn="${alias_defn%\'}" alias_cmd="${alias_defn%%[[:space:]]*}" # first word of alias - alias_cmd="${alias_cmd:1}" # lose opening quotation mark - alias_args="${alias_defn#*[[:space:]]}" # everything after first word - alias_args="${alias_args%\'}" # lose ending quotation mark + if [[ ${alias_defn} == ${alias_cmd} ]]; then + alias_args='' + else + alias_args="${alias_defn#*[[:space:]]}" # everything after first word + fi # skip aliases to pipes, boolean control structures and other command lists - [[ "${alias_args}" =~ [\|\&\;\)\(\n] ]] && continue + chars='\|\&\;\)\(\n\<\>' + if [[ "${alias_defn}" =~ [$chars] ]]; then + continue + fi # avoid expanding wildcards - read -a alias_arg_words <<< "$alias_args" + read -ra alias_arg_words <<< "$alias_args" # skip alias if there is no completion function triggered by the aliased command if ! _bash-it-array-contains-element "$alias_cmd" "${completions[@]}"; then @@ -65,8 +79,8 @@ function _bash-it-component-completion-callback-on-init-aliases() { if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then compl_wrapper="_${namespace}::${alias_name}" echo "function $compl_wrapper { - local compl_word=\$2 - local prec_word=\$3 + local compl_word=\${2?} + local prec_word=\${3?} # check if prec_word is the alias itself. if so, replace it # with the last word in the unaliased form, i.e., # alias_cmd + ' ' + alias_args. @@ -75,11 +89,11 @@ function _bash-it-component-completion-callback-on-init-aliases() { prec_word=\${prec_word#* } fi (( COMP_CWORD += ${#alias_arg_words[@]} )) - COMP_WORDS=($alias_cmd $alias_args \${COMP_WORDS[@]:1}) + COMP_WORDS=(\"$alias_cmd\" \"${alias_arg_words[@]}\" \"\${COMP_WORDS[@]:1}\") (( COMP_POINT -= \${#COMP_LINE} )) COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args} (( COMP_POINT += \${#COMP_LINE} )) - $compl_func \"$alias_cmd\" \"\$compl_word\" \"\$prec_word\" + \"$compl_func\" \"$alias_cmd\" \"\$compl_word\" \"\$prec_word\" }" >> "$tmp_file" new_completion="${new_completion/ -F $compl_func / -F $compl_wrapper }" fi From 61b6393a4a0cb161d26d875626a09c0a6faf57d4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 14 Feb 2022 15:40:37 -0800 Subject: [PATCH 049/239] lib/log: //echo/printf - Replace `echo -e` with `printf` in `_bash-it-log-message()`. - Local positional parameters to allow for defaults. - Use `if`/`then` properly. - Clean up use of `$BASH_IT_LOG_PREFIX` slightly (eliminate duplicate colons). --- lib/log.bash | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/log.bash b/lib/log.bash index 444a685446..d37859ccd5 100644 --- a/lib/log.bash +++ b/lib/log.bash @@ -55,8 +55,15 @@ function _bash-it-log-message() { param '3: message to log' group 'log' - message="$2${BASH_IT_LOG_PREFIX:-default: }$3" - _has_colors && echo -e "$1${message}${echo_normal:-}" || echo -e "${message}" + local prefix="${BASH_IT_LOG_PREFIX:-default}" + local color="${1-${echo_cyan:-}}" + local level="${2:-TRACE}" + local message="${level%: }: ${prefix%: }: ${3?}" + if _has_colors; then + printf '%b%s%b\n' "${color}" "${message}" "${echo_normal:-}" + else + printf '%s\n' "${message}" + fi } function _log_debug() { @@ -65,8 +72,9 @@ function _log_debug() { example '$ _log_debug "Loading plugin git..."' group 'log' - [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_INFO?}" ]] || return 0 - _bash-it-log-message "${echo_green:-}" "DEBUG: " "$1" + if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_INFO?}" ]]; then + _bash-it-log-message "${echo_green:-}" "DEBUG: " "$1" + fi } function _log_warning() { @@ -75,8 +83,9 @@ function _log_warning() { example '$ _log_warning "git binary not found, disabling git plugin..."' group 'log' - [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_WARNING?}" ]] || return 0 - _bash-it-log-message "${echo_yellow:-}" " WARN: " "$1" + if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_WARNING?}" ]]; then + _bash-it-log-message "${echo_yellow:-}" " WARN: " "$1" + fi } function _log_error() { @@ -85,6 +94,7 @@ function _log_error() { example '$ _log_error "Failed to load git plugin..."' group 'log' - [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_ERROR?}" ]] || return 0 - _bash-it-log-message "${echo_red:-}" "ERROR: " "$1" + if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_ERROR?}" ]]; then + _bash-it-log-message "${echo_red:-}" "ERROR: " "$1" + fi } From e7b91e7be5255255fafdf7cac51d8e5352975e33 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 15 Feb 2022 22:20:19 -0800 Subject: [PATCH 050/239] lib/log: use newly supported `composure.sh` feature - these functions can now run even if `composure.sh` has *not* been loaded at all! --- lib/log.bash | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/log.bash b/lib/log.bash index d37859ccd5..87b9ddf142 100644 --- a/lib/log.bash +++ b/lib/log.bash @@ -49,11 +49,11 @@ function _has_colors() { } function _bash-it-log-message() { - about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix' - param '1: color of the message' - param '2: log level to print before the prefix' - param '3: message to log' - group 'log' + : _about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix' + : _param '1: color of the message' + : _param '2: log level to print before the prefix' + : _param '3: message to log' + : _group 'log' local prefix="${BASH_IT_LOG_PREFIX:-default}" local color="${1-${echo_cyan:-}}" @@ -67,10 +67,10 @@ function _bash-it-log-message() { } function _log_debug() { - about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_INFO' - param '1: message to log' - example '$ _log_debug "Loading plugin git..."' - group 'log' + : _about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_INFO' + : _param '1: message to log' + : _example '$ _log_debug "Loading plugin git..."' + : _group 'log' if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_INFO?}" ]]; then _bash-it-log-message "${echo_green:-}" "DEBUG: " "$1" @@ -78,10 +78,10 @@ function _log_debug() { } function _log_warning() { - about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING' - param '1: message to log' - example '$ _log_warning "git binary not found, disabling git plugin..."' - group 'log' + : _about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING' + : _param '1: message to log' + : _example '$ _log_warning "git binary not found, disabling git plugin..."' + : _group 'log' if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_WARNING?}" ]]; then _bash-it-log-message "${echo_yellow:-}" " WARN: " "$1" @@ -89,10 +89,10 @@ function _log_warning() { } function _log_error() { - about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR' - param '1: message to log' - example '$ _log_error "Failed to load git plugin..."' - group 'log' + : _about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR' + : _param '1: message to log' + : _example '$ _log_error "Failed to load git plugin..."' + : _group 'log' if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_ERROR?}" ]]; then _bash-it-log-message "${echo_red:-}" "ERROR: " "$1" From b3ef9ea209dfdc59680c2296912a8c28f7c2a47a Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Wed, 16 Feb 2022 20:55:08 +0530 Subject: [PATCH 051/239] lib/helpers: Don't rm "$profile_path" before writing to it When the file is being re-created, we write to it, instead of appending to it. So, the rm here is unnecessary and prevents users from linking the profile file to another location that is potentially under version control. For instance, once could link to a profile file located at "$BASH_IT_CUSTOM/profiles/*.bash_it". --- lib/helpers.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 4728541a65..abcbc6758d 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -511,7 +511,6 @@ function _bash-it-profile-save() { case "$RESP" in [yY]) echo -e "${echo_green?}Overwriting profile '$name'...${echo_reset_color?}" - rm "$profile_path" break ;; [nN] | "") From 6b08284928b0db4cc8dcfc6f58f34484e2f1ef6d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 12:13:43 -0800 Subject: [PATCH 052/239] Update "preexec" from "https://github.com/rcaloras/bash-preexec@master" git-vendor-name: preexec git-vendor-dir: vendor/github.com/rcaloras/bash-preexec git-vendor-repository: https://github.com/rcaloras/bash-preexec git-vendor-ref: fd2ffa8876d3940c97ffdc3cc807e43277cf72da --- lib/preexec.bash | 8 ++--- .../rcaloras/bash-preexec/bash-preexec.sh | 32 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/preexec.bash b/lib/preexec.bash index 17cabdf974..db54a60006 100644 --- a/lib/preexec.bash +++ b/lib/preexec.bash @@ -4,9 +4,8 @@ # Load the `bash-preexec.sh` library, and define helper functions ## Prepare, load, fix, and install `bash-preexec.sh` -: "${PROMPT_COMMAND:=}" -# Disable immediate `$PROMPT_COMMAND` modification +# Disable `$PROMPT_COMMAND` modification for now. __bp_delay_install="delayed" # shellcheck source-path=SCRIPTDIR/../vendor/github.com/rcaloras/bash-preexec @@ -20,7 +19,6 @@ function __bp_require_not_readonly() { :; } # Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 __bp_enable_subshells= # blank -set +T # Modify `$PROMPT_COMMAND` now __bp_install_after_session_init @@ -42,7 +40,7 @@ function safe_append_prompt_command { local prompt_re f __bp_trim_whitespace f "${1?}" - if [ "${__bp_imported:-missing}" == "defined" ]; then + if [ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]; then # We are using bash-preexec if ! __check_precmd_conflict "${f}"; then precmd_functions+=("${f}") @@ -71,7 +69,7 @@ function safe_append_preexec { local prompt_re f __bp_trim_whitespace f "${1?}" - if [ "${__bp_imported:-missing}" == "defined" ]; then + if [ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]; then # We are using bash-preexec if ! __check_preexec_conflict "${f}"; then preexec_functions+=("${f}") diff --git a/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh b/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh index c23d0381cc..5f1208c33e 100644 --- a/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh +++ b/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh @@ -32,11 +32,20 @@ # using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. If you override # either of these after bash-preexec has been installed it will most likely break. +# Make sure this is bash that's running and return otherwise. +if [[ -z "${BASH_VERSION:-}" ]]; then + return 1; +fi + # Avoid duplicate inclusion -if [[ "${__bp_imported:-}" == "defined" ]]; then +if [[ -n "${bash_preexec_imported:-}" ]]; then return 0 fi -__bp_imported="defined" +bash_preexec_imported="defined" + +# WARNING: This variable is no longer used and should not be relied upon. +# Use ${bash_preexec_imported} instead. +__bp_imported="${bash_preexec_imported}" # Should be available to each precmd and preexec # functions, should they want it. $? and $_ are available as $? and $_, but @@ -70,7 +79,8 @@ __bp_require_not_readonly() { # history even if it starts with a space. __bp_adjust_histcontrol() { local histcontrol - histcontrol="${HISTCONTROL//ignorespace}" + histcontrol="${HISTCONTROL:-}" + histcontrol="${histcontrol//ignorespace}" # Replace ignoreboth with ignoredups if [[ "$histcontrol" == *"ignoreboth"* ]]; then histcontrol="ignoredups:${histcontrol//ignoreboth}" @@ -85,6 +95,10 @@ __bp_adjust_histcontrol() { # and unset as soon as the trace hook is run. __bp_preexec_interactive_mode="" +# These arrays are used to add functions to be run before, or after, prompts. +declare -a precmd_functions +declare -a preexec_functions + # Trims leading and trailing whitespace from $2 and writes it to the variable # name passed as $1 __bp_trim_whitespace() { @@ -154,7 +168,7 @@ __bp_set_ret_value() { __bp_in_prompt_command() { local prompt_command_array - IFS=$'\n;' read -rd '' -a prompt_command_array <<< "$PROMPT_COMMAND" + IFS=$'\n;' read -rd '' -a prompt_command_array <<< "${PROMPT_COMMAND:-}" local trimmed_arg __bp_trim_whitespace trimmed_arg "${1:-}" @@ -292,7 +306,8 @@ __bp_install() { local existing_prompt_command # Remove setting our trap install string and sanitize the existing prompt command string - existing_prompt_command="${PROMPT_COMMAND//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND + existing_prompt_command="${PROMPT_COMMAND:-}" + existing_prompt_command="${existing_prompt_command//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND existing_prompt_command="${existing_prompt_command//$__bp_install_string}" __bp_sanitize_string existing_prompt_command "$existing_prompt_command" @@ -318,17 +333,12 @@ __bp_install() { # after our session has started. This allows bash-preexec to be included # at any point in our bash profile. __bp_install_after_session_init() { - # Make sure this is bash that's running this and return otherwise. - if [[ -z "${BASH_VERSION:-}" ]]; then - return 1; - fi - # bash-preexec needs to modify these variables in order to work correctly # if it can't, just stop the installation __bp_require_not_readonly PROMPT_COMMAND HISTCONTROL HISTTIMEFORMAT || return local sanitized_prompt_command - __bp_sanitize_string sanitized_prompt_command "$PROMPT_COMMAND" + __bp_sanitize_string sanitized_prompt_command "${PROMPT_COMMAND:-}" if [[ -n "$sanitized_prompt_command" ]]; then PROMPT_COMMAND=${sanitized_prompt_command}$'\n' fi; From a93919625ddb0f46d835ac6e0b272e1ee68d65aa Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 11:52:59 -0800 Subject: [PATCH 053/239] lib/preexec: adobt `_bash_it_library_finalize_hook` Schedule modification of `$PROMPT_COMMAND` for after everything has loaded. --- lib/preexec.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/preexec.bash b/lib/preexec.bash index db54a60006..d1367d0b7a 100644 --- a/lib/preexec.bash +++ b/lib/preexec.bash @@ -20,8 +20,8 @@ function __bp_require_not_readonly() { :; } # Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 __bp_enable_subshells= # blank -# Modify `$PROMPT_COMMAND` now -__bp_install_after_session_init +# Modify `$PROMPT_COMMAND` in finalize hook +_bash_it_library_finalize_hook+=('__bp_install_after_session_init') ## Helper functions function __check_precmd_conflict() { From c1943192ce6efbab7b4d3f843319dc5fce52d5aa Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 30 Jan 2022 11:37:18 -0800 Subject: [PATCH 054/239] lib/preexec: clarify subshell guard and comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrite comment on disabling the `DEBUG` trap in subshells, which is now handled upstream as of rcaloras/bash-preexec#26. AlsΓΆ, fix the guard variable assignment to allow it to be overridden elsewhere (e.g., for testing). --- lib/preexec.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/preexec.bash b/lib/preexec.bash index d1367d0b7a..8eba0e24fe 100644 --- a/lib/preexec.bash +++ b/lib/preexec.bash @@ -17,8 +17,9 @@ function __bp_adjust_histcontrol() { :; } # Don't fail on readonly variables function __bp_require_not_readonly() { :; } -# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 -__bp_enable_subshells= # blank +# For performance, testing, and to avoid unexpected behavior: disable DEBUG traps in subshells. +# See bash-it/bash-it#1040 and rcaloras/bash-preexec#26 +: "${__bp_enable_subshells:=}" # blank # Modify `$PROMPT_COMMAND` in finalize hook _bash_it_library_finalize_hook+=('__bp_install_after_session_init') From 8246794a28296b2a83de329c8a434fa0f010e359 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 11 Feb 2022 22:42:24 -0800 Subject: [PATCH 055/239] lib/preexec: the last remnants of the `$OSTYPE` have been swept away - Use a POSIX-compliant/portable extended regular expression to match on word-boundaries, rather than guessing which regex library `bash` was linked against. See https://stackoverflow.com/a/12696899/555333 for explanation and code suggestion. --- lib/preexec.bash | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/preexec.bash b/lib/preexec.bash index 8eba0e24fe..1dbe8899fc 100644 --- a/lib/preexec.bash +++ b/lib/preexec.bash @@ -37,26 +37,20 @@ function __check_preexec_conflict() { _bash-it-array-contains-element "${f}" "${preexec_functions[@]}" } -function safe_append_prompt_command { - local prompt_re f - __bp_trim_whitespace f "${1?}" +function safe_append_prompt_command() { + local prompt_re prompt_er f - if [ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]; then + if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then # We are using bash-preexec + __bp_trim_whitespace f "${1?}" if ! __check_precmd_conflict "${f}"; then precmd_functions+=("${f}") fi else - # Set OS dependent exact match regular expression - if [[ ${OSTYPE} == darwin* ]]; then - # macOS - prompt_re="[[:<:]]${1}[[:>:]]" - else - # Linux, FreeBSD, etc. - prompt_re="\<${1}\>" - fi - - if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then + # Match on word-boundaries + prompt_re='(^|[^[:alnum:]_])' + prompt_er='([^[:alnum:]_]|$)' + if [[ ${PROMPT_COMMAND} =~ ${prompt_re}"${1}"${prompt_er} ]]; then return elif [[ -z ${PROMPT_COMMAND} ]]; then PROMPT_COMMAND="${1}" @@ -66,12 +60,12 @@ function safe_append_prompt_command { fi } -function safe_append_preexec { +function safe_append_preexec() { local prompt_re f - __bp_trim_whitespace f "${1?}" - if [ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]; then + if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then # We are using bash-preexec + __bp_trim_whitespace f "${1?}" if ! __check_preexec_conflict "${f}"; then preexec_functions+=("${f}") 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 056/239] 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 86850a05bd..873db9a60a 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 057/239] 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 873db9a60a..2f1f7a029c 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 058/239] 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 2f1f7a029c..8186165d32 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 059/239] 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 2da8f0054d..4b7f5cdd4a 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 060/239] 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 8186165d32..896062f017 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 061/239] 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 ba089392a3..5ef18e9a0a 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 062/239] 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 896062f017..be320564b2 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 e05fa477d70a793ec6dd23358ecc8a16ad45126f Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 19 Feb 2022 16:33:46 +0900 Subject: [PATCH 063/239] bash_it: source reloader.bash without arguments for the default enabling --- bash_it.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_it.sh b/bash_it.sh index 78d19b8761..a1e8cdfd1c 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -38,7 +38,7 @@ done # "_bash_it_main_file_type" param is empty so that files get sourced in glob order for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do BASH_IT_LOG_PREFIX="core: reloader: " - source "${BASH_IT}/scripts/reloader.bash" "${_bash_it_main_file_type:+skip}" "$_bash_it_main_file_type" + source "${BASH_IT}/scripts/reloader.bash" ${_bash_it_main_file_type:+"skip" "$_bash_it_main_file_type"} BASH_IT_LOG_PREFIX="core: main: " done From 41cf3cfaf2a9e3a87af0605a0c78fe4fce1d74a3 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 19 Feb 2022 15:34:57 +0900 Subject: [PATCH 064/239] plugin/blesh: override possible arguments inherited by callers --- plugins/available/blesh.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/blesh.plugin.bash b/plugins/available/blesh.plugin.bash index 7b1ce74e68..6acd19ff9d 100644 --- a/plugins/available/blesh.plugin.bash +++ b/plugins/available/blesh.plugin.bash @@ -10,7 +10,7 @@ fi _bash_it_ble_path=${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh if [[ -f $_bash_it_ble_path ]]; then # shellcheck disable=1090 - source "$_bash_it_ble_path" + source "$_bash_it_ble_path" --attach=prompt else _log_error "Could not find ble.sh in $_bash_it_ble_path" _log_error "Please install using the following command:" From ee853670a11906029ba5df1ef9402cdbb65f6370 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 19 Feb 2022 17:16:53 +0900 Subject: [PATCH 065/239] bash_it: suppress a false error by shellcheck --- bash_it.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bash_it.sh b/bash_it.sh index a1e8cdfd1c..00a1bceadb 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -38,6 +38,7 @@ done # "_bash_it_main_file_type" param is empty so that files get sourced in glob order for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do BASH_IT_LOG_PREFIX="core: reloader: " + # shellcheck disable=SC2140 source "${BASH_IT}/scripts/reloader.bash" ${_bash_it_main_file_type:+"skip" "$_bash_it_main_file_type"} BASH_IT_LOG_PREFIX="core: main: " done From 2927f672fd9eca868875594ff749150f3fec88e4 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sun, 20 Feb 2022 18:45:08 +1000 Subject: [PATCH 066/239] More user-friendly hints in bug report --- .github/ISSUE_TEMPLATE/bug_report.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index fb1bbcdf43..d4ffc4466f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -65,7 +65,7 @@ body: label: "bash-it doctor output" value: | ``` - # Smth here + # How to get: bash-it doctor ``` validations: required: false @@ -74,7 +74,7 @@ body: label: Your ~/.bashrc value: | ```bash - # Smth here + # How to get: cat ~/.bashrc ``` validations: required: true From df1881acfa5c1a367d6a9ef8edb90cda03cb0eb8 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sun, 20 Feb 2022 18:47:44 +1000 Subject: [PATCH 067/239] Room for extra details for: - bug report - feature request --- .github/ISSUE_TEMPLATE/bug_report.yml | 5 +++++ .github/ISSUE_TEMPLATE/feature_request.yml | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index d4ffc4466f..a187422efb 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -78,3 +78,8 @@ body: ``` validations: required: true + - type: textarea + attributes: + label: Notes + description: > + Provide any extra details here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 28bb4410b1..670aef64b3 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -27,4 +27,8 @@ body: description: > How has this issue affected you? What are you trying to accomplish? Providing context helps us come up with a solution that is most useful in the real world. - + - type: textarea + attributes: + label: Notes + description: > + Provide any extra details here. From fbd842b2ea44eb0bbcb915f6947da377cc31cc51 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 14 Feb 2022 15:29:55 -0800 Subject: [PATCH 068/239] 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 63734a0f8f..28c7c31863 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 069/239] lib/utilities: >| --- lib/utilities.bash | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 28c7c31863..6e65fe8fbd 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 070/239] 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 6e65fe8fbd..60f15131ef 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 071/239] 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 60f15131ef..180d66f073 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 072/239] 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 be320564b2..8430459a0c 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 4b7f5cdd4a..7073f8798b 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 180d66f073..d576c8e4ec 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 073/239] 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 d576c8e4ec..8ea6b98c24 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 074/239] 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 8430459a0c..c0ce2eb3e2 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 075/239] 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 076/239] 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 f06fa0086e..51ef93e944 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" ]] From be9a83801537638341a3979c927ac5906ae04be2 Mon Sep 17 00:00:00 2001 From: Ira Abramov <44946400+ira-bv@users.noreply.github.com> Date: Tue, 1 Mar 2022 23:22:56 +0200 Subject: [PATCH 077/239] Fix knife completion (#2098) Co-authored-by: Ira Abramov --- completion/available/knife.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/knife.completion.bash b/completion/available/knife.completion.bash index 4b9950edef..c0fb6a99da 100644 --- a/completion/available/knife.completion.bash +++ b/completion/available/knife.completion.bash @@ -55,12 +55,12 @@ _KAC_regen_cache() { # cached files can't have spaces in their names _KAC_get_cache_name_from_command() { - echo "${@/ /_SPACE_}" + echo "${@// /_SPACE_}" } # the reverse operation from the function above _KAC_get_command_from_cache_name() { - echo "${@/_SPACE_/ }" + echo "${@//_SPACE_/ }" } # given a command as argument, it fetches the cache for that command if it can find it From be755d63af4c95e63c9f46df125a6f2bcaf37497 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Wed, 2 Mar 2022 23:44:42 +0200 Subject: [PATCH 078/239] ci: Add bashcov codecov report --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0eee145cd8..e77055fa0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,23 @@ jobs: - name: Test code run: test/run + code-coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-ruby@v1 + with: + ruby-version: '2.7' + - name: Install Ruby dependencies + run: bundle update --bundler && bundle install + - name: Run tests + run: bashcov test/run + - name: Upload reports to Codecov + run: | + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov -f coverage/codecov-result.json -Z + build-docs: runs-on: ubuntu-latest From 5c592c9a6fa6f596642e79cff01241ffdba048ba Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Thu, 3 Mar 2022 22:37:39 +0200 Subject: [PATCH 079/239] Revert "ci: Add bashcov codecov report" --- .github/workflows/ci.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e77055fa0c..0eee145cd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,23 +22,6 @@ jobs: - name: Test code run: test/run - code-coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-ruby@v1 - with: - ruby-version: '2.7' - - name: Install Ruby dependencies - run: bundle update --bundler && bundle install - - name: Run tests - run: bashcov test/run - - name: Upload reports to Codecov - run: | - curl -Os https://uploader.codecov.io/latest/linux/codecov - chmod +x codecov - ./codecov -f coverage/codecov-result.json -Z - build-docs: runs-on: ubuntu-latest From 014c102b71e026b2c67dd2686583c3aba99ef9a6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 30 Jan 2022 16:31:01 -0800 Subject: [PATCH 080/239] BATS: revamp test `setup()` and `setup_test_fixture()` --- clean_files.txt | 1 - test/run | 18 ++-- test/test_helper.bash | 174 ++++++++++++++++++++----------------- test/test_helper_libs.bash | 8 -- 4 files changed, 105 insertions(+), 96 deletions(-) mode change 100755 => 100644 test/test_helper.bash delete mode 100644 test/test_helper_libs.bash diff --git a/clean_files.txt b/clean_files.txt index 54180c19fd..07417266c9 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -137,7 +137,6 @@ plugins/available/zoxide.plugin.bash test/plugins/alias-completion.plugin.bats test/run test/test_helper.bash -test/test_helper_libs.bash # themes # diff --git a/test/run b/test/run index 14d8395077..91732a3b24 100755 --- a/test/run +++ b/test/run @@ -2,17 +2,23 @@ test_directory="$(cd "$(dirname "$0")" && pwd)" bats_executable="${test_directory}/../test_lib/bats-core/bin/bats" +# Locate ourselves for easy reference. +export MAIN_BASH_IT_DIR="${test_directory%/*}" +export MAIN_BASH_IT_GITDIR="${MAIN_BASH_IT_DIR}/.git" + +# Make sure BATS is available: git submodule init && git submodule update -if [[ -z "${BASH_IT}" ]]; then - BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" - export BASH_IT +# Warn user that tests run from the current git HEAD +if ! git diff --quiet; then + echo "${BASH_SOURCE##*/}: your worktree is dirty; uncommitted changes will *not* be tested!" fi -if [[ -z "$1" ]]; then +# Which tests do we run? +if [[ $# -eq '0' ]]; then test_dirs=("${test_directory}"/{bash_it,completion,install,lib,plugins,themes}) else - test_dirs=("$1") + test_dirs=("$@") fi # Make sure that the `parallel` command is installed, @@ -41,5 +47,5 @@ if command -v parallel &> /dev/null \ "${test_dirs[@]}" else # Run `bats` in single-threaded mode. - exec "$bats_executable" ${CI:+--tap} "${test_dirs[@]}" + exec "$bats_executable" "${CI:+--tap}" "${test_dirs[@]}" fi diff --git a/test/test_helper.bash b/test/test_helper.bash old mode 100755 new mode 100644 index 06660979ac..919e75599d --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,105 +1,117 @@ -#!/usr/bin/env bats -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +# shellcheck shell=bash -unset BASH_IT_THEME -unset GIT_HOSTING -unset NGINX_PATH -unset IRC_CLIENT -unset TODO -unset SCM_CHECK -unset BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE +function setup_file() { + common_setup_file +} -export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/.." -export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/../test_lib}" +function common_setup_file() { + # export *everything* to subshells, needed to support tests + set -a -# be independent of git's system configuration -export GIT_CONFIG_NOSYSTEM + # Locate ourselves for easy reference. + TEST_MAIN_DIR="${MAIN_BASH_IT_DIR:-${BATS_TEST_DIRNAME?}/../..}/test" + TEST_DEPS_DIR="${MAIN_BASH_IT_DIR:-${TEST_MAIN_DIR}/..}/test_lib" -load "${TEST_DEPS_DIR}/bats-support/load.bash" -load "${TEST_DEPS_DIR}/bats-assert/load.bash" -load "${TEST_DEPS_DIR}/bats-file/load.bash" + # Load the BATS modules we use: + load "${TEST_DEPS_DIR}/bats-support/load.bash" + load "${TEST_DEPS_DIR}/bats-assert/load.bash" + load "${TEST_DEPS_DIR}/bats-file/load.bash" -# support 'plumbing' metadata -cite _about _param _example _group _author _version -cite about-alias about-plugin about-completion + # shellcheck disable=SC2034 # Clear any inherited environment: + XDG_DUMMY="" BASH_IT_DUMMY="" # avoid possible invalid reference: + unset "${!XDG_@}" "${!BASH_IT@}" # unset all BASH_IT* and XDG_* variables + unset GIT_HOSTING NGINX_PATH IRC_CLIENT TODO SCM_CHECK -local_setup() { - true + # Some tools, e.g. `git` use configuration files from the $HOME directory, + # which interferes with our tests. The only way to keep `git` from doing + # this seems to set HOME explicitly to a separate location. + # Refer to https://git-scm.com/docs/git-config#FILES. + readonly HOME="${BATS_SUITE_TMPDIR?}" + mkdir -p "${HOME}" + + # For `git` tests to run well, user name and email need to be set. + # Refer to https://git-scm.com/docs/git-commit#_commit_information. + # This goes to the test-specific config, due to the $HOME overridden above. + git config --global user.name "Bash It BATS Runner" + git config --global user.email "bats@bash.it" + git config --global advice.detachedHead false + git config --global init.defaultBranch "master" + + # Locate the temporary folder, avoid double-slash. + BASH_IT="${BATS_FILE_TMPDIR//\/\///}/.bash_it" + + # This sets up a local test fixture, i.e. a completely fresh and isolated Bash-it directory. This is done to avoid messing with your own Bash-it source directory. + git --git-dir="${MAIN_BASH_IT_GITDIR?}" worktree add -d "${BASH_IT}" + + load "${BASH_IT?}/vendor/github.com/erichs/composure/composure.sh" + # support 'plumbing' metadata + cite _about _param _example _group _author _version + cite about-alias about-plugin about-completion + + # Run any local test setup + local_setup_file + set +a # not needed, but symetiric! } -local_teardown() { - true +# Load standard _Bash It_ libraries +function setup_libs() { + local lib + # Use a loop to allow convenient short-circuiting for some test files + for lib in "log" "utilities" "helpers" "search" "preexec" "colors"; do + load "${BASH_IT?}/lib/${lib}.bash" || return + # shellcheck disable=SC2015 # short-circuit if we've reached the requested library + [[ "${lib}" == "${1:-}" ]] && return 0 || true + done + return 0 } -# This function sets up a local test fixture, i.e. a completely -# fresh and isolated Bash-it directory. This is done to avoid -# messing with your own Bash-it source directory. -# If you need this, call it in your .bats file's `local_setup` function. -setup_test_fixture() { - mkdir -p "$BASH_IT" - lib_directory="$(cd "$(dirname "$0")" && pwd)" - local src_topdir="$lib_directory/../../../.." - - if command -v rsync &> /dev/null; then - # Use rsync to copy Bash-it to the temp folder - rsync -qavrKL -d --delete-excluded --exclude=.git --exclude=helper.bash --exclude=enabled "$src_topdir" "$BASH_IT" - else - rm -rf "$BASH_IT" - mkdir -p "$BASH_IT" - - find "$src_topdir" \ - -mindepth 1 -maxdepth 1 \ - -not -name .git \ - -exec cp -r {} "$BASH_IT" \; - fi - - rm -rf "$BASH_IT"/enabled - rm -rf "$BASH_IT"/aliases/enabled - rm -rf "$BASH_IT"/completion/enabled - rm -rf "$BASH_IT"/plugins/enabled - - mkdir -p "$BASH_IT"/enabled - mkdir -p "$BASH_IT"/aliases/enabled - mkdir -p "$BASH_IT"/completion/enabled - mkdir -p "$BASH_IT"/plugins/enabled - - # Some tests use the BASH_IT_TEST_HOME variable, e.g. install/uninstall - export BASH_IT_TEST_HOME="$TEST_TEMP_DIR" +function local_setup_file() { + true } -setup() { - # The `temp_make` function from "bats-file" requires the tralston/bats-file fork, - # since the original ztombol/bats-file's `temp_make` does not work on macOS. - TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')" - export TEST_TEMP_DIR +function local_setup() { + true +} - export BASH_IT_TEST_DIR="${TEST_TEMP_DIR}/.bash_it" +function local_teardown() { + true +} - export BASH_IT_ROOT="${BASH_IT_TEST_DIR}/root" - export BASH_IT=$BASH_IT_TEST_DIR +function clean_test_fixture() { + rm -rf "${BASH_IT_CONFIG?}/enabled" + rm -rf "${BASH_IT_CONFIG?}/aliases/enabled" + rm -rf "${BASH_IT_CONFIG?}/completion/enabled" + rm -rf "${BASH_IT_CONFIG?}/plugins/enabled" - mkdir -p -- "${BASH_IT_ROOT}" + rm -rf "${BASH_IT_CONFIG?}/tmp/cache" + rm -rf "${BASH_IT_CONFIG?}/profiles"/test*.bash_it +} - # Some tools, e.g. `git` use configuration files from the $HOME directory, - # which interferes with our tests. The only way to keep `git` from doing this - # seems to set HOME explicitly to a separate location. - # Refer to https://git-scm.com/docs/git-config#FILES. - unset XDG_CONFIG_HOME - export HOME="${TEST_TEMP_DIR}" - mkdir -p "${HOME}" +function setup_test_fixture() { + mkdir -p "${BASH_IT_CONFIG?}/enabled" + mkdir -p "${BASH_IT_CONFIG?}/aliases/enabled" + mkdir -p "${BASH_IT_CONFIG?}/completion/enabled" + mkdir -p "${BASH_IT_CONFIG?}/plugins/enabled" +} - # For `git` tests to run well, user name and email need to be set. - # Refer to https://git-scm.com/docs/git-commit#_commit_information. - # This goes to the test-specific config, due to the $HOME overridden above. - git config --global user.name "John Doe" - git config --global user.email "johndoe@example.com" +function setup() { + # be independent of git's system configuration + export GIT_CONFIG_NOSYSTEM + # Locate the temporary folder: + BASH_IT_CONFIG="${BASH_IT?}" #"${BATS_TEST_TMPDIR//\/\///}" + export XDG_CACHE_HOME="${BATS_TEST_TMPDIR?}" + setup_test_fixture local_setup } -teardown() { +function teardown() { + unset GIT_CONFIG_NOSYSTEM local_teardown + clean_test_fixture +} - rm -rf "${BASH_IT_TEST_DIR}" - temp_del "${TEST_TEMP_DIR}" +function teardown_file() { + # This only serves to clean metadata from the real git repo. + git --git-dir="${MAIN_BASH_IT_GITDIR?}" worktree remove -f "${BASH_IT?}" } diff --git a/test/test_helper_libs.bash b/test/test_helper_libs.bash deleted file mode 100644 index fac2a9eb0b..0000000000 --- a/test/test_helper_libs.bash +++ /dev/null @@ -1,8 +0,0 @@ -# shellcheck shell=bash - -load "${BASH_IT}/lib/log.bash" -load "${BASH_IT}/lib/utilities.bash" -load "${BASH_IT}/lib/helpers.bash" -load "${BASH_IT}/lib/search.bash" -load "${BASH_IT}/lib/preexec.bash" -load "${BASH_IT}/lib/colors.bash" From cb9b999f06fe4e6d14caddaa8315d6e19ddc907d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 00:02:24 -0800 Subject: [PATCH 081/239] BATS: de-parallelize Run the test *files* in parallel, but not the tests *within* the files. This can be reverted after configuration (i.e., `$BASH_IT/enabled` et al) lives *outside* the repo. --- test/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run b/test/run index 91732a3b24..7846736654 100755 --- a/test/run +++ b/test/run @@ -44,7 +44,7 @@ if command -v parallel &> /dev/null \ fi )" exec "$bats_executable" "${CI:+--tap}" --jobs "${test_jobs_effective}" \ - "${test_dirs[@]}" + --no-parallelize-within-files "${test_dirs[@]}" else # Run `bats` in single-threaded mode. exec "$bats_executable" "${CI:+--tap}" "${test_dirs[@]}" From fd1771d45c28322c18d6eda1818bf2f5c0f4f414 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:36:09 -0800 Subject: [PATCH 082/239] test/base: adopt newly revamped `setup()` --- test/plugins/base.plugin.bats | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) mode change 100755 => 100644 test/plugins/base.plugin.bats diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats old mode 100755 new mode 100644 index 3d60986b0b..bb8c3c896c --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -1,11 +1,14 @@ #!/usr/bin/env bats -load ../test_helper -load ../test_helper_libs -load ../../plugins/available/base.plugin +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" + +function local_setup() { + setup_libs + load "${BASH_IT?}/plugins/available/base.plugin.bash" +} @test 'plugins base: ips()' { - if [[ $CI ]]; then + if [[ -n "${CI:-}" ]]; then skip 'ifconfig probably requires sudo on TravisCI' fi @@ -23,7 +26,7 @@ load ../../plugins/available/base.plugin } @test 'plugins base: pickfrom()' { - stub_file="${BASH_IT_ROOT}/stub_file" + stub_file="${BATS_TEST_TMPDIR}/stub_file" printf "l1\nl2\nl3" > $stub_file run pickfrom $stub_file assert_success @@ -31,28 +34,30 @@ load ../../plugins/available/base.plugin } @test 'plugins base: mkcd()' { - cd "${BASH_IT_ROOT}" + cd "${BATS_TEST_TMPDIR}" declare -r dir_name="-dir_with_dash" # Make sure that the directory does not exist prior to the test - rm -rf "${BASH_IT_ROOT}/${dir_name}" + rm -rf "${BATS_TEST_TMPDIR}/${dir_name}" - mkcd "${dir_name}" + run mkcd "${dir_name}" assert_success - assert_dir_exist "${BASH_IT_ROOT}/${dir_name}" - assert_equal "${PWD}" "${BASH_IT_ROOT//\/\///}/${dir_name}" + assert_dir_exist "${BATS_TEST_TMPDIR}/${dir_name}" + + mkcd "${dir_name}" + assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}" } @test 'plugins base: lsgrep()' { - for i in 1 2 3; do mkdir -p "${BASH_IT_TEST_DIR}/${i}"; done - cd $BASH_IT_TEST_DIR + for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done + cd $BASH_IT run lsgrep 2 assert_success assert_equal $output 2 } @test 'plugins base: buf()' { - declare -r file="${BASH_IT_ROOT}/file" + declare -r file="${BATS_TEST_TMPDIR}/file" touch $file # Take one timestamp before running the `buf` function From de31a308f9b7ccaad9321296d8bb91f0e67e108e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:37:20 -0800 Subject: [PATCH 083/239] test/bash_it: adopt newly revamped `setup()` --- test/bash_it/bash_it.bats | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index 13c842381b..ef3cdbab3c 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -1,19 +1,11 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper - -function local_setup { - setup_test_fixture +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" +function local_setup_file() { # Copy the test fixture to the Bash-it folder - if command -v rsync &> /dev/null - then - rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/" - else - find "$BASH_IT/test/fixtures/bash_it" \ - -mindepth 1 -maxdepth 1 \ - -exec cp -r {} "$BASH_IT/" \; - fi + cp -fRP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" || true + # don't load any libraries as the tests here test the *whole* kit } @test "bash-it: verify that the test fixture is available" { From c837232643270661d6176a80bdd8cd5a449f5f5b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:38:32 -0800 Subject: [PATCH 084/239] test/bash-it: adopt newly revamped `setup()` --- test/completion/bash-it.completion.bats | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 087a926d13..29d1dc944b 100755 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -1,17 +1,16 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../../lib/utilities -load ../../lib/helpers -load ../../completion/available/bash-it.completion +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -function local_setup { - setup_test_fixture +function local_setup_file() { + setup_libs "helpers" + load "${BASH_IT?}/completion/available/bash-it.completion.bash" } @test "completion bash-it: ensure that the _bash-it function is available" { - type -a _bash-it &> /dev/null + run type -t _bash-it assert_success + assert_output "function" } function __check_completion () { From 2a95e983d0874feec84f8a8f87e0c852c51ec411 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:08:06 -0800 Subject: [PATCH 085/239] test/install: adopt newly revamped `setup()` test/uninstall: adopt newly revamped `setup()` test/install: `local_setup_file()` --- test/install/install.bats | 59 ++++++++++++++++---------------- test/install/uninstall.bats | 67 +++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 61 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index b3aee5a7a6..c9e1794c57 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -1,19 +1,22 @@ -#!/usr/bin/env bats - -load ../test_helper - -# Determine which config file to use based on OS. -case $OSTYPE in - darwin*) - export BASH_IT_CONFIG_FILE=.bash_profile - ;; - *) - export BASH_IT_CONFIG_FILE=.bashrc - ;; -esac - -function local_setup { - setup_test_fixture +# shellcheck shell=bats + +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" + +function local_setup() { + export HOME="$BATS_TEST_TMPDIR" +} + +function local_setup_file() { + # Determine which config file to use based on OS. + case $OSTYPE in + darwin*) + export BASH_IT_CONFIG_FILE=.bash_profile + ;; + *) + export BASH_IT_CONFIG_FILE=.bashrc + ;; + esac + # don't load any libraries as the tests here test the *whole* kit } @test "install: verify that the install script exists" { @@ -25,7 +28,7 @@ function local_setup { ./install.sh --silent - assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" @@ -37,16 +40,16 @@ function local_setup { @test "install: verify that a backup file is created" { cd "$BASH_IT" - touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + touch "$HOME/$BASH_IT_CONFIG_FILE" + echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" + local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') ./install.sh --silent - assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') assert_equal "$md5_orig" "$md5_bak" } @@ -70,15 +73,15 @@ function local_setup { @test "install: verify that the template is appended" { cd "$BASH_IT" - touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + touch "$HOME/$BASH_IT_CONFIG_FILE" + echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" ./install.sh --silent --append-to-config - assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - run cat $BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE + run cat "$HOME/$BASH_IT_CONFIG_FILE" assert_line "test file content" assert_line "source \"\$BASH_IT\"/bash_it.sh" diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index 16bb7f7b9f..ab71a775f7 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -1,19 +1,22 @@ -#!/usr/bin/env bats - -load ../test_helper - -# Determine which config file to use based on OS. -case $OSTYPE in - darwin*) - export BASH_IT_CONFIG_FILE=.bash_profile - ;; - *) - export BASH_IT_CONFIG_FILE=.bashrc - ;; -esac - -function local_setup { - setup_test_fixture +# shellcheck shell=bats + +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" + +function local_setup() { + export HOME="$BATS_TEST_TMPDIR" +} + +function local_setup_file() { + # Determine which config file to use based on OS. + case $OSTYPE in + darwin*) + export BASH_IT_CONFIG_FILE=.bash_profile + ;; + *) + export BASH_IT_CONFIG_FILE=.bashrc + ;; + esac + # don't load any libraries as the tests here test the *whole* kit } @test "uninstall: verify that the uninstall script exists" { @@ -23,19 +26,18 @@ function local_setup { @test "uninstall: run the uninstall script with an existing backup file" { cd "$BASH_IT" - echo "test file content for backup" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" - echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') - - ./uninstall.sh + echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" + echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" + local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + run ./uninstall.sh assert_success - assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" - assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" - assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_conf=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') assert_equal "$md5_bak" "$md5_conf" } @@ -43,18 +45,17 @@ function local_setup { @test "uninstall: run the uninstall script without an existing backup file" { cd "$BASH_IT" - echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') - - ./uninstall.sh + echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" + local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + run ./uninstall.sh assert_success - assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" - assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" - assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_uninstall=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') assert_equal "$md5_orig" "$md5_uninstall" } From 425ef3e10afa360d2a5d8366e579bd15b7ced548 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:39:38 -0800 Subject: [PATCH 086/239] test/composure: adopt newly revamped `setup()` --- test/lib/composure.bats | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/lib/composure.bats b/test/lib/composure.bats index 8198936c96..01bfd9679c 100644 --- a/test/lib/composure.bats +++ b/test/lib/composure.bats @@ -1,6 +1,11 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" + +function local_setup_file() { + true + # don't load any libraries as the tests here test the *whole* kit +} @test "lib composure: _composure_keywords()" { run _composure_keywords From 1ddec65d56dbc92d0391f563d8c725f49386562f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:08:26 -0800 Subject: [PATCH 087/239] test/helpers: adopt newly revamped `setup()` --- test/lib/helpers.bats | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) mode change 100755 => 100644 test/lib/helpers.bats diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats old mode 100755 new mode 100644 index 8c340c58f8..38a917fe95 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -1,21 +1,15 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs -load ../../plugins/available/base.plugin -load ../../lib/colors +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -function local_setup { - setup_test_fixture +function local_setup_file() { + setup_libs "colors" + load "${BASH_IT?}/plugins/available/base.plugin.bash" +} +function local_setup() { # Copy the test fixture to the Bash-it folder - if command -v rsync &> /dev/null; then - rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/" - else - find "$BASH_IT/test/fixtures/bash_it" \ - -mindepth 1 -maxdepth 1 \ - -exec cp -r {} "$BASH_IT/" \; - fi + cp -RP "$BASH_IT/test/fixtures/bash_it"/* "$BASH_IT/" } # TODO Create global __is_enabled function From e5cd10112cb61846264242f54b3ccbba018f57f5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:40:08 -0800 Subject: [PATCH 088/239] test/log: adopt newly revamped `setup()` --- test/lib/log.bats | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/lib/log.bats b/test/lib/log.bats index bd118999f8..7d868fd6da 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -1,11 +1,10 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../../lib/colors +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -load ../../lib/log -load ../../lib/helpers -load ../../plugins/available/base.plugin +function local_setup_file() { + setup_libs "log" +} @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL From 629a1b0c0d5b2019ffca03f4aa10a7fc6630152a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:08:33 -0800 Subject: [PATCH 089/239] test/search: adopt newly revamped `setup()` --- test/lib/search.bats | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) mode change 100755 => 100644 test/lib/search.bats diff --git a/test/lib/search.bats b/test/lib/search.bats old mode 100755 new mode 100644 index 057951a0a5..e28922f455 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -1,28 +1,14 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -load ../../plugins/available/base.plugin -load ../../aliases/available/git.aliases -load ../../plugins/available/ruby.plugin -load ../../plugins/available/rails.plugin -load ../../completion/available/bundler.completion -load ../../completion/available/gem.completion -load ../../completion/available/rake.completion - -load ../../lib/helpers - -function local_setup { - setup_test_fixture - - export OLD_PATH="$PATH" - export PATH="/usr/bin:/bin:/usr/sbin" +function local_setup_file() { + setup_libs "search" } -function local_teardown { - export PATH="$OLD_PATH" - unset OLD_PATH +function local_setup() { + # shellcheck disable=SC2034 + BASH_IT_SEARCH_USE_COLOR=false } @test "search: plugin base" { From fd912117047139dfe37a6f48c7d306923d9b3896 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:08:37 -0800 Subject: [PATCH 090/239] test/utilities: adopt newly revamped `setup()` --- test/lib/utilities.bats | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/lib/utilities.bats b/test/lib/utilities.bats index a0968fce44..78913870e5 100644 --- a/test/lib/utilities.bats +++ b/test/lib/utilities.bats @@ -1,10 +1,9 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -function local_setup { - setup_test_fixture +function local_setup_file() { + setup_libs "helpers" } @test "_bash-it-component-item-is-enabled() - for a disabled item" { From beac9c430a5a9a144d5064c653d00f144945bcb8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:25:21 -0800 Subject: [PATCH 091/239] test/aliases: adopt newly revamped `setup()` --- test/completion/aliases.completion.bats | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/completion/aliases.completion.bats b/test/completion/aliases.completion.bats index 813a7bbd7a..83ae947a35 100644 --- a/test/completion/aliases.completion.bats +++ b/test/completion/aliases.completion.bats @@ -1,28 +1,30 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -# Load something, anything... -load ../../completion/available/capistrano.completion +function local_setup_file() { + setup_libs "helpers" + # Load something, anything... + load ../../completion/available/capistrano.completion +} @test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" { alias gtest="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative" - run load ../../completion/available/aliases.completion + run load "${BASH_IT?}/completion/available/aliases.completion.bash" assert_success } @test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" { alias gtest='git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative' - run load ../../completion/available/aliases.completion + run load "${BASH_IT?}/completion/available/aliases.completion.bash" assert_success } @test "alias-completion: See that having aliased rm command does not output unnecessary output" { alias rm='rm -v' - run load ../../completion/available/aliases.completion + run load "${BASH_IT?}/completion/available/aliases.completion.bash" refute_output } From 6e2e0af7f9f3592d5eda3c94e436cc21b01c9a11 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:08:53 -0800 Subject: [PATCH 092/239] test/battery: adopt newly revamped `setup()` --- test/plugins/battery.plugin.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) mode change 100755 => 100644 test/plugins/battery.plugin.bats diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats old mode 100755 new mode 100644 index 51ef93e944..487fb68f29 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -1,9 +1,11 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -load ../../plugins/available/battery.plugin +function local_setup_file() { + setup_libs "helpers" + load "${BASH_IT?}/plugins/available/battery.plugin.bash" +} # Sets up the `_command_exists` function so that it only responds `true` if called with # the name of the function that was passed in as an argument to `setup_command_exists`. From 4a9df8ec885cb937d9d571bae8bd6536883e323f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:09:02 -0800 Subject: [PATCH 093/239] test/cmd-returned-notify: adopt newly revamped `setup()` --- test/plugins/cmd-returned-notify.plugin.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) mode change 100755 => 100644 test/plugins/cmd-returned-notify.plugin.bats diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats old mode 100755 new mode 100644 index 6f3cf25a24..ca40f3b5a9 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -1,9 +1,11 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -load ../../plugins/available/cmd-returned-notify.plugin +function local_setup_file() { + setup_libs "preexec" #"command_duration" + load "${BASH_IT?}/plugins/available/cmd-returned-notify.plugin.bash" +} @test "plugins cmd-returned-notify: notify after elapsed time" { export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 From fbf7efa1b851402a51cd694d84f7706df2475ce3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:42:25 -0800 Subject: [PATCH 094/239] test/go: adopt newly revamped `setup()` --- test/plugins/go.plugin.bats | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index 258e425447..ebb9cd8823 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -1,11 +1,9 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -function local_setup() -{ - setup_test_fixture +function local_setup_file() { + setup_libs "helpers" } function setup_go_path() From a36a4c4038f6c0f685348fca0b77dfce4bd7593a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:09:09 -0800 Subject: [PATCH 095/239] test/ruby: adopt newly revamped `setup()` --- test/plugins/ruby.plugin.bats | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) mode change 100755 => 100644 test/plugins/ruby.plugin.bats diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats old mode 100755 new mode 100644 index b80adde791..7bfc64555d --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -1,24 +1,15 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -function local_setup { - setup_test_fixture - - _command_exists "ruby" && mkdir -p "$(ruby -e 'print Gem.user_dir')/bin" - - export OLD_PATH="$PATH" - export PATH="/usr/bin:/bin:/usr/sbin" -} - -function local_teardown { - export PATH="$OLD_PATH" - unset OLD_PATH +function local_setup_file() { + setup_libs "helpers" } @test "plugins ruby: remove_gem is defined" { - load ../../plugins/available/ruby.plugin + run load "${BASH_IT?}/plugins/available/ruby.plugin.bash" + assert_success + load "${BASH_IT?}/plugins/available/ruby.plugin.bash" run type remove_gem assert_line -n 1 "remove_gem () " @@ -31,7 +22,9 @@ function local_teardown { mkdir -p "$(ruby -e 'print Gem.user_dir')/bin" - load ../../plugins/available/ruby.plugin + run load "${BASH_IT?}/plugins/available/ruby.plugin.bash" + assert_success + load "${BASH_IT?}/plugins/available/ruby.plugin.bash" local last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] From b6865158774690000d64925fbbc3595e2643b910 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:09:12 -0800 Subject: [PATCH 096/239] test/xterm: adopt newly revamped `setup()` --- test/plugins/xterm.plugin.bats | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index c175d85490..4cb1ffdae0 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -1,21 +1,10 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -load ../../plugins/available/xterm.plugin - -function local_setup { - setup_test_fixture - - # Copy the test fixture to the Bash-it folder - if _command_exists rsync; then - rsync -a "$BASH_IT/test/fixtures/plugin/xterm/" "$BASH_IT/" - else - find "$BASH_IT/test/fixtures/plugin/xterm" \ - -mindepth 1 -maxdepth 1 \ - -exec cp -r {} "$BASH_IT/" \; - fi +function local_setup_file() { + setup_libs "helpers" + load "${BASH_IT?}/plugins/available/xterm.plugin.bash" } @test "plugins xterm: shorten command output" { From f0dfe1a67f1a1181e788fe85a518291a3ff732b1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:09:20 -0800 Subject: [PATCH 097/239] test/theme: adopt newly revamped `setup()` --- test/themes/base.theme.bats | 23 +++++++++++++---------- test/themes/base.theme.git.bats | 15 ++++++++++----- test/themes/base.theme.svn.bats | 29 +++++------------------------ 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 63f25133e6..81b08a01fc 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -1,8 +1,11 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs -load ../../themes/base.theme +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" + +function local_setup_file() { + setup_libs "colors" #"theme" + load "${BASH_IT?}/themes/base.theme.bash" +} @test 'themes base: battery_percentage should not exist' { run type -a battery_percentage &> /dev/null @@ -10,7 +13,7 @@ load ../../themes/base.theme } @test 'themes base: battery_percentage should exist if battery plugin loaded' { - load ../../plugins/available/battery.plugin + load "${BASH_IT?}/plugins/available/battery.plugin.bash" run type -a battery_percentage &> /dev/null assert_success @@ -28,12 +31,12 @@ load ../../themes/base.theme @test 'themes base: battery_char should exist if battery plugin loaded' { unset -f battery_char - load ../../plugins/available/battery.plugin + load "${BASH_IT?}/plugins/available/battery.plugin.bash" run type -t battery_percentage assert_success assert_line "function" - load ../../themes/base.theme + load "${BASH_IT?}/themes/base.theme.bash" run type -t battery_char assert_success assert_line "function" @@ -51,13 +54,13 @@ load ../../themes/base.theme run battery_charge assert_success - assert_line -n 0 "" + assert_output "" } @test 'themes base: battery_charge should exist if battery plugin loaded' { unset -f battery_charge - load ../../plugins/available/battery.plugin - load ../../themes/base.theme + load "${BASH_IT?}/plugins/available/battery.plugin.bash" + load "${BASH_IT?}/themes/base.theme.bash" run type -a battery_charge &> /dev/null assert_success diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index ad2c5a8d0a..b2bc7c5ae0 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -1,9 +1,14 @@ -#!/usr/bin/env bats +# shellcheck shell=bats +# shellcheck disable=SC2034 +# shellcheck disable=SC2016 -load ../test_helper -load ../test_helper_libs -load ../../themes/githelpers.theme -load ../../themes/base.theme +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" + +function local_setup_file() { + setup_libs "colors" #"theme" + load "${BASH_IT?}/themes/base.theme.bash" + load "${BASH_IT?}/themes/githelpers.theme.bash" +} add_commit() { local file_name="general-${RANDOM}" diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index 789d85e5d0..360e8636ae 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -1,29 +1,10 @@ -#!/usr/bin/env bats +# shellcheck shell=bats -load ../test_helper -load ../test_helper_libs +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -function local_setup { - setup_test_fixture - - # Copy the test fixture to the Bash-it folder - if command -v rsync &> /dev/null - then - rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/" - else - find "$BASH_IT/test/fixtures/bash_it" \ - -mindepth 1 -maxdepth 1 \ - -exec cp -r {} "$BASH_IT/" \; - fi - - export OLD_PATH="$PATH" - - load ../../themes/base.theme -} - -function local_teardown { - export PATH="$OLD_PATH" - unset OLD_PATH +function local_setup_file() { + setup_libs "colors" #"theme" + load "${BASH_IT?}/themes/base.theme.bash" } function setup_repo { From 0d55a2406c61c9769060a41e23cac879fc287b3b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:15:06 -0800 Subject: [PATCH 098/239] test/base: adopt newly revamped `setup()` --- test/plugins/base.plugin.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index bb8c3c896c..f11983f1b0 100644 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -1,9 +1,9 @@ -#!/usr/bin/env bats +# shellcheck shell=bats load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" -function local_setup() { - setup_libs +function local_setup_file() { + setup_libs "helpers" load "${BASH_IT?}/plugins/available/base.plugin.bash" } From a9dda3d3584270388f4d32772027651dd73fed24 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:26:31 -0800 Subject: [PATCH 099/239] test/preexec: adopt newly revamped `setup()` --- test/lib/preexec.bats | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib/preexec.bats b/test/lib/preexec.bats index d85f952c28..10dc666d04 100644 --- a/test/lib/preexec.bats +++ b/test/lib/preexec.bats @@ -111,7 +111,7 @@ function local_setup { @test "lib preexec: __check_precmd_conflict()" { test_precmd_function_name="test" - load ../test_helper_libs + setup_libs "preexec" run __check_precmd_conflict "$test_precmd_function_name" assert_failure @@ -124,7 +124,7 @@ function local_setup { @test "lib preexec: __check_preexec_conflict()" { test_preexec_function_name="test" - load ../test_helper_libs + setup_libs "preexec" run __check_preexec_conflict "$test_preexec_function_name" assert_failure @@ -137,7 +137,7 @@ function local_setup { @test "lib preexec: safe_append_prompt_command()" { test_precmd_function_name="test" - load ../test_helper_libs + setup_libs "preexec" export precmd_functions=() assert_equal "${precmd_functions[*]}" "" @@ -151,7 +151,7 @@ function local_setup { @test "lib preexec: safe_append_preexec()" { test_preexec_function_name="test" - load ../test_helper_libs + setup_libs "preexec" export preexec_functions=() assert_equal "${preexec_functions[*]}" "" From e496a2ce5944f8ceec717f1a1a7e0a12ed6a9b52 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 20 Feb 2022 11:03:33 -0800 Subject: [PATCH 100/239] Revert "bash_it: source reloader.bash without arguments for the default enabling" This reverts commit e05fa477d70a793ec6dd23358ecc8a16ad45126f. This reverts commit ee853670a11906029ba5df1ef9402cdbb65f6370. --- bash_it.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index 00a1bceadb..78d19b8761 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -38,8 +38,7 @@ done # "_bash_it_main_file_type" param is empty so that files get sourced in glob order for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do BASH_IT_LOG_PREFIX="core: reloader: " - # shellcheck disable=SC2140 - source "${BASH_IT}/scripts/reloader.bash" ${_bash_it_main_file_type:+"skip" "$_bash_it_main_file_type"} + source "${BASH_IT}/scripts/reloader.bash" "${_bash_it_main_file_type:+skip}" "$_bash_it_main_file_type" BASH_IT_LOG_PREFIX="core: main: " done From 0e0e0d30351f5b0e6e61510b7aacc33e23f85de9 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 20 Sep 2021 12:52:16 -0700 Subject: [PATCH 101/239] lib/theme: Fix a *few* SC2154 These variables are referenced by themes already linted. --- themes/base.theme.bash | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index d7479b3fc0..3404c8c633 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -94,10 +94,10 @@ RBFU_THEME_PROMPT_SUFFIX='|' : "${SVN_EXE:=$SCM_SVN}" function _bash_it_appearance_scm_init() { - GIT_EXE="$(type -P $SCM_GIT || true)" - P4_EXE="$(type -P $SCM_P4 || true)" - HG_EXE="$(type -P $SCM_HG || true)" - SVN_EXE="$(type -P $SCM_SVN || true)" + GIT_EXE="$(type -P "$SCM_GIT" || true)" + P4_EXE="$(type -P "$SCM_P4" || true)" + HG_EXE="$(type -P "$SCM_HG" || true)" + SVN_EXE="$(type -P "$SCM_SVN" || true)" # Check for broken SVN exe that is caused by some versions of Xcode. # See https://github.com/Bash-it/bash-it/issues/1612 for more details. @@ -235,7 +235,7 @@ function git_prompt_minimal_info { } function git_prompt_vars { - if ${SCM_GIT_USE_GITSTATUS} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then + if "${SCM_GIT_USE_GITSTATUS:-false}" && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT:-}" == "ok-sync" ]]; then # we can use faster gitstatus # use this variable in githelpers and below to choose gitstatus output SCM_GIT_GITSTATUS_RAN=true @@ -259,8 +259,8 @@ function git_prompt_vars { fi if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - commits_behind=${VCS_STATUS_COMMITS_BEHIND} - commits_ahead=${VCS_STATUS_COMMITS_AHEAD} + commits_behind=${VCS_STATUS_COMMITS_BEHIND?} + commits_ahead=${VCS_STATUS_COMMITS_AHEAD?} else IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)" fi @@ -276,7 +276,7 @@ function git_prompt_vars { if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then local stash_count if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - stash_count=${VCS_STATUS_STASHES} + stash_count=${VCS_STATUS_STASHES?} else stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')" fi @@ -286,9 +286,9 @@ function git_prompt_vars { SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} if ! _git-hide-status; then if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - untracked_count=${VCS_STATUS_NUM_UNTRACKED} - unstaged_count=${VCS_STATUS_NUM_UNSTAGED} - staged_count=${VCS_STATUS_NUM_STAGED} + untracked_count=${VCS_STATUS_NUM_UNTRACKED?} + unstaged_count=${VCS_STATUS_NUM_UNSTAGED?} + staged_count=${VCS_STATUS_NUM_STAGED?} else IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)" fi @@ -429,7 +429,7 @@ function rbenv_version_prompt { } function rbfu_version_prompt { - if [[ $RBFU_RUBY_VERSION ]]; then + if [[ -n "${RBFU_RUBY_VERSION:-}" ]]; then echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}" fi } @@ -445,12 +445,12 @@ function chruby_version_prompt { if ! chruby | grep -q '\*'; then ruby_version="${ruby_version} (system)" fi - echo -e "${CHRUBY_THEME_PROMPT_PREFIX}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX}" + echo -e "${CHRUBY_THEME_PROMPT_PREFIX:-}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX:-}" fi } function ruby_version_prompt { - if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then + if [[ "${THEME_SHOW_RUBY_PROMPT:-}" == "true" ]]; then echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)" fi } @@ -464,21 +464,22 @@ function k8s_namespace_prompt { } function virtualenv_prompt { - if [[ -n "$VIRTUAL_ENV" ]]; then - virtualenv=$(basename "$VIRTUAL_ENV") + if [[ -n "${VIRTUAL_ENV:-}" ]]; then + virtualenv="${VIRTUAL_ENV##*/}" echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" fi } function condaenv_prompt { - if [[ $CONDA_DEFAULT_ENV ]]; then - echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}" + if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then + echo -e "${CONDAENV_THEME_PROMPT_PREFIX:-}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX:-}" fi } function py_interp_prompt { + local py_version py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return - echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}" + echo -e "${PYTHON_THEME_PROMPT_PREFIX:-}${py_version}${PYTHON_THEME_PROMPT_SUFFIX:-}" } function python_version_prompt { @@ -506,7 +507,7 @@ function clock_char { function clock_prompt { CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"} CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"} - [ -z "$THEME_SHOW_CLOCK" ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"} + [[ -z "${THEME_SHOW_CLOCK:-}" ]] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"} SHOW_CLOCK=$THEME_SHOW_CLOCK if [[ "${SHOW_CLOCK}" = "true" ]]; then @@ -576,7 +577,7 @@ if ! _command_exists battery_percentage; then fi function aws_profile { - if [[ $AWS_DEFAULT_PROFILE ]]; then + if [[ -n "${AWS_DEFAULT_PROFILE:-}" ]]; then echo -e "${AWS_DEFAULT_PROFILE}" else echo -e "default" From fbc5d0a5af042bde489d68894c04213003ed6292 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 26 Jan 2022 10:56:59 -0800 Subject: [PATCH 102/239] lib/p4helpers: `shfmt` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My apologies to future `git blame` hunters β™₯ --- clean_files.txt | 1 + themes/p4helpers.theme.bash | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 54180c19fd..26b059da8d 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -160,6 +160,7 @@ themes/easy themes/essential themes/modern themes/norbu +themes/p4helpers.theme.bash themes/pete themes/powerline themes/pure diff --git a/themes/p4helpers.theme.bash b/themes/p4helpers.theme.bash index 27a777acea..30b520cc68 100644 --- a/themes/p4helpers.theme.bash +++ b/themes/p4helpers.theme.bash @@ -1,18 +1,18 @@ -#!/usr/bin/env bash +# shellcheck shell=bash function _p4-opened { - timeout 2.0s p4 opened -s 2> /dev/null + timeout 2.0s p4 opened -s 2> /dev/null } function _p4-opened-counts { - # Return the following counts seperated by tabs: - # - count of opened files - # - count of pending changesets (other than defaults) - # - count of files in the default changeset - # - count of opened files in add mode - # - count of opened files in edit mode - # - count of opened files in delete mode - _p4-opened | awk ' + # Return the following counts seperated by tabs: + # - count of opened files + # - count of pending changesets (other than defaults) + # - count of files in the default changeset + # - count of opened files in add mode + # - count of opened files in edit mode + # - count of opened files in delete mode + _p4-opened | awk ' BEGIN { opened=0; type_array["edit"]=0; From 6bacd5fb1c7a4844cc8c742ffdd3fe56ede3f062 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Mar 2022 22:54:08 -0800 Subject: [PATCH 103/239] lib/githelpers: `shfmt` && `shellcheck` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My apologies to future `git blame` hunters β™₯ --- clean_files.txt | 1 + themes/githelpers.theme.bash | 227 ++++++++++++++++++----------------- 2 files changed, 117 insertions(+), 111 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 26b059da8d..15c91227bb 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -158,6 +158,7 @@ themes/candy themes/command_duration.theme.bash themes/easy themes/essential +themes/githelpers.theme.bash themes/modern themes/norbu themes/p4helpers.theme.bash diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index 5ef18e9a0a..2fbb7e8a52 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -1,99 +1,106 @@ -#!/usr/bin/env bash +# shellcheck shell=bash -function _git-symbolic-ref { - git symbolic-ref -q HEAD 2> /dev/null +function _git-symbolic-ref() { + git symbolic-ref -q HEAD 2> /dev/null } # When on a branch, this is often the same as _git-commit-description, # but this can be different when two branches are pointing to the # same commit. _git-branch is used to explicitly choose the checked-out # branch. -function _git-branch { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - test -n "${VCS_STATUS_LOCAL_BRANCH}" && echo "${VCS_STATUS_LOCAL_BRANCH}" || return 1 - else - git symbolic-ref -q --short HEAD 2> /dev/null || return 1 - fi +function _git-branch() { + if [[ "${SCM_GIT_GITSTATUS_RAN:-}" == "true" ]]; then + if [[ -n "${VCS_STATUS_LOCAL_BRANCH:-}" ]]; then + echo "${VCS_STATUS_LOCAL_BRANCH}" + else + return 1 + fi + else + git symbolic-ref -q --short HEAD 2> /dev/null || return 1 + fi } -function _git-tag { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - test -n "${VCS_STATUS_TAG}" && echo "${VCS_STATUS_TAG}" - else - git describe --tags --exact-match 2> /dev/null - fi +function _git-tag() { + if [[ "${SCM_GIT_GITSTATUS_RAN:-}" == "true" ]]; then + if [[ -n "${VCS_STATUS_TAG:-}" ]]; then + echo "${VCS_STATUS_TAG}" + fi + else + git describe --tags --exact-match 2> /dev/null + fi } -function _git-commit-description { - git describe --contains --all 2> /dev/null +function _git-commit-description() { + git describe --contains --all 2> /dev/null } -function _git-short-sha { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - echo ${VCS_STATUS_COMMIT:0:7} - else - git rev-parse --short HEAD - fi +function _git-short-sha() { + if [[ "${SCM_GIT_GITSTATUS_RAN:-}" == "true" ]]; then + echo "${VCS_STATUS_COMMIT:0:7}" + else + git rev-parse --short HEAD + fi } # Try the checked-out branch first to avoid collision with branches pointing to the same ref. -function _git-friendly-ref { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - _git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatus - else - _git-branch || _git-tag || _git-commit-description || _git-short-sha - fi +function _git-friendly-ref() { + if [[ "${SCM_GIT_GITSTATUS_RAN:-}" == "true" ]]; then + _git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatus + else + _git-branch || _git-tag || _git-commit-description || _git-short-sha + fi } -function _git-num-remotes { - git remote | wc -l +function _git-num-remotes() { + git remote | wc -l } -function _git-upstream { - local ref - ref="$(_git-symbolic-ref)" || return 1 - git for-each-ref --format="%(upstream:short)" "${ref}" +function _git-upstream() { + local ref + ref="$(_git-symbolic-ref)" || return 1 + git for-each-ref --format="%(upstream:short)" "${ref}" } -function _git-upstream-remote { - local upstream - upstream="$(_git-upstream)" || return 1 +function _git-upstream-remote() { + local upstream branch + upstream="$(_git-upstream)" || return 1 - local branch - branch="$(_git-upstream-branch)" || return 1 - echo "${upstream%"/${branch}"}" + branch="$(_git-upstream-branch)" || return 1 + echo "${upstream%"/${branch}"}" } -function _git-upstream-branch { - local ref - ref="$(_git-symbolic-ref)" || return 1 +function _git-upstream-branch() { + local ref + ref="$(_git-symbolic-ref)" || return 1 - # git versions < 2.13.0 do not support "strip" for upstream format - # regex replacement gives the wrong result for any remotes with slashes in the name, - # so only use when the strip format fails. - git for-each-ref --format="%(upstream:strip=3)" "${ref}" 2> /dev/null || git for-each-ref --format="%(upstream)" "${ref}" | sed -e "s/.*\/.*\/.*\///" + # git versions < 2.13.0 do not support "strip" for upstream format + # regex replacement gives the wrong result for any remotes with slashes in the name, + # so only use when the strip format fails. + git for-each-ref --format="%(upstream:strip=3)" "${ref}" 2> /dev/null || git for-each-ref --format="%(upstream)" "${ref}" | sed -e "s/.*\/.*\/.*\///" } -function _git-upstream-behind-ahead { - git rev-list --left-right --count "$(_git-upstream)...HEAD" 2> /dev/null +function _git-upstream-behind-ahead() { + git rev-list --left-right --count "$(_git-upstream)...HEAD" 2> /dev/null } -function _git-upstream-branch-gone { - [[ "$(git status -s -b | sed -e 's/.* //')" == "[gone]" ]] +function _git-upstream-branch-gone() { + [[ "$(git status -s -b | sed -e 's/.* //')" == "[gone]" ]] } -function _git-hide-status { - [[ "$(git config --get bash-it.hide-status)" == "1" ]] +function _git-hide-status() { + [[ "$(git config --get bash-it.hide-status)" == "1" ]] } -function _git-status { - local git_status_flags= - [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true - git status --porcelain ${git_status_flags} 2> /dev/null +function _git-status() { + local git_status_flags= + if [[ "${SCM_GIT_IGNORE_UNTRACKED:-}" == "true" ]]; then + git_status_flags='-uno' + fi + git status --porcelain "${git_status_flags:---}" 2> /dev/null } -function _git-status-counts { - _git-status | awk ' +function _git-status-counts() { + _git-status | awk ' BEGIN { untracked=0; unstaged=0; @@ -116,60 +123,58 @@ function _git-status-counts { }' } -function _git-remote-info { - - # prompt handling only, reimplement because patching the routine below gets ugly - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - [[ "${VCS_STATUS_REMOTE_NAME}" == "" ]] && return - [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && local same_branch_name=true - local same_branch_name= - [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && same_branch_name=true - # no multiple remote support in gitstatusd - if [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" || "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]]; then - if [[ "${same_branch_name}" != "true" ]]; then - remote_info="${VCS_STATUS_REMOTE_NAME}/${VCS_STATUS_REMOTE_BRANCH}" - else - remote_info="${VCS_STATUS_REMOTE_NAME}" - fi - elif [[ ${same_branch_name} != "true" ]]; then - remote_info="${VCS_STATUS_REMOTE_BRANCH}" - fi - 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}" - fi - else - [[ "$(_git-upstream)" == "" ]] && return - - [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true - local same_branch_name= - [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true - if [[ ("${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" && "$(_git-num-remotes)" -ge 2) || - "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then - if [[ "${same_branch_name}" != "true" ]]; then - remote_info="\$(_git-upstream)" - else - remote_info="$(_git-upstream-remote)" - fi - elif [[ ${same_branch_name} != "true" ]]; then - remote_info="\$(_git-upstream-branch)" - fi - if [[ -n "${remote_info:-}" ]];then - local branch_prefix - if _git-upstream-branch-gone; then - branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}" - else - branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" - fi - echo "${branch_prefix}${remote_info}" - fi - fi +function _git-remote-info() { + local same_branch_name="" branch_prefix + # prompt handling only, reimplement because patching the routine below gets ugly + if [[ "${SCM_GIT_GITSTATUS_RAN:-}" == "true" ]]; then + [[ "${VCS_STATUS_REMOTE_NAME?}" == "" ]] && return + [[ "${VCS_STATUS_LOCAL_BRANCH?}" == "${VCS_STATUS_REMOTE_BRANCH?}" ]] && same_branch_name=true + # no multiple remote support in gitstatusd + if [[ "${SCM_GIT_SHOW_REMOTE_INFO:-}" == "true" || "${SCM_GIT_SHOW_REMOTE_INFO:-}" == "auto" ]]; then + if [[ ${same_branch_name:-} != "true" ]]; then + remote_info="${VCS_STATUS_REMOTE_NAME?}/${VCS_STATUS_REMOTE_BRANCH?}" + else + remote_info="${VCS_STATUS_REMOTE_NAME?}" + fi + elif [[ ${same_branch_name:-} != "true" ]]; then + remote_info="${VCS_STATUS_REMOTE_BRANCH?}" + fi + if [[ -n "${remote_info:-}" ]]; then + # no support for gone remote branches in gitstatusd + branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX:-}" + echo "${branch_prefix}${remote_info:-}" + fi + else + [[ "$(_git-upstream)" == "" ]] && return + + [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true + if [[ ("${SCM_GIT_SHOW_REMOTE_INFO}" == "auto" && "$(_git-num-remotes)" -ge 2) || + "${SCM_GIT_SHOW_REMOTE_INFO}" == "true" ]]; then + if [[ ${same_branch_name:-} != "true" ]]; then + # shellcheck disable=SC2016 + remote_info='$(_git-upstream)' + else + remote_info="$(_git-upstream-remote)" + fi + elif [[ ${same_branch_name:-} != "true" ]]; then + # shellcheck disable=SC2016 + remote_info='$(_git-upstream-branch)' + fi + if [[ -n "${remote_info:-}" ]]; then + local branch_prefix + if _git-upstream-branch-gone; then + branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX:-}" + else + branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX:-}" + fi + echo "${branch_prefix}${remote_info:-}" + fi + fi } # Unused by bash-it, present for API compatibility -function git_status_summary { - awk ' +function git_status_summary() { + awk ' BEGIN { untracked=0; unstaged=0; From 1d73537dbfb927324b81626d57ed7befc8126168 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 26 Jan 2022 10:58:44 -0800 Subject: [PATCH 104/239] lib/theme: `shfmt` && `shellcheck` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My apologies to future `git blame` hunters β™₯ Use the "short" host name by default (`\h`), not the fully qualified domain name (`\H`)... lib/theme: don't redefine battery_char() Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both. Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time. Don't run `date` for `$THEME_TIME_FORMAT`, use `\D{fmt}`. --- themes/base.theme.bash | 282 ++++++++++++++++++++--------------------- 1 file changed, 138 insertions(+), 144 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 3404c8c633..1706eba4dd 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -6,11 +6,11 @@ CLOCK_CHAR_THEME_PROMPT_SUFFIX='' CLOCK_THEME_PROMPT_PREFIX='' CLOCK_THEME_PROMPT_SUFFIX='' -THEME_PROMPT_HOST='\H' +THEME_PROMPT_HOST='\h' SCM= -SCM_CHECK=${SCM_CHECK:=true} +: "${SCM_CHECK:=true}" SCM_THEME_PROMPT_DIRTY=' βœ—' SCM_THEME_PROMPT_CLEAN=' βœ“' @@ -30,15 +30,15 @@ SCM_THEME_CHAR_SUFFIX='' : "${THEME_CHECK_SUDO:=false}" : "${THEME_BATTERY_PERCENTAGE_CHECK:=true}" -SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=true} -SCM_GIT_SHOW_REMOTE_INFO=${SCM_GIT_SHOW_REMOTE_INFO:=auto} -SCM_GIT_IGNORE_UNTRACKED=${SCM_GIT_IGNORE_UNTRACKED:=false} -SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false} -SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false} -SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true} -SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true} -SCM_GIT_USE_GITSTATUS=${SCM_GIT_USE_GITSTATUS:=false} -SCM_GIT_GITSTATUS_RAN=${SCM_GIT_GITSTATUS_RAN:=false} +: "${SCM_GIT_SHOW_DETAILS:=true}" +: "${SCM_GIT_SHOW_REMOTE_INFO:=auto}" +: "${SCM_GIT_IGNORE_UNTRACKED:=false}" +: "${SCM_GIT_SHOW_CURRENT_USER:=false}" +: "${SCM_GIT_SHOW_MINIMAL_INFO:=false}" +: "${SCM_GIT_SHOW_STASH_INFO:=true}" +: "${SCM_GIT_SHOW_COMMIT_COUNT:=true}" +: "${SCM_GIT_USE_GITSTATUS:=false}" +: "${SCM_GIT_GITSTATUS_RAN:=false}" SCM_GIT='git' SCM_GIT_CHAR='Β±' @@ -73,9 +73,9 @@ NVM_THEME_PROMPT_SUFFIX='|' RVM_THEME_PROMPT_PREFIX=' |' RVM_THEME_PROMPT_SUFFIX='|' -THEME_SHOW_RUBY_PROMPT=${THEME_SHOW_RUBY_PROMPT:=true} +: "${THEME_SHOW_RUBY_PROMPT:=true}" -THEME_SHOW_USER_HOST=${THEME_SHOW_USER_HOST:=false} +: "${THEME_SHOW_USER_HOST:=false}" USER_HOST_THEME_PROMPT_PREFIX='' USER_HOST_THEME_PROMPT_SUFFIX='' @@ -94,10 +94,10 @@ RBFU_THEME_PROMPT_SUFFIX='|' : "${SVN_EXE:=$SCM_SVN}" function _bash_it_appearance_scm_init() { - GIT_EXE="$(type -P "$SCM_GIT" || true)" - P4_EXE="$(type -P "$SCM_P4" || true)" - HG_EXE="$(type -P "$SCM_HG" || true)" - SVN_EXE="$(type -P "$SCM_SVN" || true)" + GIT_EXE="$(type -P "${SCM_GIT}" || true)" + P4_EXE="$(type -P "${SCM_P4}" || true)" + HG_EXE="$(type -P "${SCM_HG}" || true)" + SVN_EXE="$(type -P "${SCM_SVN}" || true)" # Check for broken SVN exe that is caused by some versions of Xcode. # See https://github.com/Bash-it/bash-it/issues/1612 for more details. @@ -107,35 +107,36 @@ function _bash_it_appearance_scm_init() { SVN_EXE="" fi fi + return 0 } _bash_it_library_finalize_hook+=('_bash_it_appearance_scm_init') -function scm { - if [[ "$SCM_CHECK" = false ]]; then - SCM=$SCM_NONE +function scm() { + if [[ "$SCM_CHECK" == false ]]; then + SCM="$SCM_NONE" elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then - SCM=$SCM_GIT + SCM="$SCM_GIT" elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then - SCM=$SCM_HG + SCM="$SCM_HG" elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then - SCM=$SCM_SVN + SCM="$SCM_SVN" elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then - SCM=$SCM_GIT + SCM="$SCM_GIT" elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then - SCM=$SCM_HG + SCM="$SCM_HG" elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then - SCM=$SCM_SVN + SCM="$SCM_SVN" elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then - SCM=$SCM_P4 + SCM="$SCM_P4" else - SCM=$SCM_NONE + SCM="$SCM_NONE" fi } -scm_prompt() { +function scm_prompt() { local CHAR CHAR="$(scm_char)" - local format=${SCM_PROMPT_FORMAT:-'[%s%s]'} + local format="${SCM_PROMPT_FORMAT:-'[%s%s]'}" if [[ "${CHAR}" != "$SCM_NONE_CHAR" ]]; then # shellcheck disable=2059 @@ -143,22 +144,22 @@ scm_prompt() { fi } -function scm_prompt_char { - if [[ -z $SCM ]]; then scm; fi +function scm_prompt_char() { + if [[ -z "$SCM" ]]; then scm; fi if [[ $SCM == "$SCM_GIT" ]]; then - SCM_CHAR=$SCM_GIT_CHAR + SCM_CHAR="$SCM_GIT_CHAR" elif [[ $SCM == "$SCM_P4" ]]; then - SCM_CHAR=$SCM_P4_CHAR + SCM_CHAR="$SCM_P4_CHAR" elif [[ $SCM == "$SCM_HG" ]]; then - SCM_CHAR=$SCM_HG_CHAR + SCM_CHAR="$SCM_HG_CHAR" elif [[ $SCM == "$SCM_SVN" ]]; then - SCM_CHAR=$SCM_SVN_CHAR + SCM_CHAR="$SCM_SVN_CHAR" else - SCM_CHAR=$SCM_NONE_CHAR + SCM_CHAR="$SCM_NONE_CHAR" fi } -function scm_prompt_vars { +function scm_prompt_vars() { scm scm_prompt_char SCM_DIRTY=0 @@ -169,19 +170,19 @@ function scm_prompt_vars { [[ $SCM == "$SCM_SVN" ]] && svn_prompt_vars && return } -function scm_prompt_info { +function scm_prompt_info() { scm scm_prompt_char scm_prompt_info_common } -function scm_prompt_char_info { +function scm_prompt_char_info() { scm_prompt_char echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" scm_prompt_info_common } -function scm_prompt_info_common { +function scm_prompt_info_common() { SCM_DIRTY=0 SCM_STATE='' @@ -202,22 +203,22 @@ function scm_prompt_info_common { { [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true } -function terraform_workspace_prompt { +function terraform_workspace_prompt() { if _command_exists terraform; then - if [ -d .terraform ]; then + if [[ -d .terraform ]]; then echo -e "$(terraform workspace show 2> /dev/null)" fi fi } -function active_gcloud_account_prompt { +function active_gcloud_account_prompt() { if _command_exists gcloud; then echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)" fi } -function git_prompt_minimal_info { - SCM_STATE=${SCM_THEME_PROMPT_CLEAN} +function git_prompt_minimal_info() { + SCM_STATE="${SCM_THEME_PROMPT_CLEAN}" _git-hide-status && return @@ -225,16 +226,16 @@ function git_prompt_minimal_info { if [[ -n "$(_git-status | tail -n1)" ]]; then SCM_DIRTY=1 - SCM_STATE=${SCM_THEME_PROMPT_DIRTY} + SCM_STATE="${SCM_THEME_PROMPT_DIRTY}" fi # Output the git prompt - SCM_PREFIX=${SCM_THEME_PROMPT_PREFIX} - SCM_SUFFIX=${SCM_THEME_PROMPT_SUFFIX} + SCM_PREFIX="${SCM_THEME_PROMPT_PREFIX}" + SCM_SUFFIX="${SCM_THEME_PROMPT_SUFFIX}" echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" } -function git_prompt_vars { +function git_prompt_vars() { if "${SCM_GIT_USE_GITSTATUS:-false}" && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT:-}" == "ok-sync" ]]; then # we can use faster gitstatus # use this variable in githelpers and below to choose gitstatus output @@ -251,99 +252,99 @@ function git_prompt_vars { local detached_prefix if _git-tag &> /dev/null; then - detached_prefix=${SCM_THEME_TAG_PREFIX} + detached_prefix="${SCM_THEME_TAG_PREFIX}" else - detached_prefix=${SCM_THEME_DETACHED_PREFIX} + detached_prefix="${SCM_THEME_DETACHED_PREFIX}" fi SCM_BRANCH="${detached_prefix}\$(_git-friendly-ref)" fi - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - commits_behind=${VCS_STATUS_COMMITS_BEHIND?} - commits_ahead=${VCS_STATUS_COMMITS_AHEAD?} + if [[ "${SCM_GIT_GITSTATUS_RAN:-}" == "true" ]]; then + commits_behind="${VCS_STATUS_COMMITS_BEHIND?}" + commits_ahead="${VCS_STATUS_COMMITS_AHEAD?}" else IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)" fi if [[ "${commits_ahead}" -gt 0 ]]; then SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}" - [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_ahead}" + [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" == "true" ]] && SCM_BRANCH+="${commits_ahead}" fi if [[ "${commits_behind}" -gt 0 ]]; then SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}" - [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_behind}" + [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" == "true" ]] && SCM_BRANCH+="${commits_behind}" fi - if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then + if [[ "${SCM_GIT_SHOW_STASH_INFO}" == "true" ]]; then local stash_count if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - stash_count=${VCS_STATUS_STASHES?} + stash_count="${VCS_STATUS_STASHES?}" else stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')" fi [[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STASH_CHAR_PREFIX}${stash_count}${SCM_GIT_STASH_CHAR_SUFFIX}" fi - SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_STATE="${GIT_THEME_PROMPT_CLEAN:-${SCM_THEME_PROMPT_CLEAN:-}}" if ! _git-hide-status; then - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - untracked_count=${VCS_STATUS_NUM_UNTRACKED?} - unstaged_count=${VCS_STATUS_NUM_UNSTAGED?} - staged_count=${VCS_STATUS_NUM_STAGED?} + if [[ "${SCM_GIT_GITSTATUS_RAN:-}" == "true" ]]; then + untracked_count="${VCS_STATUS_NUM_UNTRACKED?}" + unstaged_count="${VCS_STATUS_NUM_UNSTAGED?}" + staged_count="${VCS_STATUS_NUM_STAGED?}" else IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)" fi if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then SCM_DIRTY=1 - if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; then + if [[ "${SCM_GIT_SHOW_DETAILS}" == "true" ]]; then [[ "${staged_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STAGED_CHAR}${staged_count}" && SCM_DIRTY=3 [[ "${unstaged_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2 [[ "${untracked_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1 fi - SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_STATE="${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}" fi fi # no if for gitstatus here, user extraction is not supported by it [[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)" - SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + SCM_PREFIX="${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" + SCM_SUFFIX="${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo "") } -function p4_prompt_vars { +function p4_prompt_vars() { IFS=$'\t' read -r \ opened_count non_default_changes default_count \ add_file_count edit_file_count delete_file_count \ <<< "$(_p4-opened-counts)" if [[ "${opened_count}" -gt 0 ]]; then SCM_DIRTY=1 - SCM_STATE=${SCM_THEME_PROMPT_DIRTY} + SCM_STATE="${SCM_THEME_PROMPT_DIRTY}" [[ "${opened_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_OPENED_CHAR}${opened_count}" [[ "${non_default_changes}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_CHANGES_CHAR}${non_default_changes}" [[ "${default_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_DEFAULT_CHAR}${default_count}" else SCM_DIRTY=0 - SCM_STATE=${SCM_THEME_PROMPT_DIRTY} + SCM_STATE="${SCM_THEME_PROMPT_DIRTY}" fi - SCM_PREFIX=${P4_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - SCM_SUFFIX=${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + SCM_PREFIX="${P4_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" + SCM_SUFFIX="${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" } -function svn_prompt_vars { +function svn_prompt_vars() { if [[ -n $(svn status | head -c1 2> /dev/null) ]]; then SCM_DIRTY=1 - SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_STATE="${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}" else SCM_DIRTY=0 - SCM_STATE=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_STATE="${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}" fi - SCM_PREFIX=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - SCM_SUFFIX=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - SCM_BRANCH=$(svn info --show-item=url 2> /dev/null | awk -F/ '{ for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return - SCM_CHANGE=$(svn info --show-item=revision 2> /dev/null) + SCM_PREFIX="${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" + SCM_SUFFIX="${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" + SCM_BRANCH="$(svn info --show-item=url 2> /dev/null | awk -F/ '{ for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }')" || return + SCM_CHANGE="$(svn info --show-item=revision 2> /dev/null)" } # this functions returns absolute location of .hg directory if one exists @@ -353,7 +354,7 @@ function svn_prompt_vars { # - lets say we cd into ~/Projects/Foo/Bar # - .hg is located in ~/Projects/Foo/.hg # - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo -function get_hg_root { +function get_hg_root() { local CURRENT_DIR="${PWD}" while [[ "${CURRENT_DIR:-/}" != "/" ]]; do @@ -366,29 +367,29 @@ function get_hg_root { done } -function hg_prompt_vars { +function hg_prompt_vars() { if [[ -n $(hg status 2> /dev/null) ]]; then SCM_DIRTY=1 - SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_STATE="${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}" else SCM_DIRTY=0 - SCM_STATE=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_STATE="${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}" fi - SCM_PREFIX=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - SCM_SUFFIX=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + SCM_PREFIX="${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" + SCM_SUFFIX="${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" HG_ROOT=$(get_hg_root) - if [ -f "$HG_ROOT/branch" ]; then + if [[ -f "$HG_ROOT/branch" ]]; then # Mercurial holds it's current branch in .hg/branch file SCM_BRANCH=$(< "${HG_ROOT}/branch") - local bookmark=${HG_ROOT}/bookmarks.current - [[ -f ${bookmark} ]] && SCM_BRANCH+=:$(< "${bookmark}") + local bookmark="${HG_ROOT}/bookmarks.current" + [[ -f "${bookmark}" ]] && SCM_BRANCH+=:$(< "${bookmark}") else SCM_BRANCH=$(hg summary 2> /dev/null | grep branch: | awk '{print $2}') fi - if [ -f "$HG_ROOT/dirstate" ]; then + if [[ -f "$HG_ROOT/dirstate" ]]; then # Mercurial holds various information about the working directory in .hg/dirstate file. More on http://mercurial.selenic.com/wiki/DirState SCM_CHANGE=$(hexdump -vn 10 -e '1/1 "%02x"' "$HG_ROOT/dirstate" | cut -c-12) else @@ -396,7 +397,7 @@ function hg_prompt_vars { fi } -function nvm_version_prompt { +function nvm_version_prompt() { local node if _is_function nvm; then node=$(nvm current 2> /dev/null) @@ -405,36 +406,36 @@ function nvm_version_prompt { fi } -function node_version_prompt { +function node_version_prompt() { echo -e "$(nvm_version_prompt)" } -function rvm_version_prompt { - if which rvm &> /dev/null; then - rvm=$(rvm-prompt) || return - if [ -n "$rvm" ]; then +function rvm_version_prompt() { + if _command_exists rvm; then + rvm="$(rvm-prompt)" || return + if [[ -n "$rvm" ]]; then echo -e "$RVM_THEME_PROMPT_PREFIX$rvm$RVM_THEME_PROMPT_SUFFIX" fi fi } -function rbenv_version_prompt { +function rbenv_version_prompt() { if which rbenv &> /dev/null; then rbenv=$(rbenv version-name) || return rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}" - if [ "$rbenv" != "system" ]; then + if [[ "$rbenv" != "system" ]]; then echo -e "$RBENV_THEME_PROMPT_PREFIX$rbenv$RBENV_THEME_PROMPT_SUFFIX" fi fi } -function rbfu_version_prompt { +function rbfu_version_prompt() { if [[ -n "${RBFU_RUBY_VERSION:-}" ]]; then echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}" fi } -function chruby_version_prompt { +function chruby_version_prompt() { if _is_function chruby; then if _is_function chruby_auto; then chruby_auto @@ -449,81 +450,81 @@ function chruby_version_prompt { fi } -function ruby_version_prompt { +function ruby_version_prompt() { if [[ "${THEME_SHOW_RUBY_PROMPT:-}" == "true" ]]; then echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)" fi } -function k8s_context_prompt { +function k8s_context_prompt() { echo -e "$(kubectl config current-context 2> /dev/null)" } -function k8s_namespace_prompt { +function k8s_namespace_prompt() { echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)" } -function virtualenv_prompt { +function virtualenv_prompt() { if [[ -n "${VIRTUAL_ENV:-}" ]]; then virtualenv="${VIRTUAL_ENV##*/}" echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" fi } -function condaenv_prompt { +function condaenv_prompt() { if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then echo -e "${CONDAENV_THEME_PROMPT_PREFIX:-}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX:-}" fi } -function py_interp_prompt { +function py_interp_prompt() { local py_version - py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return + py_version="$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}')" || return echo -e "${PYTHON_THEME_PROMPT_PREFIX:-}${py_version}${PYTHON_THEME_PROMPT_SUFFIX:-}" } -function python_version_prompt { +function python_version_prompt() { echo -e "$(virtualenv_prompt)$(condaenv_prompt)$(py_interp_prompt)" } -function git_user_info { +function git_user_info() { # support two or more initials, set by 'git pair' plugin - SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%') + SCM_CURRENT_USER="$(git config user.initials | sed 's% %+%')" # if `user.initials` weren't set, attempt to extract initials from `user.name` [[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" "$(for word in $(git config user.name | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done)") [[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX" } -function clock_char { - CLOCK_CHAR=${THEME_CLOCK_CHAR:-"⌚"} - CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"} - SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"} +function clock_char() { + local clock_char clock_char_color show_clock_char + clock_char="${THEME_CLOCK_CHAR:-⌚}" + clock_char_color="${THEME_CLOCK_CHAR_COLOR:-${normal:-}}" + show_clock_char="${THEME_SHOW_CLOCK_CHAR:-"true"}" - if [[ "${SHOW_CLOCK_CHAR}" = "true" ]]; then - echo -e "${CLOCK_CHAR_COLOR}${CLOCK_CHAR_THEME_PROMPT_PREFIX}${CLOCK_CHAR}${CLOCK_CHAR_THEME_PROMPT_SUFFIX}" + if [[ "${show_clock_char}" == "true" ]]; then + echo -e "${clock_char_color}${CLOCK_CHAR_THEME_PROMPT_PREFIX}${clock_char}${CLOCK_CHAR_THEME_PROMPT_SUFFIX}" fi } -function clock_prompt { - CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"} - CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"} - [[ -z "${THEME_SHOW_CLOCK:-}" ]] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"} - SHOW_CLOCK=$THEME_SHOW_CLOCK +function clock_prompt() { + local CLOCK_COLOR="${THEME_CLOCK_COLOR:-${normal?}}" + local CLOCK_FORMAT="${THEME_CLOCK_FORMAT:-"%H:%M:%S"}" + local SHOW_CLOCK="${THEME_SHOW_CLOCK:-${THEME_CLOCK_CHECK:-true}}" + local CLOCK_STRING="\D{${CLOCK_FORMAT}}" - if [[ "${SHOW_CLOCK}" = "true" ]]; then - CLOCK_STRING=$(date +"${CLOCK_FORMAT}") + if [[ "${SHOW_CLOCK}" == "true" ]]; then echo -e "${CLOCK_COLOR}${CLOCK_THEME_PROMPT_PREFIX}${CLOCK_STRING}${CLOCK_THEME_PROMPT_SUFFIX}" fi } -function user_host_prompt { - if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then +function user_host_prompt() { + if [[ "${THEME_SHOW_USER_HOST}" == "true" ]]; then echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}" fi } # backwards-compatibility -function git_prompt_info { +function git_prompt_info() { _git-hide-status && return git_prompt_vars echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" @@ -534,7 +535,7 @@ function p4_prompt_info() { echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}" } -function svn_prompt_info { +function svn_prompt_info() { svn_prompt_vars echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" } @@ -544,39 +545,32 @@ function hg_prompt_info() { echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}" } -function scm_char { +function scm_char() { scm_prompt_char echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" } -function prompt_char { +function prompt_char() { scm_char } -function battery_char { - if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then - echo -e "${bold_red:-}$(battery_percentage)%" +function battery_char() { + # The battery_char function depends on the presence of the battery_percentage function. + if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]] && _command_exists battery_percentage; then + echo -e "${bold_red?}$(battery_percentage)%" + else + false fi } if ! _command_exists battery_charge; then # if user has installed battery plugin, skip this... function battery_charge() { - # no op - echo -n - } -fi - -# The battery_char function depends on the presence of the battery_percentage function. -# If battery_percentage is not defined, then define battery_char as a no-op. -if ! _command_exists battery_percentage; then - function battery_char() { - # no op - echo -n + : # no op } fi -function aws_profile { +function aws_profile() { if [[ -n "${AWS_DEFAULT_PROFILE:-}" ]]; then echo -e "${AWS_DEFAULT_PROFILE}" else From ac0d91b682402d916ff0055ecf59e7593e8fb303 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 19 Jan 2022 12:10:54 -0800 Subject: [PATCH 105/239] lib/theme.githelpers: remove dead code Five years deprecation is plenty warning. --- themes/githelpers.theme.bash | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index 2fbb7e8a52..719effeced 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -171,35 +171,3 @@ function _git-remote-info() { fi fi } - -# Unused by bash-it, present for API compatibility -function git_status_summary() { - awk ' - BEGIN { - untracked=0; - unstaged=0; - staged=0; - } - { - if (!after_first && $0 ~ /^##.+/) { - print $0 - seen_header = 1 - } else if ($0 ~ /^\?\? .+/) { - untracked += 1 - } else { - if ($0 ~ /^.[^ ] .+/) { - unstaged += 1 - } - if ($0 ~ /^[^ ]. .+/) { - staged += 1 - } - } - after_first = 1 - } - END { - if (!seen_header) { - print - } - print untracked "\t" unstaged "\t" staged - }' -} From 2b3af0d8c99b068b41225a02db1de70a8e05972d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 26 Jan 2022 11:02:11 -0800 Subject: [PATCH 106/239] lib/theme: eliminate a lot of subshells A lot of useless `echo`s in here. --- themes/base.theme.bash | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 1706eba4dd..61e9cb7a4f 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -206,14 +206,14 @@ function scm_prompt_info_common() { function terraform_workspace_prompt() { if _command_exists terraform; then if [[ -d .terraform ]]; then - echo -e "$(terraform workspace show 2> /dev/null)" + terraform workspace show 2> /dev/null fi fi } function active_gcloud_account_prompt() { if _command_exists gcloud; then - echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)" + gcloud config list account --format "value(core.account)" 2> /dev/null fi } @@ -291,7 +291,7 @@ function git_prompt_vars() { unstaged_count="${VCS_STATUS_NUM_UNSTAGED?}" staged_count="${VCS_STATUS_NUM_STAGED?}" else - IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)" + IFS=$'\t' read -r untracked_count unstaged_count staged_count < <(_git-status-counts) fi if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then SCM_DIRTY=1 @@ -310,14 +310,17 @@ function git_prompt_vars() { SCM_PREFIX="${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" SCM_SUFFIX="${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" - SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo "") + SCM_CHANGE=$(_git-short-sha 2> /dev/null || true) } function p4_prompt_vars() { + local opened_count non_default_changes default_count \ + add_file_count edit_file_count delete_file_count + IFS=$'\t' read -r \ opened_count non_default_changes default_count \ add_file_count edit_file_count delete_file_count \ - <<< "$(_p4-opened-counts)" + < <(_p4-opened-counts) if [[ "${opened_count}" -gt 0 ]]; then SCM_DIRTY=1 SCM_STATE="${SCM_THEME_PROMPT_DIRTY}" @@ -334,7 +337,7 @@ function p4_prompt_vars() { } function svn_prompt_vars() { - if [[ -n $(svn status | head -c1 2> /dev/null) ]]; then + if [[ -n "$(svn status | head -c1 2> /dev/null)" ]]; then SCM_DIRTY=1 SCM_STATE="${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}" else @@ -407,7 +410,7 @@ function nvm_version_prompt() { } function node_version_prompt() { - echo -e "$(nvm_version_prompt)" + nvm_version_prompt } function rvm_version_prompt() { @@ -457,14 +460,15 @@ function ruby_version_prompt() { } function k8s_context_prompt() { - echo -e "$(kubectl config current-context 2> /dev/null)" + kubectl config current-context 2> /dev/null } function k8s_namespace_prompt() { - echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)" + kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null } function virtualenv_prompt() { + local virtualenv if [[ -n "${VIRTUAL_ENV:-}" ]]; then virtualenv="${VIRTUAL_ENV##*/}" echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" @@ -507,13 +511,13 @@ function clock_char() { } function clock_prompt() { - local CLOCK_COLOR="${THEME_CLOCK_COLOR:-${normal?}}" - local CLOCK_FORMAT="${THEME_CLOCK_FORMAT:-"%H:%M:%S"}" - local SHOW_CLOCK="${THEME_SHOW_CLOCK:-${THEME_CLOCK_CHECK:-true}}" - local CLOCK_STRING="\D{${CLOCK_FORMAT}}" + local clock_color="${THEME_CLOCK_COLOR:-${normal?}}" + local clock_format="${THEME_CLOCK_FORMAT:-"%H:%M:%S"}" + local show_clock="${THEME_SHOW_CLOCK:-${THEME_CLOCK_CHECK:-true}}" + local clock_string="\D{${clock_format}}" - if [[ "${SHOW_CLOCK}" == "true" ]]; then - echo -e "${CLOCK_COLOR}${CLOCK_THEME_PROMPT_PREFIX}${CLOCK_STRING}${CLOCK_THEME_PROMPT_SUFFIX}" + if [[ "${show_clock}" == "true" ]]; then + echo -e "${clock_color}${CLOCK_THEME_PROMPT_PREFIX}${clock_string}${CLOCK_THEME_PROMPT_SUFFIX}" fi } From c6ac9109d71e833730149cb723442b17c8458531 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 26 Jan 2022 10:59:49 -0800 Subject: [PATCH 107/239] lib/theme: parameter cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve handling of parameters by adding defaults (often blank). AlsΓΆ, eliminate newlines from `echo` in many places. --- themes/base.theme.bash | 267 ++++++++++++++++++++--------------------- 1 file changed, 132 insertions(+), 135 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 61e9cb7a4f..3455812f06 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -88,21 +88,21 @@ RBENV_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' -: "${GIT_EXE:=$SCM_GIT}" -: "${P4_EXE:=$SCM_P4}" -: "${HG_EXE:=$SCM_HG}" -: "${SVN_EXE:=$SCM_SVN}" +: "${GIT_EXE:=${SCM_GIT?}}" +: "${HG_EXE:=${SCM_HG?}}" +: "${SVN_EXE:=${SCM_SVN?}}" +: "${P4_EXE:=${SCM_P4?}}" function _bash_it_appearance_scm_init() { - GIT_EXE="$(type -P "${SCM_GIT}" || true)" - P4_EXE="$(type -P "${SCM_P4}" || true)" - HG_EXE="$(type -P "${SCM_HG}" || true)" - SVN_EXE="$(type -P "${SCM_SVN}" || true)" + GIT_EXE="$(type -P "${SCM_GIT:-git}" || true)" + HG_EXE="$(type -P "${SCM_HG:-hg}" || true)" + SVN_EXE="$(type -P "${SCM_SVN:-svn}" || true)" + P4_EXE="$(type -P "${SCM_P4:-p4}" || true)" # Check for broken SVN exe that is caused by some versions of Xcode. # See https://github.com/Bash-it/bash-it/issues/1612 for more details. - if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then - if ! "$SVN_EXE" --version > /dev/null 2>&1; then + if [[ -x "${SVN_EXE-}" && -x "${SVN_EXE%/svn}/xcrun" ]]; then + if ! "${SVN_EXE}" --version > /dev/null 2>&1; then # Unset the SVN exe variable so that SVN commands are avoided. SVN_EXE="" fi @@ -112,51 +112,61 @@ function _bash_it_appearance_scm_init() { _bash_it_library_finalize_hook+=('_bash_it_appearance_scm_init') function scm() { - if [[ "$SCM_CHECK" == false ]]; then - SCM="$SCM_NONE" - elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then - SCM="$SCM_GIT" - elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then - SCM="$SCM_HG" - elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then - SCM="$SCM_SVN" - elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then - SCM="$SCM_GIT" - elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then - SCM="$SCM_HG" - elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then - SCM="$SCM_SVN" - elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then - SCM="$SCM_P4" + if [[ "${SCM_CHECK:-true}" == "false" ]]; then + SCM="${SCM_NONE-NONE}" + elif [[ -f .git/HEAD ]] && [[ -x "${GIT_EXE-}" ]]; then + SCM="${SCM_GIT?}" + elif [[ -d .hg ]] && [[ -x "${HG_EXE-}" ]]; then + SCM="${SCM_HG?}" + elif [[ -d .svn ]] && [[ -x "${SVN_EXE-}" ]]; then + SCM="${SCM_SVN?}" + elif [[ -x "${GIT_EXE-}" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then + SCM="${SCM_GIT?}" + elif [[ -x "${HG_EXE-}" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then + SCM="${SCM_HG?}" + elif [[ -x "${SVN_EXE-}" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then + SCM="${SCM_SVN?}" + elif [[ -x "${P4_EXE-}" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then + SCM="${SCM_P4?}" else - SCM="$SCM_NONE" + SCM="${SCM_NONE-NONE}" fi } function scm_prompt() { - local CHAR - CHAR="$(scm_char)" - local format="${SCM_PROMPT_FORMAT:-'[%s%s]'}" + local format="${SCM_PROMPT_FORMAT-"[%s%s]"}" + local scm_char scm_prompt_info + scm_char="$(scm_char)" + scm_prompt_info="$(scm_prompt_info)" - if [[ "${CHAR}" != "$SCM_NONE_CHAR" ]]; then + if [[ "${scm_char}" != "${SCM_NONE_CHAR:-}" ]]; then # shellcheck disable=2059 - printf "$format\n" "$CHAR" "$(scm_prompt_info)" + printf "${format}" "${scm_char}" "${scm_prompt_info}" fi } function scm_prompt_char() { - if [[ -z "$SCM" ]]; then scm; fi - if [[ $SCM == "$SCM_GIT" ]]; then - SCM_CHAR="$SCM_GIT_CHAR" - elif [[ $SCM == "$SCM_P4" ]]; then - SCM_CHAR="$SCM_P4_CHAR" - elif [[ $SCM == "$SCM_HG" ]]; then - SCM_CHAR="$SCM_HG_CHAR" - elif [[ $SCM == "$SCM_SVN" ]]; then - SCM_CHAR="$SCM_SVN_CHAR" - else - SCM_CHAR="$SCM_NONE_CHAR" - fi + if [[ -z "${SCM:-}" ]]; then + scm + fi + + case ${SCM?} in + "${SCM_GIT?}") + SCM_CHAR="${SCM_GIT_CHAR?}" + ;; + "${SCM_HG?}") + SCM_CHAR="${SCM_HG_CHAR?}" + ;; + "${SCM_SVN?}") + SCM_CHAR="${SCM_SVN_CHAR?}" + ;; + "${SCM_P4?}") + SCM_CHAR="${SCM_P4_CHAR?}" + ;; + *) + SCM_CHAR="${SCM_NONE_CHAR:-}" + ;; + esac } function scm_prompt_vars() { @@ -164,10 +174,9 @@ function scm_prompt_vars() { scm_prompt_char SCM_DIRTY=0 SCM_STATE='' - [[ $SCM == "$SCM_GIT" ]] && git_prompt_vars && return - [[ $SCM == "$SCM_P4" ]] && p4_prompt_vars && return - [[ $SCM == "$SCM_HG" ]] && hg_prompt_vars && return - [[ $SCM == "$SCM_SVN" ]] && svn_prompt_vars && return + + local prompt_vars="${SCM}_prompt_vars" + _is_function "${prompt_vars}" && "${prompt_vars}" } function scm_prompt_info() { @@ -178,29 +187,31 @@ function scm_prompt_info() { function scm_prompt_char_info() { scm_prompt_char - echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" + echo -ne "${SCM_THEME_CHAR_PREFIX-}${SCM_CHAR?}${SCM_THEME_CHAR_SUFFIX-}" scm_prompt_info_common } function scm_prompt_info_common() { + local prompt_info SCM_DIRTY=0 SCM_STATE='' - if [[ ${SCM} == "${SCM_GIT}" ]]; then - if [[ ${SCM_GIT_SHOW_MINIMAL_INFO} == true ]]; then - # user requests minimal git status information - git_prompt_minimal_info - else - # more detailed git status - git_prompt_info - fi - return - fi - - # TODO: consider adding minimal status information for hg and svn - { [[ ${SCM} == "${SCM_P4}" ]] && p4_prompt_info && return; } || true - { [[ ${SCM} == "${SCM_HG}" ]] && hg_prompt_info && return; } || true - { [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true + case ${SCM?} in + "${SCM_GIT?}") + if [[ ${SCM_GIT_SHOW_MINIMAL_INFO:-false} == "true" ]]; then + # user requests minimal git status information + prompt_info="${SCM}_prompt_minimal_info" + else + # more detailed git status + prompt_info="${SCM}_prompt_info" + fi + ;; + *) + # TODO: consider adding minimal status information for hg and svn + prompt_info="${SCM}_prompt_info" + ;; + esac + _is_function "${prompt_info}" && "${prompt_info}" } function terraform_workspace_prompt() { @@ -218,25 +229,25 @@ function active_gcloud_account_prompt() { } function git_prompt_minimal_info() { - SCM_STATE="${SCM_THEME_PROMPT_CLEAN}" + SCM_STATE="${SCM_THEME_PROMPT_CLEAN?}" _git-hide-status && return - SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)" + SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX-}\$(_git-friendly-ref)" if [[ -n "$(_git-status | tail -n1)" ]]; then SCM_DIRTY=1 - SCM_STATE="${SCM_THEME_PROMPT_DIRTY}" + SCM_STATE="${SCM_THEME_PROMPT_DIRTY?}" fi # Output the git prompt - SCM_PREFIX="${SCM_THEME_PROMPT_PREFIX}" - SCM_SUFFIX="${SCM_THEME_PROMPT_SUFFIX}" - echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" + SCM_PREFIX="${SCM_THEME_PROMPT_PREFIX-}" + SCM_SUFFIX="${SCM_THEME_PROMPT_SUFFIX-}" + echo -ne "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" } function git_prompt_vars() { - if "${SCM_GIT_USE_GITSTATUS:-false}" && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT:-}" == "ok-sync" ]]; then + if [[ "${SCM_GIT_USE_GITSTATUS:-false}" != "false" ]] && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT:-}" == "ok-sync" ]]; then # we can use faster gitstatus # use this variable in githelpers and below to choose gitstatus output SCM_GIT_GITSTATUS_RAN=true @@ -300,15 +311,15 @@ function git_prompt_vars() { [[ "${unstaged_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2 [[ "${untracked_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1 fi - SCM_STATE="${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}" + SCM_STATE="${GIT_THEME_PROMPT_DIRTY:-${SCM_THEME_PROMPT_DIRTY?}}" fi fi # no if for gitstatus here, user extraction is not supported by it [[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)" - SCM_PREFIX="${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" - SCM_SUFFIX="${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" + SCM_PREFIX="${GIT_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}" + SCM_SUFFIX="${GIT_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}" SCM_CHANGE=$(_git-short-sha 2> /dev/null || true) } @@ -323,65 +334,45 @@ function p4_prompt_vars() { < <(_p4-opened-counts) if [[ "${opened_count}" -gt 0 ]]; then SCM_DIRTY=1 - SCM_STATE="${SCM_THEME_PROMPT_DIRTY}" - [[ "${opened_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_OPENED_CHAR}${opened_count}" - [[ "${non_default_changes}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_CHANGES_CHAR}${non_default_changes}" - [[ "${default_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_DEFAULT_CHAR}${default_count}" + SCM_STATE="${SCM_THEME_PROMPT_DIRTY?}" + [[ "${opened_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_OPENED_CHAR?}${opened_count}" + [[ "${non_default_changes}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_CHANGES_CHAR?}${non_default_changes}" + [[ "${default_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_DEFAULT_CHAR?}${default_count}" else SCM_DIRTY=0 - SCM_STATE="${SCM_THEME_PROMPT_DIRTY}" + SCM_STATE="${SCM_THEME_PROMPT_CLEAN?}" fi - SCM_PREFIX="${P4_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" - SCM_SUFFIX="${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" + SCM_PREFIX="${P4_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}" + SCM_SUFFIX="${P4_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}" } function svn_prompt_vars() { if [[ -n "$(svn status | head -c1 2> /dev/null)" ]]; then SCM_DIRTY=1 - SCM_STATE="${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}" + SCM_STATE="${SVN_THEME_PROMPT_DIRTY:-${SCM_THEME_PROMPT_DIRTY?}}" else SCM_DIRTY=0 - SCM_STATE="${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}" + SCM_STATE="${SVN_THEME_PROMPT_CLEAN:-${SCM_THEME_PROMPT_CLEAN?}}" fi - SCM_PREFIX="${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" - SCM_SUFFIX="${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" + SCM_PREFIX="${SVN_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}" + SCM_SUFFIX="${SVN_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}" SCM_BRANCH="$(svn info --show-item=url 2> /dev/null | awk -F/ '{ for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }')" || return SCM_CHANGE="$(svn info --show-item=revision 2> /dev/null)" } -# this functions returns absolute location of .hg directory if one exists -# It starts in the current directory and moves its way up until it hits /. -# If we get to / then no Mercurial repository was found. -# Example: -# - lets say we cd into ~/Projects/Foo/Bar -# - .hg is located in ~/Projects/Foo/.hg -# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo -function get_hg_root() { - local CURRENT_DIR="${PWD}" - - while [[ "${CURRENT_DIR:-/}" != "/" ]]; do - if [[ -d "$CURRENT_DIR/.hg" ]]; then - echo "$CURRENT_DIR/.hg" - return - fi - - CURRENT_DIR="${CURRENT_DIR%/*}" - done -} - function hg_prompt_vars() { if [[ -n $(hg status 2> /dev/null) ]]; then SCM_DIRTY=1 - SCM_STATE="${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}" + SCM_STATE="${HG_THEME_PROMPT_DIRTY:-${SCM_THEME_PROMPT_DIRTY?}}" else SCM_DIRTY=0 - SCM_STATE="${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}" + SCM_STATE="${HG_THEME_PROMPT_CLEAN:-${SCM_THEME_PROMPT_CLEAN?}}" fi - SCM_PREFIX="${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}" - SCM_SUFFIX="${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}" + SCM_PREFIX="${HG_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}" + SCM_SUFFIX="${HG_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}" - HG_ROOT=$(get_hg_root) + HG_ROOT=$(_bash-it-find-in-ancestor ".hg") if [[ -f "$HG_ROOT/branch" ]]; then # Mercurial holds it's current branch in .hg/branch file @@ -405,7 +396,7 @@ function nvm_version_prompt() { if _is_function nvm; then node=$(nvm current 2> /dev/null) [[ "${node}" == "system" ]] && return - echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}" + echo -ne "${NVM_THEME_PROMPT_PREFIX-}${node}${NVM_THEME_PROMPT_SUFFIX-}" fi } @@ -417,7 +408,7 @@ function rvm_version_prompt() { if _command_exists rvm; then rvm="$(rvm-prompt)" || return if [[ -n "$rvm" ]]; then - echo -e "$RVM_THEME_PROMPT_PREFIX$rvm$RVM_THEME_PROMPT_SUFFIX" + echo -ne "${RVM_THEME_PROMPT_PREFIX-}${rvm}${RVM_THEME_PROMPT_SUFFIX-}" fi fi } @@ -427,14 +418,14 @@ function rbenv_version_prompt() { rbenv=$(rbenv version-name) || return rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}" if [[ "$rbenv" != "system" ]]; then - echo -e "$RBENV_THEME_PROMPT_PREFIX$rbenv$RBENV_THEME_PROMPT_SUFFIX" + echo -ne "${RBENV_THEME_PROMPT_PREFIX-}${rbenv}${RBENV_THEME_PROMPT_SUFFIX-}" fi fi } function rbfu_version_prompt() { if [[ -n "${RBFU_RUBY_VERSION:-}" ]]; then - echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}" + echo -ne "${RBFU_THEME_PROMPT_PREFIX-}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX-}" fi } @@ -449,13 +440,16 @@ function chruby_version_prompt() { if ! chruby | grep -q '\*'; then ruby_version="${ruby_version} (system)" fi - echo -e "${CHRUBY_THEME_PROMPT_PREFIX:-}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX:-}" + echo -ne "${CHRUBY_THEME_PROMPT_PREFIX-}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX-}" fi } function ruby_version_prompt() { if [[ "${THEME_SHOW_RUBY_PROMPT:-}" == "true" ]]; then - echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)" + rbfu_version_prompt + rbenv_version_prompt + rvm_version_prompt + chruby_version_prompt fi } @@ -471,32 +465,35 @@ function virtualenv_prompt() { local virtualenv if [[ -n "${VIRTUAL_ENV:-}" ]]; then virtualenv="${VIRTUAL_ENV##*/}" - echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" + echo -ne "${VIRTUALENV_THEME_PROMPT_PREFIX-}${virtualenv}${VIRTUALENV_THEME_PROMPT_SUFFIX-}" fi } function condaenv_prompt() { if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then - echo -e "${CONDAENV_THEME_PROMPT_PREFIX:-}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX:-}" + echo -ne "${CONDAENV_THEME_PROMPT_PREFIX-}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX-}" fi } function py_interp_prompt() { local py_version py_version="$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}')" || return - echo -e "${PYTHON_THEME_PROMPT_PREFIX:-}${py_version}${PYTHON_THEME_PROMPT_SUFFIX:-}" + echo -ne "${PYTHON_THEME_PROMPT_PREFIX-}${py_version}${PYTHON_THEME_PROMPT_SUFFIX-}" } function python_version_prompt() { - echo -e "$(virtualenv_prompt)$(condaenv_prompt)$(py_interp_prompt)" + virtualenv_prompt + condaenv_prompt + py_interp_prompt } function git_user_info() { + local current_user # support two or more initials, set by 'git pair' plugin - SCM_CURRENT_USER="$(git config user.initials | sed 's% %+%')" + current_user="$(git config user.initials | sed 's% %+%')" # if `user.initials` weren't set, attempt to extract initials from `user.name` - [[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" "$(for word in $(git config user.name | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done)") - [[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX" + [[ -z "${current_user}" ]] && current_user=$(printf "%s" "$(for word in $(git config user.name | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done)") + [[ -n "${current_user}" ]] && printf "%s" "${SCM_THEME_CURRENT_USER_PREFFIX-}${current_user}${SCM_THEME_CURRENT_USER_SUFFIX-}" } function clock_char() { @@ -506,7 +503,7 @@ function clock_char() { show_clock_char="${THEME_SHOW_CLOCK_CHAR:-"true"}" if [[ "${show_clock_char}" == "true" ]]; then - echo -e "${clock_char_color}${CLOCK_CHAR_THEME_PROMPT_PREFIX}${clock_char}${CLOCK_CHAR_THEME_PROMPT_SUFFIX}" + echo -ne "${clock_char_color}${CLOCK_CHAR_THEME_PROMPT_PREFIX-}${clock_char}${CLOCK_CHAR_THEME_PROMPT_SUFFIX-}" fi } @@ -517,13 +514,13 @@ function clock_prompt() { local clock_string="\D{${clock_format}}" if [[ "${show_clock}" == "true" ]]; then - echo -e "${clock_color}${CLOCK_THEME_PROMPT_PREFIX}${clock_string}${CLOCK_THEME_PROMPT_SUFFIX}" + echo -ne "${clock_color}${CLOCK_THEME_PROMPT_PREFIX-}${clock_string}${CLOCK_THEME_PROMPT_SUFFIX-}" fi } function user_host_prompt() { - if [[ "${THEME_SHOW_USER_HOST}" == "true" ]]; then - echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}" + if [[ "${THEME_SHOW_USER_HOST:-false}" == "true" ]]; then + echo -ne "${USER_HOST_THEME_PROMPT_PREFIX-}\u@${THEME_PROMPT_HOST:-\h}${USER_HOST_THEME_PROMPT_SUFFIX-}" fi } @@ -531,27 +528,27 @@ function user_host_prompt() { function git_prompt_info() { _git-hide-status && return git_prompt_vars - echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" + echo -ne "${SCM_PREFIX?}${SCM_BRANCH?}${SCM_STATE?}${SCM_SUFFIX?}" } function p4_prompt_info() { p4_prompt_vars - echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}" + echo -ne "${SCM_PREFIX?}${SCM_BRANCH?}:${SCM_CHANGE?}${SCM_STATE?}${SCM_SUFFIX?}" } function svn_prompt_info() { svn_prompt_vars - echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" + echo -ne "${SCM_PREFIX?}${SCM_BRANCH?}${SCM_STATE?}${SCM_SUFFIX?}" } function hg_prompt_info() { hg_prompt_vars - echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}" + echo -ne "${SCM_PREFIX?}${SCM_BRANCH?}:${SCM_CHANGE#*:}${SCM_STATE?}${SCM_SUFFIX?}" } function scm_char() { scm_prompt_char - echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" + echo -ne "${SCM_THEME_CHAR_PREFIX?}${SCM_CHAR?}${SCM_THEME_CHAR_SUFFIX?}" } function prompt_char() { @@ -561,7 +558,7 @@ function prompt_char() { function battery_char() { # The battery_char function depends on the presence of the battery_percentage function. if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]] && _command_exists battery_percentage; then - echo -e "${bold_red?}$(battery_percentage)%" + echo -ne "${bold_red?}$(battery_percentage)%" else false fi @@ -576,9 +573,9 @@ fi function aws_profile() { if [[ -n "${AWS_DEFAULT_PROFILE:-}" ]]; then - echo -e "${AWS_DEFAULT_PROFILE}" + echo -ne "${AWS_DEFAULT_PROFILE}" else - echo -e "default" + echo -ne "default" fi } From d86a182b6eb9d0f34c4a8f54196c38431f45eb4b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 6 Feb 2022 16:55:32 -0800 Subject: [PATCH 108/239] lib/theme: export `$LS_COLORS` et al --- themes/base.theme.bash | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 3455812f06..593bcc5170 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -1,6 +1,10 @@ # shellcheck shell=bash # shellcheck disable=SC2034 # Expected behavior for themes. +# Colors for listing files, using default color scheme. +# To customize color scheme by theme, check out https://geoff.greer.fm/lscolors/ +export CLICOLOR LSCOLORS LS_COLORS + CLOCK_CHAR_THEME_PROMPT_PREFIX='' CLOCK_CHAR_THEME_PROMPT_SUFFIX='' CLOCK_THEME_PROMPT_PREFIX='' From c9efc161ff9a05d8512dc6e4bffeb24bb1df91c3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 12 Feb 2022 21:08:29 -0800 Subject: [PATCH 109/239] lib/theme: improve performance of `scm()` - Don't invoke the source control utility when all we want to know is if we're somewhere inside the repository; use `_bash-it-find-in-ancestor()`. --- themes/base.theme.bash | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 593bcc5170..440a817cc5 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -118,19 +118,13 @@ _bash_it_library_finalize_hook+=('_bash_it_appearance_scm_init') function scm() { if [[ "${SCM_CHECK:-true}" == "false" ]]; then SCM="${SCM_NONE-NONE}" - elif [[ -f .git/HEAD ]] && [[ -x "${GIT_EXE-}" ]]; then + elif [[ -x "${GIT_EXE-}" ]] && _bash-it-find-in-ancestor '.git' > /dev/null; then SCM="${SCM_GIT?}" - elif [[ -d .hg ]] && [[ -x "${HG_EXE-}" ]]; then + elif [[ -x "${HG_EXE-}" ]] && _bash-it-find-in-ancestor '.hg' > /dev/null; then SCM="${SCM_HG?}" - elif [[ -d .svn ]] && [[ -x "${SVN_EXE-}" ]]; then + elif [[ -x "${SVN_EXE-}" ]] && _bash-it-find-in-ancestor '.svn' > /dev/null; then SCM="${SCM_SVN?}" - elif [[ -x "${GIT_EXE-}" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then - SCM="${SCM_GIT?}" - elif [[ -x "${HG_EXE-}" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then - SCM="${SCM_HG?}" - elif [[ -x "${SVN_EXE-}" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then - SCM="${SCM_SVN?}" - elif [[ -x "${P4_EXE-}" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then + elif [[ -x "${P4_EXE-}" && -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM="${SCM_P4?}" else SCM="${SCM_NONE-NONE}" @@ -376,7 +370,7 @@ function hg_prompt_vars() { SCM_PREFIX="${HG_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}" SCM_SUFFIX="${HG_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}" - HG_ROOT=$(_bash-it-find-in-ancestor ".hg") + HG_ROOT="$(_bash-it-find-in-ancestor ".hg")/.hg" if [[ -f "$HG_ROOT/branch" ]]; then # Mercurial holds it's current branch in .hg/branch file From 7762aa687a6c60e4c7b49c3c741577e5c9b62149 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 23 Feb 2022 16:38:58 -0800 Subject: [PATCH 110/239] lib/theme: `local hg_root` in `hg_prompt_vars()` --- themes/base.theme.bash | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 440a817cc5..02602bc869 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -360,6 +360,7 @@ function svn_prompt_vars() { } function hg_prompt_vars() { + local hg_root bookmark if [[ -n $(hg status 2> /dev/null) ]]; then SCM_DIRTY=1 SCM_STATE="${HG_THEME_PROMPT_DIRTY:-${SCM_THEME_PROMPT_DIRTY?}}" @@ -370,20 +371,20 @@ function hg_prompt_vars() { SCM_PREFIX="${HG_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}" SCM_SUFFIX="${HG_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}" - HG_ROOT="$(_bash-it-find-in-ancestor ".hg")/.hg" + hg_root="$(_bash-it-find-in-ancestor ".hg")/.hg" - if [[ -f "$HG_ROOT/branch" ]]; then + if [[ -f "$hg_root/branch" ]]; then # Mercurial holds it's current branch in .hg/branch file - SCM_BRANCH=$(< "${HG_ROOT}/branch") - local bookmark="${HG_ROOT}/bookmarks.current" + SCM_BRANCH=$(< "${hg_root}/branch") + bookmark="${hg_root}/bookmarks.current" [[ -f "${bookmark}" ]] && SCM_BRANCH+=:$(< "${bookmark}") else SCM_BRANCH=$(hg summary 2> /dev/null | grep branch: | awk '{print $2}') fi - if [[ -f "$HG_ROOT/dirstate" ]]; then + if [[ -f "$hg_root/dirstate" ]]; then # Mercurial holds various information about the working directory in .hg/dirstate file. More on http://mercurial.selenic.com/wiki/DirState - SCM_CHANGE=$(hexdump -vn 10 -e '1/1 "%02x"' "$HG_ROOT/dirstate" | cut -c-12) + SCM_CHANGE=$(hexdump -vn 10 -e '1/1 "%02x"' "$hg_root/dirstate" | cut -c-12) else SCM_CHANGE=$(hg summary 2> /dev/null | grep parent: | awk '{print $2}') fi From df87b41635b5f01eeaa4b51ca6fbc4df5b5164c3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 23 Feb 2022 16:54:47 -0800 Subject: [PATCH 111/239] lib/theme: use `_command_exists()` in `rbenv_version_prompt()` --- themes/base.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 02602bc869..92a56e5ec0 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -413,7 +413,7 @@ function rvm_version_prompt() { } function rbenv_version_prompt() { - if which rbenv &> /dev/null; then + if _command_exists rbenv; then rbenv=$(rbenv version-name) || return rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}" if [[ "$rbenv" != "system" ]]; then From 6734baf950d8bd7bca8821c7ecde942e1f94a0f7 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Mar 2022 23:02:29 -0800 Subject: [PATCH 112/239] test/base: lose old TravisCS skip --- test/plugins/base.plugin.bats | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index f11983f1b0..6022451a91 100644 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -8,10 +8,6 @@ function local_setup_file() { } @test 'plugins base: ips()' { - if [[ -n "${CI:-}" ]]; then - skip 'ifconfig probably requires sudo on TravisCI' - fi - declare -r localhost='127.0.0.1' run ips assert_success From dc380e9ed6f42967e759e8b66791f796db964843 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Mar 2022 23:14:33 -0800 Subject: [PATCH 113/239] =?UTF-8?q?test/battery:=20fix=20tests=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/plugins/battery.plugin.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 487fb68f29..1a2065587d 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -195,14 +195,14 @@ function setup_acpi { # Creates a `upower` function that simulates output like the real `upower` command. # The passed in parameter is used for the remaining battery percentage. function setup_upower { + trap -p PIPE | grep -q PIPE || trap '' PIPE percent="$1" BAT0="/org/freedesktop/UPower/devices/battery_BAT$RANDOM" function upower { case $1 in '-e'|'--enumerate') - # 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" + printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" ;; '-i'|'--show-info') if [[ $2 == "$BAT0" ]] From 6d422f17e44760c644f2e01363353a655a95906a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Mar 2022 23:33:05 -0800 Subject: [PATCH 114/239] Revert dc380e9ed6f42967e759e8b66791f796db964843 --- test/plugins/battery.plugin.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 1a2065587d..49199ef27c 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -195,7 +195,6 @@ function setup_acpi { # Creates a `upower` function that simulates output like the real `upower` command. # The passed in parameter is used for the remaining battery percentage. function setup_upower { - trap -p PIPE | grep -q PIPE || trap '' PIPE percent="$1" BAT0="/org/freedesktop/UPower/devices/battery_BAT$RANDOM" From 029e53a4339ed6209a550811cfd3ff9b93364494 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Mar 2022 23:37:37 -0800 Subject: [PATCH 115/239] plugin/battery: fix handling of multiple batteries with `upower` --- plugins/available/battery.plugin.bash | 12 ++++++------ test/plugins/battery.plugin.bats | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index 1f758e0cb5..b38d7f9d7b 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -4,8 +4,8 @@ about-plugin 'display info about your battery charge level' function ac_adapter_connected() { local batteries if _command_exists upower; then - batteries="$(upower -e | grep --max-count=1 -i BAT)" - upower -i "${batteries}" | grep 'state' | grep -q 'charging\|fully-charged' + IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT) + upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'charging\|fully-charged' elif _command_exists acpi; then acpi -a | grep -q "on-line" elif _command_exists pmset; then @@ -20,8 +20,8 @@ function ac_adapter_connected() { function ac_adapter_disconnected() { local batteries if _command_exists upower; then - batteries="$(upower -e | grep --max-count=1 -i BAT)" - upower -i "${batteries}" | grep 'state' | grep -q 'discharging' + IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT) + upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'discharging' elif _command_exists acpi; then acpi -a | grep -q "off-line" elif _command_exists pmset; then @@ -40,8 +40,8 @@ function battery_percentage() { local command_output batteries if _command_exists upower; then - batteries="$(upower --enumerate | grep --max-count=1 -i BAT)" - command_output="$(upower --show-info "${batteries:-}" | grep percentage | grep -o '[0-9]\+' | head -1)" + IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT) + command_output="$(upower --show-info "${batteries[0]:-}" | grep percentage | grep -o '[0-9]\+' | head -1)" elif _command_exists acpi; then command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}') elif _command_exists pmset; then diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 51ef93e944..96a0f58bcd 100755 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -199,8 +199,7 @@ function setup_upower { function upower { case $1 in '-e'|'--enumerate') - # 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" + printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" ;; '-i'|'--show-info') if [[ $2 == "$BAT0" ]] From f7cba27f10fe2f6d47e292d308e694c1b9b2f8ff Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 29 Jan 2022 22:17:42 -0800 Subject: [PATCH 116/239] lib/appearance: `shellcheck` && `shfmt` --- clean_files.txt | 1 + lib/appearance.bash | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 54180c19fd..016915aca6 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -76,6 +76,7 @@ completion/available/vuejs.completion.bash completion/available/wpscan.completion.bash # libraries +lib/appearance.bash lib/colors.bash lib/helpers.bash lib/history.bash diff --git a/lib/appearance.bash b/lib/appearance.bash index 6d0ef2ffce..9f02f74f41 100644 --- a/lib/appearance.bash +++ b/lib/appearance.bash @@ -1,19 +1,18 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # colored ls export LSCOLORS='Gxfxcxdxdxegedabagacad' -if [[ -z "$CUSTOM_THEME_DIR" ]]; then - CUSTOM_THEME_DIR="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/themes" -fi +: "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/themes"}" # Load the theme -if [[ $BASH_IT_THEME ]]; then - if [[ -f $BASH_IT_THEME ]]; then - source $BASH_IT_THEME - elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then - source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" - else - source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" - fi +# shellcheck disable=SC1090 +if [[ -n "${BASH_IT_THEME:-}" ]]; then + if [[ -f "${BASH_IT_THEME}" ]]; then + source "${BASH_IT_THEME}" + elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then + source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" + else + source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" + fi fi From 0286a50fcdb5df977bb5f2460855f3cbc110176b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 6 Feb 2022 15:22:52 -0800 Subject: [PATCH 117/239] lib/appearance: export `$CLICOLOR` instead of `$LSCOLOR` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AlsΓΆ, since the *value* of `$CLICOLOR` is not used anywhere, overload it to count the number of colors available for use elsewhere. --- lib/appearance.bash | 4 ++-- lib/log.bash | 2 +- themes/base.theme.bash | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/appearance.bash b/lib/appearance.bash index 9f02f74f41..e77a1a8032 100644 --- a/lib/appearance.bash +++ b/lib/appearance.bash @@ -1,7 +1,7 @@ # shellcheck shell=bash -# colored ls -export LSCOLORS='Gxfxcxdxdxegedabagacad' +: "${CLICOLOR:=$(tput colors)}" +export CLICOLOR : "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/themes"}" diff --git a/lib/log.bash b/lib/log.bash index 87b9ddf142..a8cb8080ec 100644 --- a/lib/log.bash +++ b/lib/log.bash @@ -45,7 +45,7 @@ function _bash-it-log-prefix-by-path() { function _has_colors() { # Check that stdout is a terminal, and that it has at least 8 colors. - [[ -t 1 && "${_bash_it_available_colors:=$(tput colors 2> /dev/null)}" -ge 8 ]] + [[ -t 1 && "${CLICOLOR:=$(tput colors 2> /dev/null)}" -ge 8 ]] } function _bash-it-log-message() { diff --git a/themes/base.theme.bash b/themes/base.theme.bash index d7479b3fc0..77c8b62195 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -1,6 +1,10 @@ # shellcheck shell=bash # shellcheck disable=SC2034 # Expected behavior for themes. +# Colors for listing files, using default color scheme. +# To customize color scheme by theme, check out https://geoff.greer.fm/lscolors/ +export CLICOLOR LSCOLORS LS_COLORS + CLOCK_CHAR_THEME_PROMPT_PREFIX='' CLOCK_CHAR_THEME_PROMPT_SUFFIX='' CLOCK_THEME_PROMPT_PREFIX='' From ad1d73aaa1537ae99334cbb412a30ef03a0bd395 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 26 Jul 2021 14:26:38 -0700 Subject: [PATCH 118/239] lib/command_duration: remove temporary files --- themes/command_duration.theme.bash | 31 +++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/themes/command_duration.theme.bash b/themes/command_duration.theme.bash index cf91785cb1..c7fb665595 100644 --- a/themes/command_duration.theme.bash +++ b/themes/command_duration.theme.bash @@ -1,40 +1,34 @@ # shellcheck shell=bash -if [ -z "$BASH_IT_COMMAND_DURATION" ] || [ "$BASH_IT_COMMAND_DURATION" != true ]; then +if [[ "${BASH_IT_COMMAND_DURATION:-false}" != true ]]; then _command_duration() { echo -n } return fi -# Define tmp dir and file -COMMAND_DURATION_TMPDIR="${TMPDIR:-/tmp}" -COMMAND_DURATION_FILE="${COMMAND_DURATION_FILE:-$COMMAND_DURATION_TMPDIR/bashit_theme_execution_$BASHPID}" +COMMAND_DURATION_START_TIME= COMMAND_DURATION_ICON=${COMMAND_DURATION_ICON:-' ο€— '} COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'} -trap _command_duration_delete_temp_file EXIT HUP INT TERM - -_command_duration_delete_temp_file() { - if [[ -f "$COMMAND_DURATION_FILE" ]]; then - rm -f "$COMMAND_DURATION_FILE" - fi -} - _command_duration_pre_exec() { - date +%s.%1N > "$COMMAND_DURATION_FILE" + local command_nano_now="$(date +%1N)" + [[ "$command_nano_now" == "1N" ]] && command_nano_now=1 + COMMAND_DURATION_START_TIME="$(date "+%s").${command_nano_now}" } _command_duration() { local command_duration command_start current_time local minutes seconds deciseconds local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds - current_time=$(date +%s.%1N) + local command_nano_now="$(date +%1N)" + [[ "$command_nano_now" == "1N" ]] && command_nano_now=1 + current_time="$(date "+%s").${command_nano_now}" - if [[ -f "$COMMAND_DURATION_FILE" ]]; then - command_start=$(< "$COMMAND_DURATION_FILE") - command_start_sseconds=${command_start%.*} + if [[ -n "${COMMAND_DURATION_START_TIME:-}" ]]; then + _bash_it_log_section="command_duration" _log_debug "calculating start time" + command_start_sseconds=${COMMAND_DURATION_START_TIME%.*} current_time_seconds=${current_time%.*} command_start_deciseconds=$((10#${command_start#*.})) @@ -42,6 +36,7 @@ _command_duration() { # seconds command_duration=$((current_time_seconds - command_start_sseconds)) + _bash_it_log_section="command_duration" _log_debug "duration: $command_duration (from $COMMAND_DURATION_START_TIME to $current_time)" if ((current_time_deciseconds >= command_start_deciseconds)); then deciseconds=$(((current_time_deciseconds - command_start_deciseconds))) @@ -49,12 +44,12 @@ _command_duration() { ((command_duration -= 1)) deciseconds=$((10 - ((command_start_deciseconds - current_time_deciseconds)))) fi - command rm "$COMMAND_DURATION_FILE" else command_duration=0 fi if ((command_duration > 0)); then + _bash_it_log_section="command_duration" _log_debug "calculating minutes and seconds" minutes=$((command_duration / 60)) seconds=$((command_duration % 60)) fi From 09e8c25b644315f3b3499776884d0c6f6c5cc863 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:39:58 -0800 Subject: [PATCH 119/239] lib/command_duration: dynamic clock hand Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string. Expressly handle COMMAND_DURATION_COLOR as blank when undefined. --- themes/command_duration.theme.bash | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/themes/command_duration.theme.bash b/themes/command_duration.theme.bash index c7fb665595..c0772d2d3f 100644 --- a/themes/command_duration.theme.bash +++ b/themes/command_duration.theme.bash @@ -9,7 +9,7 @@ fi COMMAND_DURATION_START_TIME= -COMMAND_DURATION_ICON=${COMMAND_DURATION_ICON:-' ο€— '} +COMMAND_DURATION_ICON=${COMMAND_DURATION_ICON:-' ο€— '} πŸ•˜ COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'} _command_duration_pre_exec() { @@ -18,6 +18,11 @@ _command_duration_pre_exec() { COMMAND_DURATION_START_TIME="$(date "+%s").${command_nano_now}" } +function _dynamic_clock_icon { + local -i clock_hand=$(((${1:-${SECONDS}} % 12) + 90)) + printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" +} + _command_duration() { local command_duration command_start current_time local minutes seconds deciseconds @@ -54,10 +59,11 @@ _command_duration() { seconds=$((command_duration % 60)) fi + _dynamic_clock_icon if ((minutes > 0)); then - printf "%s%s%dm %ds" "$COMMAND_DURATION_ICON" "$COMMAND_DURATION_COLOR" "$minutes" "$seconds" + printf "%s%s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds" elif ((seconds >= COMMAND_DURATION_MIN_SECONDS)); then - printf "%s%s%d.%01ds" "$COMMAND_DURATION_ICON" "$COMMAND_DURATION_COLOR" "$seconds" "$deciseconds" + printf "%s%s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds" fi } From 33505d4db1eb4b0fe31293a2b75db6f2918058fe Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:40:26 -0800 Subject: [PATCH 120/239] lib/command_duration: Refactor using `$EPOCHREALTIME` Fallback to `$SECONDS` for older versions of _Bash_. Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change. --- themes/command_duration.theme.bash | 58 ++++++++++++------------------ 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/themes/command_duration.theme.bash b/themes/command_duration.theme.bash index c0772d2d3f..791c8d4985 100644 --- a/themes/command_duration.theme.bash +++ b/themes/command_duration.theme.bash @@ -1,21 +1,13 @@ # shellcheck shell=bash +# +# Functions for measuring and reporting how long a command takes to run. -if [[ "${BASH_IT_COMMAND_DURATION:-false}" != true ]]; then - _command_duration() { - echo -n - } - return -fi +: "${COMMAND_DURATION_START_SECONDS:=${EPOCHREALTIME:-$SECONDS}}" +: "${COMMAND_DURATION_ICON:=πŸ•˜}" +: "${COMMAND_DURATION_MIN_SECONDS:=1}" -COMMAND_DURATION_START_TIME= - -COMMAND_DURATION_ICON=${COMMAND_DURATION_ICON:-' ο€— '} πŸ•˜ -COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'} - -_command_duration_pre_exec() { - local command_nano_now="$(date +%1N)" - [[ "$command_nano_now" == "1N" ]] && command_nano_now=1 - COMMAND_DURATION_START_TIME="$(date "+%s").${command_nano_now}" +function _command_duration_pre_exec() { + COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" } function _dynamic_clock_icon { @@ -23,43 +15,37 @@ function _dynamic_clock_icon { printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" } -_command_duration() { - local command_duration command_start current_time - local minutes seconds deciseconds - local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds - local command_nano_now="$(date +%1N)" - [[ "$command_nano_now" == "1N" ]] && command_nano_now=1 - current_time="$(date "+%s").${command_nano_now}" - - if [[ -n "${COMMAND_DURATION_START_TIME:-}" ]]; then - _bash_it_log_section="command_duration" _log_debug "calculating start time" - command_start_sseconds=${COMMAND_DURATION_START_TIME%.*} - current_time_seconds=${current_time%.*} +function _command_duration() { + [[ -n "${BASH_IT_COMMAND_DURATION:-}" ]] || return - command_start_deciseconds=$((10#${command_start#*.})) - current_time_deciseconds=$((10#${current_time#*.})) + local command_duration=0 command_start="${COMMAND_DURATION_START_SECONDS:-0}" + local -i minutes=0 seconds=0 deciseconds=0 + local -i command_start_seconds="${command_start%.*}" + local -i command_start_deciseconds=$((10#${command_start##*.})) + local current_time="${EPOCHREALTIME:-$SECONDS}" + local -i current_time_seconds="${current_time%.*}" + local -i current_time_deciseconds="$((10#${current_time##*.}))" + if [[ "${command_start_seconds:-0}" -gt 0 ]]; then # seconds - command_duration=$((current_time_seconds - command_start_sseconds)) - _bash_it_log_section="command_duration" _log_debug "duration: $command_duration (from $COMMAND_DURATION_START_TIME to $current_time)" + command_duration="$((current_time_seconds - command_start_seconds))" if ((current_time_deciseconds >= command_start_deciseconds)); then - deciseconds=$(((current_time_deciseconds - command_start_deciseconds))) + deciseconds="$((current_time_deciseconds - command_start_deciseconds))" else ((command_duration -= 1)) - deciseconds=$((10 - ((command_start_deciseconds - current_time_deciseconds)))) + deciseconds="$((10 - (command_start_deciseconds - current_time_deciseconds)))" fi else command_duration=0 fi if ((command_duration > 0)); then - _bash_it_log_section="command_duration" _log_debug "calculating minutes and seconds" minutes=$((command_duration / 60)) seconds=$((command_duration % 60)) fi - _dynamic_clock_icon + _dynamic_clock_icon "${command_duration}" if ((minutes > 0)); then printf "%s%s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds" elif ((seconds >= COMMAND_DURATION_MIN_SECONDS)); then @@ -67,4 +53,4 @@ _command_duration() { fi } -preexec_functions+=(_command_duration_pre_exec) +safe_append_preexec '_command_duration_pre_exec' From 6ca10cf84c4048656e0392dfc1c2561712ede7dc Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:42:18 -0800 Subject: [PATCH 121/239] plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell. AlsΓΆ, Reduce environmental pollution by not exporting every variable, and unsetting when done. Change variable names to match lib/command-duration Remove `preexec_return_notification()` in favor of `lib/command-duration`'s `_command_duration_pre_exec()`. This should now use the same preexec hook and variables as the theme library `command_duration`. tests: handle nanoseconds --- .../available/cmd-returned-notify.plugin.bash | 20 +++++++------- test/plugins/cmd-returned-notify.plugin.bats | 27 ++++++++++--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/plugins/available/cmd-returned-notify.plugin.bash b/plugins/available/cmd-returned-notify.plugin.bash index d9be5e4e9f..88c07722df 100644 --- a/plugins/available/cmd-returned-notify.plugin.bash +++ b/plugins/available/cmd-returned-notify.plugin.bash @@ -2,15 +2,15 @@ cite about-plugin about-plugin 'Alert (BEL) when process ends after a threshold of seconds' -precmd_return_notification() { - export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)})) - [[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a" - export LAST_COMMAND_TIME= +function precmd_return_notification() { + local command_start="${COMMAND_DURATION_START_SECONDS:=0}" + local current_time="${EPOCHREALTIME:-$SECONDS}" + local -i command_duration="$((${current_time%.*} - ${command_start%.*}))" + if [[ "${command_duration}" -gt "${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5}" ]]; then + printf '\a' + fi + return 0 } -preexec_return_notification() { - [[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s) -} - -precmd_functions+=(precmd_return_notification) -preexec_functions+=(preexec_return_notification) +safe_append_prompt_command 'precmd_return_notification' +safe_append_preexec '_command_duration_pre_exec' diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index ca40f3b5a9..7399d6e1c3 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -4,12 +4,13 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { setup_libs "preexec" #"command_duration" + load ../../themes/command_duration.theme load "${BASH_IT?}/plugins/available/cmd-returned-notify.plugin.bash" } @test "plugins cmd-returned-notify: notify after elapsed time" { export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export LAST_COMMAND_TIME=$(date +%s) + export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -18,7 +19,7 @@ function local_setup_file() { @test "plugins cmd-returned-notify: do not notify before elapsed time" { export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export LAST_COMMAND_TIME=$(date +%s) + export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -26,23 +27,25 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: preexec no output" { - export LAST_COMMAND_TIME= - run preexec_return_notification + export COMMAND_DURATION_START_SECONDS= + run _command_duration_pre_exec assert_success assert_output "" } @test "plugins cmd-returned-notify: preexec no output env set" { - export LAST_COMMAND_TIME=$(date +%s) - run preexec_return_notification + skip "wut" + export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + run _command_duration_pre_exec assert_failure assert_output "" } -@test "plugins cmd-returned-notify: preexec set LAST_COMMAND_TIME" { - export LAST_COMMAND_TIME= - assert_equal "${LAST_COMMAND_TIME}" "" - NOW=$(date +%s) - preexec_return_notification - assert_equal "${LAST_COMMAND_TIME}" "${NOW}" +@test "plugins cmd-returned-notify: preexec set COMMAND_DURATION_START_SECONDS" { + export COMMAND_DURATION_START_SECONDS= + assert_equal "${COMMAND_DURATION_START_SECONDS}" "" + NOW="${EPOCHREALTIME:-$SECONDS}" + _command_duration_pre_exec + # We need to make sure to account for nanoseconds... + assert_equal "${COMMAND_DURATION_START_SECONDS%.*}" "${NOW%.*}" } From 4e0e59230b77bd2f736a1bef550014c0cdc8f1e8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:43:02 -0800 Subject: [PATCH 122/239] lib/command_duration: rename `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. --- bash_it.sh | 2 -- clean_files.txt | 2 +- .../command_duration.theme.bash => lib/command_duration.bash | 0 test/plugins/cmd-returned-notify.plugin.bats | 3 +-- 4 files changed, 2 insertions(+), 5 deletions(-) rename themes/command_duration.theme.bash => lib/command_duration.bash (100%) diff --git a/bash_it.sh b/bash_it.sh index 00a1bceadb..ddc02b708f 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -51,8 +51,6 @@ if [[ -n "${BASH_IT_THEME:-}" ]]; then source "${BASH_IT}/themes/githelpers.theme.bash" BASH_IT_LOG_PREFIX="themes: p4helpers: " source "${BASH_IT}/themes/p4helpers.theme.bash" - BASH_IT_LOG_PREFIX="themes: command_duration: " - source "${BASH_IT}/themes/command_duration.theme.bash" BASH_IT_LOG_PREFIX="themes: base: " source "${BASH_IT}/themes/base.theme.bash" diff --git a/clean_files.txt b/clean_files.txt index 36bdc08c36..e52d5a9f29 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -78,6 +78,7 @@ completion/available/wpscan.completion.bash # libraries lib/appearance.bash lib/colors.bash +lib/command_duration.bash lib/helpers.bash lib/history.bash lib/log.bash @@ -155,7 +156,6 @@ themes/bobby-python themes/brainy themes/brunton themes/candy -themes/command_duration.theme.bash themes/easy themes/essential themes/githelpers.theme.bash diff --git a/themes/command_duration.theme.bash b/lib/command_duration.bash similarity index 100% rename from themes/command_duration.theme.bash rename to lib/command_duration.bash diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index 7399d6e1c3..e712cbd9e1 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -3,8 +3,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "preexec" #"command_duration" - load ../../themes/command_duration.theme + setup_libs "command_duration" load "${BASH_IT?}/plugins/available/cmd-returned-notify.plugin.bash" } From 1c2fc2837f7448988746400a2192720dda0d2da6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 29 Dec 2021 10:07:04 -0800 Subject: [PATCH 123/239] lib/command_duration: adopt `_bash_it_library_finalize_hook` --- lib/command_duration.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index 791c8d4985..bc0cca8e0a 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -53,4 +53,4 @@ function _command_duration() { fi } -safe_append_preexec '_command_duration_pre_exec' +_bash_it_library_finalize_hook+=("safe_append_preexec '_command_duration_pre_exec'") From 866e5be86b4ed26f32904d2329019e590b5e31e9 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 30 Jan 2022 16:03:58 -0800 Subject: [PATCH 124/239] lib/command_duration: tests & whitespace --- test/plugins/cmd-returned-notify.plugin.bats | 57 +++++++++----------- test/test_helper.bash | 2 +- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index e712cbd9e1..04edad9582 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -8,43 +8,34 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: notify after elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" - sleep 1 - run precmd_return_notification - assert_success - assert_output $'\a' + export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 + export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + sleep 1 + run precmd_return_notification + assert_success + assert_output $'\a' } @test "plugins cmd-returned-notify: do not notify before elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" - sleep 1 - run precmd_return_notification - assert_success - assert_output $'' + export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 + export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + sleep 1 + run precmd_return_notification + assert_success + assert_output $'' } -@test "plugins cmd-returned-notify: preexec no output" { - export COMMAND_DURATION_START_SECONDS= - run _command_duration_pre_exec - assert_success - assert_output "" +@test "lib command_duration: preexec no output" { + export COMMAND_DURATION_START_SECONDS= + run _command_duration_pre_exec + assert_success + assert_output "" } - -@test "plugins cmd-returned-notify: preexec no output env set" { - skip "wut" - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" - run _command_duration_pre_exec - assert_failure - assert_output "" -} - -@test "plugins cmd-returned-notify: preexec set COMMAND_DURATION_START_SECONDS" { - export COMMAND_DURATION_START_SECONDS= - assert_equal "${COMMAND_DURATION_START_SECONDS}" "" - NOW="${EPOCHREALTIME:-$SECONDS}" - _command_duration_pre_exec - # We need to make sure to account for nanoseconds... - assert_equal "${COMMAND_DURATION_START_SECONDS%.*}" "${NOW%.*}" +@test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" { + export COMMAND_DURATION_START_SECONDS= + assert_equal "${COMMAND_DURATION_START_SECONDS}" "" + NOW="${EPOCHREALTIME:-$SECONDS}" + _command_duration_pre_exec + # We need to make sure to account for nanoseconds... + assert_equal "${COMMAND_DURATION_START_SECONDS%.*}" "${NOW%.*}" } diff --git a/test/test_helper.bash b/test/test_helper.bash index 919e75599d..bffb59edd6 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -57,7 +57,7 @@ function common_setup_file() { function setup_libs() { local lib # Use a loop to allow convenient short-circuiting for some test files - for lib in "log" "utilities" "helpers" "search" "preexec" "colors"; do + for lib in "log" "utilities" "helpers" "search" "preexec" "colors" "command_duration"; do load "${BASH_IT?}/lib/${lib}.bash" || return # shellcheck disable=SC2015 # short-circuit if we've reached the requested library [[ "${lib}" == "${1:-}" ]] && return 0 || true From bf811cd38e30e63e0ddd7ca5138fb4e115933b2e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 00:02:52 -0800 Subject: [PATCH 125/239] BATS: require `shellcheck` on test files BATS: add `*.bats` to `.gitattributes` --- .gitattributes | 1 + .pre-commit-config.yaml | 4 +--- hooks/dot-bash.sh | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index de622e0618..8a9080546c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ *.sh text eol=lf *.bash text eol=lf +*.bats text eol=lf # Docs allow trailing whitespaces *.md whitespace=-blank-at-eol diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af5f30afe5..8c3f35253f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,6 @@ repos: hooks: - id: git-check # Configure in .gitattributes - id: shellcheck - exclude: ".bats$" - id: shfmt exclude: ".bats$" - repo: https://github.com/Lucas-C/pre-commit-hooks @@ -38,10 +37,9 @@ repos: types: [file] - id: dot-bash name: Check .bash files against bash-it requirements - exclude: "test/test_helper.bash" entry: ./hooks/dot-bash.sh language: system - files: "\\.bash$" + files: "\\.ba[ts][sh]$" types: [file] - id: clean-files-txt name: Check that clean_files.txt is sorted alphabetically. diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh index 253cb595e4..94a03708b5 100755 --- a/hooks/dot-bash.sh +++ b/hooks/dot-bash.sh @@ -12,7 +12,8 @@ for file in "$@"; do # Confirm expected schellcheck header # LINE1="$(head -n 1 "${file}")" - if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then + SCSH="${file##*.}" + if [[ "${LINE1}" != "# shellcheck shell=${SCSH}" ]]; then echo "Bash include file \`${file}\` has bad/missing shellcheck header" exit_code=1 fi From 49b477ef3f64971047088e835cbc36f69c1f46e5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:29:04 -0800 Subject: [PATCH 126/239] test/lib: `shellcheck` --- test/lib/helpers.bats | 392 ++++++++++++++++++++++-------------------- test/lib/log.bats | 33 ++-- test/lib/preexec.bats | 16 +- test/lib/search.bats | 40 ++++- 4 files changed, 271 insertions(+), 210 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 38a917fe95..b27e775e0a 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -4,25 +4,25 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { setup_libs "colors" - load "${BASH_IT?}/plugins/available/base.plugin.bash" } function local_setup() { # Copy the test fixture to the Bash-it folder - cp -RP "$BASH_IT/test/fixtures/bash_it"/* "$BASH_IT/" + cp -RP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" } # TODO Create global __is_enabled function # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function @test "bash-it: verify that the test fixture is available" { - assert_file_exist "$BASH_IT/profiles/test-bad-component.bash_it" - assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-component.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-type.bash_it" } @test "helpers: _command_exists function exists" { - run type -a _command_exists &> /dev/null + run type -t _command_exists assert_success + assert_output "function" } @test "helpers: _command_exists function positive test ls" { @@ -41,8 +41,9 @@ function local_setup() { } @test "helpers: _binary_exists function exists" { - run type -a _binary_exists &> /dev/null + run type -t _binary_exists assert_success + assert_output "function" } @test "helpers: _binary_exists function positive test ls" { @@ -67,54 +68,54 @@ function local_setup() { @test "helpers: bash-it help aliases without any aliases enabled" { run bash-it help aliases - assert_line -n 0 "" + assert_output "" } @test "helpers: bash-it help plugins" { run bash-it help plugins - assert_line -n 1 "base:" + assert_line -n 1 "composure:" } @test "helpers: bash-it help list aliases without any aliases enabled" { - run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/available/ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with ag aliases enabled" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_line -n 0 "todo.txt-cli:" } @test "helpers: bash-it help list aliases with docker-compose aliases enabled" { - ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" assert_line -n 0 "docker-compose:" } @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in the old directory" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -123,11 +124,11 @@ function local_setup() { @test "helpers: bash-it help aliases one alias enabled in global directory" { run bash-it enable alias "ag" assert_line -n 0 'ag enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run bash-it enable plugin "aws" assert_line -n 0 'aws enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---aws.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---aws.plugin.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -137,58 +138,58 @@ function local_setup() { @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line -n 0 'todo.txt-cli enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" } @test "helpers: enable the curl aliases" { run _enable-alias "curl" assert_line -n 0 'curl enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---curl.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---curl.aliases.bash" } @test "helpers: enable the apm completion through the bash-it function" { run bash-it enable completion "apm" assert_line -n 0 'apm enabled with priority 350.' - assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---apm.completion.bash" } @test "helpers: enable the brew completion" { run _enable-completion "brew" assert_line -n 0 'brew enabled with priority 375.' - assert_link_exist "$BASH_IT/enabled/375---brew.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/375---brew.completion.bash" } @test "helpers: enable the node plugin" { run _enable-plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" } @test "helpers: enable the node plugin through the bash-it function" { run bash-it enable plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: enable the node and nvm plugins through the bash-it function" { run bash-it enable plugin "node" "nvm" assert_line -n 0 'node enabled with priority 250.' assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { run bash-it enable plugin "foo-unknown" "nvm" assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable an unknown plugin" { @@ -196,11 +197,11 @@ function local_setup() { assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure - assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: enable an unknown plugin through the bash-it function" { @@ -209,11 +210,11 @@ function local_setup() { assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure - assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: disable a plugin that is not enabled" { @@ -224,75 +225,75 @@ function local_setup() { @test "helpers: enable and disable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled without a priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled without a priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin twice" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: profile load command sanity" { run _bash-it-profile-load "default" assert_success - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save command sanity" { @@ -303,14 +304,14 @@ function local_setup() { assert_line -n 1 "Saving completion configuration..." assert_line -n 2 "Saving aliases configuration..." assert_line -n 3 "All done!" - assert_file_exist "$BASH_IT/profiles/test.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile save creates valid file with only plugin enabled" { run _enable-plugin "nvm" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# plugins" assert_line -n 2 "plugins nvm" @@ -320,7 +321,7 @@ function local_setup() { run _enable-completion "bash-it" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# completion" assert_line -n 2 "completion bash-it" @@ -330,7 +331,7 @@ function local_setup() { run _enable-alias "general" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# aliases" assert_line -n 2 "aliases general" @@ -338,37 +339,53 @@ function local_setup() { @test "helpers: profile edge case, empty configuration" { run _bash-it-profile-save "test" + assert_success assert_line -n 3 "It seems like no configuration was enabled.." assert_line -n 4 "Make sure to double check that this is the wanted behavior." run _enable-alias "general" + assert_success run _enable-plugin "base" - run _enable-plugin "alias-completion" + assert_success + run _enable-completion "aliases" + assert_success run _enable-completion "bash-it" + assert_success run _enable-completion "system" + assert_success run _bash-it-profile-load "test" - assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_not_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_success + assert_line -n 0 "Trying to parse profile 'test'..." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_not_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_not_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save and load" { run _enable-alias "general" + assert_success run _enable-plugin "base" + assert_success run _enable-plugin "alias-completion" + assert_success run _enable-completion "bash-it" + assert_success run _enable-completion "system" + assert_success run _bash-it-profile-save "test" assert_success run _disable-alias "general" - assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_success + assert_output "general disabled." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" run _bash-it-profile-load "test" - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_success + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" } @test "helpers: profile load corrupted profile file: bad component" { @@ -383,10 +400,10 @@ function local_setup() { @test "helpers: profile rm sanity" { run _bash-it-profile-save "test" - assert_file_exist "$BASH_IT/profiles/test.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test.bash_it" run _bash-it-profile-rm "test" assert_line -n 0 "Removed profile 'test' successfully!" - assert_file_not_exist "$BASH_IT/profiles/test.bash_it" + assert_file_not_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile rm no params" { @@ -402,7 +419,7 @@ function local_setup() { @test "helpers: profile rm default" { run _bash-it-profile-rm "default" assert_line -n 0 -p "Can not remove the default profile..." - assert_file_exist "$BASH_IT/profiles/default.bash_it" + assert_file_exist "${BASH_IT?}/profiles/default.bash_it" } @test "helpers: profile rm bad profile name" { @@ -429,11 +446,11 @@ function local_setup() { } @test "helpers: migrate plugins and completions that share the same name" { - ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash" + ln -s "${BASH_IT?}/completion/available/dirs.completion.bash" "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" - ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/dirs.plugin.bash" "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating plugin dirs.' @@ -444,60 +461,60 @@ function local_setup() { assert_line -n 5 'dirs enabled with priority 350.' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_link_exist "$BASH_IT/enabled/350---dirs.completion.bash" - assert_link_exist "$BASH_IT/enabled/250---dirs.plugin.bash" - assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/250---dirs.plugin.bash" + assert [ ! -L "${BASH_IT?}/completion/enabled/350----dirs.completion.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----dirs.plugin.bash" ] } @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating alias todo.txt-cli.' assert_line -n 1 'todo.txt-cli disabled.' assert_line -n 2 'todo.txt-cli enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" ] } @test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225----node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/250----todo.txt-cli.aliases.bash" ] } @test "helpers: run the migrate command without anything to migrate and nothing enabled" { @@ -506,28 +523,28 @@ function local_setup() { @test "helpers: run the migrate command without anything to migrate" { run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" } function __migrate_all_components() { - subdirectory="$1" - one_type="$2" - priority="$3" + subdirectory="${1:-}" + one_type="${2:-}" + priority="${3:-}" for f in "${BASH_IT}/$subdirectory/available/"*.bash do - to_enable=$(basename $f) - if [ -z "$priority" ]; then + to_enable=$(basename "$f") + if [[ -z "$priority" ]]; then ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable" else ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable" fi done - ls ${BASH_IT}/${subdirectory}/enabled + ls "${BASH_IT?}/${subdirectory}/enabled" all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs) all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) @@ -547,47 +564,53 @@ function __migrate_all_components() { subdirectory="plugins" one_type="plugin" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all aliases" { subdirectory="aliases" one_type="aliases" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all completions" { subdirectory="completion" one_type="completion" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all plugins with previous priority" { subdirectory="plugins" one_type="plugin" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all aliases with previous priority" { subdirectory="aliases" one_type="aliases" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all completions with previous priority" { subdirectory="completion" one_type="completion" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: verify that existing components are automatically migrated when something is enabled" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run bash-it enable plugin "node" assert_line -n 0 'Migrating plugin nvm.' @@ -595,16 +618,16 @@ function __migrate_all_components() { assert_line -n 2 'nvm enabled with priority 225.' assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 4 'node enabled with priority 250.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: verify that existing components are automatically migrated when something is disabled" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" run bash-it disable plugin "node" assert_line -n 0 'Migrating plugin node.' @@ -615,89 +638,94 @@ function __migrate_all_components() { assert_line -n 5 'nvm enabled with priority 225.' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 7 'node disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---node.plugin.bash" ] } @test "helpers: enable all plugins" { + local available enabled run _enable-plugin "all" - local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "$available" "$enabled" } @test "helpers: disable all plugins" { + local available enabled enabled2 run _enable-plugin "all" - local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "$available" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" - local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure with priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins without anything enabled" { - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + local enabled enabled2 + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" assert_line -n 0 'ansible enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---ansible.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ansible.aliases.bash" } @test "helpers: describe the nvm plugin without enabling it" { @@ -707,21 +735,21 @@ function __migrate_all_components() { @test "helpers: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory with priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } diff --git a/test/lib/log.bats b/test/lib/log.bats index 7d868fd6da..906d5fa22c 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -7,77 +8,77 @@ function local_setup_file() { } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_debug "test test test" assert_output "DEBUG: default: test test test" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_warning "test test test" assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_warning "test test test" assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_warning "test test test" - refute_output + assert_output "" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug silent logging" { run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning silent logging" { run _log_warning "test test test" - refute_output + assert_output "" } @test "lib log: basic error silent logging" { run _log_error "test test test" - refute_output + assert_output "" } @test "lib log: logging with prefix" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} BASH_IT_LOG_PREFIX="nice: prefix: " run _log_debug "test test test" assert_output "DEBUG: nice: prefix: test test test" diff --git a/test/lib/preexec.bats b/test/lib/preexec.bats index 10dc666d04..3c5ed4b041 100644 --- a/test/lib/preexec.bats +++ b/test/lib/preexec.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2030 disable=SC2031 load ../test_helper @@ -11,8 +12,9 @@ function local_setup { test_prompt_string="" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" $'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' } @@ -21,8 +23,9 @@ function local_setup { test_prompt_string="nah" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"$'\n__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' } @@ -32,8 +35,9 @@ function local_setup { export PROMPT_COMMAND="$test_prompt_string" export __bp_delay_install="blarg" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" "$test_prompt_string" @@ -48,8 +52,9 @@ function local_setup { test_prompt_string="" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run __bp_install assert_success @@ -62,8 +67,9 @@ function local_setup { test_prompt_string="nah" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run __bp_install assert_success diff --git a/test/lib/search.bats b/test/lib/search.bats index e28922f455..99b7cc39c6 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -12,25 +12,30 @@ function local_setup() { } @test "search: plugin base" { - export BASH_IT_SEARCH_USE_COLOR=false run _bash-it-search-component 'plugins' 'base' + assert_success assert_line -n 0 ' plugins: base ' } @test "search: git" { + local plugin completion run _bash-it-search 'git' --no-color + assert_success assert_line -n 0 ' aliases: git gitsvn ' assert_line -n 1 -p ' plugins:' for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump" do - echo $plugin - assert_line -n 1 -p $plugin + assert_line -n 1 -p "$plugin" + done + for completion in "git" "git_flow" "git_flow_avh" "github-cli" + do + assert_line -n 2 -p "$completion" done - assert_line -n 2 ' completions: git git_flow git_flow_avh github-cli ' } @test "search: ruby gem bundle rake rails" { run _bash-it-search rails ruby gem bundler rake --no-color + assert_success assert_line -n 0 ' aliases: bundler rails ' assert_line -n 1 ' plugins: chruby chruby-auto rails ruby ' @@ -39,6 +44,7 @@ function local_setup() { @test "search: rails ruby gem bundler rake -chruby" { run _bash-it-search rails ruby gem bundler rake -chruby --no-color + assert_success assert_line -n 0 ' aliases: bundler rails ' assert_line -n 1 ' plugins: rails ruby ' @@ -47,22 +53,42 @@ function local_setup() { @test "search: @git" { run _bash-it-search '@git' --no-color + assert_success assert_line -n 0 ' aliases: git ' assert_line -n 1 ' plugins: git ' assert_line -n 2 ' completions: git ' } -@test "search: @git --enable / --disable" { - set -e +@test "search: @git --enable / --disable" { run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p 'βœ“' + + run _bash-it-search '@git' --disable --no-color + assert_success run _bash-it-search '@git' --no-color + assert_success - [[ "${lines[0]}" =~ 'βœ“' ]] + assert_line -n 0 ' aliases: git ' + assert_line -n 1 ' plugins: git ' + assert_line -n 2 ' completions: git ' +} +@test "search: @git --disable / --enable" { run _bash-it-search '@git' --disable --no-color + assert_success run _bash-it-search '@git' --no-color + assert_success assert_line -n 0 ' aliases: git ' assert_line -n 1 ' plugins: git ' assert_line -n 2 ' completions: git ' + + run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p 'βœ“' } From 45ab5b3d9668c563e2c6c3742ea8a4144fdcaaef Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:57:19 -0800 Subject: [PATCH 127/239] test/theme: `shellcheck` test: don't clobber `$PATH` BATS depends on `$PATH` somehow and if not handled properly, modifying `$PATH` breaks BATS badly. But, it doesn't seem like we have any reason to modify `$PATH` in the first place...so don't. test/svn: don't clobber `$PATH` test/ruby: don't clobber `$PATH` test/search: don't clobber `$PATH` --- test/themes/base.theme.bats | 2 +- test/themes/base.theme.git.bats | 148 ++++++++++++++++---------------- test/themes/base.theme.svn.bats | 44 ++++++---- 3 files changed, 102 insertions(+), 92 deletions(-) diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 81b08a01fc..dd2b9288ba 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -25,7 +25,7 @@ function local_setup_file() { assert_line "function" run battery_char - assert_line -n 0 "" + assert_output "" } @test 'themes base: battery_char should exist if battery plugin loaded' { diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index b2bc7c5ae0..2d43414d4b 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -20,12 +20,12 @@ add_commit() { enter_new_git_repo() { repo="$(setup_repo)" - pushd "${repo}" + pushd "${repo}" || return } setup_repo() { upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return git init . > /dev/null echo "$upstream" @@ -33,83 +33,83 @@ setup_repo() { setup_repo_with_upstream() { upstream="$(setup_repo)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return add_commit > /dev/null git checkout -b branch-two git checkout -b gone-branch git checkout master - popd > /dev/null + popd > /dev/null || return downstream="$(setup_repo)" - pushd "$downstream" > /dev/null + pushd "$downstream" > /dev/null || return add_commit > /dev/null git remote add my-remote "$upstream" git fetch my-remote git branch -u my-remote/master > /dev/null - popd > /dev/null + popd > /dev/null || return - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return git branch -d gone-branch > /dev/null - popd > /dev/null + popd > /dev/null || return - pushd "$downstream" > /dev/null + pushd "$downstream" > /dev/null || return git fetch my-remote - popd > /dev/null + popd > /dev/null || return echo "$downstream" } @test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' remote="$(setup_repo)" - pushd "$remote" + pushd "$remote" || return add_commit add_commit - popd + popd || return clone="$(mktemp -d)" - pushd "$clone" + pushd "$clone" || return git clone "$remote" clone cd clone SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑1" + assert_equal "${SCM_BRANCH?}" "${pre} ↑1" add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑2" - popd + assert_equal "${SCM_BRANCH?}" "${pre} ↑2" + popd || return - pushd "$remote" + pushd "$remote" || return add_commit add_commit add_commit - popd + popd || return - pushd "$clone/clone" + pushd "$clone/clone" || return git fetch git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑2 ↓3" + assert_equal "${SCM_BRANCH?}" "${pre} ↑2 ↓3" git reset HEAD~2 --hard SCM_GIT_BEHIND_CHAR="↓" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↓3" + assert_equal "${SCM_BRANCH?}" "${pre} ↓3" } @test 'themes base: Git: when stashes exist: it shows the number of stashes' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo add_commit @@ -121,90 +121,90 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_STASH_INFO=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} {1}" + assert_equal "${SCM_BRANCH?}" "${pre} {1}" touch file2 git add file2 git stash git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} {2}" + assert_equal "${SCM_BRANCH?}" "${pre} {2}" } @test 'themes base: Git: remote info: when there is no upstream remote: is empty' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' post=" ↑1 ↓1" enter_new_git_repo add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' { - pre="\$(_git-friendly-ref) β†’ " + pre='$(_git-friendly-ref) β†’ ' eval_pre="master β†’ " post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is auto: includes the remote when more than one remote' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' eval_pre="master" post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=auto SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}${post}" + assert_equal "${SCM_BRANCH?}" "${pre}${post}" pre="${pre} β†’ " eval_pre="${eval_pre} β†’ " git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" git remote add second-remote "$(mktemp -d)" git branch -u my-remote/master git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is false: never include the remote' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' eval_pre="master" post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return git remote add second-remote "$(mktemp -d)" git remote add third-remote "$(mktemp -d)" @@ -212,59 +212,59 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}${post}" + assert_equal "${SCM_BRANCH?}" "${pre}${post}" pre="${pre} β†’ " eval_pre="${eval_pre} β†’ " git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" } @test 'themes base: Git: remote info: when showing remote info: show if upstream branch is gone' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} β†’ my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre} β†’ my-remote${post}" git checkout gone-branch git fetch --prune --all git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} β‡’ my-remote" + assert_equal "${SCM_BRANCH?}" "${pre} β‡’ my-remote" } @test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' { enter_new_git_repo git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" git checkout -b second-branch git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when a branch is not checked out: shows that branch' { enter_new_git_repo git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" git checkout -b second-branch git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and tag: show a tag' { @@ -276,7 +276,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "tag:first-tag" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "tag:first-tag" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and no tag: show a branch' { @@ -287,7 +287,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is parent to a named ref: show relative name' { @@ -297,7 +297,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master~1" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master~1" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is not parent to a named ref: show short sha' { @@ -309,11 +309,11 @@ setup_repo_with_upstream() { git checkout "$sha" git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:$sha" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:$sha" } @test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo echo "line1" > file1 @@ -324,7 +324,7 @@ setup_repo_with_upstream() { git commit -m"commit1" git_prompt_vars - assert_equal "$SCM_STATE" " βœ“" + assert_equal "${SCM_STATE?}" " βœ“" echo "line2" >> file1 git add file1 @@ -332,56 +332,56 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_DETAILS=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1" - assert_equal "$SCM_STATE" " βœ—" - assert_equal "$SCM_DIRTY" "3" + assert_equal "${SCM_BRANCH?}" "${pre} S:1" + assert_equal "${SCM_STATE?}" " βœ—" + assert_equal "${SCM_DIRTY?}" "3" echo "line2" >> file2 echo "line2" >> file3 echo "line2" >> file4 git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1 U:3" - assert_equal "$SCM_DIRTY" "2" + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3" + assert_equal "${SCM_DIRTY?}" "2" echo "line1" > newfile5 echo "line1" > newfile6 git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1 U:3 ?:2" - assert_equal "$SCM_DIRTY" "1" + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3 ?:2" + assert_equal "${SCM_DIRTY?}" "1" git config bash-it.hide-status 1 SCM_DIRTY='nope' git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" - assert_equal "$SCM_DIRTY" "nope" + assert_equal "${SCM_BRANCH?}" "${pre}" + assert_equal "${SCM_DIRTY?}" "nope" } @test 'themes base: Git: git user info: shows user initials' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo git config user.name "Cool User" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" SCM_GIT_SHOW_CURRENT_USER=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ cu" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ cu" git config user.name "Γ‡ool Üser" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ çü" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ çü" # show initials set by `git pair` git config user.initials "ab cd" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ ab+cd" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ ab+cd" } diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index 360e8636ae..e2fc10135d 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -9,7 +9,7 @@ function local_setup_file() { function setup_repo { upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return # Create a dummy SVN folder - this will not work with an actual `svn` command, # but will be enough to trigger the SVN check in the base theme. mkdir .svn @@ -24,83 +24,93 @@ function setup_svn_path { assert_file_exist "$svn_path/svn" # Make sure that the requested SVN script is on the path - export PATH="$svn_path:/usr/bin:/bin:/usr/sbin" + export PATH="$svn_path:$PATH" } @test 'themes base: SVN: detect SVN repo' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return setup_svn_path "$BASH_IT/test/fixtures/svn/working" # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that the SVN command is used - assert_equal "$SCM" "$SCM_SVN" + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: detect SVN repo even from a subfolder' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return mkdir foo - pushd foo + pushd foo || return setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # init the base theme again so that the working SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that the SVN command is used - assert_equal "$SCM" "$SCM_SVN" + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: no SCM if no .svn folder can be found' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return rm -rf .svn setup_svn_path "$BASH_IT/test/fixtures/svn/working" # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo when using broken SVN command' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the broken SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is not used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return mkdir foo - pushd foo + pushd foo || return setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the broken SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } From 99decb80108083040470a55c235dd9c6e7acaed8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:48:03 -0800 Subject: [PATCH 128/239] test/bash_it: `shellcheck` --- test/bash_it/bash_it.bats | 258 ++++++++++++++++---------------------- 1 file changed, 111 insertions(+), 147 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index ef3cdbab3c..dc9d28112a 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -9,27 +9,24 @@ function local_setup_file() { } @test "bash-it: verify that the test fixture is available" { - assert_file_exist "$BASH_IT/aliases/available/a.aliases.bash" - assert_file_exist "$BASH_IT/aliases/available/b.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/a.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/b.aliases.bash" } @test "bash-it: load aliases in order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -37,22 +34,19 @@ function local_setup_file() { } @test "bash-it: load aliases in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/175---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/175---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -60,24 +54,21 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -85,25 +76,21 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - mkdir -p $BASH_IT/completion/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -112,25 +99,21 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - mkdir -p $BASH_IT/completion/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/450---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/450---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/950---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/950---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -139,24 +122,21 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -166,21 +146,19 @@ function local_setup_file() { } @test "bash-it: load global aliases in order" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -188,21 +166,19 @@ function local_setup_file() { } @test "bash-it: load global aliases in priority order" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/175---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/175---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -210,23 +186,21 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order" { - mkdir -p $BASH_IT/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -234,23 +208,21 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -260,27 +232,24 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { - mkdir -p $BASH_IT/enabled - mkdir -p $BASH_IT/aliases/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # Add one file in the old directory structure - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -290,53 +259,48 @@ function local_setup_file() { } @test "bash-it: load enabled aliases from new structure, priority-based" { - mkdir -p $BASH_IT/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success } @test "bash-it: load enabled aliases from old structure, priority-based" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success } @test "bash-it: load enabled aliases from old structure, without priorities" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success From 5f11a0d3a2e74b77325ce0de35ba2fed66316ad4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:29:39 -0800 Subject: [PATCH 129/239] test/completion: `shellcheck` --- test/completion/aliases.completion.bats | 2 +- test/completion/bash-it.completion.bats | 160 ++++++++++++------------ 2 files changed, 83 insertions(+), 79 deletions(-) mode change 100755 => 100644 test/completion/bash-it.completion.bats diff --git a/test/completion/aliases.completion.bats b/test/completion/aliases.completion.bats index 83ae947a35..2367e6154b 100644 --- a/test/completion/aliases.completion.bats +++ b/test/completion/aliases.completion.bats @@ -26,5 +26,5 @@ function local_setup_file() { alias rm='rm -v' run load "${BASH_IT?}/completion/available/aliases.completion.bash" - refute_output + assert_output "" } diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats old mode 100755 new mode 100644 index 29d1dc944b..7fe60e3e19 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -13,11 +13,12 @@ function local_setup_file() { assert_output "function" } -function __check_completion () { +function __check_completion() { # Get the parameters as a single value COMP_LINE=$* # Get the parameters as an array + # shellcheck disable=SC2294 eval set -- "$@" COMP_WORDS=("$@") @@ -25,7 +26,7 @@ function __check_completion () { COMP_POINT=${#COMP_LINE} # Get the last character of the line that was entered - COMP_LAST=$((${COMP_POINT} - 1)) + COMP_LAST=$((COMP_POINT - 1)) # If the last character was a space... if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then @@ -45,315 +46,318 @@ function __check_completion () { @test "completion bash-it: doctor - show options" { run __check_completion 'bash-it doctor ' - assert_line -n 0 "errors warnings all" + assert_output "errors warnings all" } @test "completion bash-it: help - show options" { run __check_completion 'bash-it help ' - assert_line -n 0 "aliases completions migrate plugins update" + assert_output "aliases completions migrate plugins update" } @test "completion bash-it: help - aliases v" { run __check_completion 'bash-it help aliases v' - assert_line -n 0 "vagrant vault vim" + assert_output "vagrant vault vim" } @test "completion bash-it: update - show options" { run __check_completion 'bash-it update ' - assert_line -n 0 "stable dev" + assert_output "stable dev" } @test "completion bash-it: update - show optional flags" { run __check_completion 'bash-it update -' - assert_line -n 0 "-s --silent" + assert_output "-s --silent" } @test "completion bash-it: search - show no options" { run __check_completion 'bash-it search ' - assert_line -n 0 "" + assert_output "" } @test "completion bash-it: migrate - show no options" { run __check_completion 'bash-it migrate ' - assert_line -n 0 "" + assert_output "" } @test "completion bash-it: show options" { run __check_completion 'bash-it ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash-ti - show options" { run __check_completion 'bash-ti ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: shit - show options" { run __check_completion 'shit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bashit - show options" { run __check_completion 'bashit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: batshit - show options" { run __check_completion 'batshit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash_it - show options" { run __check_completion 'bash_it ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: profile - show options" { run __check_completion 'bash-it profile ' - assert_line -n 0 "load save list rm" + assert_output "load save list rm" } @test "completion bash-it: profile load - show options" { run __check_completion 'bash-it profile load ' - assert_line -n 0 "default" + assert_output "default" } @test "completion bash-it: show - show options" { run __check_completion 'bash-it show ' - assert_line -n 0 "aliases completions plugins" + assert_output "aliases completions plugins" } @test "completion bash-it: enable - show options" { run __check_completion 'bash-it enable ' - assert_line -n 0 "alias completion plugin" + assert_output "alias completion plugin" } @test "completion bash-it: enable - show options a" { run __check_completion 'bash-it enable a' - assert_line -n 0 "alias" + assert_output "alias" } @test "completion bash-it: disable - show options" { run __check_completion 'bash-it disable ' - assert_line -n 0 "alias completion plugin" + assert_output "alias completion plugin" } @test "completion bash-it: disable - show options a" { run __check_completion 'bash-it disable a' - assert_line -n 0 "alias" + assert_output "alias" } @test "completion bash-it: disable - provide nothing when atom is not enabled" { run __check_completion 'bash-it disable alias ato' - assert_line -n 0 "" + assert_output "" } -@test "completion bash-it: disable - provide all when atom is not enabled" { +@test "completion bash-it: disable - provide 'all' when atom is not enabled" { run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all" + assert_output "all" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash" + run _bash-it-component-item-is-enabled "alias" "atom" + assert_success + run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the atom aliases when not enabled" { run __check_completion 'bash-it enable alias ato' - assert_line -n 0 "atom" + assert_output "atom" } @test "completion bash-it: enable - provide the a* aliases when not enabled" { run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt atom" + assert_output "all ag ansible apt atom" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the docker* plugins when docker-compose is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } From 61247a1b76ebf9da0ae8ec53498fc2a068357c6a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 14:20:40 -0800 Subject: [PATCH 130/239] test/plugin: `shellcheck` --- test/plugins/base.plugin.bats | 32 +++++++++++--------- test/plugins/cmd-returned-notify.plugin.bats | 13 ++++---- test/plugins/go.plugin.bats | 27 +++++++++-------- test/plugins/ruby.plugin.bats | 3 +- test/plugins/xterm.plugin.bats | 9 +++--- 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 6022451a91..11b8ee0cf5 100644 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -8,37 +8,39 @@ function local_setup_file() { } @test 'plugins base: ips()' { - declare -r localhost='127.0.0.1' + readonly localhost='127.0.0.1' run ips assert_success - assert_line $localhost + assert_line "$localhost" } @test 'plugins base: myip()' { + local mask_ip run myip assert_success - declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?') - [[ $mask_ip == 'Your public IP is:'*'?.?.?.?'* ]] + shopt -s extglob + mask_ip="${output//+([[:digit:]]|[[:digit:]][[:digit:]]|[[:digit:]][[:digit:]][[:digit:]])/?}" #$(echo "$output" | tr -s '0-9' '?') + [[ $mask_ip == 'Your public IP is: ?.?.?.? ' ]] } @test 'plugins base: pickfrom()' { - stub_file="${BATS_TEST_TMPDIR}/stub_file" - printf "l1\nl2\nl3" > $stub_file - run pickfrom $stub_file + stub_file="${BATS_TEST_TMPDIR?}/stub_file" + printf "l1\nl2\nl3" > "$stub_file" + run pickfrom "$stub_file" assert_success [[ $output == l? ]] } @test 'plugins base: mkcd()' { - cd "${BATS_TEST_TMPDIR}" + cd "${BATS_TEST_TMPDIR?}" declare -r dir_name="-dir_with_dash" # Make sure that the directory does not exist prior to the test - rm -rf "${BATS_TEST_TMPDIR}/${dir_name}" + rm -rf "${BATS_TEST_TMPDIR:?}/${dir_name}" run mkcd "${dir_name}" assert_success - assert_dir_exist "${BATS_TEST_TMPDIR}/${dir_name}" + assert_dir_exist "${BATS_TEST_TMPDIR?}/${dir_name}" mkcd "${dir_name}" assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}" @@ -46,20 +48,20 @@ function local_setup_file() { @test 'plugins base: lsgrep()' { for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done - cd $BASH_IT + cd "${BASH_IT?}" run lsgrep 2 assert_success - assert_equal $output 2 + assert_equal "$output" 2 } @test 'plugins base: buf()' { - declare -r file="${BATS_TEST_TMPDIR}/file" - touch $file + declare -r file="${BATS_TEST_TMPDIR?}/file" + touch "$file" # Take one timestamp before running the `buf` function declare -r stamp1=$(date +%Y%m%d_%H%M%S) - run buf $file + run buf "$file" # Take another timestamp after running `buf`. declare -r stamp2=$(date +%Y%m%d_%H%M%S) diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index 04edad9582..e120e9ef6b 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -8,8 +9,8 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: notify after elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + NOTIFY_IF_COMMAND_RETURNS_AFTER=0 + COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -17,8 +18,8 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: do not notify before elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + NOTIFY_IF_COMMAND_RETURNS_AFTER=10 + COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -26,13 +27,13 @@ function local_setup_file() { } @test "lib command_duration: preexec no output" { - export COMMAND_DURATION_START_SECONDS= + COMMAND_DURATION_START_SECONDS= run _command_duration_pre_exec assert_success assert_output "" } @test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" { - export COMMAND_DURATION_START_SECONDS= + COMMAND_DURATION_START_SECONDS= assert_equal "${COMMAND_DURATION_START_SECONDS}" "" NOW="${EPOCHREALTIME:-$SECONDS}" _command_duration_pre_exec diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index ebb9cd8823..b8fb779a4b 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -21,7 +22,7 @@ function setup_go_path() @test 'ensure _bash-it-gopath-pathmunge is defined' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' - load ../../plugins/available/go.plugin + load "${BASH_IT?}/plugins/available/go.plugin.bash" run type -t _bash-it-gopath-pathmunge assert_line 'function' } @@ -29,39 +30,39 @@ function setup_go_path() @test 'plugins go: single entry in GOPATH' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin" } @test 'plugins go: single entry in GOPATH, with space' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/go path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin" } @test 'plugins go: single entry in GOPATH, with escaped space' { skip 'huh?' { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/go\ path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin" } @test 'plugins go: multiple entries in GOPATH' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath2" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" } @test 'plugins go: multiple entries in GOPATH, with space' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/go path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" } @test 'plugins go: multiple entries in GOPATH, with escaped space' { @@ -69,6 +70,6 @@ function setup_go_path() { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/go path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" } diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 7bfc64555d..a6ff87c4f3 100644 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -16,6 +16,7 @@ function local_setup_file() { } @test "plugins ruby: PATH includes ~/.gem/ruby/bin" { + local last_path_entry if ! type ruby >/dev/null; then skip 'ruby not installed' fi @@ -26,6 +27,6 @@ function local_setup_file() { assert_success load "${BASH_IT?}/plugins/available/ruby.plugin.bash" - local last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" + last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] } diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index 4cb1ffdae0..0d2c629816 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -8,28 +9,28 @@ function local_setup_file() { } @test "plugins xterm: shorten command output" { - export SHORT_TERM_LINE=true + SHORT_TERM_LINE=true run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0" } @test "plugins xterm: full command output" { - export SHORT_TERM_LINE=false + SHORT_TERM_LINE=false run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)" } @test "plugins xterm: shorten dirname output" { - export SHORT_TERM_LINE=true + SHORT_TERM_LINE=true run _short-dirname assert_success assert_output "$(basename "${PWD}")" } @test "plugins xterm: full dirname output" { - export SHORT_TERM_LINE=false + SHORT_TERM_LINE=false run _short-dirname assert_success assert_output "${PWD}" From 6f6a99e3ebf41d91b730ed26cc1a47efceded35c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:30:10 -0800 Subject: [PATCH 131/239] test/install: `shellcheck` --- test/install/install.bats | 21 +++++++++++---------- test/install/uninstall.bats | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index c9e1794c57..c5e3187524 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -3,7 +3,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="$BATS_TEST_TMPDIR" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { @@ -20,7 +20,7 @@ function local_setup_file() { } @test "install: verify that the install script exists" { - assert_file_exist "$BASH_IT/install.sh" + assert_file_exist "${BASH_IT?}/install.sh" } @test "install: run the install script silently" { @@ -30,26 +30,27 @@ function local_setup_file() { assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "install: verify that a backup file is created" { - cd "$BASH_IT" + local md5_orig md5_bak + cd "${BASH_IT?}" touch "$HOME/$BASH_IT_CONFIG_FILE" echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') ./install.sh --silent assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') assert_equal "$md5_orig" "$md5_bak" } diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index ab71a775f7..849e01d2d6 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -3,7 +3,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="$BATS_TEST_TMPDIR" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { @@ -20,15 +20,16 @@ function local_setup_file() { } @test "uninstall: verify that the uninstall script exists" { - assert_file_exist "$BASH_IT/uninstall.sh" + assert_file_exist "${BASH_IT?}/uninstall.sh" } @test "uninstall: run the uninstall script with an existing backup file" { - cd "$BASH_IT" + local md5_bak md5_conf + cd "${BASH_IT?}" echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') run ./uninstall.sh assert_success @@ -37,16 +38,17 @@ function local_setup_file() { assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') assert_equal "$md5_bak" "$md5_conf" } @test "uninstall: run the uninstall script without an existing backup file" { - cd "$BASH_IT" + local md5_orig md5_uninstall + cd "${BASH_IT?}" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') run ./uninstall.sh assert_success @@ -55,7 +57,7 @@ function local_setup_file() { assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') assert_equal "$md5_orig" "$md5_uninstall" } From c893be359467eaadf28a3d8beabbe0b9a659a08b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:20:50 -0800 Subject: [PATCH 132/239] tests: add to `clean_files.txt` --- clean_files.txt | 7 +------ test/fixtures/bash_it/aliases/available/a.aliases.bash | 2 +- test/fixtures/bash_it/aliases/available/b.aliases.bash | 2 +- test/fixtures/bash_it/plugins/available/c.plugin.bash | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index e52d5a9f29..82b07d7b0a 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -20,6 +20,7 @@ aliases/ docs/ hooks/ scripts/ +test/ # root files # @@ -134,12 +135,6 @@ plugins/available/todo.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash -# tests -# -test/plugins/alias-completion.plugin.bats -test/run -test/test_helper.bash - # themes # themes/90210 diff --git a/test/fixtures/bash_it/aliases/available/a.aliases.bash b/test/fixtures/bash_it/aliases/available/a.aliases.bash index 9dede3f66c..7410181383 100644 --- a/test/fixtures/bash_it/aliases/available/a.aliases.bash +++ b/test/fixtures/bash_it/aliases/available/a.aliases.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="a" diff --git a/test/fixtures/bash_it/aliases/available/b.aliases.bash b/test/fixtures/bash_it/aliases/available/b.aliases.bash index 4f90a7ad66..f0321d491b 100644 --- a/test/fixtures/bash_it/aliases/available/b.aliases.bash +++ b/test/fixtures/bash_it/aliases/available/b.aliases.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="b" diff --git a/test/fixtures/bash_it/plugins/available/c.plugin.bash b/test/fixtures/bash_it/plugins/available/c.plugin.bash index 3d17ad7aeb..db52fd0f4d 100644 --- a/test/fixtures/bash_it/plugins/available/c.plugin.bash +++ b/test/fixtures/bash_it/plugins/available/c.plugin.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="c" From 93a05ccb64c95ea1e7e78d4014c3471d2b124132 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 10:20:21 -0800 Subject: [PATCH 133/239] test_helper: make lib loading default Make library loading overridable default for all tests, up through "seach". --- test/test_helper.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index bffb59edd6..7d62212630 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -66,7 +66,7 @@ function setup_libs() { } function local_setup_file() { - true + setup_libs "search" # overridable default } function local_setup() { From 810c52f91a97325813a29fb59de241a45faf3d34 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 14:25:22 -0800 Subject: [PATCH 134/239] test: add new lib files to `setup_libs()` --- test/test_helper.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index 7d62212630..9728801681 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -57,7 +57,7 @@ function common_setup_file() { function setup_libs() { local lib # Use a loop to allow convenient short-circuiting for some test files - for lib in "log" "utilities" "helpers" "search" "preexec" "colors" "command_duration"; do + for lib in "log" "utilities" "helpers" "search" "colors" "preview" "preexec" "history" "command_duration"; do load "${BASH_IT?}/lib/${lib}.bash" || return # shellcheck disable=SC2015 # short-circuit if we've reached the requested library [[ "${lib}" == "${1:-}" ]] && return 0 || true @@ -66,7 +66,7 @@ function setup_libs() { } function local_setup_file() { - setup_libs "search" # overridable default + setup_libs "colors" # overridable default } function local_setup() { From 55e698a73768128f5ad43eaec61bad0640bdecbc Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 6 Mar 2022 04:25:33 +0530 Subject: [PATCH 135/239] fix test file path from the 7fcad6ed0d9427e51b94cc721a846666cef8ea82 commit --- clean_files.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index e52d5a9f29..11a584c7de 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -136,7 +136,7 @@ plugins/available/zoxide.plugin.bash # tests # -test/plugins/alias-completion.plugin.bats +test/completion/aliases.completion.bats test/run test/test_helper.bash From 6ba527ff98de6a7fbaeba3914239580522a2dfa4 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 6 Mar 2022 11:41:27 +0530 Subject: [PATCH 136/239] feature (alias): add terraform init alias --- aliases/available/terraform.aliases.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/aliases/available/terraform.aliases.bash b/aliases/available/terraform.aliases.bash index baa9b0c7ce..fedd319899 100644 --- a/aliases/available/terraform.aliases.bash +++ b/aliases/available/terraform.aliases.bash @@ -2,6 +2,7 @@ about-alias 'Aliases for Terraform and Terragrunt' alias tf='terraform' +alias tfi='tf init' alias tfv='terraform validate' alias tfp='terraform plan' alias tfa='terraform apply' From f2b4d82527d1a402b10594fd7db3eaf3989cb97a Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 6 Mar 2022 12:00:23 +0530 Subject: [PATCH 137/239] feature (alias): add open brave browser --- aliases/available/osx.aliases.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/aliases/available/osx.aliases.bash b/aliases/available/osx.aliases.bash index e99bcae6b3..0a16c06f61 100644 --- a/aliases/available/osx.aliases.bash +++ b/aliases/available/osx.aliases.bash @@ -11,6 +11,7 @@ alias safari='open -a safari' alias firefox='open -a firefox' alias chrome='open -a "Google Chrome"' alias chromium='open -a chromium' +alias brave='open -a "Brave Browser"' alias dashcode='open -a dashcode' alias f='open -a Finder ' alias fh='open -a Finder .' From ec6d371db87c2a601eecd9170a7ad74c15a57e68 Mon Sep 17 00:00:00 2001 From: Ira Abramov <44946400+ira-bv@users.noreply.github.com> Date: Mon, 7 Mar 2022 00:23:49 +0200 Subject: [PATCH 138/239] Add a 'theme' for OMP, so the internal themes don't clash with it. (#2100) * Add a 'theme' for OMP, so the internal themes don't clash with it. * Add theme to clean_files * Add screenshot to the docs * Correct the name of the default theme in the docs. * keeping it cleaner Co-authored-by: Ira Abramov --- clean_files.txt | 1 + docs/themes-list/index.rst | 13 +++++++++++++ docs/themes-list/oh-my-posh.rst | 15 +++++++++++++++ themes/oh-my-posh/oh-my-posh.theme.bash | 8 ++++++++ 4 files changed, 37 insertions(+) create mode 100644 docs/themes-list/oh-my-posh.rst create mode 100644 themes/oh-my-posh/oh-my-posh.theme.bash diff --git a/clean_files.txt b/clean_files.txt index 11a584c7de..3c76421b68 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -161,6 +161,7 @@ themes/essential themes/githelpers.theme.bash themes/modern themes/norbu +themes/oh-my-posh themes/p4helpers.theme.bash themes/pete themes/powerline diff --git a/docs/themes-list/index.rst b/docs/themes-list/index.rst index 49c5a6236c..0275001b38 100644 --- a/docs/themes-list/index.rst +++ b/docs/themes-list/index.rst @@ -346,6 +346,19 @@ NWinkler :alt: +---- + +.. _oh_my_posh_image: + +Oh-My-Posh +^^^^^^^^^^ + + +.. image:: https://bash-it.github.io/bash-it/docs/images/oh-my-posh.png + :target: https://bash-it.github.io/bash-it/docs/images/oh-my-posh.png + :alt: + + ---- Pete diff --git a/docs/themes-list/oh-my-posh.rst b/docs/themes-list/oh-my-posh.rst new file mode 100644 index 0000000000..974adc0f19 --- /dev/null +++ b/docs/themes-list/oh-my-posh.rst @@ -0,0 +1,15 @@ +.. _oh-my-posh: + +Oh-My-Posh Theme +================ + +The oh-my-posh Χ΄themeΧ΄ is really a plug to a whole other system +of managing your prompt. To use it please start here: +`Oh-My-Posh homepage `_ + +It is beyond the scope of bash-it to install and manage oh-my-posh, +this theme is here just to make sure your OMP setup doesn't clash +with other bash-it themes. Once installed, OMP will load a default +OMP theme (jandedobbeleer), which you can then customize or override. + +Note: Nerd Fonts are highly recommended, as most of the themes are graphic candies. diff --git a/themes/oh-my-posh/oh-my-posh.theme.bash b/themes/oh-my-posh/oh-my-posh.theme.bash new file mode 100644 index 0000000000..ba3c77f1ef --- /dev/null +++ b/themes/oh-my-posh/oh-my-posh.theme.bash @@ -0,0 +1,8 @@ +# shellcheck shell=bash + +if _command_exists oh-my-posh; then + export POSH_THEME=${POSH_THEME:-https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v$(oh-my-posh --version)/themes/jandedobbeleer.omp.json} + eval "$(oh-my-posh --init --shell bash --config "${POSH_THEME}")" +else + _log_warning "The oh-my-posh binary was not found on your PATH. Falling back to your existing PS1, please see the docs for more info." +fi From 77c135956d4fbb7328ebb76360be26d59960eb2e Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 8 Mar 2022 00:01:36 +0200 Subject: [PATCH 139/239] lib: preview: Load only bash-it.sh when previewing Otherwise you change your theme to your default... --- lib/preview.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.bash b/lib/preview.bash index 96fafae7ab..46c1618ab4 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -24,7 +24,7 @@ function _bash-it-preview() { # shellcheck disable=SC2034 for BASH_IT_THEME in "${themes[@]}"; do BASH_IT_LOG_LEVEL=0 - bash --init-file "${BASH_IT_BASHRC:-${BASH_IT?}/bash_it.sh}" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"' + bash --init-file "${BASH_IT?}/bash_it.sh" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"' done } From 13531c95344cca0326b17eb454225c80841815ef Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 8 Mar 2022 00:02:23 +0200 Subject: [PATCH 140/239] lib: search: Increase delay in _bash-it-flash-term to 0.2 secs --- lib/search.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search.bash b/lib/search.bash index 7073f8798b..247e6294ae 100644 --- a/lib/search.bash +++ b/lib/search.bash @@ -347,7 +347,7 @@ function _bash-it-flash-term() { local -i len="${1:-0}" # redundant local term="${2:-}" # as currently implemented, `$match` has already been printed to screen the first time - local delay=0.1 + local delay=0.2 local color [[ "${#term}" -gt 0 ]] && len="${#term}" From 31d1a007074927d18b541036d171bcfa448cec7b Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 8 Mar 2022 20:28:01 +0200 Subject: [PATCH 141/239] tests: Use git worktree correctly git worktree -d does not work on all versions of git worktree --- test/test_helper.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index bffb59edd6..e665796576 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -41,7 +41,7 @@ function common_setup_file() { BASH_IT="${BATS_FILE_TMPDIR//\/\///}/.bash_it" # This sets up a local test fixture, i.e. a completely fresh and isolated Bash-it directory. This is done to avoid messing with your own Bash-it source directory. - git --git-dir="${MAIN_BASH_IT_GITDIR?}" worktree add -d "${BASH_IT}" + git --git-dir="${MAIN_BASH_IT_GITDIR?}" worktree add --detach "${BASH_IT}" load "${BASH_IT?}/vendor/github.com/erichs/composure/composure.sh" # support 'plumbing' metadata From 4686ce1f129a68dd487527598bb6ba6a98c47368 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 9 Mar 2022 09:38:16 +0100 Subject: [PATCH 142/239] Fix precision to use deciseconds instead of nanoseconds --- lib/command_duration.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index bc0cca8e0a..8c190acf22 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -22,9 +22,11 @@ function _command_duration() { local -i minutes=0 seconds=0 deciseconds=0 local -i command_start_seconds="${command_start%.*}" local -i command_start_deciseconds=$((10#${command_start##*.})) + command_start_deciseconds="${command_start_deciseconds:0:1}" local current_time="${EPOCHREALTIME:-$SECONDS}" local -i current_time_seconds="${current_time%.*}" local -i current_time_deciseconds="$((10#${current_time##*.}))" + current_time_deciseconds="${current_time_deciseconds:0:1}" if [[ "${command_start_seconds:-0}" -gt 0 ]]; then # seconds From 634c1f8c182996af035e4ff025ba62d0794b344b Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 9 Mar 2022 09:38:42 +0100 Subject: [PATCH 143/239] Fix spacing in string output --- lib/command_duration.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index 8c190acf22..9810ff43bc 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -49,9 +49,9 @@ function _command_duration() { _dynamic_clock_icon "${command_duration}" if ((minutes > 0)); then - printf "%s%s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds" + printf "%s %s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds" elif ((seconds >= COMMAND_DURATION_MIN_SECONDS)); then - printf "%s%s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds" + printf "%s %s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds" fi } From b839294827b97671218a583ef6e3c4d6a6e65b1f Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 9 Mar 2022 21:29:51 +0100 Subject: [PATCH 144/239] Complete rework --- themes/barbuk/barbuk.theme.bash | 224 ++++++++++++++++++++++---------- 1 file changed, 158 insertions(+), 66 deletions(-) diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index b614d148c1..9608666a19 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -1,8 +1,11 @@ # shellcheck shell=bash # shellcheck disable=SC2034 # Expected behavior for themes. -# shellcheck disable=SC2154 #TODO: fix these all. + +# Prompt defaut configuration +BARBUK_PROMPT=${BARBUK_PROMPT:="git-uptream-remote-logo ssh path scm python_venv ruby node terraform cloud duration exit"} # Theme custom glyphs +# SCM SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:='οŠ– '} SCM_GIT_CHAR_BITBUCKET=${BARBUK_BITBUCKET_CHAR:='ο…± '} SCM_GIT_CHAR_GITHUB=${BARBUK_GITHUB_CHAR:='ο‚› '} @@ -10,13 +13,20 @@ SCM_GIT_CHAR_DEFAULT=${BARBUK_GIT_DEFAULT_CHAR:='ο‡’ '} SCM_GIT_CHAR_ICON_BRANCH=${BARBUK_GIT_BRANCH_ICON:='ξ‚ '} SCM_HG_CHAR=${BARBUK_HG_CHAR:='☿ '} SCM_SVN_CHAR=${BARBUK_SVN_CHAR:='⑆ '} +# Exit code EXIT_CODE_ICON=${BARBUK_EXIT_CODE_ICON:=' '} +# Programming and tools PYTHON_VENV_CHAR=${BARBUK_PYTHON_VENV_CHAR:='ξ˜† '} -COMMAND_DURATION_ICON=${BARBUK_COMMAND_DURATION_ICON:-"$bold_blue ο€— "} +RUBY_CHAR=${BARBUK_RUBY_CHAR:=' '} +NODE_CHAR=${BARBUK_NODE_CHAR:=' '} +TERRAFORM_CHAR=${BARBUK_TERRAFORM_CHAR:="❲t❳ "} +# Cloud +AWS_PROFILE_CHAR=${BARBUK_AWS_PROFILE_CHAR:="ο™’ aws "} +SCALEWAY_PROFILE_CHAR=${BARBUK_SCALEWAY_PROFILE_CHAR:="ο™’ scw "} +GCLOUD_CHAR=${BARBUK_GCLOUD_CHAR:="ο™’ google "} # Command duration COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-1} -COMMAND_DURATION_COLOR="$normal" # Ssh user and hostname display SSH_INFO=${BARBUK_SSH_INFO:=true} @@ -24,89 +34,171 @@ HOST_INFO=${BARBUK_HOST_INFO:=long} # Bash-it default glyphs customization SCM_NONE_CHAR= -SCM_THEME_PROMPT_DIRTY=" ${bold_red}βœ—" -SCM_THEME_PROMPT_CLEAN=" ${bold_green}βœ“" +SCM_THEME_PROMPT_DIRTY=" ${bold_red?}βœ—" +SCM_THEME_PROMPT_CLEAN=" ${bold_green?}βœ“" SCM_THEME_PROMPT_PREFIX="|" -SCM_THEME_PROMPT_SUFFIX="${green}| " -SCM_GIT_BEHIND_CHAR="${bold_red}↓${normal}" -SCM_GIT_AHEAD_CHAR="${bold_green}↑${normal}" +SCM_THEME_PROMPT_SUFFIX="${green?}| " +SCM_GIT_BEHIND_CHAR="${bold_red?}↓${normal?}" +SCM_GIT_AHEAD_CHAR="${bold_green?}↑${normal?}" SCM_GIT_UNTRACKED_CHAR="βŒ€" -SCM_GIT_UNSTAGED_CHAR="${bold_yellow}β€’${normal}" -SCM_GIT_STAGED_CHAR="${bold_green}+${normal}" -GIT_THEME_PROMPT_DIRTY=" ${bold_red}βœ—" -GIT_THEME_PROMPT_CLEAN=" ${bold_green}βœ“" -GIT_THEME_PROMPT_PREFIX="${cyan}" -GIT_THEME_PROMPT_SUFFIX="${cyan}" -SCM_THEME_BRANCH_TRACK_PREFIX="${normal} ‏ ${cyan}" +SCM_GIT_UNSTAGED_CHAR="${bold_yellow?}β€’${normal?}" +SCM_GIT_STAGED_CHAR="${bold_green?}+${normal?}" +GIT_THEME_PROMPT_DIRTY=" ${bold_red?}βœ—" +GIT_THEME_PROMPT_CLEAN=" ${bold_green?}βœ“" +GIT_THEME_PROMPT_PREFIX="${cyan?}" +GIT_THEME_PROMPT_SUFFIX="${cyan?}" +SCM_THEME_BRANCH_TRACK_PREFIX="${normal?} ‏ ${cyan?}" SCM_THEME_CURRENT_USER_PREFFIX=' ο•” ' SCM_GIT_SHOW_CURRENT_USER=false +NVM_THEME_PROMPT_PREFIX='' +NVM_THEME_PROMPT_SUFFIX='' +RVM_THEME_PROMPT_PREFIX='' +RVM_THEME_PROMPT_SUFFIX='' +RBENV_THEME_PROMPT_PREFIX=' ' +RBENV_THEME_PROMPT_SUFFIX='' +RBFU_THEME_PROMPT_PREFIX='' +RBFU_THEME_PROMPT_SUFFIX='' + +function __git-uptream-remote-logo_prompt() { + [[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" + + local remote remote_domain + remote=$(_git-upstream-remote) + remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}') + + # remove // suffix for https:// url + remote_domain=${remote_domain//\//} + + case $remote_domain in + github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;; + gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;; + bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;; + *) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;; + esac + + echo "${purple?}$(scm_char)" +} + +function git_prompt_info() { + git_prompt_vars + echo -e "on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX " +} + +function __exit_prompt() { + if [[ "$exit_code" -ne 0 ]]; then + echo "${purple?}${EXIT_CODE_ICON}${yellow?}${exit_code}${bold_orange?} " + else + echo "${bold_green}" + fi +} -function _git-uptream-remote-logo { - [[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" +function __aws_profile_prompt() { + if [[ -n "${AWS_PROFILE}" ]]; then + echo -n "${bold_purple?}${AWS_PROFILE_CHAR}${normal?}${AWS_PROFILE} " + fi +} - local remote remote_domain - remote=$(_git-upstream-remote) - remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}') +function __scaleway_profile_prompt() { + if [[ -n "${SCW_PROFILE}" ]]; then + echo -n "${bold_purple?}${SCALEWAY_PROFILE_CHAR}${normal?}${SCW_PROFILE} " + fi +} - # remove // suffix for https:// url - remote_domain=${remote_domain//\//} +function __gcloud_prompt() { + local active_gcloud_account="" + + active_gcloud_account="$(active_gcloud_account_prompt)" + [[ -n "${active_gcloud_account}" ]] && echo "${bold_purple?}${GCLOUD_CHAR}${normal?}${active_gcloud_account} " +} - case $remote_domain in - github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;; - gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;; - bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;; - *) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;; - esac +function __cloud_prompt() { + __aws_profile_prompt + __scaleway_profile_prompt + __gcloud_prompt } -function git_prompt_info { - git_prompt_vars - echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX" +function __terraform_prompt() { + local terraform_workspace="" + + if [ -d .terraform ]; then + terraform_workspace="$(terraform_workspace_prompt)" + [[ -n "${terraform_workspace}" ]] && echo "${bold_purple?}${TERRAFORM_CHAR}${normal?}${terraform_workspace} " + fi } -function _exit-code { - if [[ "$1" -ne 0 ]]; then - exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}" - else - exit_code="${bold_green}" - fi +function __node_prompt() { + local node_version="" + + node_version="$(node_version_prompt)" + [[ -n "${node_version}" ]] && echo "${bold_purple?}${NODE_CHAR}${normal?}${node_version} " } -function _prompt { - local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration= +function __ruby_prompt() { + local ruby_version="" - command_duration=$(_command_duration) + ruby_version="$(ruby_version_prompt)" + [[ -n "${ruby_version}" ]] && echo "${bold_purple?}${RUBY_CHAR}${normal?}${ruby_version} " +} + +function __ssh_prompt() { + # Detect ssh + if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then + if [ "$HOST_INFO" = long ]; then + host="\H" + else + host="\h" + fi + echo "${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in " + fi +} - _exit-code exit_code - _git-uptream-remote-logo +function __python_venv_prompt() { + # Detect python venv + if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}${CONDA_DEFAULT_ENV} " + elif [[ -n "${VIRTUAL_ENV}" ]]; then + echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}$(basename "${VIRTUAL_ENV}") " + fi +} - history -a +function __path_prompt() { + local dir_color=${green?} + # Detect root shell + if [ "$(whoami)" = root ]; then + dir_color=${red?} + fi - # Detect root shell - if [ "$(whoami)" = root ]; then - dir_color=$red - fi + echo "${dir_color}\w${normal} " +} - # Detect ssh - if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then - if [ "$HOST_INFO" = long ]; then - host="\H" - else - host="\h" - fi - ssh_info="${bold_blue}\u${bold_orange}@${cyan}$host ${bold_orange}in" - fi +function __scm_prompt() { + scm_prompt_info +} - # Detect python venv - if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - python_venv="$PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV} " - elif [[ -n "${VIRTUAL_ENV}" ]]; then - python_venv="$PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}") " - fi +function __duration_prompt() { + [[ -n "$command_duration" ]] && echo "${command_duration} " +} - PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${command_duration}${exit_code}" - [[ ${#PS1} -gt $((COLUMNS * 2)) ]] && wrap_char="\\n" - PS1="${PS1}${wrap_char}❯${normal} " +function __prompt-command() { + exit_code="$?" + command_duration=$(_command_duration) + local wrap_char + + # Generate prompt + PS1="\n " + for segment in $BARBUK_PROMPT; do + local info + info="$(__"${segment}"_prompt)" + [[ -n "${info}" ]] && PS1+="${info}" + done + + # Cut prompt when it's too long + if [[ ${#PS1} -gt $((COLUMNS * 2)) ]]; then + wrap_char="\n" + fi + + PS1="${PS1}${wrap_char}❯${normal} " } -safe_append_prompt_command _prompt +safe_append_prompt_command __prompt-command + From 0068315c35cb7539addf5cf2abe10c67d6500297 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 9 Mar 2022 21:38:03 +0100 Subject: [PATCH 145/239] Update documentation --- docs/themes-list/barbuk.rst | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/themes-list/barbuk.rst b/docs/themes-list/barbuk.rst index 15fb0ef577..79477524b0 100644 --- a/docs/themes-list/barbuk.rst +++ b/docs/themes-list/barbuk.rst @@ -8,13 +8,35 @@ A minimal theme with a clean git prompt Provided Information -------------------- - * Current git remote tool logo (support: github, gitlab, bitbucket) * Current path (red when user is root) * Current git info * Last command exit code (only shown when the exit code is greater than 0) * user@hostname for ssh connection +Default configuration +^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: bash + + BARBUK_PROMPT="git-uptream-remote-logo ssh path scm python_venv ruby node terraform cloud duration exit" + +You can override BARBUK_PROMPT to display only the desired information. + +available block: + +* git-uptream-remote-logo +* ssh +* path +* scm +* python_venv +* ruby +* node +* terraform +* cloud +* duration +* exit + Fonts and glyphs ---------------- @@ -39,6 +61,12 @@ Default theme glyphs BARBUK_EXIT_CODE_ICON=' ' BARBUK_PYTHON_VENV_CHAR='ξ˜† ' BARBUK_COMMAND_DURATION_ICON=' ο€— ' + BARBUK_RUBY_CHAR=' ' + BARBUK_NODE_CHAR=' ' + BARBUK_TERRAFORM_CHAR="❲t❳ " + BARBUK_AWS_PROFILE_CHAR="ο™’ aws " + BARBUK_SCALEWAY_PROFILE_CHAR="ο™’ scw " + BARBUK_GCLOUD_CHAR="ο™’ gcp " Customize glyphs ^^^^^^^^^^^^^^^^ From e1ddf6e311a60e6affa2485bef43e28a3819f963 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 9 Mar 2022 21:59:48 +0100 Subject: [PATCH 146/239] Fix dynamic clock icon (#2120) * Fix dynamic clock icon * Use printf variable scope * shfmt do not like spaces --- lib/command_duration.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index bc0cca8e0a..686267fb6d 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -11,7 +11,10 @@ function _command_duration_pre_exec() { } function _dynamic_clock_icon { - local -i clock_hand=$(((${1:-${SECONDS}} % 12) + 90)) + local clock_hand + # clock hand value is between 90 and 9b in hexadecimal. + # so between 144 and 155 in base 10. + printf -v clock_hand '%x' $(((${1:-${SECONDS}} % 12) + 144)) printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" } From 9a71556b9980469f71e5cbcda6651e77fb44f3bc Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 9 Mar 2022 21:48:43 +0100 Subject: [PATCH 147/239] shfmt needs more spaces --- themes/barbuk/barbuk.theme.bash | 163 ++++++++++++++++---------------- 1 file changed, 81 insertions(+), 82 deletions(-) diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 9608666a19..6e6eb88aaf 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -60,145 +60,144 @@ RBFU_THEME_PROMPT_PREFIX='' RBFU_THEME_PROMPT_SUFFIX='' function __git-uptream-remote-logo_prompt() { - [[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" + [[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" - local remote remote_domain - remote=$(_git-upstream-remote) - remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}') + local remote remote_domain + remote=$(_git-upstream-remote) + remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}') - # remove // suffix for https:// url - remote_domain=${remote_domain//\//} + # remove // suffix for https:// url + remote_domain=${remote_domain//\//} - case $remote_domain in - github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;; - gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;; - bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;; - *) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;; - esac + case $remote_domain in + github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;; + gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;; + bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;; + *) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;; + esac - echo "${purple?}$(scm_char)" + echo "${purple?}$(scm_char)" } function git_prompt_info() { - git_prompt_vars - echo -e "on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX " + git_prompt_vars + echo -e "on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX " } function __exit_prompt() { - if [[ "$exit_code" -ne 0 ]]; then - echo "${purple?}${EXIT_CODE_ICON}${yellow?}${exit_code}${bold_orange?} " - else - echo "${bold_green}" - fi + if [[ "$exit_code" -ne 0 ]]; then + echo "${purple?}${EXIT_CODE_ICON}${yellow?}${exit_code}${bold_orange?} " + else + echo "${bold_green}" + fi } function __aws_profile_prompt() { - if [[ -n "${AWS_PROFILE}" ]]; then - echo -n "${bold_purple?}${AWS_PROFILE_CHAR}${normal?}${AWS_PROFILE} " - fi + if [[ -n "${AWS_PROFILE}" ]]; then + echo -n "${bold_purple?}${AWS_PROFILE_CHAR}${normal?}${AWS_PROFILE} " + fi } function __scaleway_profile_prompt() { - if [[ -n "${SCW_PROFILE}" ]]; then - echo -n "${bold_purple?}${SCALEWAY_PROFILE_CHAR}${normal?}${SCW_PROFILE} " - fi + if [[ -n "${SCW_PROFILE}" ]]; then + echo -n "${bold_purple?}${SCALEWAY_PROFILE_CHAR}${normal?}${SCW_PROFILE} " + fi } function __gcloud_prompt() { - local active_gcloud_account="" + local active_gcloud_account="" - active_gcloud_account="$(active_gcloud_account_prompt)" - [[ -n "${active_gcloud_account}" ]] && echo "${bold_purple?}${GCLOUD_CHAR}${normal?}${active_gcloud_account} " + active_gcloud_account="$(active_gcloud_account_prompt)" + [[ -n "${active_gcloud_account}" ]] && echo "${bold_purple?}${GCLOUD_CHAR}${normal?}${active_gcloud_account} " } function __cloud_prompt() { - __aws_profile_prompt - __scaleway_profile_prompt - __gcloud_prompt + __aws_profile_prompt + __scaleway_profile_prompt + __gcloud_prompt } function __terraform_prompt() { - local terraform_workspace="" + local terraform_workspace="" - if [ -d .terraform ]; then - terraform_workspace="$(terraform_workspace_prompt)" - [[ -n "${terraform_workspace}" ]] && echo "${bold_purple?}${TERRAFORM_CHAR}${normal?}${terraform_workspace} " - fi + if [ -d .terraform ]; then + terraform_workspace="$(terraform_workspace_prompt)" + [[ -n "${terraform_workspace}" ]] && echo "${bold_purple?}${TERRAFORM_CHAR}${normal?}${terraform_workspace} " + fi } function __node_prompt() { - local node_version="" + local node_version="" - node_version="$(node_version_prompt)" - [[ -n "${node_version}" ]] && echo "${bold_purple?}${NODE_CHAR}${normal?}${node_version} " + node_version="$(node_version_prompt)" + [[ -n "${node_version}" ]] && echo "${bold_purple?}${NODE_CHAR}${normal?}${node_version} " } function __ruby_prompt() { - local ruby_version="" + local ruby_version="" - ruby_version="$(ruby_version_prompt)" - [[ -n "${ruby_version}" ]] && echo "${bold_purple?}${RUBY_CHAR}${normal?}${ruby_version} " + ruby_version="$(ruby_version_prompt)" + [[ -n "${ruby_version}" ]] && echo "${bold_purple?}${RUBY_CHAR}${normal?}${ruby_version} " } function __ssh_prompt() { - # Detect ssh - if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then - if [ "$HOST_INFO" = long ]; then - host="\H" - else - host="\h" - fi - echo "${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in " - fi + # Detect ssh + if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then + if [ "$HOST_INFO" = long ]; then + host="\H" + else + host="\h" + fi + echo "${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in " + fi } function __python_venv_prompt() { - # Detect python venv - if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}${CONDA_DEFAULT_ENV} " - elif [[ -n "${VIRTUAL_ENV}" ]]; then - echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}$(basename "${VIRTUAL_ENV}") " - fi + # Detect python venv + if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}${CONDA_DEFAULT_ENV} " + elif [[ -n "${VIRTUAL_ENV}" ]]; then + echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}$(basename "${VIRTUAL_ENV}") " + fi } function __path_prompt() { - local dir_color=${green?} - # Detect root shell - if [ "$(whoami)" = root ]; then - dir_color=${red?} - fi + local dir_color=${green?} + # Detect root shell + if [ "$(whoami)" = root ]; then + dir_color=${red?} + fi - echo "${dir_color}\w${normal} " + echo "${dir_color}\w${normal} " } function __scm_prompt() { - scm_prompt_info + scm_prompt_info } function __duration_prompt() { - [[ -n "$command_duration" ]] && echo "${command_duration} " + [[ -n "$command_duration" ]] && echo "${command_duration} " } function __prompt-command() { - exit_code="$?" - command_duration=$(_command_duration) - local wrap_char + exit_code="$?" + command_duration=$(_command_duration) + local wrap_char - # Generate prompt - PS1="\n " - for segment in $BARBUK_PROMPT; do - local info - info="$(__"${segment}"_prompt)" - [[ -n "${info}" ]] && PS1+="${info}" - done + # Generate prompt + PS1="\n " + for segment in $BARBUK_PROMPT; do + local info + info="$(__"${segment}"_prompt)" + [[ -n "${info}" ]] && PS1+="${info}" + done - # Cut prompt when it's too long - if [[ ${#PS1} -gt $((COLUMNS * 2)) ]]; then - wrap_char="\n" - fi + # Cut prompt when it's too long + if [[ ${#PS1} -gt $((COLUMNS * 2)) ]]; then + wrap_char="\n" + fi - PS1="${PS1}${wrap_char}❯${normal} " + PS1="${PS1}${wrap_char}❯${normal} " } safe_append_prompt_command __prompt-command - From 23efb39fb02d6d378f10f7519c6c2d30a71d68cf Mon Sep 17 00:00:00 2001 From: BarbUk Date: Fri, 11 Mar 2022 09:08:58 +0100 Subject: [PATCH 148/239] Fix grep path when a grep alias exists --- lib/utilities.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 8ea6b98c24..6d5fd5d493 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -62,13 +62,13 @@ 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)}" + : "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}" printf "%s" "${BASH_IT_GREP:-/usr/bin/grep}" } # Runs `grep` with extended regular expressions function _bash-it-egrep() { - : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" + : "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}" "${BASH_IT_GREP:-/usr/bin/grep}" -E "$@" } From 6b0ca17df00eaef0cacada04b5d3fbc6be03bf70 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 13 Mar 2022 05:20:57 +0530 Subject: [PATCH 149/239] improve (lint): add awscli.completion.bash in clean_files.txt --- clean_files.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clean_files.txt b/clean_files.txt index 3c76421b68..de0f6c1e87 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -33,6 +33,7 @@ lint_clean_files.sh # completion/available/apm.completion.bash completion/available/awless.completion.bash +completion/available/awscli.completion.bash completion/available/bash-it.completion.bash completion/available/brew.completion.bash completion/available/cargo.completion.bash From 66fbed7f6f4256c1e361ee2be0486b581e853cf5 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 13 Mar 2022 05:21:13 +0530 Subject: [PATCH 150/239] fix (completion): format awscli --- completion/available/awscli.completion.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/completion/available/awscli.completion.bash b/completion/available/awscli.completion.bash index a30418373a..6b2c90ff5d 100644 --- a/completion/available/awscli.completion.bash +++ b/completion/available/awscli.completion.bash @@ -1,6 +1,5 @@ # shellcheck shell=bash -if _command_exists aws_completer -then +if _command_exists aws_completer; then complete -C "$(command -v aws_completer)" aws fi From a481ff41ab2a1f642e241a88340b350a4a0b2630 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Mon, 14 Mar 2022 11:20:40 +0200 Subject: [PATCH 151/239] general: Add default nano editor for the edit alias --- aliases/available/general.aliases.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 42930ab4d2..b49344895b 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -34,7 +34,7 @@ fi alias c='clear' alias cls='clear' -alias edit='${EDITOR:-${ALTERNATE_EDITOR?}}' +alias edit='${EDITOR:-${ALTERNATE_EDITOR:-nano}}' alias pager='${PAGER:=less}' alias q='exit' From 0ad2d659efd3fc87eb965289f22feabfc0946cba Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 15 Mar 2022 07:45:31 +0530 Subject: [PATCH 152/239] improve (lint): add completion/available/export.completion.bash entry --- clean_files.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clean_files.txt b/clean_files.txt index 3c76421b68..ce72829f46 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -45,6 +45,7 @@ completion/available/dmidecode.completion.bash completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/dotnet.completion.bash +completion/available/export.completion.bash completion/available/gcloud.completion.bash completion/available/gem.completion.bash completion/available/git.completion.bash From 9dd88df936604e5b2e503d3d52477714475b662f Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 15 Mar 2022 07:46:25 +0530 Subject: [PATCH 153/239] fix (completion): SC2016 in export.completion.bash --- completion/available/export.completion.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/completion/available/export.completion.bash b/completion/available/export.completion.bash index 42da3a97be..4898eb9a01 100644 --- a/completion/available/export.completion.bash +++ b/completion/available/export.completion.bash @@ -1 +1,3 @@ -complete -o nospace -S = -W '$(printenv | awk -F= "{print \$1}")' export +# shellcheck shell=bash + +complete -o nospace -S = -W "$(printenv | awk -F= "{print \$1}")" export From 088212fd32af77e66bdef1f0fe3e0c56b96e4770 Mon Sep 17 00:00:00 2001 From: Eric Villard Date: Wed, 16 Mar 2022 08:43:52 +0100 Subject: [PATCH 154/239] fix projects plugin regression This regression was introduced in ea2002a. Before this commit, when the provided project was unique under all the project paths, the command automatically change the directory to it. Currently this is no more the case. If there are many project paths set, then the project path menu is shown at every call. This PR solves this issue. Signed-off-by: Eric Villard --- plugins/available/projects.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/projects.plugin.bash b/plugins/available/projects.plugin.bash index 803864806a..34fa001e0e 100644 --- a/plugins/available/projects.plugin.bash +++ b/plugins/available/projects.plugin.bash @@ -21,7 +21,7 @@ function pj() { # with the same name in project directories IFS=':' read -ra dests <<< "${BASH_IT_PROJECT_PATHS?${FUNCNAME[0]}: project working folders must be configured}" for d in "${!dests[@]}"; do - if [[ ! -d "${dests[d]}" ]]; then + if [[ ! -d "${dests[d]}/${proj}" ]]; then unset 'dests[d]' fi done From 6ccd9f5adfde535341da8139a156ef05de6568c9 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Mon, 21 Mar 2022 08:52:46 +0530 Subject: [PATCH 155/239] fix (helpers): bashit_update function return to source path and --no-merges in log --- lib/helpers.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index c0ce2eb3e2..2ee43a17af 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -290,6 +290,7 @@ function _bash-it-update-() { DIFF=$(git diff --name-status) if [[ -n "$DIFF" ]]; then echo -e "Local changes detected in bash-it directory. Clean '$BASH_IT' directory to proceed.\n$DIFF" + popd > /dev/null || return return 1 fi @@ -334,7 +335,7 @@ function _bash-it-update-() { log_color="%Cred" fi - git log --format="${log_color}%h: %s (%an)" "${revision}" + git log --no-merges --format="${log_color}%h: %s (%an)" "${revision}" echo "" if [[ -n "${silent}" ]]; then From 8ddda1fe5c22e21d621fa0bb045805dacf4f46ef Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Fri, 15 Apr 2022 09:41:25 -0500 Subject: [PATCH 156/239] feat: support plain old node as strategy to get node version --- themes/base.theme.bash | 18 +++++++++++++++++- .../powerline-multiline.theme.bash | 2 ++ .../powerline-naked/powerline-naked.theme.bash | 2 ++ .../powerline-plain/powerline-plain.theme.bash | 2 ++ themes/powerline/powerline.theme.bash | 2 ++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 92a56e5ec0..6854d66a3a 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -74,6 +74,9 @@ SCM_NONE_CHAR='β—‹' NVM_THEME_PROMPT_PREFIX=' |' NVM_THEME_PROMPT_SUFFIX='|' +NODE_THEME_PROMPT_PREFIX=' |' +NODE_THEME_PROMPT_SUFFIX='|' + RVM_THEME_PROMPT_PREFIX=' |' RVM_THEME_PROMPT_SUFFIX='|' @@ -399,8 +402,21 @@ function nvm_version_prompt() { fi } +function node_native_version_prompt() { + local node + if which -s node; then + node=$(node --version 2> /dev/null) + echo -ne "${NODE_THEME_PROMPT_PREFIX-}${node}${NODE_THEME_PROMPT_SUFFIX-}" + fi +} + function node_version_prompt() { - nvm_version_prompt + NODE_VERSION_STRATEGY="${NODE_VERSION_STRATEGY:-nvm}" + if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then + nvm_version_prompt + elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then + node_native_version_prompt + fi } function rvm_version_prompt() { diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 48a1243e03..9db10cb409 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -39,6 +39,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 2fb4137ef0..a5aaaa34a0 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -34,6 +34,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 6ff68e8fae..162fb5ca00 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -31,6 +31,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 49b397aa1d..2772a018cd 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -37,6 +37,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} From f7d21b5191b9c11741f6e1491e02bb47f486e304 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Fri, 15 Apr 2022 09:57:05 -0500 Subject: [PATCH 157/239] chore: update docs --- docs/themes-list/powerline-base.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index faa1af3401..f38f940daa 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -81,7 +81,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv`` and ``conda`` supported) * ``ruby`` - Current ruby version if using ``rvm`` -* ``node`` - Current node version (only ``nvm`` is supported) +* ``node`` - Current node version (``nvm`` is the default strategy; set ``NODE_VERSION_STRATEGY`` to ``node`` to use ``node --version``) * ``scm`` - Version control information, ``git`` * ``terraform`` - Current terraform workspace * ``user_info`` - Current user From d7fb6b3235bfceeb36d4657631c6c3155cdfd4ff Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 15 Mar 2022 07:52:43 +0530 Subject: [PATCH 158/239] improve (lint): add completion/available/flutter.completion.bash entry --- clean_files.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clean_files.txt b/clean_files.txt index de0f6c1e87..192fefa64f 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -46,6 +46,7 @@ completion/available/dmidecode.completion.bash completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/dotnet.completion.bash +completion/available/flutter.completion.bash completion/available/gcloud.completion.bash completion/available/gem.completion.bash completion/available/git.completion.bash From e11576f260903ee2041e910b535f674dbe5c86a4 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 15 Mar 2022 07:53:11 +0530 Subject: [PATCH 159/239] fix (completion): shfmt format flutter.completion.bash --- completion/available/flutter.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/flutter.completion.bash b/completion/available/flutter.completion.bash index 62befc824d..7dde5a0709 100644 --- a/completion/available/flutter.completion.bash +++ b/completion/available/flutter.completion.bash @@ -1,5 +1,5 @@ -#!/usr/bin/bash +# shellcheck shell=bash if _command_exists flutter; then - eval "$(flutter bash-completion)" + eval "$(flutter bash-completion)" fi From 135d480c7da93443e6ac1354e6554e76e70a233b Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:31:21 +0530 Subject: [PATCH 160/239] improve (docs): exclude venv pattern in build --- docs/conf.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index cacc2d5022..f96485c616 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,7 +14,6 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) - # -- Project information ----------------------------------------------------- project = 'Bash-it' @@ -24,7 +23,6 @@ # The full version, including alpha/beta/rc tags release = '' - # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be @@ -41,8 +39,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] - +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', "venv"] # -- Options for HTML output ------------------------------------------------- From c2698882e40f31725c1cebb7bd657e0dac2845fe Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:32:15 +0530 Subject: [PATCH 161/239] fix (docs): ugraded sphinx version --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index b3015c81ce..7b7fcdd1ff 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,4 @@ -sphinx==3.2.1 +sphinx==4.5.0 sphinx-rtd-theme==0.5.0 sphinxemoji==0.1.8 docutils==0.17.1 From f2bc6c4e6d421765741bafa2752367177eb7f3cb Mon Sep 17 00:00:00 2001 From: Dylan Tuttle Date: Sun, 8 May 2022 00:49:27 -0600 Subject: [PATCH 162/239] Added update-bash section in README --- docs/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/README.md b/docs/README.md index f3d31a14fe..5d0da58343 100644 --- a/docs/README.md +++ b/docs/README.md @@ -42,6 +42,27 @@ Stop polluting your `~/bin` directory and your `.bashrc` file, fork/clone Bash-i ``git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it`` 2) Run ``~/.bash_it/install.sh`` +### Bash Dependency + +Bash-it requires Bash 4.?? or later to run correctly. Any reasonably current Linux distribution should have shipped with a compatible version of Bash. However, macOS users must upgrade from the included, obsolete Bash version 3. While some functionality might work with Bash 3, there is no guarantee that everything will work perfectly. Thus, we recommend using [Homebrew](https://brew.sh/) to ensure Bash is up to date: + +**x86 Mac** + +```bash +$ brew install bash +$ sudo sh -c 'echo /usr/local/bin/bash >> /etc/shells' +$ chsh -s /usr/local/bin/bash +``` + +**M1 Mac** +Homebrew's default installation location on M1 is ``/opt/homebrew/bin/``: + +```bash +$ brew install bash +$ sudo sh -c 'echo /opt/homebrew/bin/bash >> /etc/shells' +$ chsh -s /opt/homebrew/bin/bash +``` + That's it! :smiley: You can check out more components of Bash-it, and customize it to your desire. From c0dc83edfc4bfca914c8da3eda51f17e169e8cdf Mon Sep 17 00:00:00 2001 From: David Farrell Date: Mon, 9 May 2022 13:08:52 -0700 Subject: [PATCH 163/239] plugin(dirs): Create backup file parent directory --- plugins/available/dirs.plugin.bash | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index 34468fa061..55d2e88a1f 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -63,12 +63,15 @@ function dirs-help() { if [[ -f "${BASH_IT_DIRS_BKS?}" ]]; then # shellcheck disable=SC1090 source "${BASH_IT_DIRS_BKS?}" -elif [[ -f ~/.dirs ]]; then - mv -vn ~/.dirs "${BASH_IT_DIRS_BKS?}" - # shellcheck disable=SC1090 - source "${BASH_IT_DIRS_BKS?}" else - touch "${BASH_IT_DIRS_BKS?}" + mkdir -p "${BASH_IT_DIRS_BKS%/*}" + if [[ -f ~/.dirs ]]; then + mv -vn ~/.dirs "${BASH_IT_DIRS_BKS?}" + # shellcheck disable=SC1090 + source "${BASH_IT_DIRS_BKS?}" + else + touch "${BASH_IT_DIRS_BKS?}" + fi fi alias L='cat "${BASH_IT_DIRS_BKS?}"' From 06b4b014cf97fc68f9cad7448b3511df5c4830c8 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Thu, 19 May 2022 07:20:33 -0500 Subject: [PATCH 164/239] chore: use _command_exists based on MR feedback --- themes/base.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 6854d66a3a..2283915826 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -404,7 +404,7 @@ function nvm_version_prompt() { function node_native_version_prompt() { local node - if which -s node; then + if _command_exists node; then node=$(node --version 2> /dev/null) echo -ne "${NODE_THEME_PROMPT_PREFIX-}${node}${NODE_THEME_PROMPT_SUFFIX-}" fi From 5913d222c5e437bfcbd30b092909017476a727ab Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Thu, 19 May 2022 07:25:36 -0500 Subject: [PATCH 165/239] chore: add log stmt based on MR feedback --- themes/base.theme.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 2283915826..e25014f86b 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -412,6 +412,9 @@ function node_native_version_prompt() { function node_version_prompt() { NODE_VERSION_STRATEGY="${NODE_VERSION_STRATEGY:-nvm}" + + _log_debug "node: using version strategy '$NODE_VERSION_STRATEGY'" + if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then nvm_version_prompt elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then From 129340d24d8c75d1eb3e801487da35d56bb75ac2 Mon Sep 17 00:00:00 2001 From: Thomas Merz Date: Mon, 18 Jul 2022 14:30:59 +0200 Subject: [PATCH 166/239] =?UTF-8?q?Issue=202151=20=F0=9F=9B=82=20do=20not?= =?UTF-8?q?=20give=20users=20a=20root=20shell=20by=20executing=20arbitrary?= =?UTF-8?q?=20shell=20commands=20by=20'vim'=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20also=20by=20removing=20'sudo'=20aliases=20becaus?= =?UTF-8?q?e=20bash-it=20should=20not=20be=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20the=20business=20of=20mucking=20about=20with=20s?= =?UTF-8?q?udo=20at=20all?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aliases/available/general.aliases.bash | 4 ---- 1 file changed, 4 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index b49344895b..2511aab8a9 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -71,10 +71,6 @@ alias rd='rmdir' # Shorten extract alias xt='extract' -# sudo editors -alias svim='sudo ${VISUAL:-vim}' -alias snano='sudo nano' - # Display whatever file is regular file or folder function catt() { for i in "$@"; do From 407f2f5b5f4a2fa9e7361a4385b02b64e29cef13 Mon Sep 17 00:00:00 2001 From: Jake Boeckerman Date: Fri, 12 Aug 2022 11:02:56 -0600 Subject: [PATCH 167/239] Update github runner images Github deprecated and will remove two runner images macos-10.15 will be removed on 2022-08-30 macos-12 is available https://github.blog/changelog/2022-07-20-github-actions-the-macos-10-15-actions-runner-image-is-being-deprecated-and-will-be-removed-by-8-30-22/ ubuntu-18.04 will be removed on 2022-12-01 ubuntu-22.04 is available https://github.blog/changelog/2022-08-09-github-actions-the-ubuntu-18-04-actions-runner-image-is-being-deprecated-and-will-be-removed-by-12-1-22/ --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0eee145cd8..1d1c0ecae6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-18.04, macos-10.15, macos-11] + os: [ubuntu-20.04, ubuntu-22.04, macos-12, macos-11] runs-on: ${{ matrix.os }} From 3294df5d3e929179ec25cc6b39118a09b021dd6e Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Fri, 26 Aug 2022 07:04:07 +0200 Subject: [PATCH 168/239] Verbose version of `git add` (gav) --- aliases/available/git.aliases.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 507037e1d0..535665b14d 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -8,6 +8,7 @@ alias get='git' alias ga='git add' alias gall='git add -A' alias gap='git add -p' +alias gav='git add -v' # branch alias gb='git branch' From e5e7785c9697d2808459f9d6d7a6d8652db74d88 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Tue, 30 Aug 2022 13:21:03 -0500 Subject: [PATCH 169/239] Update variable name to match projects.plugin.bash The projects plugin was changed to reference `BASH_IT_PROJECT_PATHS` but the completion was still using `PROJECT_PATHS` --- completion/available/projects.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/projects.completion.bash b/completion/available/projects.completion.bash index 90735ee130..df4f5754dd 100644 --- a/completion/available/projects.completion.bash +++ b/completion/available/projects.completion.bash @@ -7,7 +7,7 @@ _is_function _rl_enabled || _pj() { _is_function _init_completion || return _is_function _rl_enabled || return - [ -n "$PROJECT_PATHS" ] || return + [ -n "$BASH_IT_PROJECT_PATHS" ] || return shift [ "$1" == "open" ] && shift @@ -21,7 +21,7 @@ _pj() { local -r mark_dirs=$(_rl_enabled mark-directories && echo y) local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y) - for i in ${PROJECT_PATHS//:/$'\n'}; do + for i in ${BASH_IT_PROJECT_PATHS//:/$'\n'}; do # create an array of matched subdirs k="${#COMPREPLY[@]}" for j in $( compgen -d $i/$cur ); do From 0ab80429cea4edf6216e0bb539295460ae6706fd Mon Sep 17 00:00:00 2001 From: Dylan Tuttle Date: Thu, 22 Sep 2022 16:27:52 -0600 Subject: [PATCH 170/239] Removed Bash Dependency section from README and added it to troubleshooting.rst --- docs/README.md | 21 --------------------- docs/troubleshooting.rst | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5d0da58343..f3d31a14fe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -42,27 +42,6 @@ Stop polluting your `~/bin` directory and your `.bashrc` file, fork/clone Bash-i ``git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it`` 2) Run ``~/.bash_it/install.sh`` -### Bash Dependency - -Bash-it requires Bash 4.?? or later to run correctly. Any reasonably current Linux distribution should have shipped with a compatible version of Bash. However, macOS users must upgrade from the included, obsolete Bash version 3. While some functionality might work with Bash 3, there is no guarantee that everything will work perfectly. Thus, we recommend using [Homebrew](https://brew.sh/) to ensure Bash is up to date: - -**x86 Mac** - -```bash -$ brew install bash -$ sudo sh -c 'echo /usr/local/bin/bash >> /etc/shells' -$ chsh -s /usr/local/bin/bash -``` - -**M1 Mac** -Homebrew's default installation location on M1 is ``/opt/homebrew/bin/``: - -```bash -$ brew install bash -$ sudo sh -c 'echo /opt/homebrew/bin/bash >> /etc/shells' -$ chsh -s /opt/homebrew/bin/bash -``` - That's it! :smiley: You can check out more components of Bash-it, and customize it to your desire. diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index 6503699a98..953a129aaa 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -8,9 +8,30 @@ Table of Contents * `I'm stuck in the LightDM login screen after setting up bash-it. `_ +* `I'm getting strange line break and wrapping behaviour on macOS. `_ + I'm stuck in the LightDM login screen after setting up bash-it ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ **Possible issue**\ : `#672 `_ **Solution**\ : Check `this comment `_ for detailed information about the cause and solution for this issue. + +I'm getting strange line break and wrapping behaviour on macOS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +**Possible issue**\ : `#1614 `_ + +**Solution**\ : Bash-it requires Bash 4.?? or later to run correctly. Any reasonably current Linux distribution should have shipped with a compatible version of Bash. However, macOS users must upgrade from the included, obsolete Bash version 3. While some functionality might work with Bash 3, there is no guarantee that everything will work perfectly. Thus, we recommend using `Homebrew `_ to ensure Bash is up to date: + +**x86 Mac:**\ +.. code-block:: console + $ brew install bash + $ sudo sh -c 'echo /usr/local/bin/bash >> /etc/shells' + $ chsh -s /usr/local/bin/bash + +**M1 Mac:**\ Homebrew's default installation location on M1 is ``/opt/homebrew/bin/``: +.. code-block:: console + $ brew install bash + $ sudo sh -c 'echo /opt/homebrew/bin/bash >> /etc/shells' + $ chsh -s /opt/homebrew/bin/bash From 606272ac23992283beffc6b9530581e7236eafcf Mon Sep 17 00:00:00 2001 From: Dylan Tuttle Date: Thu, 22 Sep 2022 16:49:26 -0600 Subject: [PATCH 171/239] Fixed broken code blocks in troubleshooting.rst --- docs/troubleshooting.rst | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index 953a129aaa..93d9113ab3 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -24,14 +24,22 @@ I'm getting strange line break and wrapping behaviour on macOS **Solution**\ : Bash-it requires Bash 4.?? or later to run correctly. Any reasonably current Linux distribution should have shipped with a compatible version of Bash. However, macOS users must upgrade from the included, obsolete Bash version 3. While some functionality might work with Bash 3, there is no guarantee that everything will work perfectly. Thus, we recommend using `Homebrew `_ to ensure Bash is up to date: -**x86 Mac:**\ -.. code-block:: console - $ brew install bash - $ sudo sh -c 'echo /usr/local/bin/bash >> /etc/shells' - $ chsh -s /usr/local/bin/bash - -**M1 Mac:**\ Homebrew's default installation location on M1 is ``/opt/homebrew/bin/``: -.. code-block:: console - $ brew install bash - $ sudo sh -c 'echo /opt/homebrew/bin/bash >> /etc/shells' - $ chsh -s /opt/homebrew/bin/bash +x86 Mac +^^^^^^^ + + .. code-block:: bash + + brew install bash + sudo sh -c 'echo /usr/local/bin/bash >> /etc/shells' + chsh -s /usr/local/bin/bash + +M1 Mac +^^^^^^ + +Homebrew's default installation location on M1 is ``/opt/homebrew/bin/``: + + .. code-block:: bash + + brew install bash + sudo sh -c 'echo /opt/homebrew/bin/bash >> /etc/shells' + chsh -s /opt/homebrew/bin/bash From 00062bfcb6c6a68cd2c9d2c76ed764e01e930e87 Mon Sep 17 00:00:00 2001 From: David Farrell Date: Thu, 13 Oct 2022 10:34:57 -0700 Subject: [PATCH 172/239] chore: Use grep -E / grep -F instead of egrep / fgrep (#2164) Ensures that the -E or -F option, when used, is the first option * i.e. grep -oE => grep -E -o Updates _bash-it-grep to invoke grep with just the provided arguments * This function was (and still is) unused, but decided this new functionality was actually more useful Introduces _bash-it-fgrep to invoke grep -F Removes type -P egrep from the _bash-it-*grep functions For usages that were already going to be modified, use -F if appropriate * Does not touch grep usages that may have benefited from -F, but were not otherwise considered for this PR Adds shellcheck header to modified .bash files that didn't already have it --- completion/available/fabric.completion.bash | 6 +++--- completion/available/gradle.completion.bash | 4 +++- completion/available/makefile.completion.bash | 4 +++- lib/helpers.bash | 2 +- lib/utilities.bash | 20 ++++++++++++------- lint_clean_files.sh | 4 ++-- plugins/available/aws.plugin.bash | 7 ++++--- plugins/available/jekyll.plugin.bash | 4 ++-- plugins/available/postgres.plugin.bash | 3 ++- themes/rjorgenson/rjorgenson.theme.bash | 4 +++- 10 files changed, 36 insertions(+), 22 deletions(-) diff --git a/completion/available/fabric.completion.bash b/completion/available/fabric.completion.bash index 6f746454dc..a8984d9cc3 100644 --- a/completion/available/fabric.completion.bash +++ b/completion/available/fabric.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # # Bash completion support for Fabric (http://fabfile.org/) # @@ -91,7 +91,7 @@ function __fab_completion() { -*) if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then export __FAB_COMPLETION_LONG_OPT=$( - fab --help | egrep -o "\-\-[A-Za-z_\-]+\=?" | sort -u) + fab --help | grep -E -o "\-\-[A-Za-z_\-]+\=?" | sort -u) fi opts="${__FAB_COMPLETION_LONG_OPT}" ;; @@ -101,7 +101,7 @@ function __fab_completion() { # -*) # if [[ -z "${__FAB_COMPLETION_SHORT_OPT}" ]]; then # export __FAB_COMPLETION_SHORT_OPT=$( - # fab --help | egrep -o "^ +\-[A-Za-z_\]" | sort -u) + # fab --help | grep -E -o "^ +\-[A-Za-z_\]" | sort -u) # fi # opts="${__FAB_COMPLETION_SHORT_OPT}" # ;; diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 35971d5075..ef9677c6de 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash + # Copyright (c) 2017 Eric Wendelin # Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -66,7 +68,7 @@ __gradle-generate-script-cache() { if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2>/dev/null) ]]; then # Cache all Gradle scripts - local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | egrep -v "$script_exclude_pattern") + local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | grep -E -v "$script_exclude_pattern") printf "%s\n" "${gradle_build_scripts[@]}" > $cache_dir/$cache_name fi } diff --git a/completion/available/makefile.completion.bash b/completion/available/makefile.completion.bash index e72ba6fd3b..018586cacf 100644 --- a/completion/available/makefile.completion.bash +++ b/completion/available/makefile.completion.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash + # Bash completion for Makefile # Loosely adapted from http://stackoverflow.com/a/38415982/1472048 @@ -17,7 +19,7 @@ _makecomplete() { for f in "${files[@]}" ; do while IFS='' read -r line ; do targets+=("$line") - done < <(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1) + done < <(grep -E -o '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1) done [ "${#targets[@]}" -eq 0 ] && return 0 diff --git a/lib/helpers.bash b/lib/helpers.bash index 2ee43a17af..3675b0f259 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -211,7 +211,7 @@ function _is_function() { _example '$ _is_function ls && echo exists' _group 'lib' local msg="${2:-Function '$1' does not exist}" - if LC_ALL=C type -t "$1" | _bash-it-egrep -q 'function'; then + if LC_ALL=C type -t "$1" | _bash-it-fgrep -q 'function'; then return 0 else _log_debug "$msg" diff --git a/lib/utilities.bash b/lib/utilities.bash index 6d5fd5d493..75e914b8c6 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -60,15 +60,21 @@ function _bash-it-array-dedup() { printf '%s\n' "$@" | sort -u } -# Outputs a full path of the grep found on the filesystem +# Runs `grep` with *just* the provided arguments function _bash-it-grep() { - : "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}" - printf "%s" "${BASH_IT_GREP:-/usr/bin/grep}" + : "${BASH_IT_GREP:=$(type -P grep)}" + "${BASH_IT_GREP:-/usr/bin/grep}" "$@" } -# Runs `grep` with extended regular expressions +# Runs `grep` with fixed-string expressions (-F) +function _bash-it-fgrep() { + : "${BASH_IT_GREP:=$(type -P grep)}" + "${BASH_IT_GREP:-/usr/bin/grep}" -F "$@" +} + +# Runs `grep` with extended regular expressions (-E) function _bash-it-egrep() { - : "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}" + : "${BASH_IT_GREP:=$(type -P grep)}" "${BASH_IT_GREP:-/usr/bin/grep}" -E "$@" } @@ -150,12 +156,12 @@ function _bash-it-component-list-matching() { function _bash-it-component-list-enabled() { local IFS=$'\n' component="$1" - _bash-it-component-help "${component}" | _bash-it-egrep '\[x\]' | awk '{print $1}' | sort -u + _bash-it-component-help "${component}" | _bash-it-fgrep '[x]' | awk '{print $1}' | sort -u } function _bash-it-component-list-disabled() { local IFS=$'\n' component="$1" - _bash-it-component-help "${component}" | _bash-it-egrep -v '\[x\]' | awk '{print $1}' | sort -u + _bash-it-component-help "${component}" | _bash-it-fgrep -v '[x]' | awk '{print $1}' | sort -u } # Checks if a given item is enabled for a particular component/file-type. diff --git a/lint_clean_files.sh b/lint_clean_files.sh index 26650b16de..cc2686042f 100755 --- a/lint_clean_files.sh +++ b/lint_clean_files.sh @@ -8,8 +8,8 @@ # shellcheck disable=SC2002 # Prefer 'cat' for cleaner script mapfile -t FILES < <( cat clean_files.txt \ - | grep -v -E '^\s*$' \ - | grep -v -E '^\s*#' \ + | grep -E -v '^\s*$' \ + | grep -E -v '^\s*#' \ | xargs -n1 -I{} find "{}" -type f ) diff --git a/plugins/available/aws.plugin.bash b/plugins/available/aws.plugin.bash index 54a8669171..14d26caefb 100644 --- a/plugins/available/aws.plugin.bash +++ b/plugins/available/aws.plugin.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'AWS helper functions' @@ -40,13 +41,13 @@ function __awskeys_help { function __awskeys_get { local ln=$(grep -n "\[ *$1 *\]" "${AWS_SHARED_CREDENTIALS_FILE}" | cut -d ":" -f 1) if [[ -n "${ln}" ]]; then - tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | egrep -m 2 "aws_access_key_id|aws_secret_access_key" - tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | egrep -m 1 "aws_session_token" + tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 2 -e "aws_access_key_id" -e "aws_secret_access_key" + tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 1 "aws_session_token" fi } function __awskeys_list { - local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"; grep "\[profile" "${AWS_CONFIG_FILE}" | sed "s|\[profile |\[|g") | sort | uniq)" + local credentials_list="$((grep -E '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"; grep "\[profile" "${AWS_CONFIG_FILE}" | sed "s|\[profile |\[|g") | sort | uniq)" if [[ -n $"{credentials_list}" ]]; then echo -e "Available credentials profiles:\n" for profile in ${credentials_list}; do diff --git a/plugins/available/jekyll.plugin.bash b/plugins/available/jekyll.plugin.bash index d818b07628..3c12d82662 100644 --- a/plugins/available/jekyll.plugin.bash +++ b/plugins/available/jekyll.plugin.bash @@ -30,8 +30,8 @@ function editpost() { pushd "${SITE}/_posts" > /dev/null || return for POST in *; do - DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")" - TITLE="$(grep -oE "title: (.+)" < "${POST}")" + DATE="$(echo "${POST}" | grep -E -o "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")" + TITLE="$(grep -E -o "title: (.+)" < "${POST}")" TITLE="${TITLE/title: /}" echo "${COUNTER}) ${DATE} ${TITLE}" POSTS[COUNTER]="$POST" diff --git a/plugins/available/postgres.plugin.bash b/plugins/available/postgres.plugin.bash index 8f239985e0..9f66152b5c 100644 --- a/plugins/available/postgres.plugin.bash +++ b/plugins/available/postgres.plugin.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'postgres helper functions' @@ -50,7 +51,7 @@ function postgres_status { function is_postgres_running { - $POSTGRES_BIN/pg_ctl -D $PGDATA status | egrep -o "no server running" + $POSTGRES_BIN/pg_ctl -D $PGDATA status | grep -F -o "no server running" } diff --git a/themes/rjorgenson/rjorgenson.theme.bash b/themes/rjorgenson/rjorgenson.theme.bash index 71d29e7866..6e73c4a28c 100644 --- a/themes/rjorgenson/rjorgenson.theme.bash +++ b/themes/rjorgenson/rjorgenson.theme.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash + # port of zork theme # set colors for use throughout the prompt @@ -50,7 +52,7 @@ function is_integer() { # helper function for todo-txt-count todo_txt_count() { if `hash todo.sh 2>&-`; then # is todo.sh installed - count=`todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }'` + count=`todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }'` if is_integer $count; then # did we get a sane answer back echo "${BRACKET_COLOR}[${STRING_COLOR}T:$count${BRACKET_COLOR}]$normal" fi From 7c77223b154bf8d0f7d6d879bebbb7efb91ca548 Mon Sep 17 00:00:00 2001 From: gmajkic Date: Thu, 13 Oct 2022 17:02:14 +0200 Subject: [PATCH 173/239] fix(theme): use correct escape sequence to avoid weird text overwriting --- themes/parrot/parrot.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/parrot/parrot.theme.bash b/themes/parrot/parrot.theme.bash index a0d259dd62..251eb942f7 100644 --- a/themes/parrot/parrot.theme.bash +++ b/themes/parrot/parrot.theme.bash @@ -2,7 +2,7 @@ # git branch parser function parse_git_branch() { - echo -e "\033[1;34m$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\033[0m" + echo -e "\[\033[1;34m\]$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\[\033[0m\]" } function parse_git_branch_no_color() { From 1c9cfd056bab4244cdc1b9dc3082da8e2cda7f9e Mon Sep 17 00:00:00 2001 From: David Farrell Date: Sun, 30 Oct 2022 15:15:28 -0700 Subject: [PATCH 174/239] bug:Install shellcheck wget (#2173) Installs shellcheck via wget of github release for 'stable' linux version --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d1c0ecae6..8e772ec5e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,10 +49,17 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 + # - name: Update APT Package Lists + # run: sudo apt-get update - name: Install shfmt run: GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt - name: Install shellcheck - run: brew install shellcheck + env: + scversion: stable # Or latest, vxx, etc + run: | + wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv "shellcheck-${scversion}/shellcheck" + sudo cp "shellcheck-${scversion}/shellcheck" /usr/bin/ + shellcheck --version - name: Install pre-commit run: python3 -m pip install -r test/lint-requirements.txt - name: Run lint From 7c7e4f90ec937fb6ea4acf83698a28a86ef3b875 Mon Sep 17 00:00:00 2001 From: David Farrell Date: Wed, 26 Oct 2022 15:23:11 -0700 Subject: [PATCH 175/239] bug: Use en_US when fetching EPOCHREALTIME Isolates fetching of EPOCHREALTIME to a function which sets LC_ALL=en_US.UTF-8. This ensures that the value is in decimal format, regardless of runtime locale. bug: Hide duration when no command executed --- lib/command_duration.bash | 21 ++++++++++++++++--- .../available/cmd-returned-notify.plugin.bash | 3 ++- test/plugins/cmd-returned-notify.plugin.bats | 6 +++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index cd1d6636db..ec4d828d0c 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -2,12 +2,24 @@ # # Functions for measuring and reporting how long a command takes to run. -: "${COMMAND_DURATION_START_SECONDS:=${EPOCHREALTIME:-$SECONDS}}" +# Get shell duration in decimal format regardless of runtime locale. +# Notice: This function runs as a sub-shell - notice '(' vs '{'. +function _shell_duration_en() ( + # DFARREL You would think LC_NUMERIC would do it, but not working in my local + LC_ALL='en_US.UTF-8' + printf "%s" "${EPOCHREALTIME:-$SECONDS}" +) + +: "${COMMAND_DURATION_START_SECONDS:=$(_shell_duration_en)}" : "${COMMAND_DURATION_ICON:=πŸ•˜}" : "${COMMAND_DURATION_MIN_SECONDS:=1}" function _command_duration_pre_exec() { - COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" +} + +function _command_duration_pre_cmd() { + COMMAND_DURATION_START_SECONDS="" } function _dynamic_clock_icon { @@ -20,13 +32,15 @@ function _dynamic_clock_icon { function _command_duration() { [[ -n "${BASH_IT_COMMAND_DURATION:-}" ]] || return + [[ -n "${COMMAND_DURATION_START_SECONDS:-}" ]] || return local command_duration=0 command_start="${COMMAND_DURATION_START_SECONDS:-0}" local -i minutes=0 seconds=0 deciseconds=0 local -i command_start_seconds="${command_start%.*}" local -i command_start_deciseconds=$((10#${command_start##*.})) command_start_deciseconds="${command_start_deciseconds:0:1}" - local current_time="${EPOCHREALTIME:-$SECONDS}" + local current_time + current_time="$(_shell_duration_en)" local -i current_time_seconds="${current_time%.*}" local -i current_time_deciseconds="$((10#${current_time##*.}))" current_time_deciseconds="${current_time_deciseconds:0:1}" @@ -59,3 +73,4 @@ function _command_duration() { } _bash_it_library_finalize_hook+=("safe_append_preexec '_command_duration_pre_exec'") +_bash_it_library_finalize_hook+=("safe_append_prompt_command '_command_duration_pre_cmd'") diff --git a/plugins/available/cmd-returned-notify.plugin.bash b/plugins/available/cmd-returned-notify.plugin.bash index 88c07722df..e6d221faac 100644 --- a/plugins/available/cmd-returned-notify.plugin.bash +++ b/plugins/available/cmd-returned-notify.plugin.bash @@ -4,7 +4,8 @@ about-plugin 'Alert (BEL) when process ends after a threshold of seconds' function precmd_return_notification() { local command_start="${COMMAND_DURATION_START_SECONDS:=0}" - local current_time="${EPOCHREALTIME:-$SECONDS}" + local current_time + current_time="$(_shell_duration_en)" local -i command_duration="$((${current_time%.*} - ${command_start%.*}))" if [[ "${command_duration}" -gt "${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5}" ]]; then printf '\a' diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index 04edad9582..a5ae591a51 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -9,7 +9,7 @@ function local_setup_file() { @test "plugins cmd-returned-notify: notify after elapsed time" { export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" sleep 1 run precmd_return_notification assert_success @@ -18,7 +18,7 @@ function local_setup_file() { @test "plugins cmd-returned-notify: do not notify before elapsed time" { export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" sleep 1 run precmd_return_notification assert_success @@ -34,7 +34,7 @@ function local_setup_file() { @test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" { export COMMAND_DURATION_START_SECONDS= assert_equal "${COMMAND_DURATION_START_SECONDS}" "" - NOW="${EPOCHREALTIME:-$SECONDS}" + NOW="$(_shell_duration_en)" _command_duration_pre_exec # We need to make sure to account for nanoseconds... assert_equal "${COMMAND_DURATION_START_SECONDS%.*}" "${NOW%.*}" From 5f59cb54383e912e001a7c2ad64b655cadae100f Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Fri, 30 Sep 2022 11:29:35 -0500 Subject: [PATCH 176/239] remove function wrapper around kubectl alias registration --- aliases/available/kubectl.aliases.bash | 30 +++++++++++--------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/aliases/available/kubectl.aliases.bash b/aliases/available/kubectl.aliases.bash index aaca4ca259..ce01bdafcf 100644 --- a/aliases/available/kubectl.aliases.bash +++ b/aliases/available/kubectl.aliases.bash @@ -1,20 +1,16 @@ # shellcheck shell=bash about-alias 'kubectl aliases' -function _set_pkg_aliases() { - if _command_exists kubectl; then - alias kc='kubectl' - alias kcgp='kubectl get pods' - alias kcgd='kubectl get deployments' - alias kcgn='kubectl get nodes' - alias kcdp='kubectl describe pod' - alias kcdd='kubectl describe deployment' - alias kcdn='kubectl describe node' - alias kcgpan='kubectl get pods --all-namespaces' - alias kcgdan='kubectl get deployments --all-namespaces' - # launches a disposable netshoot pod in the k8s cluster - alias kcnetshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash' - fi -} - -_set_pkg_aliases +if _command_exists kubectl; then + alias kc='kubectl' + alias kcgp='kubectl get pods' + alias kcgd='kubectl get deployments' + alias kcgn='kubectl get nodes' + alias kcdp='kubectl describe pod' + alias kcdd='kubectl describe deployment' + alias kcdn='kubectl describe node' + alias kcgpan='kubectl get pods --all-namespaces' + alias kcgdan='kubectl get deployments --all-namespaces' + # launches a disposable netshoot pod in the k8s cluster + alias kcnetshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash' +fi From 58bae6f900ce81c4f8777a9265b149c21b265627 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Mon, 28 Nov 2022 14:52:34 +0000 Subject: [PATCH 177/239] Fix call to liquidprompt function Missing leading underscore in `_lp_escape` --- themes/liquidprompt/liquidprompt.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 60e64210c4..c458ad4af5 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -39,7 +39,7 @@ _lp_git_branch() # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then - _lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" + __lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" else # In detached head state, use commit instead # No escape needed From e2fbfa6c736a087bc5ad17e3dc7bc9e0e1f157e5 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Mon, 28 Nov 2022 15:03:50 +0000 Subject: [PATCH 178/239] Update liquidprompt.theme.bash --- themes/liquidprompt/liquidprompt.theme.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index c458ad4af5..ebf55969b0 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -40,10 +40,11 @@ _lp_git_branch() # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then __lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" + lp_vcs_branch="$ret" else # In detached head state, use commit instead # No escape needed - \git rev-parse --short -q HEAD 2>/dev/null + lp_vcs_branch="$(\git rev-parse --short -q HEAD 2>/dev/null)" fi } From 7724fcab6b16c63500b2748de7ba2d961405a648 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Tue, 29 Nov 2022 08:56:31 +0000 Subject: [PATCH 179/239] Update liquidprompt.theme.bash Added `ret` to local declarations as per provided liquidprompt change notes --- themes/liquidprompt/liquidprompt.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index ebf55969b0..3e5ff013d8 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -35,7 +35,7 @@ _lp_git_branch() \git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return - local branch + local branch ret # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then From 5e92af959abcd9bec98d7df49026ba7a2c16864d Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Tue, 29 Nov 2022 11:28:21 +0000 Subject: [PATCH 180/239] Attempt to no break existing installs --- themes/liquidprompt/liquidprompt.theme.bash | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 3e5ff013d8..9631cab716 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -21,7 +21,7 @@ export LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75} export LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60} export LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-80} - +unset _lp_legacy _lp_escape __lp_escape source "$targetdir/liquidprompt" prompt() { true; } export PS2=" ┃ " @@ -29,23 +29,37 @@ export LP_PS1_PREFIX="β”Œβ”€" export LP_PS1_POSTFIX="\nβ””β–ͺ " export LP_ENABLE_RUNTIME=0 +_lp_legacy() +{ + type -t _lp_escape &> /dev/null +} + +_lp_legacy && __lp_escape() +{ + ret="$(_lp_escape "$@")" +} + _lp_git_branch() { (( LP_ENABLE_GIT )) || return \git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return - local branch ret + local commit branch ret + + commit="$(\git rev-parse --short -q HEAD 2>/dev/null)" + # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then - __lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" + __lp_escape "$commit:${branch#refs/heads/}" lp_vcs_branch="$ret" else # In detached head state, use commit instead # No escape needed - lp_vcs_branch="$(\git rev-parse --short -q HEAD 2>/dev/null)" + lp_vcs_branch="$commit" fi + _lp_legacy && echo $lp_vcs_branch || return 0 } _lp_time() { From d7b6cff2c1d4beedef7340f6e295d786a6635d20 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Tue, 29 Nov 2022 11:54:24 +0000 Subject: [PATCH 181/239] Removed trailing whitespace on line 51 --- themes/liquidprompt/liquidprompt.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 9631cab716..17458fd5f1 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -48,7 +48,7 @@ _lp_git_branch() local commit branch ret commit="$(\git rev-parse --short -q HEAD 2>/dev/null)" - + # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then From 602acc711a4deef20455b8358132ebc447f3d333 Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Fri, 2 Dec 2022 21:28:14 +0200 Subject: [PATCH 182/239] aliases: git: Modernize get default branch function --- aliases/available/git.aliases.bash | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 535665b14d..9b71859948 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -200,9 +200,5 @@ function gdv() { } function get_default_branch() { - if git branch | grep -q '^. main\s*$'; then - echo main - else - echo master - fi + git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' } From 54cdf3a60aa0540cf7809f6d8a953cf428d521b2 Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Fri, 2 Dec 2022 21:24:34 +0200 Subject: [PATCH 183/239] aliases: git: Modernize 'gpf' and make it use --force-with-lease --- aliases/available/git.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 9b71859948..aa106b572b 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -103,7 +103,8 @@ alias gpatch='git format-patch -1' # push alias gp='git push' alias gpd='git push --delete' -alias gpf='git push --force' +alias gpf='git push --force-with-lease' +alias gpff='git push --force' alias gpo='git push origin HEAD' alias gpom='git push origin $(get_default_branch)' alias gpu='git push --set-upstream' From d9c339cf2956e24e5b3e67696c812dcdcd8ac07f Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Sun, 4 Dec 2022 17:35:44 +0200 Subject: [PATCH 184/239] aliases: git: Don't use sed for extracting branch name --- aliases/available/git.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index aa106b572b..11ea2518d1 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -201,5 +201,6 @@ function gdv() { } function get_default_branch() { - git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' + branch=$(git symbolic-ref refs/remotes/origin/HEAD) + ${branch#refs/remotes/origin/} } From f0941e9ba213e87a26172e31ceb4c3b629d8e580 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Fri, 26 Aug 2022 10:07:21 +0200 Subject: [PATCH 185/239] Add more aliases for `git branch`, use long form Git can list local branches, remote branches, and both of them together. Let's use the long form of the options to make the aliases quicker to understand. As agreed in PR #2159, we introduce gbl and replace gba/gbr by gbla/gblr. gbl/gbla/gblr allow wildcard arguments for filtering branch names. --- aliases/available/git.aliases.bash | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 535665b14d..5572c9322c 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -12,10 +12,14 @@ alias gav='git add -v' # branch alias gb='git branch' -alias gbD='git branch -D' -alias gba='git branch -a' +alias gba='git branch --all' alias gbd='git branch -d' -alias gbm='git branch -m' +alias gbD='git branch -D' +alias gbl='git branch --list' +alias gbla='git branch --list --all' +alias gblr='git branch --list --remotes' +alias gbm='git branch --move' +alias gbr='git branch --remotes' alias gbt='git branch --track' alias gdel='git branch -D' From 66ae9b0de8ca313fb208be75296af2c90b024740 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 6 Dec 2022 00:22:27 +0200 Subject: [PATCH 186/239] Remove libra chat reference We will try to use Github Discussions now. --- docs/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index f3d31a14fe..b307a7abfd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,6 @@ ![Docs Status](https://readthedocs.org/projects/bash-it/badge/) ![License](https://img.shields.io/github/license/Bash-it/bash-it) ![shell](https://img.shields.io/badge/Shell-Bash-blue) -[![Join the chat at https://web.libera.chat/?channel=#bash-it](https://img.shields.io/badge/chat-on%20Libera.Chat-brightgreen.svg)](https://web.libera.chat/?channel=#bash-it) **Bash-it** is a collection of community Bash commands and scripts for Bash 3.2+. (And a shameless ripoff of [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) :smiley:) From feb468b517e1393a46eec020a07ab81d739b2a2b Mon Sep 17 00:00:00 2001 From: BF <38326544+convergedtarkus@users.noreply.github.com> Date: Wed, 25 Jan 2023 17:56:14 -0600 Subject: [PATCH 187/239] bug: Use C style strings when checking for invalid alias characters (#2188) * Use C style strings when checking for invalid alias characters Before, the '\n' would be interpreted as 'n' meaning that any alias who's command contained the letter 'n' would incorrect be skipped. * No need to escape characters in this context Escaping was just adding \ to the list multiple times Co-authored-by: David Farrell --- completion/available/aliases.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completion/available/aliases.completion.bash b/completion/available/aliases.completion.bash index f9cc1ed181..3e45e960cf 100644 --- a/completion/available/aliases.completion.bash +++ b/completion/available/aliases.completion.bash @@ -50,7 +50,7 @@ function _bash-it-component-completion-callback-on-init-aliases() { fi # skip aliases to pipes, boolean control structures and other command lists - chars='\|\&\;\)\(\n\<\>' + chars=$'|&;()<>\n' if [[ "${alias_defn}" =~ [$chars] ]]; then continue fi From 0137211d87c7d254726cd4354d694445fae7a87b Mon Sep 17 00:00:00 2001 From: Bruce <971697+tomaytotomato@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:58:53 +0000 Subject: [PATCH 188/239] Add more Maven aliases Aliases for testing only, skipping tests on Package and Compile lifecycles. Also added aliases to start stop Spring Boot, Quarkus, Micronaut and Jetty server --- aliases/available/maven.aliases.bash | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aliases/available/maven.aliases.bash b/aliases/available/maven.aliases.bash index 737826eb47..96cc620232 100644 --- a/aliases/available/maven.aliases.bash +++ b/aliases/available/maven.aliases.bash @@ -3,8 +3,13 @@ about-alias 'maven abbreviations' alias mci='mvn clean install' alias mi='mvn install' +alias mc='mvn clean' +alias mcc='mvn clean compile' alias mcp='mvn clean package' +alias mcpnt='mvn clean package -DskipTests=true' alias mp='mvn package' +alias mpnt='mvn package =DskipTests=true' +alias mct='mvn clean test' alias mrprep='mvn release:prepare' alias mrperf='mvn release:perform' alias mrrb='mvn release:rollback' @@ -12,3 +17,10 @@ alias mdep='mvn dependency:tree' alias mpom='mvn help:effective-pom' alias mcisk='mci -Dmaven.test.skip=true' alias mcpsk='mcp -Dmaven.test.skip=true' + +# Maven service plugin aliases +alias springrun='mvn spring-boot:run' +alias springstop='mvn spring-boot:stop' +alias jettyrun='mvn jetty:run' +alias quarkrun='mvn quarkus:dev' +alias microrun='mvn mn:run' From b0c38bb42e412ce341ad976ebe12ec71d993329a Mon Sep 17 00:00:00 2001 From: Bruce <971697+tomaytotomato@users.noreply.github.com> Date: Sat, 4 Feb 2023 20:42:19 +0000 Subject: [PATCH 189/239] Typo fix and rename maven service plugin aliases to be more friendly --- aliases/available/maven.aliases.bash | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/aliases/available/maven.aliases.bash b/aliases/available/maven.aliases.bash index 96cc620232..21bc99059d 100644 --- a/aliases/available/maven.aliases.bash +++ b/aliases/available/maven.aliases.bash @@ -8,7 +8,7 @@ alias mcc='mvn clean compile' alias mcp='mvn clean package' alias mcpnt='mvn clean package -DskipTests=true' alias mp='mvn package' -alias mpnt='mvn package =DskipTests=true' +alias mpnt='mvn package -DskipTests=true' alias mct='mvn clean test' alias mrprep='mvn release:prepare' alias mrperf='mvn release:perform' @@ -19,8 +19,7 @@ alias mcisk='mci -Dmaven.test.skip=true' alias mcpsk='mcp -Dmaven.test.skip=true' # Maven service plugin aliases -alias springrun='mvn spring-boot:run' -alias springstop='mvn spring-boot:stop' -alias jettyrun='mvn jetty:run' -alias quarkrun='mvn quarkus:dev' -alias microrun='mvn mn:run' +alias mspring='mvn spring-boot:run' +alias mjetty='mvn jetty:run' +alias mquark='mvn quarkus:dev' +alias mmicro='mvn mn:run' From 76e2c779150c1c08aa8af94acc0dfac6fb74f14c Mon Sep 17 00:00:00 2001 From: Bruce <971697+tomaytotomato@users.noreply.github.com> Date: Sat, 4 Feb 2023 20:45:22 +0000 Subject: [PATCH 190/239] Reordered aliases to be more friendly --- aliases/available/maven.aliases.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aliases/available/maven.aliases.bash b/aliases/available/maven.aliases.bash index 21bc99059d..2746da2c95 100644 --- a/aliases/available/maven.aliases.bash +++ b/aliases/available/maven.aliases.bash @@ -4,12 +4,12 @@ about-alias 'maven abbreviations' alias mci='mvn clean install' alias mi='mvn install' alias mc='mvn clean' +alias mct='mvn clean test' alias mcc='mvn clean compile' +alias mccnt='mvn clean compile -DskipTests=true' +alias mp='mvn package' alias mcp='mvn clean package' alias mcpnt='mvn clean package -DskipTests=true' -alias mp='mvn package' -alias mpnt='mvn package -DskipTests=true' -alias mct='mvn clean test' alias mrprep='mvn release:prepare' alias mrperf='mvn release:perform' alias mrrb='mvn release:rollback' From 78f88406cf9d6756b50ed2d3711334d4020fd913 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Wed, 22 Feb 2023 21:49:12 +0530 Subject: [PATCH 191/239] Fix lint errors in multiple files (#2192) * fix (plugins): enable interpretation of backslash escapes in colors * fix (lint): disable SC2317 in install.sh * fix (lint): SC2086 in agnoster theme * fix (lint): remove exit from install.sh as it is already implemented in the calling function --- install.sh | 1 - plugins/available/colors.plugin.bash | 4 ++-- themes/agnoster/agnoster.theme.bash | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 2bb78a3f64..58c25537b6 100755 --- a/install.sh +++ b/install.sh @@ -12,7 +12,6 @@ function _bash-it_show_usage() { echo "--no-modify-config (-n): Do not modify existing config file" echo "--append-to-config (-a): Keep existing config file and append bash-it templates at the end" echo "--overwrite-backup (-f): Overwrite existing backup" - exit 0 } # enable a thing diff --git a/plugins/available/colors.plugin.bash b/plugins/available/colors.plugin.bash index 47f55609af..73c144b88e 100644 --- a/plugins/available/colors.plugin.bash +++ b/plugins/available/colors.plugin.bash @@ -8,13 +8,13 @@ function __() { function __make_ansi() { next=$1 shift - echo "\[\e[$("__$next" "$@")m\]" + echo -e "\[\e[$("__$next" "$@")m\]" } function __make_echo() { next=$1 shift - echo "\033[$("__$next" "$@")m" + echo -e "\033[$("__$next" "$@")m" } function __reset() { diff --git a/themes/agnoster/agnoster.theme.bash b/themes/agnoster/agnoster.theme.bash index 20c184f382..d5bac5ca69 100644 --- a/themes/agnoster/agnoster.theme.bash +++ b/themes/agnoster/agnoster.theme.bash @@ -182,7 +182,7 @@ prompt_segment() { # declare -p codes if [[ $CURRENT_BG != NONE && $1 != "$CURRENT_BG" ]]; then - declare -a intermediate=("$(fg_color $CURRENT_BG)" "$(bg_color "$1")") + declare -a intermediate=("$(fg_color "$CURRENT_BG")" "$(bg_color "$1")") debug "pre prompt " "$(ansi intermediate[@])" PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR" debug "post prompt " "$(ansi codes[@])" From 05ef68acbcfbba15ad261e2632b670671c87f644 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Wed, 22 Feb 2023 21:50:45 +0530 Subject: [PATCH 192/239] Implement yarn completion (#2190) * feat (completion): add yarn completion --- clean_files.txt | 1 + completion/available/yarn.completion.bash | 5 + .../github.com/dsifford/yarn-completion/yarn | 1208 +++++++++++++++++ 3 files changed, 1214 insertions(+) create mode 100644 completion/available/yarn.completion.bash create mode 100644 vendor/github.com/dsifford/yarn-completion/yarn diff --git a/clean_files.txt b/clean_files.txt index 192fefa64f..758e3b80a7 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -76,6 +76,7 @@ completion/available/system.completion.bash completion/available/vault.completion.bash completion/available/vuejs.completion.bash completion/available/wpscan.completion.bash +completion/available/yarn.completion.bash # libraries lib/appearance.bash diff --git a/completion/available/yarn.completion.bash b/completion/available/yarn.completion.bash new file mode 100644 index 0000000000..de1240851b --- /dev/null +++ b/completion/available/yarn.completion.bash @@ -0,0 +1,5 @@ +# shellcheck shell=bash +about-completion "yarn cli completions" + +# shellcheck disable=SC1090 source=../../vendor/github.com/dsifford/yarn-completion/yarn +source "${BASH_IT}/vendor/github.com/dsifford/yarn-completion/yarn" diff --git a/vendor/github.com/dsifford/yarn-completion/yarn b/vendor/github.com/dsifford/yarn-completion/yarn new file mode 100644 index 0000000000..ff78e47137 --- /dev/null +++ b/vendor/github.com/dsifford/yarn-completion/yarn @@ -0,0 +1,1208 @@ +# shellcheck shell=bash disable=2207 +# vim: set fdm=syntax fdl=0: +# +# Version: 0.17.0 +# Yarn Version: 1.22.11 +# +# bash completion for Yarn (https://github.com/yarnpkg/yarn) +# +# To enable on-demand completion loading, copy this file to one of the following locations: +# - $BASH_COMPLETION_USER_DIR/completions/yarn +# or +# - $XDG_DATA_HOME/bash-completion/completions/yarn +# or +# - ~/.local/share/bash-completion/completions/yarn +# + +### +# Parses and extracts data from package.json files. +# +# Usage: +# __yarn_get_package_fields [-g] [-t FIELDTYPE] +# +# Options: +# -g Parse global package.json file, if available +# -t FIELDTYPE The field type being parsed (array|boolean|number|object|string) [default: object] +# +# Notes: +# If FIELDTYPE is object, then the object keys are returned. +# If FIELDTYPE is array, boolean, number, or string, then the field values are returned. +# must be a first-level field in the json file. +## +__yarn_get_package_fields() { + declare cwd=$PWD field_type=object field_key opt package_dot_json OPTIND OPTARG + + while [[ -n $cwd ]]; do + if [[ -f "$cwd/package.json" ]]; then + package_dot_json="$cwd/package.json" + break + fi + cwd="${cwd%/*}" + done + + while getopts ":gt:" opt; do + case $opt in + g) + if [[ -f $HOME/.config/yarn/global/package.json ]]; then + package_dot_json="$HOME/.config/yarn/global/package.json" + elif [[ -f $HOME/.local/share/yarn/global/package.json ]]; then + package_dot_json="$HOME/.local/share/yarn/global/package.json" + elif [[ -f $HOME/.yarn/global/package.json ]]; then + package_dot_json="$HOME/.yarn/global/package.json" + else + package_dot_json="" + fi + ;; + t) + case "$OPTARG" in + array | boolean | number | object | string) + field_type="$OPTARG" + ;; + esac + ;; + *) ;; + + esac + done + shift $((OPTIND - 1)) + + field_key='"'$1'"' + + [[ ! -f $package_dot_json || ! $field_key ]] && return + + case "$field_type" in + object) + sed -n '/'"$field_key"':[[:space:]]*{/,/^[[:space:]]*}/{ + # exclude start and end patterns + //!{ + # extract the text between the first pair of double quotes + s/^[[:space:]]*"\([^"]*\).*/\1/p + } + }' "$package_dot_json" + ;; + array) + sed -n '/'"$field_key"':[[:space:]]*\[/,/^[[:space:]]*]/{ + # exclude start and end patterns + //!{ + # extract the text between the first pair of double quotes + s/^[[:space:]]*"\([^"]*\).*/\1/p + } + }' "$package_dot_json" + ;; + boolean | number) + sed -n 's/[[:space:]]*'"$field_key"':[[:space:]]*\([a-z0-9]*\)/\1/p' "$package_dot_json" + ;; + string) + sed -n 's/[[:space:]]*'"$field_key"':[[:space:]]*"\(.*\)".*/\1/p' "$package_dot_json" + ;; + esac +} + +### +# Count all command arguments starting at a given depth, excluding flags and +# flag arguments. +# +# Usage: +# __yarn_count_args [-d INT] +# +# Options: +# -d INT The start depth to begin counting [default: 0] +# +# Globals: +# *args +# cword +## +__yarn_count_args() { + args=0 + declare -i counter=0 depth=0 + declare arg_flag_pattern opt OPTIND + arg_flag_pattern="@($(tr ' ' '|' <<< "${arg_flags[*]}"))" + + while getopts ":d:" opt; do + case $opt in + d) + depth=$OPTARG + ;; + *) ;; + esac + done + shift $((OPTIND - 1)) + + while ((counter < cword)); do + case ${words[counter]} in + -* | =) ;; + *) + # shellcheck disable=SC2053 + if [[ ${words[counter - 1]} != $arg_flag_pattern ]]; then + if ((depth-- <= 0)); then + ((args++)) + fi + fi + ;; + esac + ((counter++)) + done +} + +### +# Retrieves the command or subcommand at a given depth, or the last occurring +# command or subcommand before the cursor location if no depth is given, or if +# depth exceeds cursor location. +# +# Usage: +# __yarn_get_command [-d INT] +# +# Options: +# -d INT Depth of command to retrieve. +# +# Globals: +# *cmd +# commands +# cword +# subcommands +# words +## +__yarn_get_command() { + declare -i counter=0 cmd_depth=0 OPTIND + declare cmdlist word opt + + while getopts ":d:" opt; do + case $opt in + d) + cmd_depth="$OPTARG" + ;; + *) ;; + esac + done + shift $((OPTIND - 1)) + + cmdlist="@($(tr ' ' '|' <<< "${commands[*]} ${subcommands[*]}"))" + cmd=yarn + + while ((counter < cword)); do + word="${words[counter]}" + case "$word" in + $cmdlist) + cmd="$word" + ((--cmd_depth == 0)) && break + ;; + esac + ((counter++)) + done +} + +### +# Global fallback completion generator if all else fails. +# +# Usage: +# __yarn_fallback +# +# Globals: +# cur +## +__yarn_fallback() { + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$(__yarn_flags)" -- "$cur")) + ;; + *) + COMPREPLY=($(compgen -o plusdirs -f -- "$cur")) + ;; + esac +} + +### +# Process and merge local and global flags after removing the flags that +# have already been used. +# +# Usage: +# __yarn_flags +# +# Globals: +# flags +# global_flags +# words +## +__yarn_flags() { + declare word + declare -a existing_flags=() + + for word in "${words[@]}"; do + case "$word" in + -*) + existing_flags+=("$word") + ;; + esac + done + + LC_ALL=C comm -23 \ + <(echo "${flags[@]}" "${global_flags[@]}" | tr ' ' '\n' | LC_ALL=C sort -u) \ + <(echo "${existing_flags[@]}" | tr ' ' '\n' | LC_ALL=C sort -u) +} + +### +# Handles completions for flags that require, or optionally take, arguments. +# +# Usage: +# __yarn_flag_args +# +# Globals: +# cur +# prev +## +__yarn_flag_args() { + declare {arg,bool,dir,file,int,special}_flag_pattern + arg_flag_pattern="@($(tr ' ' '|' <<< "${arg_flags[*]}"))" + + # shellcheck disable=SC2053 + if [[ $prev != $arg_flag_pattern ]]; then + return 1 + fi + + bool_flag_pattern="@($(tr ' ' '|' <<< "${bool_arg_flags[*]}"))" + dir_flag_pattern="@($(tr ' ' '|' <<< "${dir_arg_flags[*]}"))" + file_flag_pattern="@($(tr ' ' '|' <<< "${file_arg_flags[*]}"))" + int_flag_pattern="@($(tr ' ' '|' <<< "${int_arg_flags[*]}"))" + special_flag_pattern="@($(tr ' ' '|' <<< "${special_arg_flags[*]}"))" + + case "$prev" in + $bool_flag_pattern) + COMPREPLY=($(compgen -W 'true false' -- "$cur")) + ;; + $dir_flag_pattern) + compopt -o dirnames + ;; + $file_flag_pattern) + compopt -o default -o filenames + ;; + $int_flag_pattern) + compopt -o nospace + COMPREPLY=($(compgen -W '{0..9}' -- "$cur")) + ;; + $special_flag_pattern) + case "$prev" in + --access) + COMPREPLY=($(compgen -W 'public restricted' -- "$cur")) + ;; + --groups) + COMPREPLY=($(compgen -W 'dependencies devDependencies optionalDependencies' -- "$cur")) + ;; + --level) + COMPREPLY=($(compgen -W 'info low moderate high critical' -- "$cur")) + ;; + --network-timeout) + compopt -o nospace + COMPREPLY=($(compgen -W '{1000..10000..1000}' -- "$cur")) + ;; + esac + ;; + esac + return 0 +} + +_yarn_add() { + ((depth++)) + flags=( + --audit -A + --dev -D + --exact -E + --optional -O + --peer -P + --tilde -T + --ignore-workspace-root-check -W + ) + return 1 +} + +_yarn_audit() { + ((depth++)) + flags=( + --groups + --level + --summary + ) + return 1 +} + +_yarn_autoclean() { + ((depth++)) + flags=( + --force -F + --init -I + ) + return 1 +} + +_yarn_cache() { + ((depth++)) + declare cmd + flags=( + --pattern + ) + subcommands=( + clean + dir + list + ) + __yarn_get_command + + case "$cmd" in + cache) + case "$cur" in + -*) + return 1 + ;; + *) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + *) + return 1 + ;; + esac +} + +_yarn_check() { + ((depth++)) + flags=( + --integrity + --verify-tree + ) + return 1 +} + +_yarn_config() { + ((depth++)) + declare cmd + declare subcommands=( + delete + get + list + set + ) + declare known_keys=( + ignore-optional + ignore-platform + ignore-scripts + init-author-email + init-author-name + init-author-url + init-license + init-version + no-progress + prefix + registry + save-prefix + user-agent + version-git-message + version-git-sign + version-git-tag + version-tag-prefix + ) + __yarn_get_command + + case "$cmd" in + get | delete) + case "$cur" in + -*) ;; + *) + if [[ $prev == @(get|delete) ]]; then + COMPREPLY=($(compgen -W "${known_keys[*]}" -- "$cur")) + return 0 + fi + ;; + esac + ;; + set) + case "$cur" in + -*) + flags=( + --global + ) + ;; + *) + if [[ $prev == set ]]; then + COMPREPLY=($(compgen -W "${known_keys[*]}" -- "$cur")) + return 0 + fi + ;; + esac + ;; + config) + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + esac + return 1 +} + +_yarn_create() { + ((depth++)) + declare -i args + case "$cur" in + -*) ;; + *) + __yarn_count_args -d $depth + ((args == 0)) && return 0 + ;; + esac + return 1 +} + +_yarn_generate_lock_entry() { + ((depth++)) + flags=( + --resolved + --use-manifest + ) + return 1 +} + +_yarn_global() { + ((depth++)) + declare cmd cmdlist + flags=( + --latest + --prefix + ) + subcommands=( + add + bin + list + remove + upgrade + upgrade-interactive + ) + cmdlist="@($(tr ' ' '|' <<< "${subcommands[*]}"))" + + __yarn_get_command -d 3 + + case "$cur" in + -*) ;; + *) + case "$cmd" in + $cmdlist) + "_yarn_${cmd//-/_}" 2> /dev/null + return $? + ;; + global) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + esac + + return 1 +} + +_yarn_help() { + ((depth++)) + declare -i args + case "$cur" in + -*) ;; + *) + __yarn_count_args -d $depth + if ((args == 0)); then + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) + return 0 + fi + ;; + esac + return 1 +} + +_yarn_info() { + ((depth++)) + flags=( + --json + ) + declare standard_fields=( + author + bin + bugs + contributors + dependencies + description + devDependencies + dist-tags + engines + files + homepage + keywords + license + main + maintainers + name + optionalDependencies + peerDependencies + repository + version + versions + ) + + declare -i args + __yarn_count_args -d $depth + + case "$cur" in + -*) ;; + *) + case "$args" in + 0) + COMPREPLY=( + $(compgen -W " + $(__yarn_get_package_fields dependencies) + $(__yarn_get_package_fields devDependencies) + " -- "$cur") + ) + return 0 + ;; + 1) + COMPREPLY=($(compgen -W "${standard_fields[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + esac + return 1 +} + +_yarn_init() { + ((depth++)) + flags=( + --yes -y + --private -p + --install -i + ) + return 1 +} + +_yarn_install() { + ((depth++)) + flags=( + --audit -A + ) + return 1 +} + +_yarn_licenses() { + ((depth++)) + declare cmd + subcommands=( + list + generate-disclaimer + ) + case "$cur" in + -*) ;; + *) + __yarn_get_command + case "$cmd" in + licenses) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + esac + return 1 +} + +_yarn_list() { + ((depth++)) + flags=( + --depth + --pattern + ) + return 1 +} + +_yarn_node() { + ((depth++)) + flags=( + --into + ) + return 1 +} + +_yarn_outdated() { + ((depth++)) + case "$cur" in + -*) ;; + *) + COMPREPLY=( + $(compgen -W " + $(__yarn_get_package_fields dependencies) + $(__yarn_get_package_fields devDependencies) + " -- "$cur") + ) + return 0 + ;; + esac + return 1 +} + +_yarn_owner() { + ((depth++)) + declare cmd + subcommands=( + add + list + remove + ) + __yarn_get_command + if [[ $cmd == owner ]]; then + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + fi + return 1 +} + +_yarn_pack() { + ((depth++)) + flags=( + --filename -f + ) + return 1 +} + +_yarn_policies() { + ((depth++)) + declare standard_policies=( + latest + nightly + rc + ) + + declare -i args + __yarn_count_args -d $depth + + case "$cur" in + -*) ;; + *) + case "$args" in + 0) + COMPREPLY=($(compgen -W "${standard_policies[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + esac + return 1 +} + +_yarn_publish() { + ((depth++)) + flags=( + --access + --major + --message + --minor + --new-version + --no-commit-hooks + --no-git-tag-version + --patch + --preid + --premajor + --preminor + --prepatch + --prerelease + --tag + ) + return 1 +} + +_yarn_remove() { + ((depth++)) + declare cmd dependencies devDependencies + flags=( + --ignore-workspace-root-check -W + ) + __yarn_get_command -d 1 + case "$cmd" in + global) + dependencies=$(__yarn_get_package_fields -g dependencies) + devDependencies='' + ;; + remove) + dependencies=$(__yarn_get_package_fields dependencies) + devDependencies=$(__yarn_get_package_fields devDependencies) + ;; + *) + return 1 + ;; + esac + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "$dependencies $devDependencies" -- "$cur")) + return 0 + ;; + esac + return 1 +} + +_yarn_run() { + ((depth++)) + declare cmd + subcommands=( + env + $(__yarn_get_package_fields scripts) + ) + __yarn_get_command + if [[ $cmd == run ]]; then + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + fi + return 1 +} + +_yarn_tag() { + ((depth++)) + declare cmd + subcommands=( + add + list + remove + ) + __yarn_get_command + case "$cmd" in + tag) + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + esac + return 1 +} + +_yarn_team() { + ((depth++)) + declare cmd + subcommands=( + add + create + destroy + list + remove + ) + __yarn_get_command + case "$cmd" in + team) + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + esac + return 1 +} + +_yarn_unplug() { + ((depth++)) + flags=( + --clear + --clear-all + ) + case "$cur" in + -*) ;; + *) + COMPREPLY=( + $(compgen -W " + $(__yarn_get_package_fields dependencies) + $(__yarn_get_package_fields devDependencies) + " -- "$cur") + ) + return 0 + ;; + + esac + return 1 +} + +_yarn_upgrade() { + ((depth++)) + declare cmd dependencies devDependencies + flags=( + --audit -A + --caret -C + --exact -E + --latest -L + --pattern -P + --scope -S + --tilde -T + ) + __yarn_get_command -d 1 + case "$cmd" in + global) + dependencies=$(__yarn_get_package_fields -g dependencies) + devDependencies='' + ;; + upgrade) + dependencies=$(__yarn_get_package_fields dependencies) + devDependencies=$(__yarn_get_package_fields devDependencies) + ;; + *) + return 1 + ;; + esac + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "$dependencies $devDependencies" -- "$cur")) + return 0 + ;; + esac + return 1 +} + +_yarn_upgrade_interactive() { + ((depth++)) + flags=( + --caret -C + --exact -E + --latest + --scope -S + --tilde -T + ) + return 1 +} + +_yarn_version() { + ((depth++)) + flags=( + --major + --message + --minor + --new-version + --no-commit-hooks + --no-git-tag-version + --patch + --preid + --premajor + --preminor + --prepatch + --prerelease + ) + return 1 +} + +_yarn_workspace() { + ((depth++)) + declare -i args + declare workspaces_info + + case "$cur" in + -*) ;; + *) + __yarn_count_args + case "$args" in + [0-2]) + workspaces_info=$(yarn workspaces info -s 2> /dev/null) + if [[ -n $workspaces_info ]]; then + mapfile -t < <( + sed -n 's/^ \{2\}"\([^"]*\)": {$/\1/p' <<< "$workspaces_info" + ) + COMPREPLY=($(compgen -W "${MAPFILE[*]}" -- "$cur")) + fi + return 0 + ;; + 3) + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) + return 0 + ;; + *) + declare cmd + workspaces_info=$(yarn workspaces info -s 2> /dev/null) + + if [[ -n $workspaces_info ]]; then + PWD=$( + sed -n '/^ \{2\}"'"${COMP_WORDS[2]}"'": {$/,/^ \{2\}},\{0,1\}$/{ + s/^ \{4\}"location": "\([^"]*\)",$/\1/p + }' <<< "$workspaces_info" + ) + fi + + __yarn_get_command -d 3 + "_yarn_${cmd//-/_}" 2> /dev/null + return $? + ;; + esac + ;; + esac + return 1 +} + +_yarn_workspaces() { + ((depth++)) + declare cmd + subcommands=( + info + run + ) + __yarn_get_command -d 4 + case "$cmd" in + workspaces) + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "${subcommands[*]}" -- "$cur")) + return 0 + ;; + esac + ;; + info) + return 0 + ;; + run) + __yarn_run + return 0 + ;; + esac + return 1 +} + +_yarn_why() { + ((depth++)) + case "$cur" in + -*) ;; + ./*) + compopt -o filenames + ;; + *) + declare modules + modules=$(yarn list --depth 0 | sed -n 's/.* \([a-zA-Z0-9@].*\)@.*/\1/p') || return 1 + COMPREPLY=($(compgen -W "$modules" -- "$cur")) + return 0 + ;; + esac + return 1 +} + +_yarn_yarn() { + ((depth++)) + case "$cur" in + -*) ;; + *) + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) + return 0 + ;; + esac + return 1 +} + +_yarn() { + # shellcheck disable=SC2064 + trap " + PWD=$PWD + $(shopt -p extglob) + set +o pipefail + " RETURN + + shopt -s extglob + set -o pipefail + + declare cur cmd prev + declare -a words + declare -i cword counter=1 depth=1 + declare -ar commands=( + access + add + audit + autoclean + bin + cache + check + config + create + exec + generate-lock-entry + global + help + import + info + init + install + licenses + link + list + login + logout + node + outdated + owner + pack + policies + publish + remove + run + tag + team + unlink + unplug + upgrade + upgrade-interactive + version + versions + why + workspace + workspaces + $(__yarn_get_package_fields scripts) + ) + declare -a subcommands=() + + declare -ar bool_arg_flags=( + --emoji + --production --prod + --scripts-prepend-node-path + ) + declare -ar dir_arg_flags=( + --cache-folder + --cwd + --global-folder + --into + --link-folder + --modules-folder + --preferred-cache-folder + --prefix + ) + declare -ar file_arg_flags=( + --filename -f + --use-manifest + --use-yarnrc + ) + declare -ar int_arg_flags=( + --depth + --network-concurrency + ) + declare -ar special_arg_flags=( + --access + --groups + --level + --network-timeout + ) + declare -ar optional_arg_flags=( + --emoji + --prod + --production + --scripts-prepend-node-path + ) + declare -ar skipped_arg_flags=( + --https-proxy + --message + --mutex + --new-version + --otp + --pattern -P + --proxy + --registry + --resolved + --scope -S + --tag + ) + declare -ar arg_flags=( + "${bool_arg_flags[@]}" + "${dir_arg_flags[@]}" + "${file_arg_flags[@]}" + "${int_arg_flags[@]}" + "${special_arg_flags[@]}" + "${optional_arg_flags[@]}" + "${skipped_arg_flags[@]}" + ) + + declare -ar global_flags=( + --cache-folder + --check-files + --cwd + --disable-pnp + --emoji + --enable-pnp --pnp + --flat + --focus + --force + --frozen-lockfile + --global-folder + --har + --help -h + --https-proxy + --ignore-engines + --ignore-optional + --ignore-platform + --ignore-scripts + --json + --link-duplicates + --link-folder + --modules-folder + --mutex + --network-concurrency + --network-timeout + --no-bin-links + --no-default-rc + --no-lockfile + --non-interactive + --no-node-version-check + --no-progress + --offline + --otp + --prefer-offline + --preferred-cache-folder + --prod + --production + --proxy + --pure-lockfile + --registry + --scripts-prepend-node-path + --silent -s + --skip-integrity-check + --strict-semver + --update-checksums + --use-yarnrc + --verbose + --version -v + ) + declare -a flags=() + + COMPREPLY=() + if command -v _get_comp_words_by_ref > /dev/null; then + _get_comp_words_by_ref -n = -n @ -n : cur prev words cword + elif command -v _init_completion > /dev/null; then + _init_completion + fi + + __yarn_get_command -d 1 + + __yarn_flag_args || "_yarn_${cmd//-/_}" 2> /dev/null || __yarn_fallback + + if command -v __ltrim_colon_completions > /dev/null; then + __ltrim_colon_completions "$cur" + fi +} + +if [[ ${BASH_VERSINFO[0]} -ge 4 && ${BASH_VERSINFO[1]} -ge 4 ]]; then + complete -o nosort -F _yarn yarn +else + complete -F _yarn yarn +fi \ No newline at end of file From af11a50854b7af3f9a4b1c7f4f51dafe8b89f243 Mon Sep 17 00:00:00 2001 From: OMEGA_RAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Wed, 22 Feb 2023 11:24:30 -0500 Subject: [PATCH 193/239] Allow for longer command min duration (#2198) Allows for setting "COMMAND_DURATION_MIN_SECONDS" to more than 60 seconds without adding to prompt. Previously always showed with lengths over 60 seconds regardless of setting. --- lib/command_duration.bash | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index ec4d828d0c..2b5e1b4bda 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -59,16 +59,16 @@ function _command_duration() { command_duration=0 fi - if ((command_duration > 0)); then + if ((command_duration >= COMMAND_DURATION_MIN_SECONDS)); then minutes=$((command_duration / 60)) seconds=$((command_duration % 60)) - fi - _dynamic_clock_icon "${command_duration}" - if ((minutes > 0)); then - printf "%s %s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds" - elif ((seconds >= COMMAND_DURATION_MIN_SECONDS)); then - printf "%s %s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds" + _dynamic_clock_icon "${command_duration}" + if ((minutes > 0)); then + printf "%s %s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds" + else + printf "%s %s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds" + fi fi } From b62e6141a28839ef1842ef1740650066c9b64e9b Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:14:58 +0530 Subject: [PATCH 194/239] feature (plugins): add url manipulation plugin --- plugins/available/url.plugin.bash | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 plugins/available/url.plugin.bash diff --git a/plugins/available/url.plugin.bash b/plugins/available/url.plugin.bash new file mode 100644 index 0000000000..bb4248f8e9 --- /dev/null +++ b/plugins/available/url.plugin.bash @@ -0,0 +1,44 @@ +# shellcheck shell=bash +cite about-plugin +about-plugin 'Basic url handling and manipulation functions' + +function slugify() { + about 'takes the text and transform to slug url, also supports formats like (html,link,rst,md)' + group 'url' + param "1: Text to transform (optional)" + param "2: Output format (html,rst,link,md). Omit or pass any text to return only output" + + local TXT=$1 + local OUTPUT=$2 + local SLUG + + if [[ -z $TXT ]]; then + read -rp "Enter the valid string: " TXT + fi + + # Pass 1 - Clean the url + SLUG=$(echo -n "$TXT" | tr -cd ' [:alnum:]._-' | tr -s ' ') + + # Pass 2 - Transformation + SLUG=$(echo -n "$SLUG" | tr '[:upper:]' '[:lower:]' | tr ' ' '-') + + case "$OUTPUT" in + html | htm) + echo "$TXT" + ;; + href | link) + echo "#$SLUG" + ;; + md) + echo "[$TXT](#$SLUG)" + ;; + rst) + echo "\`$TXT <#$SLUG>\`_" + ;; + + *) + echo "$SLUG" + ;; + esac + +} From 324eba4b83964440f7db72b0fdef9c4ec33c010e Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:15:23 +0530 Subject: [PATCH 195/239] improve (lint): add plugins/available/url.plugin.bash --- clean_files.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..f8dae5aecf 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -134,6 +134,7 @@ plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash plugins/available/todo.plugin.bash +plugins/available/url.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash From 0805de548f1340fbb59a4fe66fe850f74328c176 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:18:05 +0530 Subject: [PATCH 196/239] improve (plugins): add credits in url.plugin --- plugins/available/url.plugin.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/available/url.plugin.bash b/plugins/available/url.plugin.bash index bb4248f8e9..72a41bfd3a 100644 --- a/plugins/available/url.plugin.bash +++ b/plugins/available/url.plugin.bash @@ -17,6 +17,7 @@ function slugify() { fi # Pass 1 - Clean the url + # Credits: https://stackoverflow.com/a/20007549/10362396 SLUG=$(echo -n "$TXT" | tr -cd ' [:alnum:]._-' | tr -s ' ') # Pass 2 - Transformation From e38696a0acfdb6e4fbeb6963801c417d6ca7e9a7 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Fri, 24 Feb 2023 00:08:04 +0530 Subject: [PATCH 197/239] fix (completion): suppress 1091 in brew (#2130) --- completion/available/brew.completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/completion/available/brew.completion.bash b/completion/available/brew.completion.bash index 61998f8a71..01e5d533a7 100644 --- a/completion/available/brew.completion.bash +++ b/completion/available/brew.completion.bash @@ -14,17 +14,17 @@ fi _bash_it_homebrew_check || return 0 if [[ -r "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" ]]; then - # shellcheck disable=1090 + # shellcheck disable=1090,1091 source "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" elif [[ -r "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" ]]; then - # shellcheck disable=1090 + # shellcheck disable=1090,1091 source "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" elif [[ -f "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew" ]]; then # For the git-clone based installation, see here for more info: # https://github.com/Bash-it/bash-it/issues/1458 # https://docs.brew.sh/Shell-Completion - # shellcheck disable=1090 + # shellcheck disable=1090,1091 source "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew" fi From cb44790e61dbdb62b0fabe50e65edd5447a4c62c Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 17 Apr 2023 16:48:59 +0300 Subject: [PATCH 198/239] Add a --help option --- plugins/available/gif.plugin.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index a04ff5c7d1..21dcc139a5 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -64,7 +64,7 @@ function v2gif() { fi # Parse the options - args=$("$getopt" -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@") || { + args=$("$getopt" -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l help -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@") || { echo 'Terminating...' >&2 return 2 } @@ -82,6 +82,7 @@ function v2gif() { local fps="" local make_webm="" local alert=5000 + local printhelp="" while [[ $# -ge 1 ]]; do case "$1" in --) @@ -94,6 +95,11 @@ function v2gif() { opt_del_after="true" shift ;; + --help) + # Print Help + printhelp="true" + shift + ;; -h | --high) #High Quality, use gifski gifski="$(type -p gifski)" @@ -141,7 +147,7 @@ function v2gif() { esac done - if [[ -z "$*" ]]; then + if [[ -z "$*" || "$printhelp" ]]; then echo "$(tput setaf 1)No input files given. Example: v2gif file [file...] [-w ] [-l ] $(tput sgr 0)" echo "-d/--del/--delete Delete original vid if done suceessfully (and file not over the size limit)" echo "-h/--high High Quality - use Gifski instead of gifsicle" From 33342129449b549a0087c5e795d6dc271dd2ead8 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 17 Apr 2023 20:05:48 +0300 Subject: [PATCH 199/239] Fix commandline options for the current versions of gifski and gifsicle --- plugins/available/gif.plugin.bash | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index 21dcc139a5..7cca37d4d2 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -72,9 +72,9 @@ function v2gif() { eval set -- "$args" local use_gifski="" local opt_del_after="" - local maxsize="" - local lossiness="" - local maxwidthski="" + local maxsize=() + local lossiness=() + local maxwidthski=() local giftagopt="" local giftag="" local defaultfps=10 @@ -112,8 +112,8 @@ function v2gif() { shift ;; -w | --width) - maxsize="-vf scale=$2:-1" - maxwidthski="-W $2" + maxsize=(-vf "scale=$2:-1") + maxwidthski=(-W "$2") giftag="${giftag}-w$2" shift 2 ;; @@ -124,7 +124,7 @@ function v2gif() { ;; -l | --lossy) # Use giflossy parameter - lossiness="--lossy=$2" + lossiness=("--lossy=$2") giftag="${giftag}-l$2" shift 2 ;; @@ -170,7 +170,7 @@ function v2gif() { local del_after=$opt_del_after if [[ -n "$make_webm" ]]; then - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 \ -quality best -loop 0 "${file%.*}.webm" || return 2 fi @@ -190,12 +190,12 @@ function v2gif() { if [[ "$use_gifski" = "true" ]]; then # I trust @pornel to do his own resizing optimization choices - $ffmpeg -loglevel panic -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ - && $gifski v2gif-tmp-*.png "$maxwidthski" --fps "$(printf "%.0f" "$fps")" -o "$output_file" || return 2 + $ffmpeg -loglevel warning -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + && $gifski "${maxwidthski[@]}" --fps "$(printf "%.0f" "$fps")" -o "$output_file" v2gif-tmp-*.png || return 2 else - $ffmpeg -loglevel panic -i "$file" "$maxsize" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + $ffmpeg -loglevel warning -i "$file" "${maxsize[@]}" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ && $convert +dither -layers Optimize v2gif-tmp-*.png GIF:- \ - | $gifsicle "$lossiness" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 + | $gifsicle "${lossiness[@]}" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 fi rm v2gif-tmp-*.png @@ -305,7 +305,7 @@ function any2webm() { echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)" - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v "$bandwidth" -auto-alt-ref 0 \ -quality best "$fps" "$size" -loop 0 -pix_fmt yuva420p "$output_file" || return 2 From c06350908b4899554c47b55389cd1abc38d4f4d2 Mon Sep 17 00:00:00 2001 From: Edwin Rolle Date: Wed, 10 May 2023 13:49:42 +0200 Subject: [PATCH 200/239] [terraform] add alias for terraform workspace --- aliases/available/terraform.aliases.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/aliases/available/terraform.aliases.bash b/aliases/available/terraform.aliases.bash index fedd319899..b236b5fd9f 100644 --- a/aliases/available/terraform.aliases.bash +++ b/aliases/available/terraform.aliases.bash @@ -7,3 +7,4 @@ alias tfv='terraform validate' alias tfp='terraform plan' alias tfa='terraform apply' alias tfd='terraform destroy' +alias tfw='terraform workspace' From 8eb90f7ac1ccdcdd77b28df3d09a3dca063b0135 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Tue, 30 Aug 2022 16:48:54 -0500 Subject: [PATCH 201/239] Fix loading of nvm for brew-installed nvm This reverts to the original (working) version from 2017. During the most recent refactor to use the `_bash_it_homebrew_check` helper method, it was overlooked that `${BASH_IT_HOMEBREW_PREFIX}/nvm.sh` is not the equivalent to `$(brew --prefix nvm)/nvm.sh` since `BASH_IT_HOMEBREW_PREFIX` is set from `brew --prefix` instead of `brew --prefix nvm`. --- plugins/available/nvm.plugin.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 0e6da5d8cf..3966cdf24a 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -10,9 +10,9 @@ about-plugin 'node version manager configuration' export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" # This loads nvm -if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]] +if _bash_it_homebrew_check && [[ -s "$(brew --prefix nvm)/nvm.sh" ]] then - source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" + source "$(brew --prefix nvm)/nvm.sh" else [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi From 6661159b865249b6e15b2e0dc21a057f728f0b08 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:34:26 -0500 Subject: [PATCH 202/239] attempt to be more efficient when checking for brew-managed NVM install --- plugins/available/nvm.plugin.bash | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 3966cdf24a..7e123fc03f 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -9,8 +9,16 @@ cite about-plugin about-plugin 'node version manager configuration' export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" + +# first check if NVM is managed by brew +NVM_BREW_PREFIX="" +if _bash_it_homebrew_check +then + NVM_BREW_PREFIX=$(brew --prefix nvm 2>/dev/null) +fi + # This loads nvm -if _bash_it_homebrew_check && [[ -s "$(brew --prefix nvm)/nvm.sh" ]] +if [[ -n "$NVM_BREW_PREFIX" && -s "${NVM_BREW_PREFIX}/nvm.sh" ]] then source "$(brew --prefix nvm)/nvm.sh" else From c5fdefece65ef716801201dfe936fd54e5296527 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:04:47 -0500 Subject: [PATCH 203/239] reuse variable instead of invoking brew again --- plugins/available/nvm.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 7e123fc03f..4dc4c6d630 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -20,7 +20,7 @@ fi # This loads nvm if [[ -n "$NVM_BREW_PREFIX" && -s "${NVM_BREW_PREFIX}/nvm.sh" ]] then - source "$(brew --prefix nvm)/nvm.sh" + source "${NVM_BREW_PREFIX}/nvm.sh" else [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi From df0e0af1fb54808cf5757b68d93e05eeb153ff00 Mon Sep 17 00:00:00 2001 From: Roberto Schiavone Date: Tue, 3 Oct 2023 01:27:14 +0200 Subject: [PATCH 204/239] fix: bumps go version to 1.21.0 and changes go get to go install --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e772ec5e8..eb92444edd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.17 + go-version: 1.21.0 - name: Set up Python uses: actions/setup-python@v2 with: @@ -52,7 +52,7 @@ jobs: # - name: Update APT Package Lists # run: sudo apt-get update - name: Install shfmt - run: GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt + run: go install mvdan.cc/sh/v3/cmd/shfmt@latest - name: Install shellcheck env: scversion: stable # Or latest, vxx, etc From 93b58eeda97b50a58d31bd61a5a5004c0d41d2f3 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Mon, 2 Oct 2023 17:35:12 -0700 Subject: [PATCH 205/239] docs: Update Bats libraries links (#2225) --- docs/contributing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/contributing.rst b/docs/contributing.rst index 79d8ed1c7b..2ba3ce7faf 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -79,9 +79,9 @@ The following libraries are used to help with the tests: * Test Framework: https://github.com/bats-core/bats-core -* Support library for Bats-Assert: https://github.com/ztombol/bats-support -* General ``assert`` functions: https://github.com/ztombol/bats-assert -* File ``assert`` functions: https://github.com/ztombol/bats-file +* Support library for Bats-Assert: https://github.com/bats-core/bats-support +* General ``assert`` functions: https://github.com/bats-core/bats-assert +* File ``assert`` functions: https://github.com/bats-core/bats-file When verifying test results, please try to use the ``assert`` functions found in these libraries. From 4339ee95b9aba2c25f3cb0447d10dbdbd60887e7 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Tue, 3 Oct 2023 10:12:58 -0700 Subject: [PATCH 206/239] ci: Update GitHub actions v2 => v4 (#2224) --- .github/workflows/ci.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb92444edd..75fb9d848e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install greadlink if: startsWith(runner.os, 'macOS') run: brew install coreutils @@ -26,9 +26,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.8 - name: Install docs dependencies @@ -40,17 +40,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: 1.21.0 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.8 - # - name: Update APT Package Lists - # run: sudo apt-get update - name: Install shfmt run: go install mvdan.cc/sh/v3/cmd/shfmt@latest - name: Install shellcheck From 5690939f058bc9328d6cbc18968d50751baca48f Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sat, 30 Sep 2023 18:41:13 +0200 Subject: [PATCH 207/239] Add git alias `gshn` (`git show --name-only`) Adds a short Git alias for `git show --name-only`, which list the files affected by the changes only (instead of the full diff). --- aliases/available/git.aliases.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..1c34f1d8bb 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -152,6 +152,8 @@ alias gsl='git shortlog -sn' # show alias gsh='git show' +alias gshn='git show --name-only' +alias gshns='git show --name-status' # svn alias gsd='git svn dcommit' From db3eb76645218c5e078ebc5b4ba5d8d31be02a01 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 1 Oct 2023 15:09:59 +0200 Subject: [PATCH 208/239] Add more aliases for `git merge` and `git rebase` --- aliases/available/git.aliases.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..3227cd2d5a 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -97,6 +97,9 @@ fi # merge alias gm='git merge' +alias gma='git merge --abort' +alias gmc='git merge --continue' +alias gms='git merge --squash' # mv alias gmv='git mv' @@ -132,7 +135,9 @@ alias grm='git rm' # rebase alias grb='git rebase' +alias grba='git rebase --abort' alias grbc='git rebase --continue' +alias grbi='git rebase --interactive' alias grm='git rebase $(get_default_branch)' alias grmi='git rebase $(get_default_branch) -i' alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosquash' From 0e006bb4d75c52e046f64bcb298fd0f998e2f88c Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 1 Oct 2023 09:36:04 +0200 Subject: [PATCH 209/239] Add alias for `git reset --hard` and `grh` like OMZ --- aliases/available/git.aliases.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..5280237f6c 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -139,7 +139,9 @@ alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosqu alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote # reset -alias gus='git reset HEAD' +alias gus='git reset HEAD' # read as: 'git unstage' +alias grh='git reset' # equivalent to: git reset HEAD +alias grh!='git reset --hard' alias gpristine='git reset --hard && git clean -dfx' # status From bf81dc3cc7f0bb12eb349cb829460872eb63089b Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 1 Oct 2023 09:12:38 +0200 Subject: [PATCH 210/239] Fix duplicate declaration of `grm`, update `grb<*>` --- aliases/available/git.aliases.bash | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..c6ba7b4206 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -21,7 +21,6 @@ alias gblr='git branch --list --remotes' alias gbm='git branch --move' alias gbr='git branch --remotes' alias gbt='git branch --track' -alias gdel='git branch -D' # for-each-ref alias gbc='git for-each-ref --format="%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)" refs/remotes/ --sort=authorname DESC' # FROM https://stackoverflow.com/a/58623139/10362396 @@ -133,9 +132,9 @@ alias grm='git rm' # rebase alias grb='git rebase' alias grbc='git rebase --continue' -alias grm='git rebase $(get_default_branch)' -alias grmi='git rebase $(get_default_branch) -i' -alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosquash' +alias grbm='git rebase $(get_default_branch)' +alias grbmi='git rebase $(get_default_branch) -i' +alias grbma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosquash' alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote # reset From 160efd2e4819240064a90ed04b6a206b2add2bb6 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Thu, 28 Sep 2023 17:42:38 +0200 Subject: [PATCH 211/239] Short aliases for `git commit --amend` (bang) With a bang (!) character we can make amending a commit intuitively dangerous. The idea is taken from Oh-My-Zsh, https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git --- aliases/available/git.aliases.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..b88d0b089c 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -32,6 +32,9 @@ alias gca='git commit -v -a' alias gcaa='git commit -a --amend -C HEAD' # Add uncommitted and unstaged changes to the last commit alias gcam='git commit -v -am' alias gcamd='git commit --amend' +alias gc!='git commit -v --amend' +alias gca!='git commit -v -a --amend' +alias gcn!='git commit -v --amend --no-edit' alias gcm='git commit -v -m' alias gci='git commit --interactive' alias gcsam='git commit -S -am' From 0f743f28dffff19b0f4194b49c30b5fa7899f5ca Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 1 Oct 2023 14:29:50 +0200 Subject: [PATCH 212/239] Add alias for `git pull --prune` --- aliases/available/git.aliases.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..6295c444c6 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -117,6 +117,7 @@ alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)' # pull alias gl='git pull' +alias glp='git pull --prune' alias glum='git pull upstream $(get_default_branch)' alias gpl='git pull' alias gpp='git pull && git push' From 6d4d1752fc99bcc1bf6023702282bb7f20850381 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 02:25:17 -0800 Subject: [PATCH 213/239] Clean `aliases.completion.bash` --- clean_files.txt | 1 + completion/available/aliases.completion.bash | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..77805b3eb7 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -31,6 +31,7 @@ lint_clean_files.sh # completions # +completion/available/aliases.completion.bash completion/available/apm.completion.bash completion/available/awless.completion.bash completion/available/awscli.completion.bash diff --git a/completion/available/aliases.completion.bash b/completion/available/aliases.completion.bash index 3e45e960cf..a4b15959a8 100644 --- a/completion/available/aliases.completion.bash +++ b/completion/available/aliases.completion.bash @@ -20,7 +20,7 @@ function _bash-it-component-completion-callback-on-init-aliases() { completions=("${completions[@]##complete -* * -}") # strip all but last option plus trigger(s) completions=("${completions[@]#complete -}") # strip anything missed completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s) - completions=("${completions[@]#? }") # strip anything missed + completions=("${completions[@]#? }") # strip anything missed #TODO: this will fail on some completions... # create temporary file for wrapper functions and completions @@ -40,10 +40,10 @@ function _bash-it-component-completion-callback-on-init-aliases() { line="${line#alias -- }" line="${line#alias }" alias_name="${line%%=*}" - alias_defn="${line#*=\'}" # alias definition + alias_defn="${line#*=\'}" # alias definition alias_defn="${alias_defn%\'}" alias_cmd="${alias_defn%%[[:space:]]*}" # first word of alias - if [[ ${alias_defn} == ${alias_cmd} ]]; then + if [[ ${alias_defn} == "${alias_cmd}" ]]; then alias_args='' else alias_args="${alias_defn#*[[:space:]]}" # everything after first word @@ -89,7 +89,7 @@ function _bash-it-component-completion-callback-on-init-aliases() { prec_word=\${prec_word#* } fi (( COMP_CWORD += ${#alias_arg_words[@]} )) - COMP_WORDS=(\"$alias_cmd\" \"${alias_arg_words[@]}\" \"\${COMP_WORDS[@]:1}\") + COMP_WORDS=(\"$alias_cmd\" \"${alias_arg_words[*]}\" \"\${COMP_WORDS[@]:1}\") (( COMP_POINT -= \${#COMP_LINE} )) COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args} (( COMP_POINT += \${#COMP_LINE} )) From 656a0235a2b5cc833750413bcf1de7b6ce240082 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 03:36:58 -0800 Subject: [PATCH 214/239] Clean `clean.theme.bash` --- clean_files.txt | 1 + themes/clean/clean.theme.bash | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..a39c074021 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -159,6 +159,7 @@ themes/bobby-python themes/brainy themes/brunton themes/candy +themes/clean themes/easy themes/essential themes/githelpers.theme.bash diff --git a/themes/clean/clean.theme.bash b/themes/clean/clean.theme.bash index 0082d671a0..47a436b34d 100644 --- a/themes/clean/clean.theme.bash +++ b/themes/clean/clean.theme.bash @@ -1,19 +1,24 @@ +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. + # git theming -SCM_THEME_PROMPT_PREFIX="${bold_blue}(${yellow}" -SCM_THEME_PROMPT_SUFFIX="${bold_blue})${reset_color} " +SCM_THEME_PROMPT_PREFIX="${bold_blue?}(${yellow?}" +SCM_THEME_PROMPT_SUFFIX="${bold_blue?})${reset_color?} " SCM_THEME_PROMPT_CLEAN="" -SCM_THEME_PROMPT_DIRTY="${bold_red}βœ—" - +SCM_THEME_PROMPT_DIRTY="${bold_red?}βœ—" # LS colors, made with http://geoff.greer.fm/lscolors/ export LSCOLORS="Gxfxcxdxbxegedabagacad" export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' function prompt_command() { + if [ "$(whoami)" = root ]; then + no_color=${red?} + else + no_color=${white?} + fi - if [ "$(whoami)" = root ]; then no_color=$red; else no_color=$white; fi - - PS1="${no_color}\u${reset_color}:${blue}\W/${reset_color} $(scm_prompt_info)${normal}$ " + PS1="${no_color}\u${reset_color}:${blue?}\W/${reset_color} $(scm_prompt_info)${normal?}$ " } safe_append_prompt_command prompt_command From 937e50c77930f75d4baa80b2149da22c2c15909c Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 03:42:27 -0800 Subject: [PATCH 215/239] Clean `elixr.theme.bash` --- clean_files.txt | 1 + themes/elixr/elixr.theme.bash | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..0aef425425 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -160,6 +160,7 @@ themes/brainy themes/brunton themes/candy themes/easy +themes/elixr themes/essential themes/githelpers.theme.bash themes/modern diff --git a/themes/elixr/elixr.theme.bash b/themes/elixr/elixr.theme.bash index 266abbad43..d266fae89d 100644 --- a/themes/elixr/elixr.theme.bash +++ b/themes/elixr/elixr.theme.bash @@ -1,15 +1,16 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. -SCM_THEME_PROMPT_DIRTY=" ${red}βœ—" -SCM_THEME_PROMPT_CLEAN=" ${bold_green}βœ“" -SCM_THEME_PROMPT_PREFIX=" ${green}| " -SCM_THEME_PROMPT_SUFFIX="${green} |" +SCM_THEME_PROMPT_DIRTY=" ${red?}βœ—" +SCM_THEME_PROMPT_CLEAN=" ${bold_green?}βœ“" +SCM_THEME_PROMPT_PREFIX=" ${green?}| " +SCM_THEME_PROMPT_SUFFIX="${green?} |" SCM_NONE_CHAR='◐ ' SCM_GIT_SHOW_MINIMAL_INFO=true -GIT_THEME_PROMPT_DIRTY=" ${red}βœ—" -GIT_THEME_PROMPT_CLEAN=" ${bold_green}βœ“" -GIT_THEME_PROMPT_PREFIX=" ${green}|" -GIT_THEME_PROMPT_SUFFIX="${green}|" +GIT_THEME_PROMPT_DIRTY=" ${red?}βœ—" +GIT_THEME_PROMPT_CLEAN=" ${bold_green?}βœ“" +GIT_THEME_PROMPT_PREFIX=" ${green?}|" +GIT_THEME_PROMPT_SUFFIX="${green?}|" RVM_THEME_PROMPT_PREFIX="|" RVM_THEME_PROMPT_SUFFIX=" d|" @@ -17,7 +18,7 @@ RVM_THEME_PROMPT_SUFFIX=" d|" BOLD="\[\e[1m\]" function prompt_command() { - PS1="\n${bold_cyan}$(scm_prompt_char_info)$(virtualenv_prompt) ${bold_cyan}\w :${reset_color}${normal}${BOLD} " + PS1="\n${bold_cyan?}$(scm_prompt_char_info)$(virtualenv_prompt) ${bold_cyan}\w :${reset_color?}${normal?}${BOLD} " } safe_append_prompt_command prompt_command From edec6480fd9ff859cdee25c5b25b223ceae929f3 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 03:46:51 -0800 Subject: [PATCH 216/239] Tweaks to clean files scripts and file list --- clean_files.txt | 13 +------------ lint_clean_files.sh | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..b8eeb17b77 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -19,6 +19,7 @@ aliases/ docs/ hooks/ +lib/ scripts/ # root files @@ -78,18 +79,6 @@ completion/available/vuejs.completion.bash completion/available/wpscan.completion.bash completion/available/yarn.completion.bash -# libraries -lib/appearance.bash -lib/colors.bash -lib/command_duration.bash -lib/helpers.bash -lib/history.bash -lib/log.bash -lib/preexec.bash -lib/preview.bash -lib/search.bash -lib/utilities.bash - # plugins # plugins/available/alias-completion.plugin.bash diff --git a/lint_clean_files.sh b/lint_clean_files.sh index cc2686042f..b341f4f46f 100755 --- a/lint_clean_files.sh +++ b/lint_clean_files.sh @@ -10,7 +10,7 @@ mapfile -t FILES < <( cat clean_files.txt \ | grep -E -v '^\s*$' \ | grep -E -v '^\s*#' \ - | xargs -n1 -I{} find "{}" -type f + | xargs -I{} find "{}" -type f ) # We clear the BASH_IT variable to help the shellcheck checker From d985e4c96b1eb4e7374b3ab53eea3513fc9f50ce Mon Sep 17 00:00:00 2001 From: Kal McFate Date: Sat, 18 Nov 2023 14:42:33 -0700 Subject: [PATCH 217/239] Add support to powerline themes to override foreground color (#2231) --- themes/powerline-multiline/powerline-multiline.base.bash | 2 +- themes/powerline-multiline/powerline-multiline.theme.bash | 2 ++ themes/powerline-naked/powerline-naked.theme.bash | 2 ++ themes/powerline-plain/powerline-plain.theme.bash | 2 ++ themes/powerline/powerline.base.bash | 2 +- themes/powerline/powerline.theme.bash | 2 ++ 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.base.bash b/themes/powerline-multiline/powerline-multiline.base.bash index f752bd7516..0269c58c39 100644 --- a/themes/powerline-multiline/powerline-multiline.base.bash +++ b/themes/powerline-multiline/powerline-multiline.base.bash @@ -35,7 +35,7 @@ function __powerline_right_segment { (( padding += 1 )) fi - RIGHT_PROMPT+="$(set_color - ${params[1]})${pad_before_segment}${params[0]}${normal}" + RIGHT_PROMPT+="$(set_color "${POWERLINE_PROMPT_FOREGROUND_COLOR}" ${params[1]})${pad_before_segment}${params[0]}${normal}" (( padding += ${#pad_before_segment} )) (( padding += ${#params[0]} )) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 48a1243e03..d6d57e9862 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -18,6 +18,8 @@ POWERLINE_COMPACT_BEFOR_FIRST_SEGMENT=${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:= POWERLINE_COMPACT_AFTER_LAST_SEGMENT=${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${POWERLINE_COMPACT}} POWERLINE_COMPACT_PROMPT=${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}} +POWERLINE_PROMPT_FOREGROUND_COLOR=${POWERLINE_PROMPT_FOREGROUND_COLOR:=-} + USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:="ξ‚’ "} USER_INFO_THEME_PROMPT_COLOR=${POWERLINE_USER_INFO_COLOR:=32} USER_INFO_THEME_PROMPT_COLOR_SUDO=${POWERLINE_USER_INFO_COLOR_SUDO:=202} diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 2fb4137ef0..cc00b3b956 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -13,6 +13,8 @@ POWERLINE_COMPACT_BEFOR_FIRST_SEGMENT=${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:= POWERLINE_COMPACT_AFTER_LAST_SEGMENT=${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${POWERLINE_COMPACT}} POWERLINE_COMPACT_PROMPT=${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}} +POWERLINE_PROMPT_FOREGROUND_COLOR=${POWERLINE_PROMPT_FOREGROUND_COLOR:=-} + USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:="ξ‚’ "} USER_INFO_THEME_PROMPT_COLOR=${POWERLINE_USER_INFO_COLOR:=240} USER_INFO_THEME_PROMPT_COLOR_SUDO=${POWERLINE_USER_INFO_COLOR_SUDO:=202} diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 6ff68e8fae..4b7aa857f7 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -14,6 +14,8 @@ POWERLINE_COMPACT_AFTER_LAST_SEGMENT=${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${P POWERLINE_COMPACT_PROMPT=${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}} POWERLINE_PROMPT_AFTER=${POWERLINE_PROMPT_AFTER:-""} +POWERLINE_PROMPT_FOREGROUND_COLOR=${POWERLINE_PROMPT_FOREGROUND_COLOR:=-} + PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:="β“” "} CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="β“” "} PYTHON_VENV_THEME_PROMPT_COLOR=${POWERLINE_PYTHON_VENV_COLOR:=35} diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 84469e877f..b7c9a80c08 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -247,7 +247,7 @@ function __powerline_left_segment() { fi fi - LEFT_PROMPT+="$(set_color - "${params[1]}")${pad_before_segment}${params[0]}${normal}" + LEFT_PROMPT+="$(set_color "${POWERLINE_PROMPT_FOREGROUND_COLOR}" "${params[1]}")${pad_before_segment}${params[0]}${normal}" LAST_SEGMENT_COLOR=${params[1]} ((SEGMENTS_AT_LEFT += 1)) } diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 49b397aa1d..cb5c4814f9 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -16,6 +16,8 @@ POWERLINE_COMPACT_BEFOR_FIRST_SEGMENT=${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:= POWERLINE_COMPACT_AFTER_LAST_SEGMENT=${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${POWERLINE_COMPACT}} POWERLINE_COMPACT_PROMPT=${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}} +POWERLINE_PROMPT_FOREGROUND_COLOR=${POWERLINE_PROMPT_FOREGROUND_COLOR:=-} + USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:="ξ‚’ "} USER_INFO_THEME_PROMPT_COLOR=${POWERLINE_USER_INFO_COLOR:=32} USER_INFO_THEME_PROMPT_COLOR_SUDO=${POWERLINE_USER_INFO_COLOR_SUDO:=202} From d6efc5b7d4d1c1ab6f33522e17eff928c953d7e8 Mon Sep 17 00:00:00 2001 From: Pablo Palazon Date: Thu, 23 Nov 2023 17:01:51 +0100 Subject: [PATCH 218/239] Add pre-jgitflow function --- clean_files.txt | 1 + plugins/available/jgitflow.plugin.bash | 55 ++++++++++++++++---------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..459572d532 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -115,6 +115,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/java.plugin.bash plugins/available/jekyll.plugin.bash +plugins/available/jgitflow.plugin.bash plugins/available/jump.plugin.bash plugins/available/latex.plugin.bash plugins/available/less-pretty-cat.plugin.bash diff --git a/plugins/available/jgitflow.plugin.bash b/plugins/available/jgitflow.plugin.bash index 83ee8a23f6..ff972f6221 100644 --- a/plugins/available/jgitflow.plugin.bash +++ b/plugins/available/jgitflow.plugin.bash @@ -1,47 +1,60 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Maven jgitflow build helpers' +function pre-jgitflow { + about 'helper function for execute before jgitflow' + group 'jgitflow' +} + +function test-pre-jgitflow { + about 'helper function for starting a new hotfix' + group 'jgitflow' + + echo "Init pre-maven" && pre-jgitflow && echo "Finish pre-maven" +} + function hotfix-start { - about 'helper function for starting a new hotfix' - group 'jgitflow' + about 'helper function for starting a new hotfix' + group 'jgitflow' - mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS} } function hotfix-finish { - about 'helper function for finishing a hotfix' - group 'jgitflow' + about 'helper function for finishing a hotfix' + group 'jgitflow' - mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags + pre-jgitflow && mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags && mvn clean } function feature-start { - about 'helper function for starting a new feature' - group 'jgitflow' + about 'helper function for starting a new feature' + group 'jgitflow' - mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS} } function feature-finish { - about 'helper function for finishing a feature' - group 'jgitflow' + about 'helper function for finishing a feature' + group 'jgitflow' - mvn jgitflow:feature-finish ${JGITFLOW_MVN_ARGUMENTS} - echo -e '\033[32m----------------------------------------------------------------\033[0m' - echo -e '\033[32m===== REMEMBER TO CREATE A NEW RELEASE TO DEPLOY THIS FEATURE ====\033[0m' - echo -e '\033[32m----------------------------------------------------------------\033[0m' + pre-jgitflow && mvn jgitflow:feature-finish ${JGITFLOW_MVN_ARGUMENTS} && mvn clean + echo -e '\033[32m----------------------------------------------------------------\033[0m' + echo -e '\033[32m===== REMEMBER TO CREATE A NEW RELEASE TO DEPLOY THIS FEATURE ====\033[0m' + echo -e '\033[32m----------------------------------------------------------------\033[0m' } function release-start { - about 'helper function for starting a new release' - group 'jgitflow' + about 'helper function for starting a new release' + group 'jgitflow' - mvn jgitflow:release-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:release-start ${JGITFLOW_MVN_ARGUMENTS} } function release-finish { - about 'helper function for finishing a release' - group 'jgitflow' + about 'helper function for finishing a release' + group 'jgitflow' - mvn jgitflow:release-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags + pre-jgitflow && mvn jgitflow:release-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags && mvn clean } From 87d3527789d78905cfc9b6d0acdcb3782e07d5da Mon Sep 17 00:00:00 2001 From: w453y Date: Sat, 2 Dec 2023 00:55:49 +0530 Subject: [PATCH 219/239] added new theme (lambda) --- clean_files.txt | 1 + themes/lambda/lambda.theme.bash | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 themes/lambda/lambda.theme.bash diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..c12df79231 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -170,6 +170,7 @@ themes/pete themes/powerline themes/pure themes/purity +themes/lambda # vendor init files # diff --git a/themes/lambda/lambda.theme.bash b/themes/lambda/lambda.theme.bash new file mode 100644 index 0000000000..b3d6910c01 --- /dev/null +++ b/themes/lambda/lambda.theme.bash @@ -0,0 +1,30 @@ +function set_prompt { + local user_color="\[\033[1;31m\]" # bold red for username + local at_color="\[\033[1;37m\]" # bold white for @ symbol + local host_color="\[\033[1;31m\]" # bold red for hostname + local in_color="\[\033[1;37m\]" # bold white for "in" + local dir_color="\[\033[1;35m\]" # bold purple for current working directory + local git_color="\[\033[1;36m\]" # bold cyan for Git information + local time_color="\[\033[1;32m\]" # bold green for time taken + local reset_color="\[\033[0m\]" # reset color + local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol + + local end_time=$(date +%s%3N) # current time in milliseconds + local time_taken=$(( (end_time - start_time) )) # time in milliseconds + + PS1="${user_color}╭─\\u" # username + PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname + PS1+="${in_color} in" # "in" between hostname and current directory + PS1+="${dir_color} \\w" # current working directory + + # Git information (status symbol) + PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" + + if [ $time_taken -gt 0 ]; then + PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds + fi + + PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after +} + +PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' \ No newline at end of file From 6d77ba022512fc1eac5041bfa30c27a0dcdc17c3 Mon Sep 17 00:00:00 2001 From: Abdul Wasey <86080041+w453y@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:16:11 +0000 Subject: [PATCH 220/239] Update clean_files.txt --- clean_files.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index c12df79231..ffa5dd08e5 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -162,6 +162,7 @@ themes/candy themes/easy themes/essential themes/githelpers.theme.bash +themes/lambda themes/modern themes/norbu themes/oh-my-posh @@ -170,7 +171,7 @@ themes/pete themes/powerline themes/pure themes/purity -themes/lambda + # vendor init files # From 178e24fd7102c1e948c3c88cee5664af50ae86db Mon Sep 17 00:00:00 2001 From: Abdul Wasey <86080041+w453y@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:20:48 +0000 Subject: [PATCH 221/239] Update lambda.theme.bash --- themes/lambda/lambda.theme.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/themes/lambda/lambda.theme.bash b/themes/lambda/lambda.theme.bash index b3d6910c01..8f3d5baf49 100644 --- a/themes/lambda/lambda.theme.bash +++ b/themes/lambda/lambda.theme.bash @@ -1,3 +1,6 @@ +#!/bin/bash +# shellcheck disable=SC1090,SC2034 + function set_prompt { local user_color="\[\033[1;31m\]" # bold red for username local at_color="\[\033[1;37m\]" # bold white for @ symbol @@ -27,4 +30,4 @@ function set_prompt { PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after } -PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' \ No newline at end of file +PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' From 3bd701d15c74563285b586412eb834343ea107ae Mon Sep 17 00:00:00 2001 From: BarbUk Date: Thu, 8 Feb 2024 13:26:48 +0100 Subject: [PATCH 222/239] Fix clock_hand to display correct hour hand --- lib/command_duration.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index 2b5e1b4bda..08ca256cb6 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -26,7 +26,7 @@ function _dynamic_clock_icon { local clock_hand # clock hand value is between 90 and 9b in hexadecimal. # so between 144 and 155 in base 10. - printf -v clock_hand '%x' $(((${1:-${SECONDS}} % 12) + 144)) + printf -v clock_hand '%x' $((((${1:-${SECONDS}} -1 ) % 12) + 144)) printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" } From c14e77eee03cc26d5b1dc9d14fa69cc736d6e5fc Mon Sep 17 00:00:00 2001 From: BarbUk Date: Thu, 8 Feb 2024 13:47:17 +0100 Subject: [PATCH 223/239] Lint --- lib/command_duration.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index 08ca256cb6..352ef0f01a 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -26,7 +26,7 @@ function _dynamic_clock_icon { local clock_hand # clock hand value is between 90 and 9b in hexadecimal. # so between 144 and 155 in base 10. - printf -v clock_hand '%x' $((((${1:-${SECONDS}} -1 ) % 12) + 144)) + printf -v clock_hand '%x' $((((${1:-${SECONDS}} - 1) % 12) + 144)) printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" } From dc4979ca20a81fee36d2c2c79103560633565d50 Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Tue, 19 Mar 2024 22:59:45 +0200 Subject: [PATCH 224/239] Added new Inretio theme. --- clean_files.txt | 1 + themes/inretio/inretio.theme.bash | 99 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 themes/inretio/inretio.theme.bash diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..0ba14ff020 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -170,6 +170,7 @@ themes/pete themes/powerline themes/pure themes/purity +themes/inretio # vendor init files # diff --git a/themes/inretio/inretio.theme.bash b/themes/inretio/inretio.theme.bash new file mode 100644 index 0000000000..ceac5a296b --- /dev/null +++ b/themes/inretio/inretio.theme.bash @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +# Inretio theme for Bash-it +# Contact: bashit@inretio.eu + +# Inspired by existing themes: +# - metal +# - bobby + +# virtualenv prompts +VIRTUALENV_CHAR=" β“”" +VIRTUALENV_THEME_PROMPT_PREFIX="" +VIRTUALENV_THEME_PROMPT_SUFFIX="" + +# SCM prompts +SCM_NONE_CHAR="" +SCM_GIT_CHAR="[Β±] " +SCM_GIT_BEHIND_CHAR="${red}↓${normal}" +SCM_GIT_AHEAD_CHAR="${bold_green}↑${normal}" +SCM_GIT_UNTRACKED_CHAR="βŒ€" +SCM_GIT_UNSTAGED_CHAR="${bold_yellow}β€’${normal}" +SCM_GIT_STAGED_CHAR="${bold_green}+${normal}" + +SCM_THEME_PROMPT_DIRTY="" +SCM_THEME_PROMPT_CLEAN="" +SCM_THEME_PROMPT_PREFIX="" +SCM_THEME_PROMPT_SUFFIX="" + +# Git status prompts +GIT_THEME_PROMPT_DIRTY=" ${red}βœ—${normal}" +GIT_THEME_PROMPT_CLEAN=" ${bold_green}βœ“${normal}" +GIT_THEME_PROMPT_PREFIX="" +GIT_THEME_PROMPT_SUFFIX="" + +# ICONS ======================================================================= + +icon_start="β”Œβ”€β”€" +icon_user=" 🐧 " +icon_host=" πŸ’» " +icon_directory=" πŸ“‚ " +icon_branch="🌡" +icon_end="β””> " + +# extra spaces ensure legiblity in prompt + +# FUNCTIONS =================================================================== + +# Display virtual environment info +function _virtualenv_prompt { + VIRTUALENV_DETAILS="" + VIRTUALENV_CHAR="" + + # $VIRTUAL_ENV is set and is non-zero length + if [[ -n "$VIRTUAL_ENV" ]]; then + # Check if Python 3 exists + if command -v python3 >/dev/null 2>&1; then + VIRTUALENV_DETAILS="$($VIRTUAL_ENV/bin/python --version | sed 's,Python ,,') on [$(basename $VIRTUAL_ENV)]" + VIRTUALENV_CHAR=" 🐍" + else + VIRTUALENV_DETAILS="[$(basename $VIRTUAL_ENV)]" + VIRTUALENV_CHAR=" β“”" + fi + fi + + echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" +} + +# Rename tab +function tabname { + printf "\e]1;$1\a" +} + +# Rename window +function winname { + printf "\e]2;$1\a" +} + +_theme_clock() { + printf '[%s]' "$(clock_prompt)" + + if [ "${THEME_SHOW_CLOCK_CHAR}" == "true" ]; then + printf '%s' "$(clock_char) " + fi +} +THEME_SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"false"} +THEME_CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$red"} +THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"} +THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%Y-%m-%d %H:%M:%S"} + +# PROMPT OUTPUT =============================================================== + +# Displays the current prompt +function prompt_command() { + PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${green}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white}${normal}\n${icon_end}" + PS2="${icon_end}" +} + +# Runs prompt (this bypasses bash_it $PROMPT setting) +safe_append_prompt_command prompt_command From adb01ad8c28b9bd0e63ee10e2bcd8f0576f3c21a Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Wed, 20 Mar 2024 12:15:06 +0200 Subject: [PATCH 225/239] Added documentation for new Inretio theme. --- docs/themes-list/index.rst | 15 +++++++++++++++ docs/themes-list/inretio.rst | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 docs/themes-list/inretio.rst diff --git a/docs/themes-list/index.rst b/docs/themes-list/index.rst index 0275001b38..0196ba62ed 100644 --- a/docs/themes-list/index.rst +++ b/docs/themes-list/index.rst @@ -221,6 +221,21 @@ Envy ---- +Inretio +^^^^^^^ + + +.. image:: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-black.png + :target: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-black.png + :alt: Inretio theme in dark color scheme + + +.. image:: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-white.png + :target: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-white.png + :alt: Inretio theme in light color scheme + +---- + Iterate ^^^^^^^ diff --git a/docs/themes-list/inretio.rst b/docs/themes-list/inretio.rst new file mode 100644 index 0000000000..7850616ae5 --- /dev/null +++ b/docs/themes-list/inretio.rst @@ -0,0 +1,32 @@ +.. _inretio: + +Inretio Theme +========== + +Simple theme showing date and time, username and hostname, current folder, Git details and as a bonus - virtual environment along with Python version available in it. + +Inspired by existing themes: +- metal +- bobby + +Examples +-------- + +In Git-tracked folder: + +.. code-block:: bash + + β”Œβ”€β”€[2024-03-20 12:05:07] 🐧 gytis πŸ’» gytis-legion πŸ“‚ bash-it on 🌡 theme-inretio βŒ€1 βœ— + β””> ls + aliases clean_files.txt custom hooks lib lint_clean_files.sh profiles template test_lib uninstall.sh + bash_it.sh completion docs install.sh LICENSE plugins scripts test themes vendor + + +In Python virtual environment: + +.. code-block:: bash + + β”Œβ”€β”€[2024-03-20 12:07:32] 🐧 gytis πŸ’» gytis-legion 🐍 3.12.2 on [general] πŸ“‚ general + β””> ls + bin include lib lib64 pyvenv.cfg share + From f486dc9f426c3c4e6d60faf19a62149bfbe8d1db Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Wed, 20 Mar 2024 13:07:22 +0200 Subject: [PATCH 226/239] Fix documentation: title underline too short. --- docs/themes-list/inretio.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/themes-list/inretio.rst b/docs/themes-list/inretio.rst index 7850616ae5..0e424a99f8 100644 --- a/docs/themes-list/inretio.rst +++ b/docs/themes-list/inretio.rst @@ -1,7 +1,7 @@ .. _inretio: Inretio Theme -========== +============= Simple theme showing date and time, username and hostname, current folder, Git details and as a bonus - virtual environment along with Python version available in it. From dcafe3ce70c24144f4daf408cfe078a751208ad6 Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Wed, 20 Mar 2024 13:09:48 +0200 Subject: [PATCH 227/239] Fix sorting in clean_files.txt list. --- clean_files.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index 0ba14ff020..c6c48d4589 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -162,6 +162,7 @@ themes/candy themes/easy themes/essential themes/githelpers.theme.bash +themes/inretio themes/modern themes/norbu themes/oh-my-posh @@ -170,7 +171,6 @@ themes/pete themes/powerline themes/pure themes/purity -themes/inretio # vendor init files # From c34f56e7cbffa68d893f8e25d1f83d693a929842 Mon Sep 17 00:00:00 2001 From: "Alexandre Nepomniachtchi (aka alexnav)" Date: Tue, 26 Mar 2024 17:58:21 +0100 Subject: [PATCH 228/239] (update) Add some new aliases for logginng --- aliases/available/git.aliases.bash | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..cd6e31cf71 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -3,6 +3,7 @@ about-alias 'common git abbreviations' alias g='git' alias get='git' +alias got='git ' # add alias ga='git add' @@ -79,6 +80,8 @@ alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' +alias ghist='git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short' # Use it to be fast and without color. +alias gprogress='git log --pretty=format:\"%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d\" --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. # ls-files alias gu='git ls-files . --exclude-standard --others' # Show untracked files @@ -129,6 +132,7 @@ alias grv='git remote -v' # rm alias grm='git rm' +alias grmc='git rm --cached' # Removes the file only from the Git repository, but not from the filesystem. This is useful to undo some of the changes you made to a file before you commit it. # rebase alias grb='git rebase' From e9facb2b229682ef67d4c5c9eb4c89cdb59b14c3 Mon Sep 17 00:00:00 2001 From: "Alexandre Nepomniachtchi (aka alexnav)" Date: Tue, 26 Mar 2024 18:28:55 +0100 Subject: [PATCH 229/239] (fix) log aliases for git. --- aliases/available/git.aliases.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index cd6e31cf71..71fc5178cf 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -80,8 +80,8 @@ alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' -alias ghist='git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short' # Use it to be fast and without color. -alias gprogress='git log --pretty=format:\"%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d\" --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. +alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. +alias gprogress='git log --pretty=format:'\''%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d'\'' --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. # ls-files alias gu='git ls-files . --exclude-standard --others' # Show untracked files From 608b4399f341dab576e69084d429da6ab6f30b1f Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Thu, 28 Mar 2024 12:05:32 +0200 Subject: [PATCH 230/239] Fix theme file header as required by hooks/dot-bash.sh line 15. --- themes/inretio/inretio.theme.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/inretio/inretio.theme.bash b/themes/inretio/inretio.theme.bash index ceac5a296b..58ac36ddfb 100644 --- a/themes/inretio/inretio.theme.bash +++ b/themes/inretio/inretio.theme.bash @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # Inretio theme for Bash-it # Contact: bashit@inretio.eu From 1743bebca8038c24bd5ddc5ba0504b7c7dbbbcfc Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Fri, 21 Jun 2024 21:02:20 +0530 Subject: [PATCH 231/239] Support conda environement for bira theme --- themes/bira/bira.theme.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/themes/bira/bira.theme.bash b/themes/bira/bira.theme.bash index f30d8d5d00..cba4e425b8 100644 --- a/themes/bira/bira.theme.bash +++ b/themes/bira/bira.theme.bash @@ -6,6 +6,8 @@ SCM_THEME_PROMPT_SUFFIX="β€Ί${reset_color?}" VIRTUALENV_THEME_PROMPT_PREFIX=" ${cyan?}β€Ή" VIRTUALENV_THEME_PROMPT_SUFFIX="β€Ί${reset_color?}" +CONDAENV_THEME_PROMPT_PREFIX=" ${cyan?}β€Ή" +CONDAENV_THEME_PROMPT_SUFFIX="β€Ί${reset_color?}" bold="\[\e[1m\]" @@ -18,7 +20,7 @@ fi function prompt_command() { local current_dir=" ${bold_blue?}\w${normal?}${reset_color?}" local virtualenv_prompt scm_prompt_info - virtualenv_prompt="$(virtualenv_prompt)" + virtualenv_prompt="${virtualenv_prompt:-$(condaenv_prompt)}" scm_prompt_info="$(scm_prompt_info)" PS1="╭─${user_host?}${current_dir}${virtualenv_prompt}${scm_prompt_info}\n╰─${bold?}\\$ ${normal?}" } From 81bbf4408e633640f7aa176bff62f4d65732bbd0 Mon Sep 17 00:00:00 2001 From: Blackteahamburger Date: Tue, 27 Aug 2024 15:32:22 +0800 Subject: [PATCH 232/239] bash_profile.template.bash: fix theme location --- template/bash_profile.template.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 3def286612..4b90990489 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -11,7 +11,7 @@ export BASH_IT="{{BASH_IT}}" # Lock and Load a custom theme file. # Leave empty to disable theming. -# location /.bash_it/themes/ +# location "$BASH_IT"/themes/ export BASH_IT_THEME='bobby' # Some themes can show whether `sudo` has a current token or not. From 345d0081b98f805f4368746f346b5d6eb0a218d6 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 17 Apr 2023 20:05:48 +0300 Subject: [PATCH 233/239] Fix commandline options for the current versions of gifski and gifsicle --- plugins/available/gif.plugin.bash | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index a04ff5c7d1..1f47f1f013 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -72,9 +72,9 @@ function v2gif() { eval set -- "$args" local use_gifski="" local opt_del_after="" - local maxsize="" - local lossiness="" - local maxwidthski="" + local maxsize=() + local lossiness=() + local maxwidthski=() local giftagopt="" local giftag="" local defaultfps=10 @@ -106,8 +106,8 @@ function v2gif() { shift ;; -w | --width) - maxsize="-vf scale=$2:-1" - maxwidthski="-W $2" + maxsize=(-vf "scale=$2:-1") + maxwidthski=(-W "$2") giftag="${giftag}-w$2" shift 2 ;; @@ -118,7 +118,7 @@ function v2gif() { ;; -l | --lossy) # Use giflossy parameter - lossiness="--lossy=$2" + lossiness=("--lossy=$2") giftag="${giftag}-l$2" shift 2 ;; @@ -164,7 +164,7 @@ function v2gif() { local del_after=$opt_del_after if [[ -n "$make_webm" ]]; then - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 \ -quality best -loop 0 "${file%.*}.webm" || return 2 fi @@ -184,12 +184,12 @@ function v2gif() { if [[ "$use_gifski" = "true" ]]; then # I trust @pornel to do his own resizing optimization choices - $ffmpeg -loglevel panic -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ - && $gifski v2gif-tmp-*.png "$maxwidthski" --fps "$(printf "%.0f" "$fps")" -o "$output_file" || return 2 + $ffmpeg -loglevel warning -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + && $gifski "${maxwidthski[@]}" --fps "$(printf "%.0f" "$fps")" -o "$output_file" v2gif-tmp-*.png || return 2 else - $ffmpeg -loglevel panic -i "$file" "$maxsize" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + $ffmpeg -loglevel warning -i "$file" "${maxsize[@]}" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ && $convert +dither -layers Optimize v2gif-tmp-*.png GIF:- \ - | $gifsicle "$lossiness" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 + | $gifsicle "${lossiness[@]}" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 fi rm v2gif-tmp-*.png @@ -299,7 +299,7 @@ function any2webm() { echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)" - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v "$bandwidth" -auto-alt-ref 0 \ -quality best "$fps" "$size" -loop 0 -pix_fmt yuva420p "$output_file" || return 2 From d60d806ab4fe5c37a86e4c6849498fdf964e49fa Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 5 Nov 2024 11:13:13 +0200 Subject: [PATCH 234/239] new version of oh-my-posh breaks the init commandline, fixing to the new syntax of v24 --- themes/oh-my-posh/oh-my-posh.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/oh-my-posh/oh-my-posh.theme.bash b/themes/oh-my-posh/oh-my-posh.theme.bash index ba3c77f1ef..430c8acb4c 100644 --- a/themes/oh-my-posh/oh-my-posh.theme.bash +++ b/themes/oh-my-posh/oh-my-posh.theme.bash @@ -2,7 +2,7 @@ if _command_exists oh-my-posh; then export POSH_THEME=${POSH_THEME:-https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v$(oh-my-posh --version)/themes/jandedobbeleer.omp.json} - eval "$(oh-my-posh --init --shell bash --config "${POSH_THEME}")" + eval "$(oh-my-posh init bash --config "${POSH_THEME}")" else _log_warning "The oh-my-posh binary was not found on your PATH. Falling back to your existing PS1, please see the docs for more info." fi From fa6b4921cee361b31567d9ef9bccde3673325a4f Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 5 Nov 2024 11:27:18 +0200 Subject: [PATCH 235/239] Pass the shellcheck lint test --- themes/brainy/brainy.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index e1c3617531..b93c768f56 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -168,7 +168,7 @@ ___brainy_prompt_battery() { box="[|]" ac_adapter_connected && charging="+" ac_adapter_disconnected && charging="-" - info+=$charging + info+="$charging" [ "$info" == "100+" ] && info="AC" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } From f1822f9467ca597bc254a8349eed147c1b2581a8 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 10:06:10 +0200 Subject: [PATCH 236/239] lint cleanup for shfmt --- clean_files.txt | 1 + docs/themes-list/inretio.rst | 1 - plugins/available/browser.plugin.bash | 81 ++++++++++++++------------- themes/inretio/inretio.theme.bash | 52 ++++++++--------- themes/lambda/lambda.theme.bash | 46 +++++++-------- 5 files changed, 93 insertions(+), 88 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index e8dff795bf..cf8d8bcb72 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/base.plugin.bash plugins/available/basher.plugin.bash plugins/available/battery.plugin.bash plugins/available/blesh.plugin.bash +plugins/available/browser.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/colors.plugin.bash plugins/available/direnv.plugin.bash diff --git a/docs/themes-list/inretio.rst b/docs/themes-list/inretio.rst index 0e424a99f8..d37287d07c 100644 --- a/docs/themes-list/inretio.rst +++ b/docs/themes-list/inretio.rst @@ -29,4 +29,3 @@ In Python virtual environment: β”Œβ”€β”€[2024-03-20 12:07:32] 🐧 gytis πŸ’» gytis-legion 🐍 3.12.2 on [general] πŸ“‚ general β””> ls bin include lib lib64 pyvenv.cfg share - diff --git a/plugins/available/browser.plugin.bash b/plugins/available/browser.plugin.bash index f7d820aa07..b65d92ca76 100644 --- a/plugins/available/browser.plugin.bash +++ b/plugins/available/browser.plugin.bash @@ -1,39 +1,40 @@ +# shellcheck shell=bash # based on https://gist.github.com/318247 cite about-plugin about-plugin 'render commandline output in your browser' +# shellcheck disable=SC2120 function browser() { - about 'pipe html to a browser' - example '$ echo "

hi mom!

" | browser' - example '$ ron -5 man/rip.5.ron | browser' - group 'browser' + about 'pipe html to a browser' + example '$ echo "

hi mom!

" | browser' + example '$ ron -5 man/rip.5.ron | browser' + group 'browser' - if [ -t 0 ]; then - if [ -n "$1" ]; then - open $1 - else - reference browser - fi + if [ -t 0 ]; then + if [ -n "$1" ]; then + open "$1" + else + reference browser + fi - else - f="/tmp/browser.$RANDOM.html" - cat /dev/stdin > $f - open $f - fi + else + f="/tmp/browser.$RANDOM.html" + cat /dev/stdin > $f + open $f + fi } - function wmate() { - about 'pipe hot spicy interwebs into textmate and cleanup!' - example '$ wmate google.com' - group 'browser' - - if [ -t 0 ]; then - if [ -n "$1" ]; then - wget -qO- $1 | /usr/bin/mate + about 'pipe hot spicy interwebs into textmate and cleanup!' + example '$ wmate google.com' + group 'browser' -TIDY=`/usr/bin/osascript << EOT + if [ -t 0 ]; then + if [ -n "$1" ]; then + wget -qO- "$1" | /usr/bin/mate + TIDY=$( + /usr/bin/osascript << EOT tell application "TextMate" activate end tell @@ -53,24 +54,26 @@ tell application "System Events" end tell end tell end tell -EOT` +EOT + ) + export TIDY - else - reference wmate - fi - fi + else + reference wmate + fi + fi } function raw() { - about 'write wget into a temp file and pump it into your browser' - example '$ raw google.com' - group 'browser' + about 'write wget into a temp file and pump it into your browser' + example '$ raw google.com' + group 'browser' - if [ -t 0 ]; then - if [ -n "$1" ]; then - wget -qO- $1 | browser - else - reference raw - fi - fi + if [ -t 0 ]; then + if [ -n "$1" ]; then + wget -qO- "$1" | browser + else + reference raw + fi + fi } diff --git a/themes/inretio/inretio.theme.bash b/themes/inretio/inretio.theme.bash index 58ac36ddfb..1db6c6d1f4 100644 --- a/themes/inretio/inretio.theme.bash +++ b/themes/inretio/inretio.theme.bash @@ -16,11 +16,11 @@ VIRTUALENV_THEME_PROMPT_SUFFIX="" # SCM prompts SCM_NONE_CHAR="" SCM_GIT_CHAR="[Β±] " -SCM_GIT_BEHIND_CHAR="${red}↓${normal}" -SCM_GIT_AHEAD_CHAR="${bold_green}↑${normal}" +SCM_GIT_BEHIND_CHAR="${red?}↓${normal?}" +SCM_GIT_AHEAD_CHAR="${bold_green?}↑${normal?}" SCM_GIT_UNTRACKED_CHAR="βŒ€" -SCM_GIT_UNSTAGED_CHAR="${bold_yellow}β€’${normal}" -SCM_GIT_STAGED_CHAR="${bold_green}+${normal}" +SCM_GIT_UNSTAGED_CHAR="${bold_yellow?}β€’${normal?}" +SCM_GIT_STAGED_CHAR="${bold_green?}+${normal?}" SCM_THEME_PROMPT_DIRTY="" SCM_THEME_PROMPT_CLEAN="" @@ -28,8 +28,8 @@ SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" # Git status prompts -GIT_THEME_PROMPT_DIRTY=" ${red}βœ—${normal}" -GIT_THEME_PROMPT_CLEAN=" ${bold_green}βœ“${normal}" +GIT_THEME_PROMPT_DIRTY=" ${red?}βœ—${normal?}" +GIT_THEME_PROMPT_CLEAN=" ${bold_green?}βœ“${normal?}" GIT_THEME_PROMPT_PREFIX="" GIT_THEME_PROMPT_SUFFIX="" @@ -48,32 +48,32 @@ icon_end="β””> " # Display virtual environment info function _virtualenv_prompt { - VIRTUALENV_DETAILS="" - VIRTUALENV_CHAR="" - - # $VIRTUAL_ENV is set and is non-zero length - if [[ -n "$VIRTUAL_ENV" ]]; then - # Check if Python 3 exists - if command -v python3 >/dev/null 2>&1; then - VIRTUALENV_DETAILS="$($VIRTUAL_ENV/bin/python --version | sed 's,Python ,,') on [$(basename $VIRTUAL_ENV)]" - VIRTUALENV_CHAR=" 🐍" - else - VIRTUALENV_DETAILS="[$(basename $VIRTUAL_ENV)]" - VIRTUALENV_CHAR=" β“”" - fi - fi - - echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" + VIRTUALENV_DETAILS="" + VIRTUALENV_CHAR="" + + # $VIRTUAL_ENV is set and is non-zero length + if [[ -n "$VIRTUAL_ENV" ]]; then + # Check if Python 3 exists + if command -v python3 > /dev/null 2>&1; then + VIRTUALENV_DETAILS="$("$VIRTUAL_ENV/bin/python" --version | sed 's,Python ,,') on [$(basename "$VIRTUAL_ENV")]" + VIRTUALENV_CHAR=" 🐍" + else + VIRTUALENV_DETAILS="[$(basename "$VIRTUAL_ENV")]" + VIRTUALENV_CHAR=" β“”" + fi + fi + + echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" } # Rename tab function tabname { - printf "\e]1;$1\a" + printf "\e]1;%s\a" "$1" } # Rename window function winname { - printf "\e]2;$1\a" + printf "\e]2;%s\a" "$1" } _theme_clock() { @@ -92,8 +92,8 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%Y-%m-%d %H:%M:%S"} # Displays the current prompt function prompt_command() { - PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${green}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white}${normal}\n${icon_end}" - PS2="${icon_end}" + PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green?}\u${normal}${icon_host}${bold_cyan?}\h${normal}${green?}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple?}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white?}${normal}\n${icon_end}" + PS2="${icon_end}" } # Runs prompt (this bypasses bash_it $PROMPT setting) diff --git a/themes/lambda/lambda.theme.bash b/themes/lambda/lambda.theme.bash index 8f3d5baf49..59f82a4a81 100644 --- a/themes/lambda/lambda.theme.bash +++ b/themes/lambda/lambda.theme.bash @@ -1,33 +1,35 @@ -#!/bin/bash +# shellcheck shell=bash # shellcheck disable=SC1090,SC2034 function set_prompt { - local user_color="\[\033[1;31m\]" # bold red for username - local at_color="\[\033[1;37m\]" # bold white for @ symbol - local host_color="\[\033[1;31m\]" # bold red for hostname - local in_color="\[\033[1;37m\]" # bold white for "in" - local dir_color="\[\033[1;35m\]" # bold purple for current working directory - local git_color="\[\033[1;36m\]" # bold cyan for Git information - local time_color="\[\033[1;32m\]" # bold green for time taken - local reset_color="\[\033[0m\]" # reset color - local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol + local user_color="\[\033[1;31m\]" # bold red for username + local at_color="\[\033[1;37m\]" # bold white for @ symbol + local host_color="\[\033[1;31m\]" # bold red for hostname + local in_color="\[\033[1;37m\]" # bold white for "in" + local dir_color="\[\033[1;35m\]" # bold purple for current working directory + local git_color="\[\033[1;36m\]" # bold cyan for Git information + local time_color="\[\033[1;32m\]" # bold green for time taken + local reset_color="\[\033[0m\]" # reset color + local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol - local end_time=$(date +%s%3N) # current time in milliseconds - local time_taken=$(( (end_time - start_time) )) # time in milliseconds + local end_time time_taken + end_time=$(date +%s%3N) # current time in milliseconds + # shellcheck disable=SC2154 + time_taken=$((end_time - start_time)) # time in milliseconds - PS1="${user_color}╭─\\u" # username - PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname - PS1+="${in_color} in" # "in" between hostname and current directory - PS1+="${dir_color} \\w" # current working directory + PS1="${user_color}╭─\\u" # username + PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname + PS1+="${in_color} in" # "in" between hostname and current directory + PS1+="${dir_color} \\w" # current working directory - # Git information (status symbol) - PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" + # Git information (status symbol) + PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" - if [ $time_taken -gt 0 ]; then - PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds - fi + if [ $time_taken -gt 0 ]; then + PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds + fi - PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after + PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after } PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' From 092b1ea9373a4a9a51cd0787747404f7e2e248d4 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 11:54:59 +0200 Subject: [PATCH 237/239] linting the bats --- test/plugins/cmd-returned-notify.plugin.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index d8aa9248ff..19965032aa 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -9,8 +9,9 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: notify after elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + NOTIFY_IF_COMMAND_RETURNS_AFTER=0 + COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + export COMMAND_DURATION_START_SECONDS NOTIFY_IF_COMMAND_RETURNS_AFTER sleep 1 run precmd_return_notification assert_success @@ -18,8 +19,9 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: do not notify before elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + NOTIFY_IF_COMMAND_RETURNS_AFTER=10 + COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + export COMMAND_DURATION_START_SECONDS NOTIFY_IF_COMMAND_RETURNS_AFTER sleep 1 run precmd_return_notification assert_success From 9df0c64a4936843a6907de1bbf5bf1e03c1f3027 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 11:58:10 +0200 Subject: [PATCH 238/239] linting the bats --- aliases/available/git.aliases.bash | 6 +++--- test/plugins/battery.plugin.bats | 1 + themes/base.theme.bash | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index f56675e66d..829505ddfd 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -83,7 +83,7 @@ alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' -alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. +alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. alias gprogress='git log --pretty=format:'\''%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d'\'' --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. # ls-files @@ -153,8 +153,8 @@ alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosqu alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote # reset -alias gus='git reset HEAD' # read as: 'git unstage' -alias grh='git reset' # equivalent to: git reset HEAD +alias gus='git reset HEAD' # read as: 'git unstage' +alias grh='git reset' # equivalent to: git reset HEAD alias grh!='git reset --hard' alias gpristine='git reset --hard && git clean -dfx' diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 49199ef27c..6665207f3a 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -271,6 +271,7 @@ function setup_ioreg { percent="$1" function ioreg { + # shellcheck disable=SC2317 printf "\"MaxCapacity\" = 100\n\"CurrentCapacity\" = %s" "${percent}" } } diff --git a/themes/base.theme.bash b/themes/base.theme.bash index e25014f86b..d78baa6adf 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -416,9 +416,9 @@ function node_version_prompt() { _log_debug "node: using version strategy '$NODE_VERSION_STRATEGY'" if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then - nvm_version_prompt + nvm_version_prompt elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then - node_native_version_prompt + node_native_version_prompt fi } From a79a0e5e3eec5b47621a028eecd1c622e5d7d605 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 14:01:01 +0200 Subject: [PATCH 239/239] I merged the jgit too soon. --- plugins/available/jgitflow.plugin.bash | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/available/jgitflow.plugin.bash b/plugins/available/jgitflow.plugin.bash index ff972f6221..f0405cb916 100644 --- a/plugins/available/jgitflow.plugin.bash +++ b/plugins/available/jgitflow.plugin.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2086 cite about-plugin about-plugin 'Maven jgitflow build helpers' @@ -18,21 +19,21 @@ function hotfix-start { about 'helper function for starting a new hotfix' group 'jgitflow' - pre-jgitflow && mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS} } function hotfix-finish { about 'helper function for finishing a hotfix' group 'jgitflow' - pre-jgitflow && mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags && mvn clean + pre-jgitflow && mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags && mvn clean } function feature-start { about 'helper function for starting a new feature' group 'jgitflow' - pre-jgitflow && mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS} } function feature-finish {