From 19db142aae592039f4ae0c5c7e0bcbf623cc88cb Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Mon, 15 Mar 2021 20:18:59 +0530 Subject: [PATCH 001/114] completion (feature): dart cli --- clean_files.txt | 1 + completion/available/dart.completion.bash | 47 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 completion/available/dart.completion.bash diff --git a/clean_files.txt b/clean_files.txt index 5cececcf..1498d979 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -68,6 +68,7 @@ completion/available/cargo.completion.bash completion/available/composer.completion.bash completion/available/conda.completion.bash completion/available/consul.completion.bash +completion/available/dart.completion.bash completion/available/django.completion.bash completion/available/docker.completion.bash completion/available/docker-machine.completion.bash diff --git a/completion/available/dart.completion.bash b/completion/available/dart.completion.bash new file mode 100644 index 00000000..9497103b --- /dev/null +++ b/completion/available/dart.completion.bash @@ -0,0 +1,47 @@ +# shellcheck shell=bash + +__dart_completion() { + local prev=$(_get_pword) + local curr=$(_get_cword) + + local HELP="--help -h" + local VERBOSE="-v --verbose" + local DEFAULT="$BASE --authtoken --region" + + case $prev in + analyze) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP --fatal-infos --no-fatal-warnings --fatal-warnings" -- "$curr")) + ;; + compile) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP aot-snapshot exe js jit-snapshot kernel" -- "$curr")) + ;; + create) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP --template -t --no-pub --pub --force" -- "$curr")) + ;; + -t | --template) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "console-simple console-full package-simple web-simple" -- "$curr")) + ;; + format) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP $VERBOSE -o --output --fix -l --line-length" -- "$curr")) + ;; + pub) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP $VERBOSE --version --no-trace --trace --verbosity cache deps downgrade get global logout outdated publish run upgrade uploader version" -- "$curr")) + ;; + run) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP --observe --enable-vm-service --no-pause-isolates-on-exit --no-pause-isolates-on-unhandled-exceptions --no-warn-on-pause-with-no-debugger --pause-isolates-on-exit --pause-isolates-on-unhandled-exceptions --warn-on-pause-with-no-debugger" -- "$curr")) + ;; + *) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP $VERBOSE --version --enable-analytics --disable-analytics help analyze compile create format pub run test" -- "$curr")) + ;; + esac +} + +complete -F __dart_completion dart From ed97b9d51f1b21a480ac48b5f0fb790bc371709e Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Fri, 26 Mar 2021 01:55:37 +0530 Subject: [PATCH 002/114] dart completion (improvement): requested by @NoahGorny --- completion/available/dart.completion.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/completion/available/dart.completion.bash b/completion/available/dart.completion.bash index 9497103b..ece96d5c 100644 --- a/completion/available/dart.completion.bash +++ b/completion/available/dart.completion.bash @@ -6,7 +6,6 @@ __dart_completion() { local HELP="--help -h" local VERBOSE="-v --verbose" - local DEFAULT="$BASE --authtoken --region" case $prev in analyze) @@ -37,7 +36,7 @@ __dart_completion() { # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "$HELP --observe --enable-vm-service --no-pause-isolates-on-exit --no-pause-isolates-on-unhandled-exceptions --no-warn-on-pause-with-no-debugger --pause-isolates-on-exit --pause-isolates-on-unhandled-exceptions --warn-on-pause-with-no-debugger" -- "$curr")) ;; - *) + dart) # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "$HELP $VERBOSE --version --enable-analytics --disable-analytics help analyze compile create format pub run test" -- "$curr")) ;; From 7f193a2e0514495ec2ddb5e1b80a2087ab7183f6 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 16 May 2021 13:52:05 +0300 Subject: [PATCH 003/114] Add pure theme to clean_files.txt --- clean_files.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clean_files.txt b/clean_files.txt index 40dd3ed3..2a72dafc 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -111,6 +111,7 @@ themes/command_duration.theme.bash themes/easy themes/modern themes/powerline +themes/pure themes/purity # vendor init files From b65a7cc67cf74e055c1e5c4a4ee5e59c0ed26be5 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 16 May 2021 13:59:18 +0300 Subject: [PATCH 004/114] themes: Lint pure theme --- themes/pure/pure.theme.bash | 44 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash index 0be40b5a..e409eddf 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash + # scm theming SCM_THEME_PROMPT_PREFIX="|" SCM_THEME_PROMPT_SUFFIX="" @@ -17,30 +19,30 @@ VIRTUALENV_THEME_PROMPT_SUFFIX=")" # 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:' scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)$(scm_prompt_info)]" - fi + CHAR=$(scm_char) + if [[ $CHAR = "$SCM_NONE_CHAR" ]]; then + return + else + echo -e "[$(scm_char)$(scm_prompt_info)]" + fi } pure_prompt() { - ps_host="${bold_blue}\h${normal}"; - ps_user="${green}\u${normal}"; - ps_user_mark="${green} $ ${normal}"; - ps_root="${red}\u${red}"; - ps_root_mark="${red} # ${normal}" - ps_path="${yellow}\w${normal}"; - - # make it work - case $(id -u) 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" - ;; - esac + ps_host="${bold_blue}\h${normal}" + ps_user="${green}\u${normal}" + ps_user_mark="${green} $ ${normal}" + ps_root="${red}\u${red}" + ps_root_mark="${red} # ${normal}" + ps_path="${yellow}\w${normal}" + # make it work + case $(id -u) 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" + ;; + esac } safe_append_prompt_command pure_prompt From 2ae0350f5d5cf1fd66f962e4ce73809d6689045b Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 16 May 2021 16:53:03 +0300 Subject: [PATCH 005/114] themes: base: Add unified scm_prompt function --- themes/base.theme.bash | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a1520397..5663c4a0 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -121,6 +121,18 @@ function scm { fi } +scm_prompt() { + local CHAR=$(scm_char) + local format=${SCM_PROMPT_FORMAT:-'[%s%s]'} + + if [[ $CHAR = "$SCM_NONE_CHAR" ]]; then + return + else + # shellcheck disable=2059 + printf "$format\n" "$CHAR" "$(scm_prompt_info)" + fi +} + function scm_prompt_char { if [[ -z $SCM ]]; then scm; fi if [[ $SCM == "$SCM_GIT" ]]; then From dff892e0a31e3e2797d5406099cb8513b59e5eb4 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 16 May 2021 16:53:32 +0300 Subject: [PATCH 006/114] themes: Adapt themes to new scm_prompt api --- themes/binaryanomaly/binaryanomaly.theme.bash | 9 ------ themes/brunton/brunton.theme.bash | 10 +----- themes/codeword/codeword.theme.bash | 11 +------ themes/doubletime/doubletime.theme.bash | 31 +------------------ themes/gallifrey/gallifrey.theme.bash | 20 ++++-------- themes/mairan/mairan.theme.bash | 16 ++-------- themes/modern-t/modern-t.theme.bash | 15 ++------- themes/modern-time/modern-time.theme.bash | 15 ++------- themes/modern/modern.theme.bash | 14 ++------- themes/pure/pure.theme.bash | 9 ------ themes/ramses/ramses.theme.bash | 16 ++-------- themes/rjorgenson/rjorgenson.theme.bash | 15 ++------- themes/slick/slick.theme.bash | 16 ++-------- themes/zork/zork.theme.bash | 16 ++-------- 14 files changed, 33 insertions(+), 180 deletions(-) diff --git a/themes/binaryanomaly/binaryanomaly.theme.bash b/themes/binaryanomaly/binaryanomaly.theme.bash index f6740f35..c2efa237 100644 --- a/themes/binaryanomaly/binaryanomaly.theme.bash +++ b/themes/binaryanomaly/binaryanomaly.theme.bash @@ -31,15 +31,6 @@ function set_user_color() { esac } -scm_prompt() { - CHAR=$(scm_char) - if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then - return - else - echo "[$(scm_char)$(scm_prompt_info)]" - fi -} - # Define custom colors we need # non-printable bytes in PS1 need to be contained within \[ \]. # Otherwise, bash will count them in the length of the prompt diff --git a/themes/brunton/brunton.theme.bash b/themes/brunton/brunton.theme.bash index c0bfd49f..27b822ca 100644 --- a/themes/brunton/brunton.theme.bash +++ b/themes/brunton/brunton.theme.bash @@ -15,16 +15,8 @@ is_vim_shell() { fi } -scm_prompt() { - CHAR=$(scm_char) - if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then - return - else - echo " $(scm_char) (${white}$(scm_prompt_info)${normal})" - fi -} - prompt() { + SCM_PROMPT_FORMAT=' %s (%s)' PS1="${white}${background_blue} \u${normal}${background_blue}@${red}${background_blue}\h $(clock_prompt) ${reset_color}${normal} $(battery_charge)\n${bold_black}${background_white} \w ${normal}$(scm_prompt)$(is_vim_shell)\n${white}>${normal} " } diff --git a/themes/codeword/codeword.theme.bash b/themes/codeword/codeword.theme.bash index 96723ce3..e23a3fc3 100644 --- a/themes/codeword/codeword.theme.bash +++ b/themes/codeword/codeword.theme.bash @@ -3,16 +3,6 @@ SCM_THEME_PROMPT_DIRTY="${bold_red} ✗${normal}" SCM_THEME_PROMPT_CLEAN="${bold_green} ✓${normal}" SCM_GIT_CHAR="${green}±${normal}" -scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo " [$(scm_char)$(scm_prompt_info)]" - fi -} - mark_prompt() { echo "${green}\$${normal}" } @@ -25,6 +15,7 @@ user_host_path_prompt() { } prompt() { + SCM_PROMPT_FORMAT=' [%s%s]' PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) " } diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash index 3f686668..6b6aa150 100644 --- a/themes/doubletime/doubletime.theme.bash +++ b/themes/doubletime/doubletime.theme.bash @@ -28,17 +28,6 @@ else THEME_PROMPT_HOST_COLOR="$blue" fi -doubletime_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ]; then - return - elif [ $CHAR = $SCM_GIT_CHAR ]; then - echo "$(git_prompt_status)" - else - echo "[$(scm_prompt_info)]" - fi -} - function prompt_setter() { # Save history history -a @@ -46,27 +35,9 @@ function prompt_setter() { history -r PS1=" $(clock_prompt) $(scm_char) [${THEME_PROMPT_HOST_COLOR}\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w -$(doubletime_scm_prompt)$reset_color $ " +$(scm_prompt)$reset_color $ " PS2='> ' PS4='+ ' } safe_append_prompt_command prompt_setter - -git_prompt_status() { - local git_status_output - git_status_output=$(git status 2> /dev/null ) - if [ -n "$(echo $git_status_output | grep 'Changes not staged')" ]; then - git_status="${bold_red}$(scm_prompt_info) ✗" - elif [ -n "$(echo $git_status_output | grep 'Changes to be committed')" ]; then - git_status="${bold_yellow}$(scm_prompt_info) ^" - elif [ -n "$(echo $git_status_output | grep 'Untracked files')" ]; then - git_status="${bold_cyan}$(scm_prompt_info) +" - elif [ -n "$(echo $git_status_output | grep 'nothing to commit')" ]; then - git_status="${bold_green}$(scm_prompt_info) ${green}✓" - else - git_status="$(scm_prompt_info)" - fi - echo "[$git_status${normal}]" - -} diff --git a/themes/gallifrey/gallifrey.theme.bash b/themes/gallifrey/gallifrey.theme.bash index ddb89778..3ba48d71 100644 --- a/themes/gallifrey/gallifrey.theme.bash +++ b/themes/gallifrey/gallifrey.theme.bash @@ -4,26 +4,18 @@ SCM_THEME_PROMPT_SUFFIX=")${normal}" SCM_THEME_PROMPT_DIRTY="*" SCM_THEME_PROMPT_CLEAN="" -SCM_GIT_CHAR="g" -SCM_SVN_CHAR="s" -SCM_HG_CHAR="h" +SCM_GIT_CHAR="${green}±${normal}" +SCM_SVN_CHAR="${bold_cyan}⑆${normal}" +SCM_HG_CHAR="${bold_red}☿${normal}" ### 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:' -scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "$(scm_prompt_info) " - fi -} +gallifrey_prompt() { + SCM_PROMPT_FORMAT='%s%s' -pure_prompt() { ps_host="${green}\h${normal}"; ps_user_mark="${bold}\$${normal}"; ps_root_mark="${normal}§" @@ -38,4 +30,4 @@ pure_prompt() { esac } -safe_append_prompt_command pure_prompt +safe_append_prompt_command gallifrey_prompt diff --git a/themes/mairan/mairan.theme.bash b/themes/mairan/mairan.theme.bash index e6728824..89466ead 100644 --- a/themes/mairan/mairan.theme.bash +++ b/themes/mairan/mairan.theme.bash @@ -69,16 +69,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$GREEN$(scm_prompt_info)]" - fi -} - # show chroot if exist chroot(){ if [ -n "$debian_chroot" ] @@ -99,7 +89,7 @@ my_ve(){ } prompt() { - + SCM_PROMPT_FORMAT="[%s$GREEN%s]" my_ps_host="$BOLD$ORANGE\h${normal}"; # yes, these are the the same for now ... my_ps_host_root="$ORANGE\h${normal}"; @@ -114,10 +104,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} + 0) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} └─▪ ${prompt_symbol} ${normal}" ;; - *) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(modern_scm_prompt)${normal}$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} + *) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)${normal}$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} └─▪ ${prompt_symbol} ${normal}" ;; esac diff --git a/themes/modern-t/modern-t.theme.bash b/themes/modern-t/modern-t.theme.bash index 48e923aa..197f5a23 100644 --- a/themes/modern-t/modern-t.theme.bash +++ b/themes/modern-t/modern-t.theme.bash @@ -32,26 +32,17 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - prompt() { + SCM_PROMPT_FORMAT='[%s][%s]' if [ $? -ne 0 ] then # Yes, the indenting on these is weird, but it has to be like # this otherwise it won't display properly. - PS1="${TITLEBAR}${bold_red}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]${reset_color}$(modern_scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}${bold_red}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]${reset_color}$(scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) ${bold_red}└─▪${normal} " else - PS1="${TITLEBAR}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]$(modern_scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]$(scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) └─▪ " fi } diff --git a/themes/modern-time/modern-time.theme.bash b/themes/modern-time/modern-time.theme.bash index e42226df..fc8458ff 100644 --- a/themes/modern-time/modern-time.theme.bash +++ b/themes/modern-time/modern-time.theme.bash @@ -28,30 +28,21 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - modern_current_time_prompt() { echo "[$(date '+%l:%M%p')]" } prompt() { + SCM_PROMPT_FORMAT='[%s][%s]' if [ $? -ne 0 ] then # Yes, the indenting on these is weird, but it has to be like # this otherwise it won't display properly. - PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(modern_scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) ${bold_red}└─▪${normal} " else - PS1="${TITLEBAR}┌─$(modern_scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}┌─$(scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) └─▪ " fi } diff --git a/themes/modern/modern.theme.bash b/themes/modern/modern.theme.bash index f14fd4fd..3a51267c 100644 --- a/themes/modern/modern.theme.bash +++ b/themes/modern/modern.theme.bash @@ -26,15 +26,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - detect_venv() { python_venv="" # Detect python venv @@ -46,11 +37,12 @@ detect_venv() { } prompt() { + SCM_PROMPT_FORMAT='[%s][%s]' retval=$? if [[ retval -ne 0 ]]; then - PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(modern_scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n${bold_red}└─▪${normal} " + PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n${bold_red}└─▪${normal} " else - PS1="${TITLEBAR}┌─$(modern_scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n└─▪ " + PS1="${TITLEBAR}┌─$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n└─▪ " fi detect_venv PS1+="${python_venv}${dir_color}" diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash index e409eddf..3672a72c 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -18,15 +18,6 @@ VIRTUALENV_THEME_PROMPT_SUFFIX=")" # 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:' -scm_prompt() { - CHAR=$(scm_char) - if [[ $CHAR = "$SCM_NONE_CHAR" ]]; then - return - else - echo -e "[$(scm_char)$(scm_prompt_info)]" - fi -} - pure_prompt() { ps_host="${bold_blue}\h${normal}" ps_user="${green}\u${normal}" diff --git a/themes/ramses/ramses.theme.bash b/themes/ramses/ramses.theme.bash index 7795cf75..054a3160 100644 --- a/themes/ramses/ramses.theme.bash +++ b/themes/ramses/ramses.theme.bash @@ -36,16 +36,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - # show chroot if exist chroot(){ if [ -n "$debian_chroot" ] @@ -71,7 +61,7 @@ my_ve(){ } prompt() { - + SCM_PROMPT_FORMAT='[%s][%s]' my_ps_host="${green}\h${normal}"; # yes, these are the the same for now ... my_ps_host_root="${green}\h${normal}"; @@ -86,10 +76,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}] + 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}] ▪ " ;; - *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version) + *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version) |─[${bold_purple}\w${normal}] ▪ " ;; diff --git a/themes/rjorgenson/rjorgenson.theme.bash b/themes/rjorgenson/rjorgenson.theme.bash index e866f0ea..71d29e78 100644 --- a/themes/rjorgenson/rjorgenson.theme.bash +++ b/themes/rjorgenson/rjorgenson.theme.bash @@ -57,16 +57,6 @@ todo_txt_count() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "${BRACKET_COLOR}[${CHAR}${BRACKET_COLOR}][${STRING_COLOR}$(scm_prompt_info)${BRACKET_COLOR}]$normal" - fi -} - my_prompt_char() { if [[ $OSTYPE =~ "darwin" ]]; then echo "${BRACKET_COLOR}➞ ${normal}" @@ -76,6 +66,7 @@ my_prompt_char() { } prompt() { + SCM_PROMPT_FORMAT="${BRACKET_COLOR}[%s${BRACKET_COLOR}][${STRING_COLOR}%s${BRACKET_COLOR}]" my_ps_host="${STRING_COLOR}\h${normal}"; my_ps_user="${STRING_COLOR}\u${normal}"; @@ -84,10 +75,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_root${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(modern_scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) + 0) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_root${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) ${BRACKET_COLOR}└─$(my_prompt_char)${normal}" ;; - *) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_user${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(modern_scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) + *) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_user${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) ${BRACKET_COLOR}└─$(todo_txt_count)$(my_prompt_char)" ;; esac diff --git a/themes/slick/slick.theme.bash b/themes/slick/slick.theme.bash index aafdc25d..b0979b7c 100644 --- a/themes/slick/slick.theme.bash +++ b/themes/slick/slick.theme.bash @@ -43,18 +43,8 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - prompt() { - + SCM_PROMPT_FORMAT='[%s][%s]' case $HOSTNAME in "clappy"* ) my_ps_host="${green}\h${normal}"; ;; @@ -70,10 +60,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}[$my_ps_root][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + 0) PS1="${TITLEBAR}[$my_ps_root][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) $ " ;; - *) PS1="${TITLEBAR}[$my_ps_user][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version)$(__my_venv_prompt)[${cyan}\w${normal}]$(is_vim_shell) + *) PS1="${TITLEBAR}[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)$(__my_venv_prompt)[${cyan}\w${normal}]$(is_vim_shell) $ " ;; esac diff --git a/themes/zork/zork.theme.bash b/themes/zork/zork.theme.bash index b5872314..c8053450 100644 --- a/themes/zork/zork.theme.bash +++ b/themes/zork/zork.theme.bash @@ -36,16 +36,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - # show chroot if exist chroot(){ if [ -n "$debian_chroot" ] @@ -71,7 +61,7 @@ my_ve(){ } prompt() { - + SCM_PROMPT_FORMAT='[%s][%s]' my_ps_host="${green}\h${normal}"; # yes, these are the the same for now ... my_ps_host_root="${green}\h${normal}"; @@ -86,10 +76,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) └─▪ " ;; - *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) └─▪ " ;; esac From 1e6113f7b7fb89d799ae100b4f586968d6e85837 Mon Sep 17 00:00:00 2001 From: Cristian Lupascu Date: Fri, 4 Jun 2021 15:07:06 +0300 Subject: [PATCH 007/114] Add command duration to the powerline theme family Fix the __powerline_duration_prompt: location & unused variable `prompt` Remove the duration segment from powerline* theme defaults Different color for duration prompt segment --- docs/themes-list/powerline-base.rst | 1 + themes/powerline-multiline/powerline-multiline.theme.bash | 2 ++ themes/powerline/powerline.base.bash | 5 +++++ themes/powerline/powerline.theme.bash | 2 ++ 4 files changed, 10 insertions(+) diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index 85ba2388..b3907c6b 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -70,6 +70,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * ``battery`` - Battery information (you'll need to enable the ``battery`` plugin) * ``clock`` - Current time in ``HH:MM:SS`` format * ``cwd`` - Current working directory including full folder hierarchy (c.f. ``wd``\ ) +* ``duration`` - Duration of the last command. See :ref:`Command duration ` for details. * ``gcloud`` - Current gcloud active account * ``hostname`` - Host name of machine * ``in_toolbox`` - Show identifier if running inside a `toolbox `_ diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index a1663e6f..05c04987 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -94,6 +94,8 @@ COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} +COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129} + POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"} POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"} diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 43ee8be1..a3f71642 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -210,6 +210,11 @@ function __powerline_command_number_prompt() { echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}" } +function __powerline_duration_prompt() { + local duration=$(_command_duration) + [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}" +} + function __powerline_left_segment() { local params IFS="|" read -ra params <<< "${1}" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 794121b8..6b45d2d0 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -91,6 +91,8 @@ COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} 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"} safe_append_prompt_command __powerline_prompt_command From 2444a57cc568b67c14d7f5ea39b6bfd6d9e6a62d Mon Sep 17 00:00:00 2001 From: ofir shtrull Date: Thu, 10 Jun 2021 16:04:56 +0300 Subject: [PATCH 008/114] feat: add k8s namespace indicator (#1887) * Add k8s namespace to prompt --- docs/themes-list/powerline-base.rst | 1 + themes/base.theme.bash | 4 ++++ .../powerline-multiline/powerline-multiline.theme.bash | 3 +++ themes/powerline-naked/powerline-naked.theme.bash | 3 +++ themes/powerline-plain/powerline-plain.theme.bash | 3 +++ themes/powerline/powerline.base.bash | 10 ++++++++++ themes/powerline/powerline.theme.bash | 3 +++ 7 files changed, 27 insertions(+) diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index b3907c6b..faa1af34 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -76,6 +76,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * ``in_toolbox`` - Show identifier if running inside a `toolbox `_ * ``in_vim`` - Show identifier if running in ``:terminal`` from vim * ``k8s_context`` - Show current kubernetes context +* ``k8s_namespace`` - Show current kubernetes namespace * ``last_status`` - Exit status of last run command * ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv`` and ``conda`` supported) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a1520397..bc4718f2 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -437,6 +437,10 @@ function k8s_context_prompt { echo -e "$(kubectl config current-context 2> /dev/null)" } +function k8s_namespace_prompt { + echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)" +} + function virtualenv_prompt { if [[ -n "$VIRTUAL_ENV" ]]; then virtualenv=$(basename "$VIRTUAL_ENV") diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 05c04987..48a1243e 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -55,6 +55,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 417ae71a..2fb4137e 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -50,6 +50,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 0b8f4f56..6ff68e8f 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -47,6 +47,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=60} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index a3f71642..98bcd82c 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -85,6 +85,16 @@ function __powerline_k8s_context_prompt() { [[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}" } +function __powerline_k8s_namespace_prompt() { + local kubernetes_namespace="" + + if _command_exists kubectl; then + kubernetes_namespace="$(k8s_namespace_prompt)" + fi + + [[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR}" +} + function __powerline_python_venv_prompt() { set +u local python_venv="" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 6b45d2d0..d7ac77ed 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -52,6 +52,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} From 01b916c5440c6e54109b071b8354551bb1cfafe6 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Fri, 11 Jun 2021 12:41:28 +0530 Subject: [PATCH 009/114] helpers (bugfix): restart bashit after upgrade --- lib/helpers.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index bf63c362..7474f423 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -203,7 +203,7 @@ _bash-it_pull_and_update_inner() { _bash-it-migrate echo "" echo "All done, enjoy!" - bash-it reload + bash-it restart else echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." fi From 682fd32a13eaefe6ed1a144d45e7eb937a513ba4 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Thu, 17 Jun 2021 08:51:02 +0530 Subject: [PATCH 010/114] lint (bugfix): wpscan completion linting fix --- clean_files.txt | 1 + completion/available/wpscan.completion.bash | 22 ++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 40dd3ed3..ceec3b55 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -71,6 +71,7 @@ completion/available/rustup.completion.bash completion/available/sdkman.completion.bash completion/available/vault.completion.bash completion/available/vuejs.completion.bash +completion/available/wpscan.completion.bash # plugins # diff --git a/completion/available/wpscan.completion.bash b/completion/available/wpscan.completion.bash index f9ea5790..5d2e2daa 100644 --- a/completion/available/wpscan.completion.bash +++ b/completion/available/wpscan.completion.bash @@ -1,15 +1,15 @@ -#!/usr/bin/bash +# shellcheck shell=bash if command -v wpscan > /dev/null; then - __wpscan_completion() { - local OPTS=("--help --hh --version --url --ignore-main-redirect --verbose --output --format --detection-mode --scope --headers --user-agent --vhost --random-user-agent --user-agents-list --http-auth --max-threads --throttle --request-timeout --connect-timeout --disable-tlc-checks --proxy --proxy-auth --cookie-string --cookie-jar --cache-ttl --clear-cache --server --cache-dir --update --no-update --wp-content-dir --wp-plugins-dir --wp-version-detection --main-theme-detection --enumerate --exclude-content-based --plugins-list --plugins-detection --plugins-version-all --plugins-version-detection --themes-list --themes-detection --themes-version-all --themes-version-detection --timthumbs-list --timthumbs-detection --config-backups-list --config-backups-detection --db-exports-list --db-exports-detection --medias-detection --users-list --users-detection --passwords --usernames --multicall-max-passwords --password-attack --stealthy") - COMPREPLY=() - for _opt_ in ${OPTS[@]}; do - if [[ "$_opt_" == "$2"* ]]; then - COMPREPLY+=("$_opt_") - fi - done - } + __wpscan_completion() { + local OPTS=("--help --hh --version --url --ignore-main-redirect --verbose --output --format --detection-mode --scope --headers --user-agent --vhost --random-user-agent --user-agents-list --http-auth --max-threads --throttle --request-timeout --connect-timeout --disable-tlc-checks --proxy --proxy-auth --cookie-string --cookie-jar --cache-ttl --clear-cache --server --cache-dir --update --no-update --wp-content-dir --wp-plugins-dir --wp-version-detection --main-theme-detection --enumerate --exclude-content-based --plugins-list --plugins-detection --plugins-version-all --plugins-version-detection --themes-list --themes-detection --themes-version-all --themes-version-detection --timthumbs-list --timthumbs-detection --config-backups-list --config-backups-detection --db-exports-list --db-exports-detection --medias-detection --users-list --users-detection --passwords --usernames --multicall-max-passwords --password-attack --stealthy") + COMPREPLY=() + for _opt_ in "${OPTS[@]}"; do + if [[ "$_opt_" == "$2"* ]]; then + COMPREPLY+=("$_opt_") + fi + done + } - complete -F __wpscan_completion wpscan + complete -F __wpscan_completion wpscan fi From a3f5b5f29a477737053522c69e550f904585a2dc Mon Sep 17 00:00:00 2001 From: Ron Green <11993626+georgettica@users.noreply.github.com> Date: Thu, 17 Jun 2021 10:37:19 +0300 Subject: [PATCH 011/114] chore(pre-commit): bump version done in the beginning because of build issues, but was solved during the work on #1897 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index caed0df9..a5c90be0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - id: check-added-large-files - repo: https://github.com/jumanjihouse/pre-commit-hooks - rev: 2.1.4 + rev: 2.1.5 hooks: - id: git-check # Configure in .gitattributes - id: shellcheck From e51fe1fe2b67fd2409d08a2a0bca2f445c640a2e Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Wed, 23 Jun 2021 15:55:42 +0530 Subject: [PATCH 012/114] Abort upgrade if unsaved changes found in bashit directory (#1890) helper (improvement): added safeguard for unsaved changes --- lib/helpers.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 7474f423..26956193 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -224,6 +224,9 @@ _bash-it-update-() { cd "${BASH_IT}" || return + DIFF=$(git diff --name-status) + [ -n "$DIFF" ] && echo -e "Local changes detected in bash-it directory. Clean '$BASH_IT' directory to proceed.\n$DIFF" && return 1 + if [ -z "$BASH_IT_REMOTE" ]; then BASH_IT_REMOTE="origin" fi From 0f3e4dc8becec94b6dcd599cc15ceee78e9f808f Mon Sep 17 00:00:00 2001 From: Zhengnan Zhao Date: Wed, 23 Jun 2021 06:26:48 -0400 Subject: [PATCH 013/114] Have git check out main branch if present (#1886) Create function to get default git branch, and use main branch if present --- aliases/available/git.aliases.bash | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 478861ba..5b80d475 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -37,8 +37,8 @@ alias gcb='git checkout -b' alias gco='git checkout' alias gcob='git checkout -b' alias gcobu='git checkout -b ${USER}/' -alias gcom='git checkout master' -alias gcpd='git checkout master; git pull; git branch -D' +alias gcom='git checkout $(get_default_branch)' +alias gcpd='git checkout $(get_default_branch); git pull; git branch -D' alias gct='git checkout --track' # clone @@ -64,7 +64,7 @@ alias gf='git fetch --all --prune' alias gft='git fetch --all --prune --tags' alias gftv='git fetch --all --prune --tags --verbose' alias gfv='git fetch --all --prune --verbose' -alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master' +alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/$(get_default_branch)' alias gup='git fetch && git rebase' # log @@ -104,7 +104,7 @@ alias gp='git push' alias gpd='git push --delete' alias gpf='git push --force' alias gpo='git push origin HEAD' -alias gpom='git push origin master' +alias gpom='git push origin $(get_default_branch)' alias gpu='git push --set-upstream' alias gpunch='git push --force-with-lease' alias gpuo='git push --set-upstream origin' @@ -112,7 +112,7 @@ alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)' # pull alias gl='git pull' -alias glum='git pull upstream master' +alias glum='git pull upstream $(get_default_branch)' alias gpl='git pull' alias gpp='git pull && git push' alias gpr='git pull --rebase' @@ -128,9 +128,9 @@ alias grm='git rm' # rebase alias grb='git rebase' alias grbc='git rebase --continue' -alias grm='git rebase master' -alias grmi='git rebase master -i' -alias gprom='git fetch origin master && git rebase origin/master && git update-ref refs/heads/master origin/master' # Rebase with latest remote master +alias grm='git rebase $(get_default_branch)' +alias grmi='git rebase $(get_default_branch) -i' +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' @@ -174,7 +174,7 @@ alias gsu='git submodule update --init --recursive' # these aliases requires git v2.23+ alias gsw='git switch' alias gswc='git switch --create' -alias gswm='git switch master' +alias gswm='git switch $(get_default_branch)' alias gswt='git switch --track' # tag @@ -196,3 +196,11 @@ esac function gdv() { git diff --ignore-all-space "$@" | vim -R - } + +function get_default_branch() { + if git branch | grep -q main; then + echo main + else + echo master + fi +} From d4ebba174c72fb5646d9227b98143e00665d4b8a Mon Sep 17 00:00:00 2001 From: Ron Green <11993626+georgettica@users.noreply.github.com> Date: Wed, 23 Jun 2021 15:02:04 +0300 Subject: [PATCH 014/114] feat(git): add git unpushed alias (#1897) * feat(git): add git unpushed alias --- 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 5b80d475..8cafa82b 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -71,6 +71,7 @@ alias gup='git fetch && git rebase' alias gg='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' alias ggf='git log --graph --date=short --pretty=format:'\''%C(auto)%h %Cgreen%an%Creset %Cblue%cd%Creset %C(auto)%d %s'\''' alias ggs='gg --stat' +alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # FROM https://stackoverflow.com/questions/39220870/in-git-list-names-of-branches-with-unpushed-commits 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' From aad58bc9105f539c4e61d3d764a7b6446c0118d2 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Tue, 6 Jul 2021 22:21:46 -0500 Subject: [PATCH 015/114] move to Libera.Chat --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index fe18c80e..33c1b03f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ ![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://webchat.freenode.net/?channel=#bash-it](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://webchat.freenode.net/?channel=#bash-it) +[![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 61c0357414a5686861024c89def5e10078cad6bd Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 6 Feb 2021 23:29:18 +0200 Subject: [PATCH 016/114] completion: pip: Only invoke pip when trying to complete it This should greatly reduce shell load time, as the pip invocation takes a lot of time --- completion/available/pip.completion.bash | 10 +++++++++- completion/available/pip3.completion.bash | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/completion/available/pip.completion.bash b/completion/available/pip.completion.bash index 7ed8c17e..a20df4cd 100644 --- a/completion/available/pip.completion.bash +++ b/completion/available/pip.completion.bash @@ -7,5 +7,13 @@ # you should first initialize the corresponding environment. # So that pip is in the system's path. if _command_exists pip; then - eval "$(pip completion --bash)" + function __bash_it_complete_pip() { + if _command_exists _pip_completion; then + _pip_completion "$@" + else + eval "$(pip completion --bash)" + _pip_completion "$@" + fi + } + complete -o default -F __bash_it_complete_pip pip fi diff --git a/completion/available/pip3.completion.bash b/completion/available/pip3.completion.bash index c2b58564..d69460a5 100644 --- a/completion/available/pip3.completion.bash +++ b/completion/available/pip3.completion.bash @@ -7,5 +7,13 @@ # you should first initialize the corresponding environment. # So that pip3 is in the system's path. if _command_exists pip3; then - eval "$(pip3 completion --bash)" + function __bash_it_complete_pip3() { + if _command_exists _pip_completion; then + _pip_completion "$@" + else + eval "$(pip3 completion --bash)" + _pip_completion "$@" + fi + } + complete -o default -F __bash_it_complete_pip3 pip3 fi From 43947e2cbc247634e9129bd193a0a08a7e0d316e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 26 Jul 2021 13:04:53 -0700 Subject: [PATCH 017/114] completion/system: prefer direct invocation Instead of using the profile.d version, just invoke the script. The profile.d script preemptively short-circuits if it thinks that bash-completions has already been loaded, which it does by using the $BASH_COMPLETION variable, which is expressly supported by upstream to specify the location of the script...so it will entirely be never loaded if this is set. --- completion/available/system.completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 completion/available/system.completion.bash diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash old mode 100644 new mode 100755 index 8c4f71dc..2fe9b210 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -14,12 +14,12 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then fi -if [[ "$(uname -s)" == 'Darwin' ]] && _command_exists brew ; then +if [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path - if [[ -r "$BREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then + if [[ -r "$BREW_PREFIX"/etc/bash_completion ]] ; then # shellcheck disable=SC1090 - source "$BREW_PREFIX"/etc/profile.d/bash_completion.sh + source "$BREW_PREFIX"/etc/bash_completion fi fi From 893c8dbb96b0a1a6d2bf0ad6a7f9218a66598f44 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 26 Jul 2021 13:09:08 -0700 Subject: [PATCH 018/114] completion/system: support $BASH_COMPLETION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bash-completion supports pre-defining $BASH_COMPLETION as the path to the main script, so use that if it's defined. Alsö, don't load homebrew's completion if we've successfully loaded one already. --- completion/available/system.completion.bash | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index 2fe9b210..b64fb82b 100755 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -1,9 +1,11 @@ #!/usr/bin/env bash - +# # Loads the system's Bash completion modules. # If Homebrew is installed (OS X), it's Bash completion modules are loaded. -if [[ -r /etc/bash_completion ]] ; then +if [[ -r "${BASH_COMPLETION:-}" ]] ; then + source "${BASH_COMPLETION}" +elif [[ -r /etc/bash_completion ]] ; then # shellcheck disable=SC1091 source /etc/bash_completion @@ -12,9 +14,7 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then # shellcheck disable=SC1091 source /etc/profile.d/bash_completion.sh -fi - -if [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then +elif [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path From a6d58351e7cb73786b58b8c4f805bfaac6451a10 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Mon, 4 Mar 2013 21:39:05 -0500 Subject: [PATCH 019/114] Fixed defaults autocompletion. Need to use grep WITHOUT case-sensitivity. Otherwise results such as com.apple.iChat and com.apple.imagent won't be handled correctly and neither one can be completed. Fixed another comparison that prevented "defaults read com.apple.iChat " from correctly returning the available defaults keys in that file. --- completion/available/defaults.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/defaults.completion.bash b/completion/available/defaults.completion.bash index 5a8d0340..1a4ad620 100644 --- a/completion/available/defaults.completion.bash +++ b/completion/available/defaults.completion.bash @@ -13,7 +13,7 @@ _defaults_domains() COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} - local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep -i "^$cur" ) + local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep "^$cur" ) local IFS=$'\n' COMPREPLY=( $domains ) if [[ $( echo '-app' | grep "^$cur" ) ]]; then @@ -56,7 +56,7 @@ _defaults() # Both a domain and command have been specified - if [[ ${COMP_WORDS[1]} == [${cmds// /|}] ]]; then + if [[ ${COMP_WORDS[1]} =~ [${cmds// /|}] ]]; then cmd=${COMP_WORDS[1]} domain=${COMP_WORDS[2]} key_index=3 From de9ea54b81d451f3232e5fa8268de9626f5f5508 Mon Sep 17 00:00:00 2001 From: John D Pell <52194+gaelicWizard@users.noreply.github.com> Date: Sat, 14 Aug 2021 00:20:12 -0700 Subject: [PATCH 020/114] Don't call external `uname` when `$OSTYPE` will do (#1911) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib/helpers: use `$OSTYPE` instead of `$(uname)` * plugins/osx: use `$OSTYPE` instead of `$(uname)` * plugins/boot2docker: use `$OSTYPE` instead of `$(uname)` * plugins/python: use `$OSTYPE` instead of `$(uname)` * plugins/base: use `$OSTYPE` instead of `$(uname)` Alsö, use `[[` instead of `[` as the former has less insane argument handling being shell syntax rather than a builtin command that must emulate being a real binary * completion/brew: use `$OSTYPE` instead of `$(uname)` * completion/git: use `$OSTYPE` instead of `$(uname)` Alsö, use `[[` instead of `[`. * completion/fabric: use `$OSTYPE` instead of `uname` * theme/demula: use `$OSTYPE` instead of `$(uname)` * theme/rana: use `$OSTYPE` instead of `$(uname)` --- completion/available/brew.completion.bash | 2 +- completion/available/fabric.completion.bash | 4 ++-- completion/available/git.completion.bash | 4 ++-- lib/helpers.bash | 4 ++-- plugins/available/base.plugin.bash | 23 +++++++++++---------- plugins/available/boot2docker.plugin.bash | 2 +- plugins/available/osx.plugin.bash | 12 +++++------ plugins/available/python.plugin.bash | 4 ++-- themes/demula/demula.theme.bash | 2 +- themes/rana/rana.theme.bash | 2 +- 10 files changed, 30 insertions(+), 29 deletions(-) mode change 100644 => 100755 completion/available/fabric.completion.bash mode change 100644 => 100755 completion/available/git.completion.bash mode change 100644 => 100755 lib/helpers.bash mode change 100644 => 100755 themes/demula/demula.theme.bash mode change 100644 => 100755 themes/rana/rana.theme.bash diff --git a/completion/available/brew.completion.bash b/completion/available/brew.completion.bash index 91c288de..2149d20d 100644 --- a/completion/available/brew.completion.bash +++ b/completion/available/brew.completion.bash @@ -5,7 +5,7 @@ about-completion "brew completion" # Load late to make sure `system` completion loads first # BASH_IT_LOAD_PRIORITY: 375 -if [[ "$(uname -s)" != 'Darwin' ]]; then +if [[ "$OSTYPE" != 'darwin'* ]]; then _log_warning "unsupported operating system - only 'Darwin' is supported" return 0 fi diff --git a/completion/available/fabric.completion.bash b/completion/available/fabric.completion.bash old mode 100644 new mode 100755 index 7809b380..6f746454 --- a/completion/available/fabric.completion.bash +++ b/completion/available/fabric.completion.bash @@ -41,8 +41,8 @@ export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~" # Set command to get time of last file modification as seconds since Epoch -case `uname` in - Darwin|FreeBSD) +case "$OSTYPE" in + 'darwin'*|'freebsd'*) __FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'" ;; *) diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash old mode 100644 new mode 100755 index 0020ad1b..b9bb1bb6 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Only operate on MacOS since there are no linux paths -if [[ "$(uname -s)" != 'Darwin' ]] ; then +if [[ "$OSTYPE" != 'darwin'* ]] ; then _log_warning "unsupported operating system - only 'Darwin' is supported" return 0 fi @@ -24,7 +24,7 @@ _git_bash_completion_paths=( # Load the first completion file found for _comp_path in "${_git_bash_completion_paths[@]}" ; do - if [ -r "$_comp_path" ] ; then + if [[ -r "$_comp_path" ]] ; then _git_bash_completion_found=true source "$_comp_path" break diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100644 new mode 100755 index 26956193..34149040 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -11,8 +11,8 @@ BASH_IT_LOAD_PRIORITY_SEPARATOR="---" # 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) -case "$(uname)" in - Darwin*) BASH_IT_SED_I_PARAMETERS=(-i "") +case "$OSTYPE" in + 'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "") esac function _command_exists () diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 6da1384e..922fd9ec 100755 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -33,7 +33,7 @@ function myip () for url in ${list[*]} do res=$(curl -fs "${url}") - if [ $? -eq 0 ];then + if [[ $? -eq 0 ]];then break; fi done @@ -48,7 +48,7 @@ function pickfrom () example '$ pickfrom /usr/share/dict/words' group 'base' local file=$1 - [ -z "$file" ] && reference $FUNCNAME && return + [[ -z "$file" ]] && reference $FUNCNAME && return length=$(cat $file | wc -l) n=$(expr $RANDOM \* $length \/ 32768 + 1) head -n $n $file | tail -1 @@ -70,7 +70,7 @@ function passgen () # Create alias pass to passgen when pass isn't installed or # BASH_IT_LEGACY_PASS is true. -if ! command -v pass &>/dev/null || [ "$BASH_IT_LEGACY_PASS" = true ] +if ! command -v pass &>/dev/null || [[ "$BASH_IT_LEGACY_PASS" = true ]] then alias pass=passgen fi @@ -129,15 +129,15 @@ function usage () about 'disk usage per directory, in Mac OS X and Linux' param '1: directory name' group 'base' - if [ $(uname) = "Darwin" ]; then + if [[ "$OSTYPE" == 'darwin'* ]]; then if [ -n "$1" ]; then du -hd 1 "$1" else du -hd 1 fi - elif [ $(uname) = "Linux" ]; then - if [ -n "$1" ]; then + elif [[ "$OSTYPE" = 'linux'* ]]; then + if [[ -n "$1" ]]; then du -h --max-depth=1 "$1" else du -h --max-depth=1 @@ -145,7 +145,8 @@ function usage () fi } -if [ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ] && [ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]; then +if [[ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ]] && [[ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]] +then # if user has installed todo plugin, skip this... function t () { @@ -180,11 +181,11 @@ mkiso () group 'base' if type "mkisofs" > /dev/null; then - [ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1 - [ -z ${2+x} ] && local destpath=../ || local destpath=$2 - [ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3 + [[ -z ${1+x} ]] && local isoname=${PWD##*/} || local isoname=$1 + [[ -z ${2+x} ]] && local destpath=../ || local destpath=$2 + [[ -z ${3+x} ]] && local srcpath=${PWD} || local srcpath=$3 - if [ ! -f "${destpath}${isoname}.iso" ]; then + if [[ ! -f "${destpath}${isoname}.iso" ]]; then echo "writing ${isoname}.iso to ${destpath} from ${srcpath}" mkisofs -V ${isoname} -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}" else diff --git a/plugins/available/boot2docker.plugin.bash b/plugins/available/boot2docker.plugin.bash index c8b389c3..f19e91ef 100644 --- a/plugins/available/boot2docker.plugin.bash +++ b/plugins/available/boot2docker.plugin.bash @@ -3,7 +3,7 @@ about-plugin 'Helpers to get Docker setup correctly for boot2docker' # Note, this might need to be different if you have an older version # of boot2docker, or its configured for a different IP -if [[ `uname -s` == "Darwin" ]]; then +if [[ "$OSTYPE" == 'darwin'* ]]; then export DOCKER_HOST="tcp://192.168.59.103:2376" export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm" export DOCKER_TLS_VERIFY=1 diff --git a/plugins/available/osx.plugin.bash b/plugins/available/osx.plugin.bash index 2c16820c..ca1f66b8 100644 --- a/plugins/available/osx.plugin.bash +++ b/plugins/available/osx.plugin.bash @@ -2,7 +2,7 @@ cite about-plugin about-plugin 'osx-specific functions' # OS X: Open new tabs in same directory -if [ $(uname) = "Darwin" ]; then +if [[ $OSTYPE == 'darwin'* ]]; then if type update_terminal_cwd > /dev/null 2>&1 ; then if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then PROMPT_COMMAND="${PROMPT_COMMAND%;};update_terminal_cwd" @@ -46,13 +46,13 @@ function dock-switch() { example '$ dock-switch 2d' group 'osx' - if [ $(uname) = "Darwin" ]; then + if [[ "$OSTYPE" = 'darwin'* ]]; then - if [ $1 = 3d ] ; then + if [[ $1 = 3d ]] ; then defaults write com.apple.dock no-glass -boolean NO killall Dock - elif [ $1 = 2d ] ; then + elif [[ $1 = 2d ]] ; then defaults write com.apple.dock no-glass -boolean YES killall Dock @@ -90,7 +90,7 @@ function prevcurl() { param '1: url' group 'osx' - if [ ! $(uname) = "Darwin" ] + if [[ ! $OSTYPE = 'darwin'* ]] then echo "This function only works with Mac OS X" return 1 @@ -103,7 +103,7 @@ function refresh-launchpad() { example '$ refresh-launchpad' group 'osx' - if [ $(uname) = "Darwin" ];then + if [[ "$OSTYPE" = 'darwin'* ]];then defaults write com.apple.dock ResetLaunchPad -bool TRUE killall Dock else diff --git a/plugins/available/python.plugin.bash b/plugins/available/python.plugin.bash index ceba6268..77fa7dd6 100644 --- a/plugins/available/python.plugin.bash +++ b/plugins/available/python.plugin.bash @@ -1,7 +1,7 @@ cite about-plugin about-plugin 'alias "shttp" to SimpleHTTPServer' -if [ $(uname) = "Linux" ] +if [[ "$OSTYPE" == 'linux'* ]] then alias shttp='python2 -m SimpleHTTPServer' else @@ -16,7 +16,7 @@ function pyedit() { xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"` - if [ "$xpyc" == "" ]; then + if [[ "$xpyc" == "" ]]; then echo "Python module $1 not found" return -1 diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash old mode 100644 new mode 100755 index e85c18f7..7d8d6cc8 --- a/themes/demula/demula.theme.bash +++ b/themes/demula/demula.theme.bash @@ -98,7 +98,7 @@ prompt() { local MOVE_CURSOR_RIGHTMOST='\033[500C' local MOVE_CURSOR_5_LEFT='\033[5D' - if [ $(uname) = "Linux" ]; + if [[ "$OSTYPE" = 'linux'* ]] then PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT} $(safe_battery_charge)${RESTORE_CURSOR}\ diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash old mode 100644 new mode 100755 index 25530397..3da74d6d --- a/themes/rana/rana.theme.bash +++ b/themes/rana/rana.theme.bash @@ -181,7 +181,7 @@ prompt() { local MOVE_CURSOR_RIGHTMOST='\033[500C' local MOVE_CURSOR_5_LEFT='\033[5D' - if [ $(uname) = "Linux" ]; + if [[ "$OSTYPE" == 'linux'* ]]; then PS1="${TITLEBAR} ${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\ From 6ee4cb459798831d8f887b14feeef59c20d4772d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 12 Aug 2021 22:07:38 -0700 Subject: [PATCH 021/114] EditorConfig: don't specify indent size When using tabs, `indent_size` should be set to `tab`, which is the default. Furthermore, `tab_width` (which is likely what was intended when `indent_size` was entered) should be left up to the user. If the user likes an 8-character indent, then let them. If they like 2-character indent size, then let them. Using tabs means that this all works normally for everyone, even if it's different on different screens. --- .editorconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index e35a1b04..e0eb8455 100755 --- a/.editorconfig +++ b/.editorconfig @@ -17,7 +17,6 @@ indent_style = tab [{**.*sh,test/run}] indent_style = tab -indent_size = 4 shell_variant = bash binary_next_line = true # like -bn From 67eff71d7234a7b4f899e894997669b0ae980646 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 15 Aug 2021 21:27:59 +0300 Subject: [PATCH 022/114] defaults: Revert to old comparison Also fix a small bug along the way :) --- completion/available/defaults.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/defaults.completion.bash b/completion/available/defaults.completion.bash index 1a4ad620..c43c0aae 100644 --- a/completion/available/defaults.completion.bash +++ b/completion/available/defaults.completion.bash @@ -41,8 +41,8 @@ _defaults() COMPREPLY=( $( compgen -W "$cmds" -- $cur ) ) return 0 elif [[ "$prev" == "-host" ]]; then - return 0 _known_hosts -a + return 0 else _defaults_domains return 0 @@ -56,7 +56,7 @@ _defaults() # Both a domain and command have been specified - if [[ ${COMP_WORDS[1]} =~ [${cmds// /|}] ]]; then + if [[ ${COMP_WORDS[1]} == [${cmds// /|}] ]]; then cmd=${COMP_WORDS[1]} domain=${COMP_WORDS[2]} key_index=3 From caec973c18844b6edaf6ba62450867c7165e801f Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 17 Aug 2021 23:40:19 +0300 Subject: [PATCH 023/114] helpers: Pop pwd correctly when not needing to update --- lib/helpers.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 34149040..31e3fec8 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -243,6 +243,7 @@ _bash-it-update-() { if [[ -z "$TARGET" ]]; then echo "Can not find tags, so can not update to latest stable version..." + cd "${old_pwd}" &> /dev/null return fi else From 9566a3ec18e6e39b9457f4d79b85192a0aa0459d Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 17 Aug 2021 23:49:04 +0300 Subject: [PATCH 024/114] helpers: Improve pull_and_update_inner by restoring old pwd Renamed the function to _bash-it_update_migrate_and_restart Use pushd/popd instead of passing another parameter Document the function so it will be clear that it does not return --- lib/helpers.bash | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 31e3fec8..4d058fd1 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -194,7 +194,10 @@ _bash-it-update-stable() { _bash-it-update- stable "$@" } -_bash-it_pull_and_update_inner() { +_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' git checkout "$1" &> /dev/null if [[ $? -eq 0 ]]; then echo "Bash-it successfully updated." @@ -203,7 +206,9 @@ _bash-it_pull_and_update_inner() { _bash-it-migrate echo "" echo "All done, enjoy!" - bash-it restart + # Don't forget to restore the original pwd! + popd &> /dev/null + _bash-it-restart else echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." fi @@ -220,9 +225,8 @@ _bash-it-update-() { silent=true fi done - local old_pwd="${PWD}" - cd "${BASH_IT}" || return + pushd "${BASH_IT}" &> /dev/null || return DIFF=$(git diff --name-status) [ -n "$DIFF" ] && echo -e "Local changes detected in bash-it directory. Clean '$BASH_IT' directory to proceed.\n$DIFF" && return 1 @@ -243,7 +247,7 @@ _bash-it-update-() { if [[ -z "$TARGET" ]]; then echo "Can not find tags, so can not update to latest stable version..." - cd "${old_pwd}" &> /dev/null + popd &> /dev/null return fi else @@ -284,12 +288,12 @@ _bash-it-update-() { if [[ $silent ]]; then echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..." - _bash-it_pull_and_update_inner $TARGET $version + _bash-it_update_migrate_and_restart $TARGET $version else read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP case $RESP in [yY]|"") - _bash-it_pull_and_update_inner $TARGET $version + _bash-it_update_migrate_and_restart $TARGET $version ;; [nN]) echo "Not updating…" @@ -306,7 +310,7 @@ _bash-it-update-() { echo "Bash-it is up to date, nothing to do!" fi fi - cd "${old_pwd}" &> /dev/null || return + popd &> /dev/null } _bash-it-migrate() { From 9e255c21392adf612f735381c98ec9e2683d6c21 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 8 Aug 2021 00:54:27 -0400 Subject: [PATCH 025/114] lib/helpers: new function to set BASH_IT_HOMEBREW_PREFIX New function `_bash_it_homebrew_check()` sets global variable `$BASH_IT_HOMEBREW_PREFIX` using `brew --prefix` if `brew` exists as a valid command. If `brew` isn't installed, then return failure. Plugins can test for `brew` by calling this function and, if it succeeds, they can rely on `$BASH_IT_HOMEBREW_PREFIX` being defined properly. --- lib/helpers.bash | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 4d058fd1..82c710a0 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -48,6 +48,19 @@ function _completion_exists () complete -p "$1" &> /dev/null && _log_warning "$msg" ; } +function _bash_it_homebrew_check() +{ + if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]] + then # variable isn't set + if _binary_exists 'brew' + then # Homebrew is installed + BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)" + else # Homebrew is not installed. + false # return failure if brew not installed. + fi + fi +} + function _make_reload_alias() { echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" } From 65ef8e2e8be9fc6ded3611751725a32548c933c2 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 11 Aug 2021 18:05:20 -0700 Subject: [PATCH 026/114] Use _bash_it_homebrew_check() in plugins, completions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use new function `_bash_it_homebrew_check()` in existing plugins and completions which look for Homebrew. Alsö, use `$OSTYPE` instead of calling external `uname` binary. --- completion/available/brew.completion.bash | 16 +++++++--------- completion/available/system.completion.bash | 9 ++++----- plugins/available/autojump.plugin.bash | 4 ++-- plugins/available/nvm.plugin.bash | 4 ++-- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/completion/available/brew.completion.bash b/completion/available/brew.completion.bash index 2149d20d..61998f8a 100644 --- a/completion/available/brew.completion.bash +++ b/completion/available/brew.completion.bash @@ -11,22 +11,20 @@ if [[ "$OSTYPE" != 'darwin'* ]]; then fi # Make sure brew is installed -_command_exists brew || return 0 +_bash_it_homebrew_check || return 0 -BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} - -if [[ -r "$BREW_PREFIX"/etc/bash_completion.d/brew ]]; then +if [[ -r "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" ]]; then # shellcheck disable=1090 - source "$BREW_PREFIX"/etc/bash_completion.d/brew + source "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" -elif [[ -r "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]]; then +elif [[ -r "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" ]]; then # shellcheck disable=1090 - source "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh + source "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" -elif [[ -f "$BREW_PREFIX"/completions/bash/brew ]]; then +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 - source "$BREW_PREFIX"/completions/bash/brew + source "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew" fi diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index b64fb82b..142e0880 100755 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -14,12 +14,11 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then # shellcheck disable=SC1091 source /etc/profile.d/bash_completion.sh -elif [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then - BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} - +elif _bash_it_homebrew_check +then # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path - if [[ -r "$BREW_PREFIX"/etc/bash_completion ]] ; then + if [[ -r "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then # shellcheck disable=SC1090 - source "$BREW_PREFIX"/etc/bash_completion + source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh fi fi diff --git a/plugins/available/autojump.plugin.bash b/plugins/available/autojump.plugin.bash index 345ecadb..7e6df7fc 100644 --- a/plugins/available/autojump.plugin.bash +++ b/plugins/available/autojump.plugin.bash @@ -3,8 +3,8 @@ about-plugin 'Autojump configuration, see https://github.com/wting/autojump for # Only supports the Homebrew variant, Debian and Arch at the moment. # Feel free to provide a PR to support other install locations -if command -v brew &>/dev/null && [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]]; then - . $(brew --prefix)/etc/profile.d/autojump.sh +if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then + . "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" elif command -v dpkg &>/dev/null && dpkg -s autojump &>/dev/null ; then . "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" elif command -v pacman &>/dev/null && pacman -Q autojump &>/dev/null ; then diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index e845d922..87dce644 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -9,9 +9,9 @@ about-plugin 'node version manager configuration' export NVM_DIR=${NVM_DIR:-$HOME/.nvm} # This loads nvm -if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ] +if _bash_it_homebrew_check && [ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ] then - . $(brew --prefix nvm)/nvm.sh + . "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" else [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" fi From 0f28824ad5161ed0ad0e6c8c63713f28096fec7c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 14 Aug 2021 18:23:06 -0700 Subject: [PATCH 027/114] lib/helpers: invert test in _bash_it_homebrew_check() Check if `brew` is installed every time, and *unset* `$BASH_IT_HOMEBREW_PREFIX` if not found. This accounts for the edge-case of a user _uninstalling_ Homebrew without restarting the shell. --- lib/helpers.bash | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 82c710a0..a3468a63 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -50,14 +50,17 @@ function _completion_exists () function _bash_it_homebrew_check() { - if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]] - then # variable isn't set - if _binary_exists 'brew' - then # Homebrew is installed + if _binary_exists 'brew' + then # Homebrew is installed + if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]] + then # variable isn't set BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)" - else # Homebrew is not installed. - false # return failure if brew not installed. + else + true # Variable is set already, don't invoke `brew`. fi + else # Homebrew is not installed. + BASH_IT_HOMEBREW_PREFIX= # clear variable, if set to anything. + false # return failure if brew not installed. fi } From 02c13b7921ac86e8ec4742ce82c9c883f678c3da Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 20:02:48 -0700 Subject: [PATCH 028/114] lib/log: handle undefined variables If the user hasn't defined BASH_IT_LOG_LEVEL, then the integer comparison fails. Handle it by defaulting to '1'. If lib/log is loaded improperly, the BASH_IT_LOG_PREFIX may be undefined. Unlikely, but no harm in handling it too. Likewise, if no theme is loaded, then $echo_green, $echo_normal, et al are not defined. --- lib/log.bash | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) mode change 100644 => 100755 lib/log.bash diff --git a/lib/log.bash b/lib/log.bash old mode 100644 new mode 100755 index 105c9064..401fa3fa --- a/lib/log.bash +++ b/lib/log.bash @@ -22,8 +22,8 @@ function _log_general() param '3: message to log' group 'log' - message=$2${BASH_IT_LOG_PREFIX}$3 - _has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}" + message=$2${BASH_IT_LOG_PREFIX:-default: }$3 + _has_colors && echo -e "$1${message}${echo_normal:-}" || echo -e "${message}" } function _log_debug() @@ -33,8 +33,8 @@ function _log_debug() example '$ _log_debug "Loading plugin git..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 - _log_general "${echo_green}" "DEBUG: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 + _log_general "${echo_green:-}" "DEBUG: " "$1" } function _log_warning() @@ -44,7 +44,7 @@ function _log_warning() example '$ _log_warning "git binary not found, disabling git plugin..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 + [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 _log_general "${echo_yellow}" " WARN: " "$1" } @@ -55,6 +55,6 @@ function _log_error() example '$ _log_error "Failed to load git plugin..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 - _log_general "${echo_red}" "ERROR: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 + _log_general "${echo_red:-}" "ERROR: " "$1" } From bcd67db4ab7a6514ca58c24db9e53a4c1b60da8b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 21:09:51 -0700 Subject: [PATCH 029/114] lib/preview: handle unbound parameter If $BASH_PREVIEW is unset, treat it as blank. --- lib/preview.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/preview.bash b/lib/preview.bash index d0fb0623..418839cd 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -1,4 +1,4 @@ -if [[ $BASH_PREVIEW ]]; +if [[ "${BASH_PREVIEW:-}" ]]; then unset BASH_PREVIEW #Prevent infinite looping echo " From 5001995e92d78cc29c580d9f7e1ad5dad2dd0071 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 21:25:45 -0700 Subject: [PATCH 030/114] Deal with unabound BASH_IT_RELOAD_LEGACY --- bash_it.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_it.sh b/bash_it.sh index cb504202..12893990 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -144,7 +144,7 @@ if [ -e "$HOME/.jekyllconfig" ]; then fi # BASH_IT_RELOAD_LEGACY is set. -if ! command -v reload &> /dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then +if ! command -v reload &> /dev/null && [ -n "${BASH_IT_RELOAD_LEGACY:-}" ]; then case $OSTYPE in darwin*) alias reload='source ~/.bash_profile' From f71fa5be2cb5ce177e593a6f62cd584f0364d7dd Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 21:30:28 -0700 Subject: [PATCH 031/114] Handle unbound variables Handle BASH_IT, BASH_IT_OLD_BASH_SETUP, BASH_IT_THEME, BASH_THEME, and PROMPT. --- bash_it.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index 12893990..b8d3aeef 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -3,7 +3,7 @@ BASH_IT_LOG_PREFIX="core: main: " # Only set $BASH_IT if it's not already set -if [ -z "$BASH_IT" ]; then +if [ -z "${BASH_IT:-}" ]; then # Setting $BASH to maintain backwards compatibility export BASH_IT=$BASH BASH="$(bash -c 'echo $BASH')" @@ -20,12 +20,12 @@ source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh 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!" +[ -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 +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" + export BASH_IT_THEME="${BASH_THEME:-}" unset BASH_THEME fi @@ -122,7 +122,7 @@ for _bash_it_config_file in $CUSTOM; do done unset _bash_it_config_file -if [[ $PROMPT ]]; then +if [[ "${PROMPT:-}" ]]; then export PS1="\[""$PROMPT""\]" fi From 233fcc30910c84ddd490ea41644f881c1b8fdba1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 21:46:18 -0700 Subject: [PATCH 032/114] lib/log: handle undefined variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expressly deal with if $echo_yellow hasn’t been defined --- lib/log.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/log.bash b/lib/log.bash index 401fa3fa..32626d76 100755 --- a/lib/log.bash +++ b/lib/log.bash @@ -45,7 +45,7 @@ function _log_warning() group 'log' [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 - _log_general "${echo_yellow}" " WARN: " "$1" + _log_general "${echo_yellow:-}" " WARN: " "$1" } function _log_error() From 0eff44930c3aa9b01d408ff06374a671c8266263 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 21:59:40 -0700 Subject: [PATCH 033/114] lib/utilities: handle unbound parameter Expressly handle unbound $BASH_IT_GREP when testing for value --- lib/utilities.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 lib/utilities.bash diff --git a/lib/utilities.bash b/lib/utilities.bash old mode 100644 new mode 100755 index db63956d..b6322a1d --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -58,7 +58,7 @@ _bash-it-array-dedup() { # Outputs a full path of the grep found on the filesystem _bash-it-grep() { - if [[ -z "${BASH_IT_GREP}" ]] ; then + if [[ -z "${BASH_IT_GREP:-}" ]] ; then export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')" fi printf "%s " "${BASH_IT_GREP}" From 8fb75cf0e396952e152424cb5fdadb2d1ae1e1bc Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 23:01:02 -0700 Subject: [PATCH 034/114] lib/helpers: handle unbound parameter Expressly handle $BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE being not-set as being blank. --- lib/helpers.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index a3468a63..81d01c72 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -156,7 +156,7 @@ bash-it () $func $arg done - if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then + if [ -n "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:-}" ]; then _bash-it-reload fi else From bd9f4015a7d6b09d2848efaf393637836e7b48b7 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 23:18:56 -0700 Subject: [PATCH 035/114] lib/helpers: handle unset parameter Expressly handle $BASH_IT_REMOTE as blank when variable is not set. --- lib/helpers.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 81d01c72..a528c14c 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -354,8 +354,8 @@ _bash-it-migrate() { disable_func="_disable-$single_type" enable_func="_enable-$single_type" - $disable_func $component_name - $enable_func $component_name + $disable_func "$component_name" + $enable_func "$component_name" done done @@ -375,7 +375,7 @@ _bash-it-version() { cd "${BASH_IT}" || return - if [ -z $BASH_IT_REMOTE ]; then + if [ -z "${BASH_IT_REMOTE:-}" ]; then BASH_IT_REMOTE="origin" fi From cd65e0925fe4338caebb171b8c2da13322f3e2de Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 14 Aug 2021 20:19:12 -0700 Subject: [PATCH 036/114] plugins/base: unbound BASH_IT_LEGACY_PASS Expressly handle as blank when $BASH_IT_LEGACY_PASS is not set. --- plugins/available/base.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 922fd9ec..8499a2df 100755 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -70,7 +70,7 @@ function passgen () # Create alias pass to passgen when pass isn't installed or # BASH_IT_LEGACY_PASS is true. -if ! command -v pass &>/dev/null || [[ "$BASH_IT_LEGACY_PASS" = true ]] +if ! command -v pass &>/dev/null || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]] then alias pass=passgen fi From 0c412442f5108805a1f5e3cd602b1458b1f16556 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 11 Aug 2021 18:11:44 -0700 Subject: [PATCH 037/114] completion/system: give up hope Give up and accept defeat that bash-completion can't reasonably be audited for unbound parameters. Wrap invocation with disabling strictness, and restore after if it was enabled. --- completion/available/system.completion.bash | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index 142e0880..c4230a1c 100755 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -3,6 +3,14 @@ # Loads the system's Bash completion modules. # If Homebrew is installed (OS X), it's Bash completion modules are loaded. +if shopt -qo nounset +then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase. + BASH_IT_RESTORE_NOUNSET=true + shopt -uo nounset +else + BASH_IT_RESTORE_NOUNSET=false +fi + if [[ -r "${BASH_COMPLETION:-}" ]] ; then source "${BASH_COMPLETION}" elif [[ -r /etc/bash_completion ]] ; then @@ -22,3 +30,9 @@ then source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh fi fi + +if $BASH_IT_RESTORE_NOUNSET +then + shopt -so nounset +fi +unset BASH_IT_RESTORE_NOUNSET From 3654198deb8e56f915515dbba96f1422f6d52016 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 1 Aug 2021 21:45:35 -0700 Subject: [PATCH 038/114] Tests for 'default' prefix --- test/lib/log.bats | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/lib/log.bats b/test/lib/log.bats index 015068e6..f4a04f0e 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -11,19 +11,19 @@ load ../../lib/log @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL run _log_debug "test test test" - assert_output "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 run _log_warning "test test test" - assert_output " WARN: 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 run _log_error "test test test" - assert_output "ERROR: test test test" + assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { @@ -35,13 +35,13 @@ load ../../lib/log @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING run _log_warning "test test test" - assert_output " WARN: 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 run _log_error "test test test" - assert_output "ERROR: test test test" + assert_output "ERROR: default: test test test" } @@ -60,7 +60,7 @@ load ../../lib/log @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR run _log_error "test test test" - assert_output "ERROR: test test test" + assert_output "ERROR: default: test test test" } @test "lib log: basic debug silent logging" { From 85408743fa41a0331fb6fed57e0539a0a43117df Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 3 Aug 2021 18:18:14 -0400 Subject: [PATCH 039/114] lib/log: default to no logging at all Set the default when BASH_IT_LOG_LEVEL is unbound to log level none: no warnings or errors are reported at all. --- lib/log.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/log.bash b/lib/log.bash index 32626d76..6bc53a12 100755 --- a/lib/log.bash +++ b/lib/log.bash @@ -33,7 +33,7 @@ function _log_debug() example '$ _log_debug "Loading plugin git..."' group 'log' - [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 _log_general "${echo_green:-}" "DEBUG: " "$1" } @@ -44,7 +44,7 @@ function _log_warning() example '$ _log_warning "git binary not found, disabling git plugin..."' group 'log' - [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 _log_general "${echo_yellow:-}" " WARN: " "$1" } @@ -55,6 +55,6 @@ function _log_error() example '$ _log_error "Failed to load git plugin..."' group 'log' - [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 _log_general "${echo_red:-}" "ERROR: " "$1" } From ecfcaba32eb0269cb854a7a677d14bb0489eeba8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 26 Aug 2021 13:56:58 -0700 Subject: [PATCH 040/114] completion/system: accomodate multiple versions For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2. --- completion/available/system.completion.bash | 39 ++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index c4230a1c..a8a29c84 100755 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -5,14 +5,16 @@ if shopt -qo nounset then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase. - BASH_IT_RESTORE_NOUNSET=true + __bash_it_restore_nounset=true shopt -uo nounset else - BASH_IT_RESTORE_NOUNSET=false + __bash_it_restore_nounset=false fi if [[ -r "${BASH_COMPLETION:-}" ]] ; then + # shellcheck disable=SC1091 source "${BASH_COMPLETION}" + elif [[ -r /etc/bash_completion ]] ; then # shellcheck disable=SC1091 source /etc/bash_completion @@ -24,15 +26,34 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then elif _bash_it_homebrew_check then - # 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=SC1090 - source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh - fi + : ${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." + ;; + 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" + if [[ -r "$BASH_COMPLETION" ]] ; then + # shellcheck disable=SC1090 + source "$BASH_COMPLETION" + else + unset BASH_COMPLETION + fi + ;; + 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=SC1090 + source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh + fi + ;; + esac fi -if $BASH_IT_RESTORE_NOUNSET +if $__bash_it_restore_nounset then shopt -so nounset fi -unset BASH_IT_RESTORE_NOUNSET +unset __bash_it_restore_nounset From feacd560b6a15e29b5ebe4c53d6e8920050111bd Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 14 Aug 2021 18:26:45 -0700 Subject: [PATCH 041/114] completion/system: update wording on shell version --- completion/available/system.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index a8a29c84..113a93f5 100755 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -30,7 +30,7 @@ then case "${BASH_VERSION}" in 1*|2*|3.0*|3.1*) - _log_warning "Cannot load completion due to version of shell." + _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. From c6f6d8c27a03cfe67dcf9cefcc32dba73ae549d8 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Thu, 9 Sep 2021 11:18:17 +0300 Subject: [PATCH 042/114] plugins: Fix shellcheck warnings on already linted files --- plugins/available/alias-completion.plugin.bash | 2 +- plugins/available/git.plugin.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index 390b10e3..0db9b04b 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -70,7 +70,7 @@ function alias_completion { local compl_func="${new_completion/#* -F /}" compl_func="${compl_func%% *}" # avoid recursive call loops by ignoring our own functions - if [[ "${compl_func#_$namespace::}" == "$compl_func" ]]; then + if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then local compl_wrapper="_${namespace}::${alias_name}" echo "function $compl_wrapper { local compl_word=\$2 diff --git a/plugins/available/git.plugin.bash b/plugins/available/git.plugin.bash index e4efc3fe..6a85e7dc 100644 --- a/plugins/available/git.plugin.bash +++ b/plugins/available/git.plugin.bash @@ -309,7 +309,7 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo [$DATE] + echo "[$DATE]" git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00" NEXT=$DATE done From ec3b8d645f5d06f840f72a901a5e6c816809cc20 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 10 Sep 2021 16:54:51 +0300 Subject: [PATCH 043/114] Revert "ci: Remove macos-11.0 as it is unreliable" --- .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 dcef30aa..03b75882 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15] + os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15, macos-11.0] runs-on: ${{ matrix.os }} From 8c0860588dc2d44a6edba4ee10a9c55e70e1f24f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 23:15:49 -0700 Subject: [PATCH 044/114] themes/base: don't invoke svn if possible If we are specifically in the situation #1612, then check for a working `svn` command. If we're not in that situation, then don't waste time on it. --- test/fixtures/svn/broken/xcrun | 0 test/fixtures/svn/working/xcrun | 0 themes/base.theme.bash | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100755 test/fixtures/svn/broken/xcrun create mode 100755 test/fixtures/svn/working/xcrun diff --git a/test/fixtures/svn/broken/xcrun b/test/fixtures/svn/broken/xcrun new file mode 100755 index 00000000..e69de29b diff --git a/test/fixtures/svn/working/xcrun b/test/fixtures/svn/working/xcrun new file mode 100755 index 00000000..e69de29b diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 4d6a1b7f..e39dd121 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -92,7 +92,7 @@ SVN_EXE=$(which svn 2> /dev/null || 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" ]]; then +if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then if ! "$SVN_EXE" --version > /dev/null 2>&1; then # Unset the SVN exe variable so that SVN commands are avoided. SVN_EXE="" From 9c1dbbcf12a59fc5a8c7c4389e283b4e2c02c477 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 29 Jul 2021 00:21:18 -0700 Subject: [PATCH 045/114] lib/scmhelpers: reorder SCM detection waterfall This reduces the need to invoke subprocesses --- themes/base.theme.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index e39dd121..51c34e2e 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -104,18 +104,18 @@ function scm { SCM=$SCM_NONE elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT - elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then - SCM=$SCM_GIT - elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then - SCM=$SCM_P4 elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG - elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; 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 fi From 476fcb4325837b10bb17a68eb886ac18a909e7c4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 09:59:04 -0700 Subject: [PATCH 046/114] lib/theme: new `_bash_it_appearance_scm_init()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wrap init code in a function and call the function immediately. Several plugins do this, and it allows us to more easily implement a hooks-based system in the future. Alsö, avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot. --- test/themes/base.theme.svn.bats | 23 ++++++++++++----------- themes/base.theme.bash | 30 +++++++++++++++++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index f2866c8d..d1c2c311 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -7,7 +7,6 @@ load ../../lib/log cite _about _param _example _group _author _version load ../../lib/helpers -load ../../themes/base.theme function local_setup { setup_test_fixture @@ -23,6 +22,8 @@ function local_setup { fi export OLD_PATH="$PATH" + + load ../../themes/base.theme } function local_teardown { @@ -56,8 +57,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -73,8 +74,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -89,8 +90,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used @@ -103,8 +104,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is not used @@ -120,8 +121,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 51c34e2e..5cc791b4 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -85,19 +85,27 @@ RBENV_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' -GIT_EXE=$(which git 2> /dev/null || true) -P4_EXE=$(which p4 2> /dev/null || true) -HG_EXE=$(which hg 2> /dev/null || true) -SVN_EXE=$(which svn 2> /dev/null || true) +: "${GIT_EXE:=$SCM_GIT}" +: "${P4_EXE:=$SCM_P4}" +: "${HG_EXE:=$SCM_HG}" +: "${SVN_EXE:=$SCM_SVN}" -# 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 - # Unset the SVN exe variable so that SVN commands are avoided. - SVN_EXE="" +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)" + + # 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 + # Unset the SVN exe variable so that SVN commands are avoided. + SVN_EXE="" + fi fi -fi +} +_bash_it_appearance_scm_init function scm { if [[ "$SCM_CHECK" = false ]]; then From ffe15ebfe04e19db104527d87d56eefc06841fb6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 13:36:10 -0700 Subject: [PATCH 047/114] themes: use `_save-and-reload-history()` First pass to use _Bash It_'s automatic history management. --- themes/codeword/codeword.theme.bash | 10 +++------- themes/doubletime/doubletime.theme.bash | 6 ++---- .../doubletime_multiline.theme.bash | 6 ++---- .../doubletime_multiline_pyonly.theme.bash | 6 ++---- themes/nwinkler/nwinkler.theme.bash | 6 ++---- .../nwinkler_random_colors.theme.bash | 6 ++---- themes/pete/pete.theme.bash | 6 ++---- themes/rainbowbrite/rainbowbrite.theme.bash | 6 ++---- 8 files changed, 17 insertions(+), 35 deletions(-) mode change 100644 => 100755 themes/doubletime/doubletime.theme.bash mode change 100644 => 100755 themes/doubletime_multiline/doubletime_multiline.theme.bash mode change 100644 => 100755 themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash mode change 100644 => 100755 themes/nwinkler/nwinkler.theme.bash mode change 100644 => 100755 themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash mode change 100644 => 100755 themes/pete/pete.theme.bash mode change 100644 => 100755 themes/rainbowbrite/rainbowbrite.theme.bash diff --git a/themes/codeword/codeword.theme.bash b/themes/codeword/codeword.theme.bash index e23a3fc3..beab6a4a 100644 --- a/themes/codeword/codeword.theme.bash +++ b/themes/codeword/codeword.theme.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash + SCM_THEME_PROMPT_PREFIX=${SCM_THEME_PROMPT_SUFFIX} SCM_THEME_PROMPT_DIRTY="${bold_red} ✗${normal}" SCM_THEME_PROMPT_CLEAN="${bold_green} ✓${normal}" @@ -19,11 +21,5 @@ prompt() { PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) " } -share_history() { - history -a - history -c - history -r -} - -safe_append_prompt_command share_history +safe_append_prompt_command '_save-and-reload-history 1' safe_append_prompt_command prompt diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash old mode 100644 new mode 100755 index 6b6aa150..8186db73 --- a/themes/doubletime/doubletime.theme.bash +++ b/themes/doubletime/doubletime.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash SCM_THEME_PROMPT_DIRTY='' SCM_THEME_PROMPT_CLEAN='' @@ -30,9 +30,7 @@ fi function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [${THEME_PROMPT_HOST_COLOR}\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w $(scm_prompt)$reset_color $ " diff --git a/themes/doubletime_multiline/doubletime_multiline.theme.bash b/themes/doubletime_multiline/doubletime_multiline.theme.bash old mode 100644 new mode 100755 index 6da88253..18213571 --- a/themes/doubletime_multiline/doubletime_multiline.theme.bash +++ b/themes/doubletime_multiline/doubletime_multiline.theme.bash @@ -1,12 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt) \w diff --git a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash old mode 100644 new mode 100755 index 5f1951e9..9bc4c334 --- a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash +++ b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash @@ -1,12 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt) \w diff --git a/themes/nwinkler/nwinkler.theme.bash b/themes/nwinkler/nwinkler.theme.bash old mode 100644 new mode 100755 index f9fe4933..983c8d00 --- a/themes/nwinkler/nwinkler.theme.bash +++ b/themes/nwinkler/nwinkler.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Two line prompt showing the following information: # (time) SCM [username@hostname] pwd (SCM branch SCM status) @@ -29,9 +29,7 @@ prompt_setter() { else PROMPT_END=$PROMPT_END_DIRTY fi # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)) $(scm_char) [${blue}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' diff --git a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash old mode 100644 new mode 100755 index f6eff908..05391b0b --- a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash +++ b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # Two line prompt showing the following information: # (time) SCM [username@hostname] pwd (SCM branch SCM status) @@ -96,9 +96,7 @@ prompt_setter() { else PROMPT_END=$PROMPT_END_DIRTY fi # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)${reset_color}) $(scm_char) [${USERNAME_COLOR}\u${reset_color}@${HOSTNAME_COLOR}\H${reset_color}] ${PATH_COLOR}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' diff --git a/themes/pete/pete.theme.bash b/themes/pete/pete.theme.bash old mode 100644 new mode 100755 index 73fdb053..d29553f8 --- a/themes/pete/pete.theme.bash +++ b/themes/pete/pete.theme.bash @@ -1,10 +1,8 @@ -#!/usr/bin/env bash +# shellcheck shell=bash prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)) $(scm_char) [$blue\u$reset_color@$green\H$reset_color] $yellow\w${reset_color}$(scm_prompt_info)$(ruby_version_prompt) $reset_color " PS2='> ' PS4='+ ' diff --git a/themes/rainbowbrite/rainbowbrite.theme.bash b/themes/rainbowbrite/rainbowbrite.theme.bash old mode 100644 new mode 100755 index 63c64b72..07e5843f --- a/themes/rainbowbrite/rainbowbrite.theme.bash +++ b/themes/rainbowbrite/rainbowbrite.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # based off of n0qorg # looks like, if you're in a git repo: @@ -7,9 +7,7 @@ prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 # displays user@server in purple # PS1="$red$(scm_char) $purple\u@\h$reset_color:$blue\w$yellow$(scm_prompt_info)$(ruby_version_prompt) $black\$$reset_color " # no user@server From 9d656747a9761306cf4d9b9875d0c659cc7da88c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 14:01:46 -0700 Subject: [PATCH 048/114] themes: remove executable bit --- themes/demula/demula.theme.bash | 0 themes/doubletime/doubletime.theme.bash | 0 themes/doubletime_multiline/doubletime_multiline.theme.bash | 0 .../doubletime_multiline_pyonly.theme.bash | 0 themes/liquidprompt/liquidprompt.theme.bash | 0 themes/nwinkler/nwinkler.theme.bash | 0 themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash | 0 themes/pete/pete.theme.bash | 0 themes/rainbowbrite/rainbowbrite.theme.bash | 0 themes/rana/rana.theme.bash | 0 10 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 themes/demula/demula.theme.bash mode change 100755 => 100644 themes/doubletime/doubletime.theme.bash mode change 100755 => 100644 themes/doubletime_multiline/doubletime_multiline.theme.bash mode change 100755 => 100644 themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash mode change 100755 => 100644 themes/liquidprompt/liquidprompt.theme.bash mode change 100755 => 100644 themes/nwinkler/nwinkler.theme.bash mode change 100755 => 100644 themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash mode change 100755 => 100644 themes/pete/pete.theme.bash mode change 100755 => 100644 themes/rainbowbrite/rainbowbrite.theme.bash mode change 100755 => 100644 themes/rana/rana.theme.bash diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash old mode 100755 new mode 100644 diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash old mode 100755 new mode 100644 diff --git a/themes/doubletime_multiline/doubletime_multiline.theme.bash b/themes/doubletime_multiline/doubletime_multiline.theme.bash old mode 100755 new mode 100644 diff --git a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash old mode 100755 new mode 100644 diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash old mode 100755 new mode 100644 diff --git a/themes/nwinkler/nwinkler.theme.bash b/themes/nwinkler/nwinkler.theme.bash old mode 100755 new mode 100644 diff --git a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash old mode 100755 new mode 100644 diff --git a/themes/pete/pete.theme.bash b/themes/pete/pete.theme.bash old mode 100755 new mode 100644 diff --git a/themes/rainbowbrite/rainbowbrite.theme.bash b/themes/rainbowbrite/rainbowbrite.theme.bash old mode 100755 new mode 100644 diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash old mode 100755 new mode 100644 From dee55a03cc373a2ac89a476b61912e7acfe8485a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 23:45:34 -0700 Subject: [PATCH 049/114] drop `dirname` in favor of native Bash strings (1 of 2) Convert `var=${dirname $filename)` to `var="${filename%/*}` in cases where there is no ambiguity. Make sure that the path in `$BASH_IT` is absolute because this path gets embedded in the template `.bash_profile` file if selected by the user. --- install.sh | 2 +- lib/utilities.bash | 8 ++++---- plugins/available/z_autoenv.plugin.bash | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 4940360f..13721fd2 100755 --- a/install.sh +++ b/install.sh @@ -184,7 +184,7 @@ if [[ $no_modify_config ]] && [[ $append_to_config ]]; then exit 1 fi -BASH_IT="$(cd "$(dirname "$0")" && pwd)" +BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)" case $OSTYPE in darwin*) diff --git a/lib/utilities.bash b/lib/utilities.bash index b6322a1d..e072b52d 100755 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -71,12 +71,12 @@ _bash-it-grep() { ########################################################################### _bash-it-component-help() { - local component=$(_bash-it-pluralize-component "${1}") - local file=$(_bash-it-component-cache-file ${component}) + local component="$(_bash-it-pluralize-component "${1}")" + local file="$(_bash-it-component-cache-file "${component}")" if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then rm -f "${file}" 2>/dev/null local func="_bash-it-${component}" - ${func} | $(_bash-it-grep) -E ' \[' | cat > ${file} + "${func}" | $(_bash-it-grep) -E ' \[' | cat > "${file}" fi cat "${file}" } @@ -84,7 +84,7 @@ _bash-it-component-help() { _bash-it-component-cache-file() { local component=$(_bash-it-pluralize-component "${1}") local file="${BASH_IT}/tmp/cache/${component}" - [[ -f ${file} ]] || mkdir -p $(dirname ${file}) + [[ -f "${file}" ]] || mkdir -p "${file%/*}" printf "${file}" } diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index 553a7ba3..a2f97d28 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -11,7 +11,7 @@ autoenv_init() typeset target home _file typeset -a _files target=$1 - home="$(dirname "$HOME")" + home="${HOME%/*}" _files=( $( while [[ "$PWD" != "/" && "$PWD" != "$home" ]] From 470341b23aef737faedc0c77909bfc21cc28abc0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 23:47:10 -0700 Subject: [PATCH 050/114] Drop `basename` in favor of Bash strings Convert `var=$(basename $file)` to `var="${file##*/}"` --- lib/helpers.bash | 10 +++++----- plugins/available/jekyll.plugin.bash | 10 +++++----- plugins/available/osx-timemachine.plugin.bash | 2 +- plugins/available/virtualenv.plugin.bash | 12 +++++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index a528c14c..9b95fe65 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -340,7 +340,7 @@ _bash-it-migrate() { do for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")` do - typeset ff=$(basename $f) + typeset ff="${f##*/}" # Get the type of component from the extension typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') @@ -501,7 +501,7 @@ _bash-it-describe () do # Check for both the old format without the load priority, and the extended format with the priority declare enabled_files enabled_file - enabled_file=$(basename $f) + enabled_file="${f##*/}" enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l) if [ $enabled_files -gt 0 ]; then @@ -603,9 +603,9 @@ _disable-thing () printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." return fi - rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" + rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}" else - rm "${BASH_IT}/enabled/$(basename $plugin_global)" + rm "${BASH_IT}/enabled/${plugin_global##*/}" fi fi @@ -681,7 +681,7 @@ _enable-thing () return fi - to_enable=$(basename $to_enable) + to_enable="${to_enable##*/}" # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) if [ ! -z "$enabled_plugin" ] ; then diff --git a/plugins/available/jekyll.plugin.bash b/plugins/available/jekyll.plugin.bash index 6254a87f..c340c432 100644 --- a/plugins/available/jekyll.plugin.bash +++ b/plugins/available/jekyll.plugin.bash @@ -16,7 +16,7 @@ editpost() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -77,7 +77,7 @@ newpost() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site JEKYLL_FORMATTING=${MARKUPS[$loc]} @@ -280,7 +280,7 @@ function testsite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -312,7 +312,7 @@ function buildsite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -347,7 +347,7 @@ function deploysite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site REMOTE=${REMOTES[$loc]} diff --git a/plugins/available/osx-timemachine.plugin.bash b/plugins/available/osx-timemachine.plugin.bash index f29d6ece..3d7ff00c 100644 --- a/plugins/available/osx-timemachine.plugin.bash +++ b/plugins/available/osx-timemachine.plugin.bash @@ -15,7 +15,7 @@ function time-machine-list-machines() { local tmdest="$(time-machine-destination)/Backups.backupdb" find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read line ; do - echo "$(basename "$line")" + echo "${line##*/}" done } diff --git a/plugins/available/virtualenv.plugin.bash b/plugins/available/virtualenv.plugin.bash index 468870cd..f1c85987 100644 --- a/plugins/available/virtualenv.plugin.bash +++ b/plugins/available/virtualenv.plugin.bash @@ -14,8 +14,8 @@ function mkvenv { about 'create a new virtualenv for this directory' group 'virtualenv' - cwd=`basename \`pwd\`` - mkvirtualenv --distribute $cwd + local cwd="${PWD##*/}" + mkvirtualenv --distribute "$cwd" } @@ -23,19 +23,21 @@ function mkvbranch { about 'create a new virtualenv for the current branch' group 'virtualenv' - mkvirtualenv --distribute "$(basename `pwd`)@$SCM_BRANCH" + local cwd="${PWD##*/}" + mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}" } function wovbranch { about 'sets workon branch' group 'virtualenv' - workon "$(basename `pwd`)@$SCM_BRANCH" + local cwd="${PWD##*/}" + workon "${cwd}@${SCM_BRANCH}" } function wovenv { about 'works on the virtualenv for this directory' group 'virtualenv' - workon "$(basename `pwd`)" + workon "${PWD##*/}" } From 435151819f0d76819256d03285fea4004432bee2 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 14 Sep 2021 23:30:05 -0700 Subject: [PATCH 051/114] EditorConfig: set `indent_size = tab` Despite `indent_size` being set to `tab` by default, it turns out that we set `indent_size` to `2` for `*` at the top of this file. So, for everywhere else, explicitly set `indent_size` to the default (`tab`). This should achieve the goal of my last patch to `.editorconfig`. --- .editorconfig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index e0eb8455..8a181ef5 100755 --- a/.editorconfig +++ b/.editorconfig @@ -13,16 +13,18 @@ insert_final_newline = true trim_trailing_whitespace = false [.git*] +indent_size = tab indent_style = tab [{**.*sh,test/run}] +indent_size = tab indent_style = tab shell_variant = bash binary_next_line = true # like -bn switch_case_indent = true # like -ci space_redirects = true # like -sr -keep_padding = false # like -kp +keep_padding = false # like -kp end_of_line = lf charset = utf-8 trim_trailing_whitespace = true From 1c3cbf7ca66dc0dc357683c936fdc8d3963212b3 Mon Sep 17 00:00:00 2001 From: John D Pell <52194+gaelicWizard@users.noreply.github.com> Date: Sat, 18 Sep 2021 02:50:59 -0700 Subject: [PATCH 052/114] Delete `.shellcheckrc` (#1947) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CI: disable Ubuntu 16.04 as it's EOL https://github.blog/changelog/2021-04-29-github-actions-ubuntu-16-04-lts-virtual-environment-will-be-removed-on-september-20-2021/ * main: lint false positive * install: lint * plugins/cmd-returned-notify: don't `export` * plugins/xterm: lint * plugins/git: lint * plugins/goenv: lint * plugins/alias-completion: lint false positives * plugins/alias-completion: fix SC2155, SC2154 Declare `locals` at the top of the function * completion: lint completions using `bash_completion` functions Match the style of the existing code * completion/knife: lint false positives * completion/knife: lint * completion/sdkman: lint * completion/composer: lint * Move `.shellcheckrc` under `themes/` * lib/theme: fix SC2155, SC2154, SC2034 * lib/colors: don't warn on unused variables We assign a large number of variables here and they may or may not be used anywhere else, so disable SC2034 for this file (only). Alsö disable SC2005 as the functions in this file were written before `printf` was invented and have to do some fancy metascripting to get escape sequences interpreted reliably. I’m not smart enough to fix this to use `printf`, so leave it for now. * themes/agnoster: lint * themes: disable SC2154 for colors Each one of these themes will need it’s own fix for SC2154, possibly upstream. Due to the way themes are, it's entirely normal to have a *lot* of false positives for SC2034. So much so, that I have to admit that it is probably just not worth linting for SC2034 despite my dislike of blanket ignore rules. * themes: disable SC2154, fix SC2155 Each one of these themes will need it’s own fix for SC2154, possibly upstream. Due to the way themes are, it's entirely normal to have a *lot* of false positives for SC2034. So much so, that I have to admit that it is probably just not worth linting for SC2034 despite my dislike of blanket ignore rules. * Delete `.shellcheckrc` * remove executable bit --- .github/workflows/ci.yml | 2 +- .shellcheckrc | 6 -- bash_it.sh | 3 +- completion/available/composer.completion.bash | 14 ++-- completion/available/dart.completion.bash | 2 + .../available/dmidecode.completion.bash | 2 + completion/available/knife.completion.bash | 12 ++-- completion/available/ngrok.completion.bash | 2 + .../available/notify-send.completion.bash | 2 + completion/available/sdkman.completion.bash | 16 +++-- completion/available/vuejs.completion.bash | 2 + hooks/dot-bash.sh | 2 +- hooks/dot-sh.sh | 2 +- install.sh | 28 ++++---- lib/helpers.bash | 0 lib/log.bash | 0 lib/search.bash | 0 lib/utilities.bash | 0 .../available/alias-completion.plugin.bash | 23 +++--- .../available/cmd-returned-notify.plugin.bash | 2 +- plugins/available/git.plugin.bash | 71 +++++++++---------- plugins/available/goenv.plugin.bash | 2 +- plugins/available/xterm.plugin.bash | 24 ++++--- scripts/reloader.bash | 3 +- themes/90210/90210.theme.bash | 5 +- themes/agnoster/agnoster.theme.bash | 3 +- themes/atomic/atomic.theme.bash | 2 + themes/bakke/bakke.theme.bash | 2 + themes/barbuk/barbuk.theme.bash | 2 + themes/base.theme.bash | 22 +++--- themes/binaryanomaly/binaryanomaly.theme.bash | 2 + themes/bira/bira.theme.bash | 2 + themes/bobby-python/bobby-python.theme.bash | 2 + themes/bobby/bobby.theme.bash | 2 + themes/brainy/brainy.theme.bash | 2 + themes/brunton/brunton.theme.bash | 2 + themes/candy/candy.theme.bash | 2 + themes/colors.theme.bash | 4 +- themes/easy/easy.theme.bash | 2 + themes/modern/modern.theme.bash | 2 + themes/powerline/powerline.base.bash | 22 +++--- themes/powerline/powerline.theme.bash | 1 + themes/pure/pure.theme.bash | 2 + themes/purity/purity.theme.bash | 6 +- 44 files changed, 183 insertions(+), 126 deletions(-) delete mode 100644 .shellcheckrc mode change 100755 => 100644 lib/helpers.bash mode change 100755 => 100644 lib/log.bash mode change 100755 => 100644 lib/search.bash mode change 100755 => 100644 lib/utilities.bash mode change 100644 => 100755 scripts/reloader.bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03b75882..f42c096b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15, macos-11.0] + os: [ubuntu-20.04, ubuntu-18.04, macos-10.15, macos-11.0] runs-on: ${{ matrix.os }} diff --git a/.shellcheckrc b/.shellcheckrc deleted file mode 100644 index 6418bd8f..00000000 --- a/.shellcheckrc +++ /dev/null @@ -1,6 +0,0 @@ -# We use colors and not assigned -disable=SC2154 -# Hard to fix -disable=SC2155 -# shellcheck is wrong on some -disable=SC2034 diff --git a/bash_it.sh b/bash_it.sh index b8d3aeef..679ffdaf 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -114,6 +114,7 @@ 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 BASH_IT_LOG_PREFIX="custom: $filename: " _log_debug "Loading custom file..." # shellcheck disable=SC1090 @@ -122,7 +123,7 @@ for _bash_it_config_file in $CUSTOM; do done unset _bash_it_config_file -if [[ "${PROMPT:-}" ]]; then +if [[ -n "${PROMPT:-}" ]]; then export PS1="\[""$PROMPT""\]" fi diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index eefe50fa..176f0832 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -3,14 +3,14 @@ cite "about-completion" about-completion "composer completion" function __composer_completion() { - local cur coms opts com + local cur coms opts com words COMPREPLY=() _get_comp_words_by_ref -n : cur words # lookup for command for word in "${words[@]:1}"; do - if [[ $word != -* ]]; then - com=$word + if [[ "${word}" != -* ]]; then + com="${word}" break fi done @@ -19,7 +19,7 @@ function __composer_completion() { if [[ ${cur} == --* ]]; then opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir" - case "$com" in + case "${com}" in about) opts="${opts} " ;; @@ -109,18 +109,18 @@ function __composer_completion() { # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) - __ltrim_colon_completions "$cur" + __ltrim_colon_completions "${cur}" return 0 fi # completing for a command - if [[ "$cur" == "$com" ]]; then + if [[ "${cur}" == "${com}" ]]; then coms="about archive browse clear-cache config create-project depends diagnose dump-autoload exec global help init install licenses list outdated prohibits remove require run-script search self-update show status suggests update validate" # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${coms}" -- "${cur}")) - __ltrim_colon_completions "$cur" + __ltrim_colon_completions "${cur}" return 0 fi diff --git a/completion/available/dart.completion.bash b/completion/available/dart.completion.bash index ece96d5c..b7563443 100644 --- a/completion/available/dart.completion.bash +++ b/completion/available/dart.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __dart_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) local HELP="--help -h" diff --git a/completion/available/dmidecode.completion.bash b/completion/available/dmidecode.completion.bash index fc50c1f0..4a884524 100644 --- a/completion/available/dmidecode.completion.bash +++ b/completion/available/dmidecode.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash function __dmidecode_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) case $prev in diff --git a/completion/available/knife.completion.bash b/completion/available/knife.completion.bash index 83b332f9..4b9950ed 100644 --- a/completion/available/knife.completion.bash +++ b/completion/available/knife.completion.bash @@ -42,6 +42,7 @@ _KAC_is_file_newer_than() { _KAC_regen_cache() { local CACHE_NAME=$1 local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME" + # shellcheck disable=SC2155 local TMP_FILE=$(mktemp "$_KAC_CACHE_TMP_DIR/$CACHE_NAME.XXXX") shift 1 # discard the temp file if it's empty AND the previous command didn't exit successfully, but still mark the cache as updated @@ -66,6 +67,7 @@ _KAC_get_command_from_cache_name() { # otherwise it waits for the cache to be generated # in either case, it regenerates the cache, and sets the _KAC_CACHE_PATH env variable # for obvious reason, do NOT call that in a sub-shell (in particular, no piping) +# shellcheck disable=SC2155 _KAC_get_and_regen_cache() { # the cache name can't have space in it local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@") @@ -100,7 +102,7 @@ _KAC_clean_cache() { # perform a cache cleaning when loading this file # On big systems this could baloon up to a 30 second run or more, so not enabling by default. -[[ "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache +[[ -n "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache ##################################### ### End of cache helper functions ### @@ -118,7 +120,7 @@ _KAC_get_current_base_command() { local PREVIOUS="knife" local I=1 local CURRENT - while [ $I -le "$COMP_CWORD" ]; do + while [[ "${I}" -le "${COMP_CWORD}" ]]; do # command words are all lower-case echo "${COMP_WORDS[$I]}" | grep -E "^[a-z]+$" > /dev/null || break CURRENT="$PREVIOUS ${COMP_WORDS[$I]}" @@ -127,12 +129,13 @@ _KAC_get_current_base_command() { I=$((I + 1)) done _KAC_CURRENT_COMMAND=$PREVIOUS - [ $I -le "$COMP_CWORD" ] && _KAC_CURRENT_COMMAND_NB_WORDS=$I + [[ "${I}" -le "${COMP_CWORD}" ]] && _KAC_CURRENT_COMMAND_NB_WORDS="${I}" } # searches the position of the currently completed argument in the current base command # (i.e. handles "plural" arguments such as knife cookbook upload cookbook1 cookbook2 and so on...) # assumes the current base command is complete +# shellcheck disable=SC2155 _KAC_get_current_arg_position() { local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1)) local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH") @@ -150,10 +153,11 @@ _KAC_get_current_arg_position() { _knife() { _KAC_get_and_regen_cache _KAC_knife_commands local RAW_LIST ITEM REGEN_CMD ARG_POSITION + # shellcheck disable=SC2034 COMREPLY=() # get correct command & arg pos _KAC_get_current_base_command && ARG_POSITION=$(_KAC_get_current_arg_position) || ARG_POSITION=$((COMP_CWORD + 1)) - RAW_LIST=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH" | cut -d ' ' -f $ARG_POSITION | uniq) + RAW_LIST=$(grep -E "^${_KAC_CURRENT_COMMAND}" "${_KAC_CACHE_PATH}" | cut -d ' ' -f "${ARG_POSITION}" | uniq) # we need to process that raw list a bit, most notably for placeholders # NOTE: I chose to explicitely fetch & cache _certain_ informations for the server (cookbooks & node names, etc) diff --git a/completion/available/ngrok.completion.bash b/completion/available/ngrok.completion.bash index ffbdd3c8..ca50a16f 100644 --- a/completion/available/ngrok.completion.bash +++ b/completion/available/ngrok.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __ngrok_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) local BASE_NO_CONF="--log --log-format --log-level --help" diff --git a/completion/available/notify-send.completion.bash b/completion/available/notify-send.completion.bash index b2c171e9..676485f8 100644 --- a/completion/available/notify-send.completion.bash +++ b/completion/available/notify-send.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash function __notify-send_completions() { + # shellcheck disable=SC2155 local curr=$(_get_cword) + # shellcheck disable=SC2155 local prev=$(_get_pword) case $prev in diff --git a/completion/available/sdkman.completion.bash b/completion/available/sdkman.completion.bash index 7f0157f3..2dc09088 100644 --- a/completion/available/sdkman.completion.bash +++ b/completion/available/sdkman.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash -_sdkman_complete() { + +function _sdkman_complete() { local CANDIDATES local CANDIDATE_VERSIONS + local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}" COMPREPLY=() @@ -10,7 +12,7 @@ _sdkman_complete() { elif [ "$COMP_CWORD" -eq 2 ]; then case "${COMP_WORDS[COMP_CWORD - 1]}" in "install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug") - CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ') + CANDIDATES="${SDKMAN_CANDIDATES_CSV//,/${IFS:0:1}}" mapfile -t COMPREPLY < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}") ;; "env") @@ -46,17 +48,17 @@ _sdkman_complete() { return 0 } -_sdkman_candidate_local_versions() { +function _sdkman_candidate_local_versions() { CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1") } -_sdkman_candidate_all_versions() { +function _sdkman_candidate_all_versions() { candidate="$1" CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate") - if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then + if [[ "${SDKMAN_OFFLINE_MODE:-false}" == "true" ]]; then CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS else # sdkman has a specific output format for Java candidate since @@ -70,12 +72,12 @@ _sdkman_candidate_all_versions() { # "+" - local version # "*" - installed # ">" - currently in use - CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort | uniq -u) " + CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort -u) " fi } -__sdkman_cleanup_local_versions() { +function __sdkman_cleanup_local_versions() { __sdkman_build_version_csv "$1" | tr ',' ' ' diff --git a/completion/available/vuejs.completion.bash b/completion/available/vuejs.completion.bash index bbd79b9c..751658f0 100644 --- a/completion/available/vuejs.completion.bash +++ b/completion/available/vuejs.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __vuejs_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) case $prev in diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh index 7a9dc8bc..253cb595 100755 --- a/hooks/dot-bash.sh +++ b/hooks/dot-bash.sh @@ -18,4 +18,4 @@ for file in "$@"; do fi done -exit $exit_code +exit "${exit_code:-0}" diff --git a/hooks/dot-sh.sh b/hooks/dot-sh.sh index 3fa63216..e1086bb6 100755 --- a/hooks/dot-sh.sh +++ b/hooks/dot-sh.sh @@ -18,4 +18,4 @@ for file in "$@"; do fi done -exit $exit_code +exit "${exit_code:-0}" diff --git a/install.sh b/install.sh index 4940360f..45c975fd 100755 --- a/install.sh +++ b/install.sh @@ -83,8 +83,8 @@ function _bash-it_check_for_backup() { fi echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2 - if ! [[ $overwrite_backup ]]; then - while ! [[ $silent ]]; do + if [[ -z "${overwrite_backup}" ]]; then + while [[ -z "${silent}" ]]; do read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP case $RESP in [yY]) @@ -100,9 +100,9 @@ function _bash-it_check_for_backup() { esac done fi - if ! [[ $overwrite_backup ]]; then + if [[ -z "${overwrite_backup}" ]]; then echo -e "\033[91mInstallation aborted. Please come back soon!\033[m" - if [[ $silent ]]; then + if [[ -n "${silent}" ]]; then echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m" fi exit 1 @@ -114,8 +114,8 @@ function _bash-it_check_for_backup() { function _bash-it_modify_config_files() { _bash-it_check_for_backup - if ! [[ $silent ]]; then - while ! [[ $append_to_config ]]; do + if [[ -z "${silent}" ]]; then + while [[ -z "${append_to_config}" ]]; do read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice case $choice in [yY]) @@ -131,7 +131,7 @@ function _bash-it_modify_config_files() { esac done fi - if [[ $append_to_config ]]; then + if [[ -n "${append_to_config}" ]]; then # backup/append _bash-it_backup_append else @@ -174,12 +174,12 @@ done shift $((OPTIND - 1)) -if [[ $silent ]] && [[ $interactive ]]; then +if [[ -n "${silent}" && -n "${interactive}" ]]; then echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m" exit 1 fi -if [[ $no_modify_config ]] && [[ $append_to_config ]]; then +if [[ -n "${no_modify_config}" && -n "${append_to_config}" ]]; then echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m" exit 1 fi @@ -197,7 +197,7 @@ esac BACKUP_FILE=$CONFIG_FILE.bak echo "Installing bash-it" -if ! [[ $no_modify_config ]]; then +if [[ -z "${no_modify_config}" ]]; then _bash-it_modify_config_files fi @@ -212,10 +212,10 @@ cite _about _param _example _group _author _version # shellcheck source=./lib/helpers.bash source "$BASH_IT/lib/helpers.bash" -if [[ $interactive ]] && ! [[ $silent ]]; then +if [[ -n $interactive && -z "${silent}" ]]; then for type in "aliases" "plugins" "completion"; do - echo -e "\033[0;32mEnabling $type\033[0m" - _bash-it_load_some $type + echo -e "\033[0;32mEnabling ${type}\033[0m" + _bash-it_load_some "$type" done else echo "" @@ -230,7 +230,7 @@ fi echo "" echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m" # shellcheck disable=SC2086 -echo -e "\033[0;32mTo start using it, open a new tab or 'source "$HOME/$CONFIG_FILE"'.\033[0m" +echo -e "\033[0;32mTo start using it, open a new tab or 'source "~/$CONFIG_FILE"'.\033[0m" echo "" echo "To show the available aliases/completions/plugins, type one of the following:" echo " bash-it show aliases" diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100755 new mode 100644 diff --git a/lib/log.bash b/lib/log.bash old mode 100755 new mode 100644 diff --git a/lib/search.bash b/lib/search.bash old mode 100755 new mode 100644 diff --git a/lib/utilities.bash b/lib/utilities.bash old mode 100755 new mode 100644 diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index 0db9b04b..eb368d93 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -19,6 +19,8 @@ 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 alias_arg_words new_completion compl_func compl_wrapper # parse function based completion definitions, where capture group 2 => function and 3 => trigger local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)' @@ -26,28 +28,25 @@ function alias_completion { local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'" # create array of function completion triggers, keeping multi-word triggers together - eval "local completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" + eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" ((${#completions[@]} == 0)) && return 0 # create temporary file for wrapper functions and completions - local tmp_file tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1 - local completion_loader completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')" # read in " '' ''" lines from defined aliases - local line - - # shellcheck disable=SC2162 # some aliases do have backslashes that needs to be interpreted + # shellcheck disable=SC2162 while read line; do - eval "local alias_tokens; alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error - local alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }" + 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]# }" # skip aliases to pipes, boolean control structures and other command lists # (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters) - eval "local alias_arg_words; alias_arg_words=($alias_args)" 2> /dev/null || continue + eval "alias_arg_words=($alias_args)" 2> /dev/null || continue # avoid expanding wildcards read -a alias_arg_words <<< "$alias_args" @@ -63,15 +62,15 @@ function alias_completion { continue fi fi - local new_completion="$(complete -p "$alias_cmd" 2> /dev/null)" + new_completion="$(complete -p "$alias_cmd" 2> /dev/null)" # create a wrapper inserting the alias arguments if any if [[ -n $alias_args ]]; then - local compl_func="${new_completion/#* -F /}" + compl_func="${new_completion/#* -F /}" compl_func="${compl_func%% *}" # avoid recursive call loops by ignoring our own functions if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then - local compl_wrapper="_${namespace}::${alias_name}" + compl_wrapper="_${namespace}::${alias_name}" echo "function $compl_wrapper { local compl_word=\$2 local prec_word=\$3 diff --git a/plugins/available/cmd-returned-notify.plugin.bash b/plugins/available/cmd-returned-notify.plugin.bash index a3050875..d9be5e4e 100644 --- a/plugins/available/cmd-returned-notify.plugin.bash +++ b/plugins/available/cmd-returned-notify.plugin.bash @@ -9,7 +9,7 @@ precmd_return_notification() { } preexec_return_notification() { - [ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s) + [[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s) } precmd_functions+=(precmd_return_notification) diff --git a/plugins/available/git.plugin.bash b/plugins/available/git.plugin.bash index 6a85e7dc..3a130955 100644 --- a/plugins/available/git.plugin.bash +++ b/plugins/available/git.plugin.bash @@ -2,12 +2,13 @@ cite about-plugin about-plugin 'git helper functions' +# shellcheck disable=SC2016 function git_remote { - about "adds remote $GIT_HOSTING:$1 to current repo" + about 'adds remote $GIT_HOSTING:$1 to current repo' group "git" - echo "Running: git remote add origin ${GIT_HOSTING}:$1.git" - git remote add origin "$GIT_HOSTING:$1".git + echo "Running: git remote add origin ${GIT_HOSTING:?}:$1.git" + git remote add origin "${GIT_HOSTING}:${1}".git } function git_first_push { @@ -24,14 +25,14 @@ function git_pub() { BRANCH=$(git rev-parse --abbrev-ref HEAD) echo "Publishing ${BRANCH} to remote origin" - git push -u origin "$BRANCH" + git push -u origin "${BRANCH}" } function git_revert() { about 'applies changes to HEAD that revert all changes after this commit' group 'git' - git reset "$1" + git reset "${1:?}" git reset --soft "HEAD@{1}" git commit -m "Revert to ${1}" git reset --hard @@ -49,9 +50,7 @@ function git_rollback() { } function commit_exists() { - git rev-list --quiet "$1" - status=$? - if [ $status -ne 0 ]; then + if git rev-list --quiet "${1:?}"; then echo "Commit ${1} does not exist" kill -INT $$ fi @@ -61,7 +60,7 @@ function git_rollback() { while true; do # shellcheck disable=SC2162 read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP - case $RESP in + case "${RESP}" in [yY]) echo "Rolling back to commit ${1} with unstaged changes" @@ -87,7 +86,7 @@ function git_rollback() { while true; do # shellcheck disable=SC2162 read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP - case $RESP in + case "${RESP}" in [yY]) keep_changes "$1" @@ -134,8 +133,8 @@ function git_info() { # print all remotes and thier details for remote in $(git remote show); do - echo "$remote": - git remote show "$remote" + echo "${remote}": + git remote show "${remote}" echo done @@ -172,32 +171,32 @@ function git_stats { AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ') LOGOPTS="" if [ "$1" == '-w' ]; then - LOGOPTS="$LOGOPTS -w" + LOGOPTS="${LOGOPTS} -w" shift fi if [ "$1" == '-M' ]; then - LOGOPTS="$LOGOPTS -M" + LOGOPTS="${LOGOPTS} -M" shift fi if [ "$1" == '-C' ]; then - LOGOPTS="$LOGOPTS -C --find-copies-harder" + LOGOPTS="${LOGOPTS} -C --find-copies-harder" shift fi - for a in $AUTHORS; do + for a in ${AUTHORS}; do echo '-------------------' - echo "Statistics for: $a" + echo "Statistics for: ${a}" echo -n "Number of files changed: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f3 | sort -iu | wc -l + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f3 | sort -iu | wc -l echo -n "Number of lines added: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f1 | awk '{s+=$1} END {print s}' + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f1 | awk '{s+=$1} END {print s}' echo -n "Number of lines deleted: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f2 | awk '{s+=$1} END {print s}' + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f2 | awk '{s+=$1} END {print s}' echo -n "Number of merges: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --merges --author="$a" | grep -c '^commit' + git log ${LOGOPTS} --all --merges --author="${a}" | grep -c '^commit' done else echo "you're currently not in a git repository" @@ -212,18 +211,16 @@ function gittowork() { result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null) - if [[ $result =~ ERROR ]]; then + if [[ "${result}" =~ ERROR ]]; then echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'" - elif [[ $1 = list ]]; then - echo "$result" + elif [[ $1 == list ]]; then + echo "${result}" else if [[ -f .gitignore ]]; then - result=$(echo "$result" | grep -v "# Created by http://www.gitignore.io") + result=$(grep -v "# Created by http://www.gitignore.io" <<< "${result}") echo ".gitignore already exists, appending..." - echo "$result" >> .gitignore - else - echo "$result" > .gitignore fi + echo "${result}" >> .gitignore fi } @@ -257,7 +254,7 @@ function gitignore-reload() { fi # Prompt user to commit or stash changes and exit - if [ $err = 1 ]; then + if [[ "${err}" == 1 ]]; then echo >&2 "Please commit or stash them." fi @@ -265,7 +262,7 @@ function gitignore-reload() { # If we're here, then there are no uncommited or unstaged changes dangling around. # Proceed to reload .gitignore - if [ $err = 0 ]; then + if [[ "${err}" == 0 ]]; then # Remove all cached files git rm -r --cached . @@ -290,6 +287,7 @@ function git-changelog() { return 1 fi + # shellcheck disable=SC2155 local NEXT=$(date +%F) if [[ "$2" == "md" ]]; then @@ -298,9 +296,9 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo "### $DATE" - git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00" - NEXT=$DATE + echo "### ${DATE}" + git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00" + NEXT=${DATE} done else echo "CHANGELOG $1" @@ -309,9 +307,10 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo "[$DATE]" - git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00" - NEXT=$DATE + echo "[${DATE}]" + git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00" + # shellcheck disable=SC2034 + NEXT=${DATE} done fi } diff --git a/plugins/available/goenv.plugin.bash b/plugins/available/goenv.plugin.bash index d00fce67..17e4a0ff 100644 --- a/plugins/available/goenv.plugin.bash +++ b/plugins/available/goenv.plugin.bash @@ -30,7 +30,7 @@ eval "$(goenv init - bash)" # If moving to a directory with a goenv version set, reload the shell # to ensure the shell environment matches expectations. _bash-it-goenv-preexec() { - export GOENV_OLD_VERSION="$(goenv version-name)" + GOENV_OLD_VERSION="$(goenv version-name)" } _bash-it-goenv-precmd() { if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index 4f4fd50d..b8747a25 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -3,29 +3,37 @@ cite about-plugin about-plugin 'automatically set your xterm title with host and location info' _short-dirname() { - local dir_name=$(dirs +0) - [ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}" + local dir_name="${PWD/~/\~}" + if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then + echo "${dir_name##*/}" + else + echo "${dir_name}" + fi } _short-command() { local input_command="$*" - [ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}" + if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then + echo "${input_command%% *}" + else + echo "${input_command}" + fi } set_xterm_title() { - local title="$1" - echo -ne "\033]0;$title\007" + local title="${1:-}" + echo -ne "\033]0;${title}\007" } precmd_xterm_title() { - set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR" + set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}" } preexec_xterm_title() { - set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" + set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" } -case "$TERM" in +case "${TERM:-dumb}" in xterm* | rxvt*) precmd_functions+=(precmd_xterm_title) preexec_functions+=(preexec_xterm_title) diff --git a/scripts/reloader.bash b/scripts/reloader.bash old mode 100644 new mode 100755 index f22de67e..4bc24941 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -5,6 +5,7 @@ function _set-prefix-based-on-path() { filename=$(_bash-it-get-component-name-from-path "$1") extension=$(_bash-it-get-component-type-from-path "$1") + # shellcheck disable=SC2034 BASH_IT_LOG_PREFIX="$extension: $filename: " } @@ -15,7 +16,7 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then alias|completion|plugin) _bash_it_config_type=$1 _log_debug "Loading enabled $1 components..." ;; - *|'') + ''|*) _log_debug "Loading all enabled components..." ;; esac diff --git a/themes/90210/90210.theme.bash b/themes/90210/90210.theme.bash index 180764c8..3db3f17b 100644 --- a/themes/90210/90210.theme.bash +++ b/themes/90210/90210.theme.bash @@ -1,4 +1,7 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. + SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" SCM_THEME_PROMPT_PREFIX=" |" @@ -11,7 +14,7 @@ GIT_THEME_PROMPT_SUFFIX="${green}|" # Nicely formatted terminal prompt function prompt_command() { - export PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ " + PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ " } safe_append_prompt_command prompt_command diff --git a/themes/agnoster/agnoster.theme.bash b/themes/agnoster/agnoster.theme.bash index ba3e2c9a..20c184f3 100644 --- a/themes/agnoster/agnoster.theme.bash +++ b/themes/agnoster/agnoster.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # vim: ft=bash ts=2 sw=2 sts=2 # # agnoster's Theme - https://gist.github.com/3712874 @@ -220,7 +221,7 @@ prompt_virtualenv() { # Context: user@hostname (who am I and where am I) prompt_context() { - local user=$(whoami) + local user="${USER:-${LOGNAME:?}}" if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then prompt_segment black default "$user@\h" diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 6bde6801..03dc9e95 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Atomic Bash Prompt for Bash-it # By lfelipe base on the theme brainy of MunifTanjim diff --git a/themes/bakke/bakke.theme.bash b/themes/bakke/bakke.theme.bash index 725350a0..d7bfbbe8 100644 --- a/themes/bakke/bakke.theme.bash +++ b/themes/bakke/bakke.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 8e09d4be..b614d148 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Theme custom glyphs SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '} diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 5cc791b4..1e0409d3 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. CLOCK_CHAR_THEME_PROMPT_PREFIX='' CLOCK_CHAR_THEME_PROMPT_SUFFIX='' @@ -130,12 +131,11 @@ function scm { } scm_prompt() { - local CHAR=$(scm_char) + local CHAR + CHAR="$(scm_char)" local format=${SCM_PROMPT_FORMAT:-'[%s%s]'} - if [[ $CHAR = "$SCM_NONE_CHAR" ]]; then - return - else + if [[ "${CHAR}" != "$SCM_NONE_CHAR" ]]; then # shellcheck disable=2059 printf "$format\n" "$CHAR" "$(scm_prompt_info)" fi @@ -352,15 +352,15 @@ function svn_prompt_vars { # - .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) + local CURRENT_DIR="${PWD}" - while [ "$CURRENT_DIR" != "/" ]; do - if [ -d "$CURRENT_DIR/.hg" ]; then + while [[ "${CURRENT_DIR:-/}" != "/" ]]; do + if [[ -d "$CURRENT_DIR/.hg" ]]; then echo "$CURRENT_DIR/.hg" return fi - CURRENT_DIR=$(dirname "$CURRENT_DIR") + CURRENT_DIR="${CURRENT_DIR%/*}" done } @@ -552,7 +552,7 @@ function prompt_char { function battery_char { if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then - echo -e "${bold_red}$(battery_percentage)%" + echo -e "${bold_red:-}$(battery_percentage)%" fi } @@ -594,7 +594,7 @@ function __check_precmd_conflict() { function safe_append_prompt_command { local prompt_re - if [ "${__bp_imported}" == "defined" ]; then + if [ "${__bp_imported:-missing}" == "defined" ]; then # We are using bash-preexec if ! __check_precmd_conflict "${1}"; then precmd_functions+=("${1}") @@ -609,7 +609,7 @@ function safe_append_prompt_command { prompt_re="\<${1}\>" fi - if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then + if [[ ${PROMPT_COMMAND[*]:-} =~ ${prompt_re} ]]; then return elif [[ -z ${PROMPT_COMMAND} ]]; then PROMPT_COMMAND="${1}" diff --git a/themes/binaryanomaly/binaryanomaly.theme.bash b/themes/binaryanomaly/binaryanomaly.theme.bash index c2efa237..c4488c4c 100644 --- a/themes/binaryanomaly/binaryanomaly.theme.bash +++ b/themes/binaryanomaly/binaryanomaly.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Detect whether a reboot is required function show_reboot_required() { diff --git a/themes/bira/bira.theme.bash b/themes/bira/bira.theme.bash index ae8f0efe..7db03000 100644 --- a/themes/bira/bira.theme.bash +++ b/themes/bira/bira.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX=" ${yellow}‹" SCM_THEME_PROMPT_SUFFIX="›${reset_color}" diff --git a/themes/bobby-python/bobby-python.theme.bash b/themes/bobby-python/bobby-python.theme.bash index 9144e251..ebb3eab0 100644 --- a/themes/bobby-python/bobby-python.theme.bash +++ b/themes/bobby-python/bobby-python.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/bobby/bobby.theme.bash b/themes/bobby/bobby.theme.bash index bdf388f7..98d2cd8d 100644 --- a/themes/bobby/bobby.theme.bash +++ b/themes/bobby/bobby.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index db8377ba..e1c36175 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Brainy Bash Prompt for Bash-it # by MunifTanjim diff --git a/themes/brunton/brunton.theme.bash b/themes/brunton/brunton.theme.bash index 27b822ca..166fcc84 100644 --- a/themes/brunton/brunton.theme.bash +++ b/themes/brunton/brunton.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" diff --git a/themes/candy/candy.theme.bash b/themes/candy/candy.theme.bash index be53d373..7753e934 100644 --- a/themes/candy/candy.theme.bash +++ b/themes/candy/candy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. function prompt_command() { PS1="${green}\u@\h $(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue} →${bold_blue} ${reset_color} ${normal}" diff --git a/themes/colors.theme.bash b/themes/colors.theme.bash index fbb1dc5c..d5044d05 100644 --- a/themes/colors.theme.bash +++ b/themes/colors.theme.bash @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2005 +# shellcheck disable=SC2034 function __ { echo "$@" diff --git a/themes/easy/easy.theme.bash b/themes/easy/easy.theme.bash index a48eb824..7e2e3389 100644 --- a/themes/easy/easy.theme.bash +++ b/themes/easy/easy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX="${bold_green}[ ${normal}" SCM_THEME_PROMPT_SUFFIX="${bold_green} ] " diff --git a/themes/modern/modern.theme.bash b/themes/modern/modern.theme.bash index 3a51267c..eadb0762 100644 --- a/themes/modern/modern.theme.bash +++ b/themes/modern/modern.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 98bcd82c..ade3670d 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -1,4 +1,7 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. + # Define this here so it can be used by all of the Powerline themes THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} @@ -139,7 +142,7 @@ function __powerline_scm_prompt() { } function __powerline_cwd_prompt() { - local cwd=$(pwd | sed "s|^${HOME}|~|") + local cwd="${PWD/$HOME/\~}" echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" } @@ -157,10 +160,10 @@ function __powerline_clock_prompt() { } function __powerline_battery_prompt() { - local color="" - local battery_status="$(battery_percentage 2> /dev/null)" + local color="" battery_status + battery_status="$(battery_percentage 2> /dev/null)" - if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then + if [[ -z "${battery_status}" || "${battery_status}" == "-1" || "${battery_status}" == "no" ]]; then true else if [[ "$((10#${battery_status}))" -le 5 ]]; then @@ -176,7 +179,7 @@ function __powerline_battery_prompt() { } function __powerline_in_vim_prompt() { - if [ -n "$VIMRUNTIME" ]; then + if [[ -n "$VIMRUNTIME" ]]; then echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}" fi } @@ -221,7 +224,8 @@ function __powerline_command_number_prompt() { } function __powerline_duration_prompt() { - local duration=$(_command_duration) + local duration + duration=$(_command_duration) [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}" } @@ -265,7 +269,7 @@ function __powerline_last_status_prompt() { function __powerline_prompt_command() { local last_status="$?" ## always the first - local separator_char="${POWERLINE_PROMPT_CHAR}" + local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color LEFT_PROMPT="" SEGMENTS_AT_LEFT=0 @@ -277,7 +281,7 @@ function __powerline_prompt_command() { ## left prompt ## for segment in $POWERLINE_PROMPT; do - local info="$(__powerline_"${segment}"_prompt)" + info="$(__powerline_"${segment}"_prompt)" [[ -n "${info}" ]] && __powerline_left_segment "${info}" done @@ -289,7 +293,7 @@ function __powerline_prompt_command() { # 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. - local prompt_color="$(set_color "${LAST_SEGMENT_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="${normal}" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index d7ac77ed..49b397aa 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # shellcheck source=../../themes/powerline/powerline.base.bash . "$BASH_IT/themes/powerline/powerline.base.bash" diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash index 3672a72c..99476f4a 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # scm theming SCM_THEME_PROMPT_PREFIX="|" diff --git a/themes/purity/purity.theme.bash b/themes/purity/purity.theme.bash index 8fc03bf3..22a3fbfb 100644 --- a/themes/purity/purity.theme.bash +++ b/themes/purity/purity.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${bold_red}⊘${normal}" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" @@ -26,8 +28,8 @@ venv_prompt() { } function prompt_command() { - retval=$? - local ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")" + local retval=$? ret_status + ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")" PS1="\n${PURITY_THEME_PROMPT_COLOR}\w $(scm_prompt_info)\n${ret_status}$(venv_prompt)" } From 1f6d6aa147d47b69e23e390bca662494bebba0d9 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 5 Sep 2021 17:28:54 -0700 Subject: [PATCH 053/114] Use `$PWD` instead of `\`pwd\`` Don't subshell when there's a shell parameter for it. --- completion/available/gradle.completion.bash | 4 ++-- plugins/available/dirs.plugin.bash | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 2b33383f..6ec8c697 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -23,8 +23,8 @@ COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') __gradle-set-project-root-dir() { - local dir=`pwd` - project_root_dir=`pwd` + local dir="${PWD}" + project_root_dir="${PWD}" while [[ $dir != '/' ]]; do if [[ -f "$dir/settings.gradle" || -f "$dir/gradlew" ]]; then project_root_dir=$dir diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index c215f7ec..5f27db01 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -86,7 +86,7 @@ S () { sed "/$@/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; - echo "$@"=\"`pwd`\" >> ~/.dirs; + echo "$@"=\""${PWD}"\" >> ~/.dirs; source ~/.dirs ; } From 5fc418e479aa79a6192182b93ef4b6d5801cb7c6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 18 Sep 2021 13:15:13 -0700 Subject: [PATCH 054/114] Use `${PWD}` instead of `$(pwd)` Don't subshell when there's a shell parameter for it. --- completion/available/hub.completion.bash | 2 +- lib/helpers.bash | 2 +- plugins/available/dirs.plugin.bash | 4 ++-- themes/powerturk/powerturk.theme.bash | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 themes/powerturk/powerturk.theme.bash diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index 79d76bf0..74c530a8 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -227,7 +227,7 @@ EOF ((c++)) done if [ -z "$name" ]; then - repo=$(basename "$(pwd)") + repo="$(basename "${PWD}")" fi case "$prev" in -d|-h) diff --git a/lib/helpers.bash b/lib/helpers.bash index 9b95fe65..61705a04 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -449,7 +449,7 @@ _bash-it-restart() { _about 'restarts the shell in order to fully reload it' _group 'lib' - saved_pwd=$(pwd) + saved_pwd="${PWD}" case $OSTYPE in darwin*) diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index 5f27db01..2c1adf7a 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -23,7 +23,7 @@ alias 8="pushd +8" alias 9="pushd +9" # Clone this location -alias pc="pushd \$(pwd)" +alias pc='pushd "${PWD}"' # Push new location alias pu="pushd" @@ -73,7 +73,7 @@ G () { example '$ G ..' group 'dirs' - cd "${1:-$(pwd)}" ; + cd "${1:-${PWD}}" ; } S () { diff --git a/themes/powerturk/powerturk.theme.bash b/themes/powerturk/powerturk.theme.bash old mode 100644 new mode 100755 index 4590a8aa..3352f680 --- a/themes/powerturk/powerturk.theme.bash +++ b/themes/powerturk/powerturk.theme.bash @@ -43,7 +43,7 @@ _swd(){ begin="" # The unshortened beginning of the path. shortbegin="" # The shortened beginning of the path. current="" # The section of the path we're currently working on. - end="${2:-$(pwd)}/" # The unmodified rest of the path. + end="${2:-${PWD}}/" # The unmodified rest of the path. if [[ "$end" =~ "$HOME" ]]; then INHOME=1 From 8d1e802565d0e0b6d4f110c48984d5015a6c040f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 5 Sep 2021 17:35:05 -0700 Subject: [PATCH 055/114] test: Use `${PWD}` instead of `$(pwd)` --- test/plugins/base.plugin.bats | 2 +- test/run | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 7daf2619..1def481e 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -40,7 +40,7 @@ load ../../plugins/available/base.plugin mkcd "${dir_name}" assert_success assert_dir_exist "${BASH_IT_ROOT}/${dir_name}" - assert_equal $(pwd) "${BASH_IT_ROOT}/${dir_name}" + assert_equal "${PWD}" "${BASH_IT_ROOT}/${dir_name}" } @test 'plugins base: lsgrep()' { diff --git a/test/run b/test/run index 88202916..fe4ac847 100755 --- a/test/run +++ b/test/run @@ -6,7 +6,7 @@ git submodule init && git submodule update if [ -z "${BASH_IT}" ]; then declare BASH_IT - BASH_IT=$(cd ${test_directory} && dirname "$(pwd)") + BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" export BASH_IT fi From a375e7131e3e4402ad2e81ae2701c9842ee1df2b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 6 Sep 2021 23:15:37 -0700 Subject: [PATCH 056/114] Remove executable bit --- completion/available/fabric.completion.bash | 0 completion/available/git.completion.bash | 0 completion/available/system.completion.bash | 0 plugins/available/base.plugin.bash | 0 plugins/available/jump.plugin.bash | 0 plugins/available/todo.plugin.bash | 0 themes/powerturk/powerturk.theme.bash | 0 7 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 completion/available/fabric.completion.bash mode change 100755 => 100644 completion/available/git.completion.bash mode change 100755 => 100644 completion/available/system.completion.bash mode change 100755 => 100644 plugins/available/base.plugin.bash mode change 100755 => 100644 plugins/available/jump.plugin.bash mode change 100755 => 100644 plugins/available/todo.plugin.bash mode change 100755 => 100644 themes/powerturk/powerturk.theme.bash diff --git a/completion/available/fabric.completion.bash b/completion/available/fabric.completion.bash old mode 100755 new mode 100644 diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash old mode 100755 new mode 100644 diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash old mode 100755 new mode 100644 diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash old mode 100755 new mode 100644 diff --git a/plugins/available/jump.plugin.bash b/plugins/available/jump.plugin.bash old mode 100755 new mode 100644 diff --git a/plugins/available/todo.plugin.bash b/plugins/available/todo.plugin.bash old mode 100755 new mode 100644 diff --git a/themes/powerturk/powerturk.theme.bash b/themes/powerturk/powerturk.theme.bash old mode 100755 new mode 100644 From f6c5717a7abf672e37f9367c6473d38b83fcd36f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:52:46 -0700 Subject: [PATCH 057/114] plugins/textmate: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/textmate.plugin.bash | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index b8fcee4f..8fdc0c10 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash # tests diff --git a/plugins/available/textmate.plugin.bash b/plugins/available/textmate.plugin.bash index e3538c1e..5c81f195 100644 --- a/plugins/available/textmate.plugin.bash +++ b/plugins/available/textmate.plugin.bash @@ -1,7 +1,9 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'set textmate as a default editor' -if $(command -v mate &> /dev/null) ; then - export EDITOR="$(which mate) -w" - export GIT_EDITOR=$EDITOR +if _command_exists mate; then + EDITOR="$(type -p mate) -w" + GIT_EDITOR="$EDITOR" + export EDITOR GIT_EDITOR fi From a7955b972c2f45e044de925629fb02d89e11593b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:53:59 -0700 Subject: [PATCH 058/114] plugins/powerline: use `_command_exists` Addresses bash-it/bash-it#1632 --- plugins/available/powerline.plugin.bash | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/available/powerline.plugin.bash b/plugins/available/powerline.plugin.bash index 3d91e658..1927bf3e 100644 --- a/plugins/available/powerline.plugin.bash +++ b/plugins/available/powerline.plugin.bash @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +# shellcheck shell=bash cite about-plugin about-plugin 'enables powerline daemon' -command -v powerline-daemon &>/dev/null || return +_command_exists powerline-daemon || return powerline-daemon -q #the following should not be executed if bashit powerline themes in use @@ -14,13 +14,13 @@ case "$BASH_IT_THEME" in esac POWERLINE_BASH_CONTINUATION=1 POWERLINE_BASH_SELECT=1 -bashPowerlineInit=$(python -c \ +bashPowerlineInit="$(python -c \ "import os; \ import powerline;\ print(os.path.join(os.path.dirname(\ powerline.__file__),\ 'bindings', \ 'bash', \ - 'powerline.sh'))") + 'powerline.sh'))")" [ -e $bashPowerlineInit ] || return -. $bashPowerlineInit +source $bashPowerlineInit From 9378a8318f91b5ae1b11efa11e8e2e33f27215ea Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:16:51 -0700 Subject: [PATCH 059/114] plugins/nvm: use `_command_exists` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses bash-it/bash-it#1632 alsö, quote variable, &c. --- plugins/available/nvm.plugin.bash | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 87dce644..0e6da5d8 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -1,22 +1,23 @@ -# Bash-it no longer bundles nvm, as this was quickly becoming outdated. +# shellcheck shell=bash # # BASH_IT_LOAD_PRIORITY: 225 # +# Bash-it no longer bundles nvm, as this was quickly becoming outdated. # Please install nvm from https://github.com/creationix/nvm.git if you want to use it. cite about-plugin about-plugin 'node version manager configuration' -export NVM_DIR=${NVM_DIR:-$HOME/.nvm} +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 "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]] then - . "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" + source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" else - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi -if ! command -v nvm &>/dev/null +if ! _command_exists nvm then function nvm() { echo "Bash-it no longer bundles the nvm script. Please install the latest version from" From e701660ff161385fd63c10a53a168ff5e18c3404 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:21 -0700 Subject: [PATCH 060/114] plugins/node: use `_command_exists` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses bash-it/bash-it#1632 alsö, quote variable, use `[[`, &c. --- clean_files.txt | 1 + plugins/available/node.plugin.bash | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8fdc0c10..3f597470 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/node.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 65df3da3..8bf876df 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,13 +1,14 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Node.js helper functions' +# Check that we have npm +_command_exists npm || return + # Ensure local modules are preferred in PATH pathmunge "./node_modules/.bin" "after" -# Check that we have npm -out=$(command -v npm 2>&1) || return - # If not using nodenv, ensure global modules are in PATH -if [[ ! $out == *"nodenv/shims"* ]] ; then - pathmunge "$(npm config get prefix)/bin" "after" +if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then + pathmunge "$(npm config get prefix)/bin" "after" fi From 635e5488ba1bf530e1046968fdb1bdf8873cc461 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:58:47 -0700 Subject: [PATCH 061/114] plugins/jump: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/jump.plugin.bash | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 3f597470..9c24975b 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/jump.plugin.bash plugins/available/node.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/jump.plugin.bash b/plugins/available/jump.plugin.bash index 26d6467d..1713d1b7 100644 --- a/plugins/available/jump.plugin.bash +++ b/plugins/available/jump.plugin.bash @@ -1,9 +1,12 @@ +# shellcheck shell=bash +# shellcheck disable=SC2016 cite about-plugin about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding' -__init_jump() { - command -v jump &> /dev/null || return - eval "$(jump shell bash "${JUMP_OPTS[@]}")" +function __init_jump() { + if _command_exists jump; then + eval "$(jump shell bash "${JUMP_OPTS[@]}")" + fi } __init_jump From 3e2ec1232d14cacb142e6bab2c16aa00fdab9915 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:39:43 -0700 Subject: [PATCH 062/114] plugins/hub: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/hub.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index 9c24975b..173995c5 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash plugins/available/textmate.plugin.bash diff --git a/plugins/available/hub.plugin.bash b/plugins/available/hub.plugin.bash index 0a67a7af..e9a8cbab 100644 --- a/plugins/available/hub.plugin.bash +++ b/plugins/available/hub.plugin.bash @@ -1,4 +1,7 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load hub, if you are using it' -command -v hub &> /dev/null && eval "$(hub alias -s)" +if _command_exists hub; then + eval "$(hub alias -s)" +fi From 39d6488c6be8fc3e5c082fd85351b1c36f9247c1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:17:00 -0700 Subject: [PATCH 063/114] plugins/base: use `_command_exists` Addresses bash-it/bash-it#1632 --- plugins/available/base.plugin.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 8499a2df..b0899ce9 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -5,10 +5,10 @@ function ips () { about 'display all ip addresses for this host' group 'base' - if command -v ifconfig &>/dev/null + if _command_exists ifconfig then ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' - elif command -v ip &>/dev/null + elif _command_exists ip then ip addr | grep -oP 'inet \K[\d.]+' else @@ -70,7 +70,7 @@ function passgen () # Create alias pass to passgen when pass isn't installed or # BASH_IT_LEGACY_PASS is true. -if ! command -v pass &>/dev/null || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]] +if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]] then alias pass=passgen fi @@ -81,7 +81,7 @@ function pmdown () param '1: markdown file' example '$ pmdown README.md' group 'base' - if command -v markdown &>/dev/null + if _command_exists markdown then markdown $1 | browser else From de58fdd73fa6316626080c8b73df3b9a669aa1da Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:57:21 -0700 Subject: [PATCH 064/114] plugins/autojump: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/autojump.plugin.bash | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 173995c5..26496237 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -77,6 +77,7 @@ completion/available/wpscan.completion.bash # plugins # plugins/available/alias-completion.plugin.bash +plugins/available/autojump.plugin.bash plugins/available/basher.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/docker-machine.plugin.bash diff --git a/plugins/available/autojump.plugin.bash b/plugins/available/autojump.plugin.bash index 7e6df7fc..dc8fbbb4 100644 --- a/plugins/available/autojump.plugin.bash +++ b/plugins/available/autojump.plugin.bash @@ -1,12 +1,15 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Autojump configuration, see https://github.com/wting/autojump for more details' # Only supports the Homebrew variant, Debian and Arch at the moment. # Feel free to provide a PR to support other install locations if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then - . "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" -elif command -v dpkg &>/dev/null && dpkg -s autojump &>/dev/null ; then - . "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" -elif command -v pacman &>/dev/null && pacman -Q autojump &>/dev/null ; then - . "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)" + source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" +elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then + # shellcheck disable=SC1090 + source "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" +elif _command_exists pacman && pacman -Q autojump &> /dev/null; then + # shellcheck disable=SC1090 + source "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)" fi From e2915df1e5363cf2aa829537bfe1b2e2d0998ab1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:14:42 -0700 Subject: [PATCH 065/114] completions/wpscan: use `_command_exists` Addresses bash-it/bash-it#1632 --- completion/available/wpscan.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/wpscan.completion.bash b/completion/available/wpscan.completion.bash index 5d2e2daa..8891ab7f 100644 --- a/completion/available/wpscan.completion.bash +++ b/completion/available/wpscan.completion.bash @@ -1,7 +1,7 @@ # shellcheck shell=bash -if command -v wpscan > /dev/null; then - __wpscan_completion() { +if _command_exists wpscan; then + function __wpscan_completion() { local OPTS=("--help --hh --version --url --ignore-main-redirect --verbose --output --format --detection-mode --scope --headers --user-agent --vhost --random-user-agent --user-agents-list --http-auth --max-threads --throttle --request-timeout --connect-timeout --disable-tlc-checks --proxy --proxy-auth --cookie-string --cookie-jar --cache-ttl --clear-cache --server --cache-dir --update --no-update --wp-content-dir --wp-plugins-dir --wp-version-detection --main-theme-detection --enumerate --exclude-content-based --plugins-list --plugins-detection --plugins-version-all --plugins-version-detection --themes-list --themes-detection --themes-version-all --themes-version-detection --timthumbs-list --timthumbs-detection --config-backups-list --config-backups-detection --db-exports-list --db-exports-detection --medias-detection --users-list --users-detection --passwords --usernames --multicall-max-passwords --password-attack --stealthy") COMPREPLY=() for _opt_ in "${OPTS[@]}"; do From 8e169388d237f504a3d6a6dd4452fa516e55db96 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:16:54 -0700 Subject: [PATCH 066/114] completions/laravel: use `_command_exists` Addresses bash-it/bash-it#1632 --- completion/available/laravel.completion.bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/completion/available/laravel.completion.bash b/completion/available/laravel.completion.bash index 7bd6f223..9298a7bf 100644 --- a/completion/available/laravel.completion.bash +++ b/completion/available/laravel.completion.bash @@ -1,7 +1,9 @@ #!/usr/bin/bash -if command -v laravel > /dev/null; then - __laravel_completion() { +if _command_exists laravel +then + function __laravel_completion() + { local OPTS=("-h --help -q --quiet --ansi --no-ansi -n --no-interaction -v -vv -vvv --verbose help list new") COMPREPLY=() for _opt_ in ${OPTS[@]}; do @@ -9,7 +11,7 @@ if command -v laravel > /dev/null; then COMPREPLY+=("$_opt_") fi done - } + } complete -F __laravel_completion laravel fi From cace3a591d2dd2612b906ca0c07e03c436c7f82e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:17:10 -0700 Subject: [PATCH 067/114] main: use `_command_exists` Addresses bash-it/bash-it#1632 --- bash_it.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_it.sh b/bash_it.sh index 679ffdaf..215c33c7 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -145,7 +145,7 @@ if [ -e "$HOME/.jekyllconfig" ]; then fi # BASH_IT_RELOAD_LEGACY is set. -if ! command -v reload &> /dev/null && [ -n "${BASH_IT_RELOAD_LEGACY:-}" ]; then +if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then case $OSTYPE in darwin*) alias reload='source ~/.bash_profile' From 757a5bf25bc6135b9d66082bbf5d86c3cac27f58 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:17:12 -0700 Subject: [PATCH 068/114] aliases/vim: use `_command_exists` --- aliases/available/vim.aliases.bash | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/aliases/available/vim.aliases.bash b/aliases/available/vim.aliases.bash index d19057d0..d5dcdc54 100644 --- a/aliases/available/vim.aliases.bash +++ b/aliases/available/vim.aliases.bash @@ -2,11 +2,7 @@ cite 'about-alias' about-alias 'vim abbreviations' -VIM=$(command -v vim) -GVIM=$(command -v gvim) -MVIM=$(command -v mvim) - -if [[ -n $VIM ]]; then +if _command_exists vim; then alias v='$VIM' # open the vim help in fullscreen incorporated from # https://stackoverflow.com/a/4687513 @@ -17,9 +13,9 @@ fi # http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek case $OSTYPE in darwin*) - [[ -n $MVIM ]] && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } + _command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } ;; *) - [[ -n $GVIM ]] && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } + _command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } ;; esac From 5eccc59d27a8176f0ed428a351f9cdcaca466a4e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 17:35:24 -0700 Subject: [PATCH 069/114] completion/git_flow_avh: use `_command_exists` --- completion/available/git_flow_avh.completion.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completion/available/git_flow_avh.completion.bash b/completion/available/git_flow_avh.completion.bash index 0b73a0be..abb51bf8 100644 --- a/completion/available/git_flow_avh.completion.bash +++ b/completion/available/git_flow_avh.completion.bash @@ -505,6 +505,7 @@ __git_flow_list_branches () } # alias __git_find_on_cmdline for backwards compatibility -if [ -z "`type -t __git_find_on_cmdline`" ]; then +if ! _command_exists __git_find_on_cmdline +then alias __git_find_on_cmdline=__git_find_subcommand fi From c29eb16dfcc57fef252377a00251712f3448f7df Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 17:36:30 -0700 Subject: [PATCH 070/114] completion/git_flow: use `_command_exists` --- completion/available/git_flow.completion.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completion/available/git_flow.completion.bash b/completion/available/git_flow.completion.bash index 04f20ccd..7bfc9ef4 100644 --- a/completion/available/git_flow.completion.bash +++ b/completion/available/git_flow.completion.bash @@ -172,6 +172,7 @@ __git_flow_list_hotfixes () } # temporarily wrap __git_find_on_cmdline() for backwards compatibility -if [ -z "`type -t __git_find_subcommand`" ]; then +if ! _command_exists __git_find_subcommand +then alias __git_find_subcommand=__git_find_on_cmdline fi From ccd8b52e896f477576b23f03b526897b0e905272 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:21:55 -0700 Subject: [PATCH 071/114] plugins/virtualenv: use `_command_exists` --- plugins/available/virtualenv.plugin.bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/available/virtualenv.plugin.bash b/plugins/available/virtualenv.plugin.bash index f1c85987..41d55ddf 100644 --- a/plugins/available/virtualenv.plugin.bash +++ b/plugins/available/virtualenv.plugin.bash @@ -1,12 +1,14 @@ +# shellcheck shell=bash +# # make sure virtualenvwrapper is enabled if available cite about-plugin about-plugin 'virtualenvwrapper and pyenv-virtualenvwrapper helper functions' if _command_exists pyenv; then - pyenv virtualenvwrapper -else - [[ `which virtualenvwrapper.sh` ]] && . virtualenvwrapper.sh + pyenv virtualenvwrapper +elif _command_exists virtualenvwrapper.sh; then + source virtualenvwrapper.sh fi From b14bb4735e597c80603ffe7d8e007d6c8e5260c4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:00:07 -0700 Subject: [PATCH 072/114] plugins/ruby: use `_command_exists` --- plugins/available/ruby.plugin.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index 4ab891d9..b1164106 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -1,9 +1,11 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'ruby and rubygems specific functions and settings' # Make commands installed with 'gem install --user-install' available # ~/.gem/ruby/${RUBY_VERSION}/bin/ -if which ruby >/dev/null && which gem >/dev/null; then +if _command_exists ruby && _command_exists gem +then pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after fi From cff6f3464aab19f333acdcfe855feec435e15d26 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:33 -0700 Subject: [PATCH 073/114] plugins/rbenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/rbenv.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index 26496237..f5a63e6c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/rbenv.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/rbenv.plugin.bash b/plugins/available/rbenv.plugin.bash index 2b01669d..f3605f58 100644 --- a/plugins/available/rbenv.plugin.bash +++ b/plugins/available/rbenv.plugin.bash @@ -1,7 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load rbenv, if you are using it' export RBENV_ROOT="$HOME/.rbenv" pathmunge "$RBENV_ROOT/bin" -[[ `which rbenv 2>/dev/null` ]] && eval "$(rbenv init - bash)" +if _command_exists rbenv; then + eval "$(rbenv init - bash)" +fi From a31145335e34a12bb2cc1a542105e5ee0ae0bba7 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:44 -0700 Subject: [PATCH 074/114] plugins/pyenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/pyenv.plugin.bash | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index f5a63e6c..da7af75c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index 4d8db4fb..dc8df3ad 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -1,12 +1,15 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load pyenv, if you are using it' export PYENV_ROOT="$HOME/.pyenv" pathmunge "$PYENV_ROOT/bin" -[[ `which pyenv 2>/dev/null` ]] && eval "$(pyenv init - bash)" +if _command_exists pyenv; then + eval "$(pyenv init - bash)" +fi #Load pyenv virtualenv if the virtualenv plugin is installed. if pyenv virtualenv-init - &> /dev/null; then - eval "$(pyenv virtualenv-init - bash)" + eval "$(pyenv virtualenv-init - bash)" fi From f0179c79ce3cb035bf8b0ac2725a7339d381cc47 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:54 -0700 Subject: [PATCH 075/114] plugins/plenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/plenv.plugin.bash | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index da7af75c..aab0e611 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/plenv.plugin.bash plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/textmate.plugin.bash diff --git a/plugins/available/plenv.plugin.bash b/plugins/available/plenv.plugin.bash index 1da2d61b..79a9cf49 100644 --- a/plugins/available/plenv.plugin.bash +++ b/plugins/available/plenv.plugin.bash @@ -1,18 +1,16 @@ +# shellcheck shell=bash +# # plugin for plenv cite about-plugin about-plugin 'plenv plugin for Perl' -if [[ -e "${HOME}/.plenv/bin" ]] ; then - - # load plenv bin dir into path if it exists - pathmunge "${HOME}/.plenv/bin" - +if [[ -d "${HOME}/.plenv/bin" ]]; then + # load plenv bin dir into path if it exists + pathmunge "${HOME}/.plenv/bin" fi -if [[ `which plenv` ]] ; then - - # init plenv - eval "$(plenv init - bash)" - +if _command_exists plenv; then + # init plenv + eval "$(plenv init - bash)" fi From b038ea58699679b1d017122bc268bc0dd3d5310a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:47:35 -0700 Subject: [PATCH 076/114] plugins/nodenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/nodenv.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index aab0e611..cd56b2d0 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/nodenv.plugin.bash plugins/available/plenv.plugin.bash plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash diff --git a/plugins/available/nodenv.plugin.bash b/plugins/available/nodenv.plugin.bash index 1bbe7fbd..262a57c3 100644 --- a/plugins/available/nodenv.plugin.bash +++ b/plugins/available/nodenv.plugin.bash @@ -1,7 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load nodenv, if you are using it' export NODENV_ROOT="$HOME/.nodenv" pathmunge "$NODENV_ROOT/bin" -[[ `which nodenv` ]] && eval "$(nodenv init - bash)" +if _command_exists nodenv; then + eval "$(nodenv init - bash)" +fi From c98424308abe0f7252aebf9c5ea335acf018e856 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:48:13 -0700 Subject: [PATCH 077/114] plugins/direnv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/direnv.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index cd56b2d0..2242ef5e 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -80,6 +80,7 @@ plugins/available/alias-completion.plugin.bash plugins/available/autojump.plugin.bash plugins/available/basher.plugin.bash plugins/available/cmd-returned-notify.plugin.bash +plugins/available/direnv.plugin.bash plugins/available/docker-machine.plugin.bash plugins/available/git.plugin.bash plugins/available/go.plugin.bash diff --git a/plugins/available/direnv.plugin.bash b/plugins/available/direnv.plugin.bash index 5fd564f5..62788600 100644 --- a/plugins/available/direnv.plugin.bash +++ b/plugins/available/direnv.plugin.bash @@ -1,4 +1,7 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load direnv, if you are using it: https://direnv.net/' -[ -x "$(which direnv)" ] && eval "$(direnv hook bash)" +if _command_exists direnv; then + eval "$(direnv hook bash)" +fi From ef0c64322fd64f7cafe92e359fd9e3cdf21ed7c8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:00:46 -0700 Subject: [PATCH 078/114] completion/travis: use `_command_exists` --- completion/available/travis.completion.bash | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/completion/available/travis.completion.bash b/completion/available/travis.completion.bash index 28d599aa..49d8f2cc 100644 --- a/completion/available/travis.completion.bash +++ b/completion/available/travis.completion.bash @@ -1,5 +1,10 @@ -if [[ -x "$(which travis)" ]]; then - __TRAVIS_COMPLETION_SCRIPT="${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh" - [[ -f "${__TRAVIS_COMPLETION_SCRIPT}" ]] && source "${__TRAVIS_COMPLETION_SCRIPT}" +# shellcheck shell=bash + +if _command_exists travis +then + if [[ -s "${__TRAVIS_COMPLETION_SCRIPT:=${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh}" ]] + then + source "${__TRAVIS_COMPLETION_SCRIPT}" + fi unset __TRAVIS_COMPLETION_SCRIPT fi From bb555aefbfb84c7c9c05067b9b0fbf09b143a7ea Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:00:59 -0700 Subject: [PATCH 079/114] completion/pew: use `_command_exists` --- completion/available/pew.completion.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/completion/available/pew.completion.bash b/completion/available/pew.completion.bash index 73d62e39..04e67ecb 100644 --- a/completion/available/pew.completion.bash +++ b/completion/available/pew.completion.bash @@ -1 +1,6 @@ -[[ -x "$(which pew)" ]] && source "$(pew shell_config)" +# shellcheck shell=bash + +if _command_exists pew +then + source "$(pew shell_config)" +fi From dca96e0c39b2548234e583a6eb5ce981b682f4f5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:01:54 -0700 Subject: [PATCH 080/114] completion/consul: use `_command_exists` --- completion/available/consul.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completion/available/consul.completion.bash b/completion/available/consul.completion.bash index 3697ffc5..511cf372 100644 --- a/completion/available/consul.completion.bash +++ b/completion/available/consul.completion.bash @@ -3,5 +3,5 @@ cite "about-completion" about-completion "Hashicorp consul completion" if _command_exists consul; then - complete -C "$(which consul)" consul + complete -C "$(command -v consul)" consul fi From 699d893befaa3ad51ecbb8ce7cff455aa664299c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:02 -0700 Subject: [PATCH 081/114] completion/awscli: use `_command_exists` --- completion/available/awscli.completion.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/completion/available/awscli.completion.bash b/completion/available/awscli.completion.bash index 530bdd27..a3041837 100644 --- a/completion/available/awscli.completion.bash +++ b/completion/available/awscli.completion.bash @@ -1 +1,6 @@ -[[ -x "$(which aws_completer)" ]] && complete -C "$(which aws_completer)" aws +# shellcheck shell=bash + +if _command_exists aws_completer +then + complete -C "$(command -v aws_completer)" aws +fi From 6618457f9ed989b5f763e4bda29b7ed9578891e0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:17 -0700 Subject: [PATCH 082/114] aliases/general: use `_command_exists` --- aliases/available/general.aliases.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 0c7bcd9d..61ebe538 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -30,7 +30,7 @@ then alias grep='grep --color=auto' fi -if which gshuf &> /dev/null +if _command_exists gshuf then alias shuf=gshuf fi @@ -65,7 +65,7 @@ alias -- -='cd -' # Go back alias h='history' # Tree -if [ ! -x "$(which tree 2>/dev/null)" ] +if ! _command_exists tree then alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" fi From 88d66bbfca0b7cc15a2e58ed44444c391d2c0293 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:24 -0700 Subject: [PATCH 083/114] aliases/curl: use `_command_exists` --- aliases/available/curl.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/curl.aliases.bash b/aliases/available/curl.aliases.bash index 3ced1bb5..a6b2b344 100644 --- a/aliases/available/curl.aliases.bash +++ b/aliases/available/curl.aliases.bash @@ -6,7 +6,8 @@ about-alias 'Curl aliases for convenience.' # set apt aliases function _set_pkg_aliases() { - if [ -x $(which curl) ]; then + if _command_exists curl + then # follow redirects alias cl='curl -L' # follow redirects, download as original name From 0ad1af8306f0f51c218a682663b13d5a8dda930c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:28 -0700 Subject: [PATCH 084/114] aliases/apt: use `_command_exists` --- aliases/available/apt.aliases.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aliases/available/apt.aliases.bash b/aliases/available/apt.aliases.bash index 2f444931..b7ef274c 100644 --- a/aliases/available/apt.aliases.bash +++ b/aliases/available/apt.aliases.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # # -binaryanomaly @@ -8,7 +8,8 @@ about-alias 'Apt and dpkg aliases for Ubuntu and Debian distros.' # set apt aliases function _set_pkg_aliases() { - if [ -x $(which apt) ]; then + if _command_exists apt + then alias apts='apt-cache search' alias aptshow='apt-cache show' alias aptinst='sudo apt-get install -V' From 679d8b10b6776e48843227f0f9327b5a3d7d697e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 01:16:46 -0700 Subject: [PATCH 085/114] completion/gradle: use `_command_exists` --- completion/available/gradle.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 6ec8c697..786450a6 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -58,9 +58,9 @@ __gradle-set-cache-name() { __gradle-set-files-checksum() { # Cache MD5 sum of all Gradle scripts and modified timestamps - if builtin command -v md5 > /dev/null; then + if _command_exists md5; then gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)") - elif builtin command -v md5sum > /dev/null; then + elif _command_exists md5sum; then gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}') else echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH" From 699720fe8bca6aa301a80c7eb244551806926eee Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:28:32 -0700 Subject: [PATCH 086/114] completion/docker-compose: use `_command_exists` --- completion/available/docker-compose.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 completion/available/docker-compose.completion.bash diff --git a/completion/available/docker-compose.completion.bash b/completion/available/docker-compose.completion.bash old mode 100644 new mode 100755 index bf2c13fb..1102f5d9 --- a/completion/available/docker-compose.completion.bash +++ b/completion/available/docker-compose.completion.bash @@ -676,7 +676,7 @@ _docker_compose() { done local completions_func=_docker_compose_${command//-/_} - declare -F $completions_func >/dev/null && $completions_func + _is_function $completions_func && $completions_func eval "$previous_extglob_setting" return 0 From 8e9438d7159c677ef4b7691c6842bc6bdbb164ac Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:30:35 -0700 Subject: [PATCH 087/114] completion/hub: use `_command_exists` --- completion/available/hub.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index 74c530a8..67a5e29b 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -23,12 +23,12 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # If there is no git tab completion, but we have the _completion loader try to load it -if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; then +if ! _is_function _git && _is_function _completion_loader; then _completion_loader git fi # Check that git tab completion is available and we haven't already set up completion -if declare -F _git > /dev/null && ! declare -F __git_list_all_commands_without_hub > /dev/null; then +if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # Duplicate and rename the 'list_all_commands' function eval "$(declare -f __git_list_all_commands | \ sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" From eabdf41b833609bea386f21ebe8200198b48dbb3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:32:19 -0700 Subject: [PATCH 088/114] lib/theme: use `_command_exists` --- themes/base.theme.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 1e0409d3..f9f5190d 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -396,7 +396,7 @@ function hg_prompt_vars { function nvm_version_prompt { local node - if declare -f -F nvm &> /dev/null; then + 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}" @@ -433,8 +433,8 @@ function rbfu_version_prompt { } function chruby_version_prompt { - if declare -f -F chruby &> /dev/null; then - if declare -f -F chruby_auto &> /dev/null; then + if _is_function chruby; then + if _is_function chruby_auto; then chruby_auto fi From a2e32f37c55362960e0ad89d56c1715a5867cfbc Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:32:52 -0700 Subject: [PATCH 089/114] theme/dulcie: use `_command_exists` --- themes/dulcie/dulcie.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 themes/dulcie/dulcie.theme.bash diff --git a/themes/dulcie/dulcie.theme.bash b/themes/dulcie/dulcie.theme.bash old mode 100644 new mode 100755 index a83b62fb..f70c7864 --- a/themes/dulcie/dulcie.theme.bash +++ b/themes/dulcie/dulcie.theme.bash @@ -77,7 +77,7 @@ dulcie_prompt() { printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}" # Open the new terminal in the same directory - declare -f __vte_osc7 > /dev/null && __vte_osc7 + _is_function __vte_osc7 && __vte_osc7 PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]" if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then From 8a03f451b2669faf4fa98b99978e8ba570948613 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 01:26:02 -0700 Subject: [PATCH 090/114] lib/helpers: simplify `_command_exists()` and `_binary_exists()` Remove subshell and just use a regular `if` --- lib/helpers.bash | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib/helpers.bash diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100644 new mode 100755 index 61705a04..fbc6aa88 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -23,7 +23,13 @@ function _command_exists () _example '$ _command_exists ls && echo exists' _group 'lib' local msg="${2:-Command '$1' does not exist!}" - type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -t "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _binary_exists () @@ -34,7 +40,13 @@ function _binary_exists () _example '$ _binary_exists ls && echo exists' _group 'lib' local msg="${2:-Binary '$1' does not exist!}" - type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -P "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _completion_exists () From fb6e05d91528bf83175f92b5481d0ee6d6a88c39 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:39:19 -0700 Subject: [PATCH 091/114] completions/sqlmap: use `_command_exists` Addresses bash-it/bash-it#1632 --- completion/available/sqlmap.completion.bash | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/completion/available/sqlmap.completion.bash b/completion/available/sqlmap.completion.bash index 16addf85..213dd817 100644 --- a/completion/available/sqlmap.completion.bash +++ b/completion/available/sqlmap.completion.bash @@ -1,21 +1,22 @@ -#!/bin/bash +# shellcheck shell=bash # ---------------------------------------------------------------------------+ # | -# Thanks to Alexander Korznikov | +# Thanks to Alexander Korznikov | # http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html | # | # ---------------------------------------------------------------------------+ -if command -v sqlmap > /dev/null; then +if _command_exists sqlmap +then - _sqlmap() + function _sqlmap() { local cur prev COMPREPLY=() - cur=$(_get_cword) - prev=$(_get_pword) + cur="$(_get_cword)" + prev="$(_get_pword)" case $prev in @@ -143,7 +144,7 @@ if command -v sqlmap > /dev/null; then --mobile --page-rank --purge-output --smart \ --sqlmap-shell --wizard ' COMPREPLY=( $( \ - (while read -d ' ' i; do + (while read -d ' ' i; do [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && continue # flatten array with spaces on either side, @@ -152,7 +153,7 @@ if command -v sqlmap > /dev/null; then COMPREPLY=" ${COMPREPLY[@]} " # remove word from list of completions COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) - done + done printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}" ) ) From 6e2e945771fb4488e5bc1b875db5c9221c1fc102 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 13:21:16 -0700 Subject: [PATCH 092/114] aliases/vim: simplify code flow --- aliases/available/vim.aliases.bash | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/aliases/available/vim.aliases.bash b/aliases/available/vim.aliases.bash index d5dcdc54..b426d270 100644 --- a/aliases/available/vim.aliases.bash +++ b/aliases/available/vim.aliases.bash @@ -2,20 +2,14 @@ cite 'about-alias' about-alias 'vim abbreviations' -if _command_exists vim; then - alias v='$VIM' - # open the vim help in fullscreen incorporated from - # https://stackoverflow.com/a/4687513 - alias vimh='${VIM} -c ":h | only"' -fi +_command_exists vim || return + +alias v='vim' +# open the vim help in fullscreen incorporated from +# https://stackoverflow.com/a/4687513 +alias vimh='vim -c ":h | only"' # open vim in new tab is taken from # http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek -case $OSTYPE in - darwin*) - _command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } - ;; - *) - _command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } - ;; -esac +_command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } +_command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } From 8a81fd7271756c657896075f438d658e2898896e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 13:33:34 -0700 Subject: [PATCH 093/114] plugins/ruby: prepare for `shellcheck` --- clean_files.txt | 1 + plugins/available/ruby.plugin.bash | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 2242ef5e..cbf14ee4 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -95,6 +95,7 @@ plugins/available/nodenv.plugin.bash plugins/available/plenv.plugin.bash plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash +plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index b1164106..3520d5e1 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -4,15 +4,14 @@ about-plugin 'ruby and rubygems specific functions and settings' # Make commands installed with 'gem install --user-install' available # ~/.gem/ruby/${RUBY_VERSION}/bin/ -if _command_exists ruby && _command_exists gem -then - pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after +if _command_exists ruby && _command_exists gem; then + pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after fi -function remove_gem { - about 'removes installed gem' - param '1: installed gem name' - group 'ruby' +function remove_gem() { + about 'removes installed gem' + param '1: installed gem name' + group 'ruby' - gem list | grep $1 | awk '{ print $1; }' | xargs sudo gem uninstall + gem list | grep "${1?}" | awk '{ print $1; }' | xargs sudo gem uninstall } From e5e7c7c55b523d769b6a962ddd88e679c3e94fdf Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 13:37:18 -0700 Subject: [PATCH 094/114] plugin/ruby: add missing parameter error message --- plugins/available/ruby.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index 3520d5e1..aed8daf8 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -13,5 +13,5 @@ function remove_gem() { param '1: installed gem name' group 'ruby' - gem list | grep "${1?}" | awk '{ print $1; }' | xargs sudo gem uninstall + gem list | grep "${1:?${FUNCNAME[0]}: no gem name provided}" | awk '{ print $1; }' | xargs sudo gem uninstall } From be90e655f167aa1c19b33769b033ea9877531288 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 13:47:26 -0700 Subject: [PATCH 095/114] completion/laravel: simplify code flow And apply `shfmt` and fix `shellcheck` --- clean_files.txt | 1 + completion/available/laravel.completion.bash | 29 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 2242ef5e..2ba7be78 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -58,6 +58,7 @@ completion/available/jungle.completion.bash completion/available/knife.completion.bash completion/available/kontena.completion.bash completion/available/kubectl.completion.bash +completion/available/laravel.completion.bash completion/available/lerna.completion.bash completion/available/minikube.completion.bash completion/available/ngrok.completion.bash diff --git a/completion/available/laravel.completion.bash b/completion/available/laravel.completion.bash index 9298a7bf..8f032568 100644 --- a/completion/available/laravel.completion.bash +++ b/completion/available/laravel.completion.bash @@ -1,17 +1,16 @@ -#!/usr/bin/bash +# shellcheck shell=bash -if _command_exists laravel -then - function __laravel_completion() - { - local OPTS=("-h --help -q --quiet --ansi --no-ansi -n --no-interaction -v -vv -vvv --verbose help list new") - COMPREPLY=() - for _opt_ in ${OPTS[@]}; do - if [[ "$_opt_" == "$2"* ]]; then - COMPREPLY+=("$_opt_") - fi - done - } +_command_exists laravel || return - complete -F __laravel_completion laravel -fi +function __laravel_completion() { + local OPTS=('-h' '--help' '-q' '--quiet' '--ansi' '--no-ansi' '-n' '--no-interaction' '-v' '-vv' '-vvv' '--verbose' 'help' 'list' 'new') + local _opt_ + COMPREPLY=() + for _opt_ in "${OPTS[@]}"; do + if [[ "$_opt_" == "$2"* ]]; then + COMPREPLY+=("$_opt_") + fi + done +} + +complete -F __laravel_completion laravel From 0471a20c7cf5440bb5180f815254cc30873acbd9 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 13:00:36 -0700 Subject: [PATCH 096/114] lib/helpers: new function `_bash-it-find-in-ancestor()` New function to do a search looking for a sibling to a parent of the current directory, for example to find `../../.git` to indicate that `$PWD` is inside a git repository. --- lib/helpers.bash | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index fbc6aa88..26f1c3a6 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -849,3 +849,21 @@ then fi } fi + +function _bash-it-find-in-ancestor() ( + # We're deliberately using a subshell for this entire function for simplicity. + # By using a subshell, we can use ${PWD} without special handling, and can + # just `cd ..` to move up the directory heirarchy. + # Let the shell do the work. + local kin + while [[ "${PWD}" != '/' ]]; do + for kin in "$@"; do + if [[ -r "${PWD}/${kin}" ]]; then + printf '%s' "${PWD}" + return "$?" + fi + done + command cd .. || return "$?" + done + return 1 +) From 7ed12083f26ce95cb9018bf6688fdba2e96514dc Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 15:29:47 -0700 Subject: [PATCH 097/114] gradle: adopt `_bash_it_find_in_ancestor()` --- completion/available/gradle.completion.bash | 14 +++----------- plugins/available/gradle.plugin.bash | 15 +++------------ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 786450a6..35971d50 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -22,17 +22,9 @@ # Avoid inaccurate completions for subproject tasks COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') -__gradle-set-project-root-dir() { - local dir="${PWD}" - project_root_dir="${PWD}" - while [[ $dir != '/' ]]; do - if [[ -f "$dir/settings.gradle" || -f "$dir/gradlew" ]]; then - project_root_dir=$dir - return 0 - fi - dir="$(dirname "$dir")" - done - return 1 +function __gradle-set-project-root-dir() { + project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")" + return "$?" } __gradle-init-cache-dir() { diff --git a/plugins/available/gradle.plugin.bash b/plugins/available/gradle.plugin.bash index 6267bd84..8dec1313 100644 --- a/plugins/available/gradle.plugin.bash +++ b/plugins/available/gradle.plugin.bash @@ -3,19 +3,10 @@ about-plugin 'Add a gw command to use gradle wrapper if present, else use system function gw() { local file="gradlew" - local curr_path="${PWD}" - local result="gradle" + local result - # Search recursively upwards for file. - until [[ "${curr_path}" == "/" ]]; do - if [[ -e "${curr_path}/${file}" ]]; then - result="${curr_path}/${file}" - break - else - curr_path=$(dirname "${curr_path}") - fi - done + result="$(_bash-it-find-in-ancestor "${file}")" # Call gradle - "${result}" $* + "${result:-gradle}" $* } From e8966ea2a58efe6c3d6337e4deff15c7b8a55d45 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 13:10:19 -0700 Subject: [PATCH 098/114] lib/helpers: cite `_bash-it-find-in-ancestor()` Add `composure.sh` citation with examples and rewrite internal comments to describe the code flow. --- lib/helpers.bash | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 26f1c3a6..94df885d 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -850,12 +850,21 @@ then } fi +# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in +# 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() ( - # We're deliberately using a subshell for this entire function for simplicity. - # By using a subshell, we can use ${PWD} without special handling, and can - # just `cd ..` to move up the directory heirarchy. - # Let the shell do the work. + 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. while [[ "${PWD}" != '/' ]]; do for kin in "$@"; do if [[ -r "${PWD}/${kin}" ]]; then From 55be49e8871194ec8c34a2ffa9f6589775e6d773 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:16:54 -0700 Subject: [PATCH 099/114] plugins/less-pretty-cat: use `_command_exists` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses bash-it/bash-it#1632 Alsö, code style cleanup: quote variables, handle unbound parameters, &c. --- plugins/available/less-pretty-cat.plugin.bash | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index b6b9d1f0..bfe0fe09 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -1,13 +1,9 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'pygmentize instead of cat to terminal if possible' -if $(command -v pygmentize &> /dev/null) ; then - # get the full paths to binaries - CAT_BIN=$(which cat) - LESS_BIN=$(which less) - BASH_IT_CCAT_STYLE="${BASH_IT_CCAT_STYLE:=default}" - BASH_IT_CLESS_STYLE="${BASH_IT_CLESS_STYLE:=default}" - +if _command_exists pygmentize +then # pigmentize cat and less outputs - call them ccat and cless to avoid that # especially cat'ed output in scripts gets mangled with pygemtized meta characters function ccat() @@ -15,17 +11,21 @@ if $(command -v pygmentize &> /dev/null) ; then about 'runs either pygmentize or cat on each file passed in' param '*: files to concatenate (as normally passed to cat)' example 'cat mysite/manage.py dir/text-file.txt' - for var; + local file + : "${BASH_IT_CCAT_STYLE:=default}" + + for file in "$@" do - pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var"; + pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$file" 2>/dev/null || command cat "$file"; done } function cless() { - about 'it pigments the file passed in and passes it to less for pagination' + about 'pigments the file passed in and passes it to less for pagination' param '$1: the file to paginate with less' example 'less mysite/manage.py' - pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R + : "${BASH_IT_CLESS_STYLE:=default}" + pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g "$@" | command less -R } fi From 58576483773e3f90f0044b078f8a6d9b8b61a163 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 22 Sep 2021 14:16:23 -0700 Subject: [PATCH 100/114] plugins/less-pretty-cat: simplify code flow Convert from indented if-block to return then unindented code. This should have basically one line change at the top, one line removed at the bottom, and then all whitespace. --- clean_files.txt | 1 + plugins/available/less-pretty-cat.plugin.bash | 49 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 2242ef5e..240c6059 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash +plugins/available/less-pretty-cat.plugin.bash plugins/available/node.plugin.bash plugins/available/nodenv.plugin.bash plugins/available/plenv.plugin.bash diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index bfe0fe09..cde646c5 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -2,30 +2,29 @@ cite about-plugin about-plugin 'pygmentize instead of cat to terminal if possible' -if _command_exists pygmentize -then - # pigmentize cat and less outputs - call them ccat and cless to avoid that - # especially cat'ed output in scripts gets mangled with pygemtized meta characters - function ccat() - { - about 'runs either pygmentize or cat on each file passed in' - param '*: files to concatenate (as normally passed to cat)' - example 'cat mysite/manage.py dir/text-file.txt' - local file - : "${BASH_IT_CCAT_STYLE:=default}" +_command_exists pygmentize || return - for file in "$@" - do - pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$file" 2>/dev/null || command cat "$file"; - done - } +# pigmentize cat and less outputs - call them ccat and cless to avoid that +# especially cat'ed output in scripts gets mangled with pygemtized meta characters +function ccat() { + about 'runs either pygmentize or cat on each file passed in' + param '*: files to concatenate (as normally passed to cat)' + example 'ccat mysite/manage.py dir/text-file.txt' - function cless() - { - about 'pigments the file passed in and passes it to less for pagination' - param '$1: the file to paginate with less' - example 'less mysite/manage.py' - : "${BASH_IT_CLESS_STYLE:=default}" - pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g "$@" | command less -R - } -fi + local file + : "${BASH_IT_CCAT_STYLE:=default}" + + for file in "$@"; do + pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$file" 2> /dev/null || command cat "$file" + done +} + +function cless() { + about 'pigments the file passed in and passes it to less for pagination' + param '1: the file to paginate with less' + example 'cless mysite/manage.py' + + : "${BASH_IT_CLESS_STYLE:=default}" + + pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g "$@" | command less -R +} From 84c96665ce03cbaa904c0120a5e9f48015ee796a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 23 Sep 2021 14:51:21 -0700 Subject: [PATCH 101/114] completion/wpscan: simplify code flow (whitespace) Convert from indented if-block to return then unindented code. This should have basically one line change at the top, one line removed at the bottom, and then all whitespace. --- completion/available/wpscan.completion.bash | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/completion/available/wpscan.completion.bash b/completion/available/wpscan.completion.bash index 8891ab7f..105468a3 100644 --- a/completion/available/wpscan.completion.bash +++ b/completion/available/wpscan.completion.bash @@ -1,15 +1,16 @@ # shellcheck shell=bash -if _command_exists wpscan; then - function __wpscan_completion() { - local OPTS=("--help --hh --version --url --ignore-main-redirect --verbose --output --format --detection-mode --scope --headers --user-agent --vhost --random-user-agent --user-agents-list --http-auth --max-threads --throttle --request-timeout --connect-timeout --disable-tlc-checks --proxy --proxy-auth --cookie-string --cookie-jar --cache-ttl --clear-cache --server --cache-dir --update --no-update --wp-content-dir --wp-plugins-dir --wp-version-detection --main-theme-detection --enumerate --exclude-content-based --plugins-list --plugins-detection --plugins-version-all --plugins-version-detection --themes-list --themes-detection --themes-version-all --themes-version-detection --timthumbs-list --timthumbs-detection --config-backups-list --config-backups-detection --db-exports-list --db-exports-detection --medias-detection --users-list --users-detection --passwords --usernames --multicall-max-passwords --password-attack --stealthy") - COMPREPLY=() - for _opt_ in "${OPTS[@]}"; do - if [[ "$_opt_" == "$2"* ]]; then - COMPREPLY+=("$_opt_") - fi - done - } +_command_exists wpscan || return - complete -F __wpscan_completion wpscan -fi +function __wpscan_completion() { + local _opt_ + local OPTS=('--help' '--hh' '--version' '--url' '--ignore-main-redirect' '--verbose' '--output' '--format' '--detection-mode' '--scope' '--headers' '--user-agent' '--vhost' '--random-user-agent' '--user-agents-list' '--http-auth' '--max-threads' '--throttle' '--request-timeout' '--connect-timeout' '--disable-tlc-checks' '--proxy' '--proxy-auth' '--cookie-string' '--cookie-jar' '--cache-ttl' '--clear-cache' '--server' '--cache-dir' '--update' '--no-update' '--wp-content-dir' '--wp-plugins-dir' '--wp-version-detection' '--main-theme-detection' '--enumerate' '--exclude-content-based' '--plugins-list' '--plugins-detection' '--plugins-version-all' '--plugins-version-detection' '--themes-list' '--themes-detection' '--themes-version-all' '--themes-version-detection' '--timthumbs-list' '--timthumbs-detection' '--config-backups-list' '--config-backups-detection' '--db-exports-list' '--db-exports-detection' '--medias-detection' '--users-list' '--users-detection' '--passwords' '--usernames' '--multicall-max-passwords' '--password-attack' '--stealthy') + COMPREPLY=() + for _opt_ in "${OPTS[@]}"; do + if [[ "$_opt_" == "$2"* ]]; then + COMPREPLY+=("$_opt_") + fi + done +} + +complete -F __wpscan_completion wpscan From 2ddb40751f5dcdfbeb196a6d24deac599f39411f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 23 Sep 2021 15:42:23 -0700 Subject: [PATCH 102/114] plugin/less-pretty-cat: remove `|| cat` The logic to run `cat` if `pygmentize` fails seems useless, so just remove it. --- plugins/available/less-pretty-cat.plugin.bash | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index cde646c5..139e5188 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -7,24 +7,17 @@ _command_exists pygmentize || return # pigmentize cat and less outputs - call them ccat and cless to avoid that # especially cat'ed output in scripts gets mangled with pygemtized meta characters function ccat() { - about 'runs either pygmentize or cat on each file passed in' + about 'runs pygmentize on each file passed in' param '*: files to concatenate (as normally passed to cat)' example 'ccat mysite/manage.py dir/text-file.txt' - local file - : "${BASH_IT_CCAT_STYLE:=default}" - - for file in "$@"; do - pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$file" 2> /dev/null || command cat "$file" - done + pygmentize -f 256 -O style="${BASH_IT_CCAT_STYLE:-default}" -g "$@" } function cless() { - about 'pigments the file passed in and passes it to less for pagination' - param '1: the file to paginate with less' + about 'pigments the files passed in and passes to less for pagination' + param '*: the files to paginate with less' example 'cless mysite/manage.py' - : "${BASH_IT_CLESS_STYLE:=default}" - - pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g "$@" | command less -R + pygmentize -f 256 -O style="${BASH_IT_CLESS_STYLE:-default}" -g "$@" | command less -R } From b897c7d3ce5a7ca5198ab05a6489c556b19f3d0f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 23 Sep 2021 22:21:02 -0700 Subject: [PATCH 103/114] completion/pip: simplify code flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Short-circuit the loader rather than indenting nearly the whole file. ALSÖ, assign the `_pip_completion()` handler directly once it's loaded so that we get out of the way once we load it. --- completion/available/pip.completion.bash | 23 ++++++++++++----------- completion/available/pip3.completion.bash | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/completion/available/pip.completion.bash b/completion/available/pip.completion.bash index a20df4cd..f094d6ed 100644 --- a/completion/available/pip.completion.bash +++ b/completion/available/pip.completion.bash @@ -6,14 +6,15 @@ # If the pip package is installed within virtual environments, say, python managed by pyenv, # you should first initialize the corresponding environment. # So that pip is in the system's path. -if _command_exists pip; then - function __bash_it_complete_pip() { - if _command_exists _pip_completion; then - _pip_completion "$@" - else - eval "$(pip completion --bash)" - _pip_completion "$@" - fi - } - complete -o default -F __bash_it_complete_pip pip -fi +_command_exists pip || return + +function __bash_it_complete_pip() { + if _command_exists _pip_completion; then + complete -o default -F _pip_completion pip + _pip_completion "$@" + else + eval "$(pip completion --bash)" + _pip_completion "$@" + fi +} +complete -o default -F __bash_it_complete_pip pip diff --git a/completion/available/pip3.completion.bash b/completion/available/pip3.completion.bash index d69460a5..34abc053 100644 --- a/completion/available/pip3.completion.bash +++ b/completion/available/pip3.completion.bash @@ -6,14 +6,15 @@ # If the pip package is installed within virtual environments, say, python managed by pyenv, # you should first initialize the corresponding environment. # So that pip3 is in the system's path. -if _command_exists pip3; then - function __bash_it_complete_pip3() { - if _command_exists _pip_completion; then - _pip_completion "$@" - else - eval "$(pip3 completion --bash)" - _pip_completion "$@" - fi - } - complete -o default -F __bash_it_complete_pip3 pip3 -fi +_command_exists pip3 || return + +function __bash_it_complete_pip3() { + if _command_exists _pip_completion; then + complete -o default -F _pip_completion pip3 + _pip_completion "$@" + else + eval "$(pip3 completion --bash)" + _pip_completion "$@" + fi +} +complete -o default -F __bash_it_complete_pip3 pip3 From 2ada4142668496fef6802e7cbc871c0836b43abb Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 00:38:54 -0700 Subject: [PATCH 104/114] plugins/percol: use `_command_exists` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses bash-it/bash-it#1632 And use `_log_warning`. Alsö, code style cleanup: quote things, handle unbound parameters, &c. Alsö alsö, short-circuit if not installed or inadequate _Bash_ version. --- plugins/available/percol.plugin.bash | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/plugins/available/percol.plugin.bash b/plugins/available/percol.plugin.bash index c1fc807c..cc83683e 100644 --- a/plugins/available/percol.plugin.bash +++ b/plugins/available/percol.plugin.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Search&Select history with percol' @@ -12,24 +13,26 @@ about-plugin 'Search&Select history with percol' # Usage ## C-r to search&select from history -_replace_by_history() { - if command -v tac>/dev/null; then +_command_exists percol || return + +if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then + _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin." + _log_warning "Your current Bash version is $BASH_VERSION." + return +else + bind -x '"\C-r": _replace_by_history' +fi + +function _replace_by_history() { + local HISTTIMEFORMAT= # Ensure we can parse history properly + if _command_exists tac + then alias _tac=tac else alias _tac="tail -r" fi - local l=$(HISTTIMEFORMAT= history | _tac | sed -e 's/^\ *[0-9]*\ *//' | percol --query "$READLINE_LINE") - READLINE_LINE="$l" + #TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}" + local l="$(history | _tac | sed -e 's/^\ *[0-9]*\ *//' | percol --query "${READLINE_LINE:-}")" + READLINE_LINE="${l}" READLINE_POINT=${#l} } - - -if command -v percol>/dev/null; then - current_version=${BASH_VERSION%%[^0-9]*} - if [ $current_version -lt 4 ]; then - echo -e "\033[91mWarning: You have to upgrade Bash to Bash v4.x to use the 'percol' plugin.\033[m" - echo -e "\033[91m Your current Bash version is $BASH_VERSION.\033[m" - else - bind -x '"\C-r": _replace_by_history' - fi -fi From 92282c479550994105c10c5b64034d22a5af23a0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 00:39:07 -0700 Subject: [PATCH 105/114] plugin/percol: `shellcheck` & `shfmt` According to `shellcheck`, the `_tac` alias simply doesn't work. At all. Ever. See SC2262 and SC2263. --- clean_files.txt | 1 + plugins/available/percol.plugin.bash | 21 ++++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 2242ef5e..cf8d082a 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -92,6 +92,7 @@ plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash plugins/available/nodenv.plugin.bash +plugins/available/percol.plugin.bash plugins/available/plenv.plugin.bash plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash diff --git a/plugins/available/percol.plugin.bash b/plugins/available/percol.plugin.bash index cc83683e..97986ccf 100644 --- a/plugins/available/percol.plugin.bash +++ b/plugins/available/percol.plugin.bash @@ -16,23 +16,18 @@ about-plugin 'Search&Select history with percol' _command_exists percol || return if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then - _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin." - _log_warning "Your current Bash version is $BASH_VERSION." - return + _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin." + _log_warning "Your current Bash version is $BASH_VERSION." + return else - bind -x '"\C-r": _replace_by_history' + bind -x '"\C-r": _replace_by_history' fi function _replace_by_history() { local HISTTIMEFORMAT= # Ensure we can parse history properly - if _command_exists tac - then - alias _tac=tac - else - alias _tac="tail -r" - fi #TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}" - local l="$(history | _tac | sed -e 's/^\ *[0-9]*\ *//' | percol --query "${READLINE_LINE:-}")" - READLINE_LINE="${l}" - READLINE_POINT=${#l} + local l + l="$(history | tail -r | sed -e 's/^\ *[0-9]*\ *//' | percol --query "${READLINE_LINE:-}")" + READLINE_LINE="${l}" + READLINE_POINT=${#l} } From e22aac855ef7bf2b9d09f086d64df272bdd23d1b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 21:10:01 -0700 Subject: [PATCH 106/114] completion/git: expand search range - Remove limitation on OS. - Add search for Mac OS X developer tools locations by using `xcrun` instead of trying to guess paths. - Add search for locations based on path of `$GIT_EXE` (set by `lib/theme`). --- completion/available/git.completion.bash | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index b9bb1bb6..16b21f2c 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -1,28 +1,31 @@ -#!/usr/bin/env bash - -# Only operate on MacOS since there are no linux paths -if [[ "$OSTYPE" != 'darwin'* ]] ; then - _log_warning "unsupported operating system - only 'Darwin' is supported" - return 0 -fi +# shellcheck shell=bash +# +# Locate and load completions for `git`. # Make sure git is installed -_command_exists git || return 0 +_command_exists git || return # Don't handle completion if it's already managed -if complete -p git &>/dev/null ; then +if complete -p git &>/dev/null; then _log_warning "completion already loaded - this usually means it is safe to stop using this completion" return 0 fi -_git_bash_completion_found=false +_git_bash_completion_xcrun_git= +if _command_exists xcrun; then + _git_bash_completion_xcrun_git="$(xcrun --find git)" +fi _git_bash_completion_paths=( + # Standard locations + "${GIT_EXE%/*}/../share/git-core/git-completion.bash" + "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" + "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" # MacOS non-system locations - '/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash' - '/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash' + "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" ) # Load the first completion file found +_git_bash_completion_found=false for _comp_path in "${_git_bash_completion_paths[@]}" ; do if [[ -r "$_comp_path" ]] ; then _git_bash_completion_found=true @@ -35,5 +38,4 @@ done if [[ "${_git_bash_completion_found}" == false ]]; then _log_warning "no completion files found - please try enabling the 'system' completion instead." fi -unset _git_bash_completion_paths -unset _git_bash_completion_found +unset "${!_git_bash_completion@}" From b0750fa49fcdc4fe102ea6b907c3a7b9ac0518a3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 21:10:32 -0700 Subject: [PATCH 107/114] completion/git: `shfmt` && `shellcheck` --- clean_files.txt | 1 + completion/available/git.completion.bash | 33 ++++++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 2242ef5e..cff2c60b 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -49,6 +49,7 @@ completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/gcloud.completion.bash completion/available/gem.completion.bash +completion/available/git.completion.bash completion/available/github-cli.completion.bash completion/available/go.completion.bash completion/available/helm.completion.bash diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index 16b21f2c..31b77fa3 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -6,9 +6,9 @@ _command_exists git || return # Don't handle completion if it's already managed -if complete -p git &>/dev/null; then - _log_warning "completion already loaded - this usually means it is safe to stop using this completion" - return 0 +if complete -p git &> /dev/null; then + _log_warning "completion already loaded - this usually means it is safe to stop using this completion" + return 0 fi _git_bash_completion_xcrun_git= @@ -16,26 +16,27 @@ if _command_exists xcrun; then _git_bash_completion_xcrun_git="$(xcrun --find git)" fi _git_bash_completion_paths=( - # Standard locations - "${GIT_EXE%/*}/../share/git-core/git-completion.bash" - "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" - "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" - # MacOS non-system locations - "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" + # Standard locations + "${GIT_EXE%/*}/../share/git-core/git-completion.bash" + "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" + "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" + # MacOS non-system locations + "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" ) # Load the first completion file found _git_bash_completion_found=false -for _comp_path in "${_git_bash_completion_paths[@]}" ; do - if [[ -r "$_comp_path" ]] ; then - _git_bash_completion_found=true - source "$_comp_path" - break - fi +for _comp_path in "${_git_bash_completion_paths[@]}"; do + if [[ -r "$_comp_path" ]]; then + _git_bash_completion_found=true + # shellcheck disable=SC1090 # don't follow + source "$_comp_path" + break + fi done # Cleanup if [[ "${_git_bash_completion_found}" == false ]]; then - _log_warning "no completion files found - please try enabling the 'system' completion instead." + _log_warning "no completion files found - please try enabling the 'system' completion instead." fi unset "${!_git_bash_completion@}" From a4e4f30ff14209ea69ddee1e6a028627573d839a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 26 Sep 2021 11:54:32 -0700 Subject: [PATCH 108/114] plugins/percol: `bind` Move `bind` below function definition --- plugins/available/percol.plugin.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/available/percol.plugin.bash b/plugins/available/percol.plugin.bash index 97986ccf..027dfdc4 100644 --- a/plugins/available/percol.plugin.bash +++ b/plugins/available/percol.plugin.bash @@ -19,8 +19,6 @@ if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin." _log_warning "Your current Bash version is $BASH_VERSION." return -else - bind -x '"\C-r": _replace_by_history' fi function _replace_by_history() { @@ -31,3 +29,4 @@ function _replace_by_history() { READLINE_LINE="${l}" READLINE_POINT=${#l} } +bind -x '"\C-r": _replace_by_history' From c2c76a380ab4c505b5800da471719bdb26d2dfa4 Mon Sep 17 00:00:00 2001 From: John D Pell <52194+gaelicWizard@users.noreply.github.com> Date: Tue, 28 Sep 2021 05:13:27 -0700 Subject: [PATCH 109/114] plugin/base: improvements (#1930) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * plugins/base: code style improvements Quote variables, use $@ and $array[@] instead of $*, typeset some integers, remove unneccesasary binary invocation, use shell features when possible, remove `eval`, &c. * plugins/base: conditional function definitions Instead of functions failing when required tools aren't installed, just don't define the function. Alsö, don't redefine del() if it already exists. * plugins/base: rewrite `usage()` Reimplement disk usage function using Bash syntax and simpler layout, without having to invoke an external binary. * plugins/base: revamp `quiet()` New implementation that is even quieter. * plugins/base: `myip()` * plugins/base: `pickfrom()` * plugins/base: `passgen()` Fix `passgen()` to not need `tr`, remove one subshell, and eliminate a useless `echo`. * plugins/base: `mkcd()` * plugins/base: `mkiso()` * plugins/base: remove `banish-cookies()` Adobe Flash is gone with the wind. Alsö, this would be something someone would do *once* and shouldn't be a function... * plugins/base: `lsgrep` is SC2010 The `lsgrep()` function is *itself* explicitly forbidden by `shellcheck` rule SC2010. Alsö, s/`$*`/`$@` * plugins/base: `mkiso()` Expressly handle unbound parameters. * plugins/base: remove `command_exists` * plugin/base: lint SC2154 && SC2144 Newly undisabled `shellcheck` rules * plugin/base: import libs for tests * plugin/base: `shfmt` Apply `shfmt` using current project settings. My apologies to future `git blame` hunters. ♥ --- clean_files.txt | 1 + plugins/available/base.plugin.bash | 342 +++++++++++++---------------- test/lib/helpers.bats | 2 +- test/lib/log.bats | 3 +- test/plugins/base.plugin.bats | 2 + test/plugins/battery.plugin.bats | 2 + 6 files changed, 161 insertions(+), 191 deletions(-) mode change 100644 => 100755 test/plugins/battery.plugin.bats diff --git a/clean_files.txt b/clean_files.txt index cb715e8f..8388bb52 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -79,6 +79,7 @@ completion/available/wpscan.completion.bash # plugins/available/alias-completion.plugin.bash plugins/available/autojump.plugin.bash +plugins/available/base.plugin.bash plugins/available/basher.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/direnv.plugin.bash diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index b0899ce9..6490ab88 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -1,216 +1,180 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'miscellaneous tools' -function ips () -{ - about 'display all ip addresses for this host' - group 'base' - if _command_exists ifconfig - then - ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' - elif _command_exists ip - then - ip addr | grep -oP 'inet \K[\d.]+' - else - echo "You don't have ifconfig or ip command installed!" - fi +function ips() { + about 'display all ip addresses for this host' + group 'base' + if _command_exists ifconfig; then + ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' + elif _command_exists ip; then + ip addr | grep -oP 'inet \K[\d.]+' + else + echo "You don't have ifconfig or ip command installed!" + fi } -function down4me () -{ - about 'checks whether a website is down for you, or everybody' - param '1: website url' - example '$ down4me http://www.google.com' - group 'base' - curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' +function down4me() { + about 'checks whether a website is down for you, or everybody' + param '1: website url' + example '$ down4me http://www.google.com' + group 'base' + curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' } -function myip () -{ - about 'displays your ip address, as seen by the Internet' - group 'base' - list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/") - for url in ${list[*]} - do - res=$(curl -fs "${url}") - if [[ $? -eq 0 ]];then - break; - fi - done - res=$(echo "$res" | grep -Eo '[0-9\.]+') - echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}" +function myip() { + about 'displays your ip address, as seen by the Internet' + group 'base' + list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/") + for url in "${list[@]}"; do + if res="$(curl -fs "${url}")"; then + break + fi + done + res="$(echo "$res" | grep -Eo '[0-9\.]+')" + echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}" } -function pickfrom () -{ - about 'picks random line from file' - param '1: filename' - example '$ pickfrom /usr/share/dict/words' - group 'base' - local file=$1 - [[ -z "$file" ]] && reference $FUNCNAME && return - length=$(cat $file | wc -l) - n=$(expr $RANDOM \* $length \/ 32768 + 1) - head -n $n $file | tail -1 +function pickfrom() { + about 'picks random line from file' + param '1: filename' + example '$ pickfrom /usr/share/dict/words' + group 'base' + local file=${1:-} + local -i n=0 length + if [[ ! -r "$file" ]]; then + reference "${FUNCNAME[0]}" && return + fi + length="$(wc -l < "$file")" + n=$((RANDOM * length / 32768 + 1)) + head -n "$n" "$file" | tail -1 } -function passgen () -{ - about 'generates random password from dictionary words' - param 'optional integer length' - param 'if unset, defaults to 4' - example '$ passgen' - example '$ passgen 6' - group 'base' - local i pass length=${1:-4} - pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done)) - echo "With spaces (easier to memorize): $pass" - echo "Without (use this as the password): $(echo $pass | tr -d ' ')" +function passgen() { + about 'generates random password from dictionary words' + param 'optional integer length' + param 'if unset, defaults to 4' + example '$ passgen' + example '$ passgen 6' + group 'base' + local -i i length=${1:-4} + local pass + # shellcheck disable=SC2034 + pass="$(for i in $(eval "echo {1..$length}"); do pickfrom /usr/share/dict/words; done)" + echo "With spaces (easier to memorize): ${pass//$'\n'/ }" + echo "Without spaces (easier to brute force): ${pass//$'\n'/}" } # Create alias pass to passgen when pass isn't installed or # BASH_IT_LEGACY_PASS is true. -if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]] -then - alias pass=passgen +if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then + alias pass=passgen fi -function pmdown () -{ - about 'preview markdown file in a browser' - param '1: markdown file' - example '$ pmdown README.md' - group 'base' - if _command_exists markdown - then - markdown $1 | browser - else - echo "You don't have a markdown command installed!" - fi -} +if _command_exists markdown && _command_exists browser; then + function pmdown() { + about 'preview markdown file in a browser' + param '1: markdown file' + example '$ pmdown README.md' + group 'base' -function mkcd () -{ - about 'make one or more directories and cd into the last one' - param 'one or more directories to create' - example '$ mkcd foo' - example '$ mkcd /tmp/img/photos/large' - example '$ mkcd foo foo1 foo2 fooN' - example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing' - group 'base' - mkdir -p -- "$@" && eval cd -- "\"\$$#\"" -} - -function lsgrep () -{ - about 'search through directory contents with grep' - group 'base' - ls | grep "$*" -} - -function quiet () -{ - about 'what *does* this do?' - group 'base' - $* &> /dev/null & -} - -function banish-cookies () -{ - about 'redirect .adobe and .macromedia files to /dev/null' - group 'base' - rm -r ~/.macromedia ~/.adobe - ln -s /dev/null ~/.adobe - ln -s /dev/null ~/.macromedia -} - -function usage () -{ - about 'disk usage per directory, in Mac OS X and Linux' - param '1: directory name' - group 'base' - if [[ "$OSTYPE" == 'darwin'* ]]; then - if [ -n "$1" ]; then - du -hd 1 "$1" - else - du -hd 1 - fi - - elif [[ "$OSTYPE" = 'linux'* ]]; then - if [[ -n "$1" ]]; then - du -h --max-depth=1 "$1" - else - du -h --max-depth=1 - fi - fi -} - -if [[ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ]] && [[ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]] -then -# if user has installed todo plugin, skip this... - function t () - { - about 'one thing todo' - param 'if not set, display todo item' - param '1: todo text' - if [[ "$*" == "" ]] ; then - cat ~/.t - else - echo "$*" > ~/.t - fi - } + markdown "${1?}" | browser + } fi -function command_exists () -{ - about 'checks for existence of a command' - param '1: command to check' - example '$ command_exists ls && echo exists' - group 'base' - type "$1" &> /dev/null ; +function mkcd() { + about 'make one or more directories and cd into the last one' + param 'one or more directories to create' + example '$ mkcd foo' + example '$ mkcd /tmp/img/photos/large' + example '$ mkcd foo foo1 foo2 fooN' + example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing' + group 'base' + mkdir -p -- "$@" && cd -- "${!#}" || return } -mkiso () -{ - about 'creates iso from current dir in the parent dir (unless defined)' - param '1: ISO name' - param '2: dest/path' - param '3: src/path' - example 'mkiso' - example 'mkiso ISO-Name dest/path src/path' - group 'base' - - if type "mkisofs" > /dev/null; then - [[ -z ${1+x} ]] && local isoname=${PWD##*/} || local isoname=$1 - [[ -z ${2+x} ]] && local destpath=../ || local destpath=$2 - [[ -z ${3+x} ]] && local srcpath=${PWD} || local srcpath=$3 - - if [[ ! -f "${destpath}${isoname}.iso" ]]; then - echo "writing ${isoname}.iso to ${destpath} from ${srcpath}" - mkisofs -V ${isoname} -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}" - else - echo "${destpath}${isoname}.iso already exists" - fi - else - echo "mkisofs cmd does not exist, please install cdrtools" - fi +# shellcheck disable=SC2010 +function lsgrep() { + about 'search through directory contents with grep' + group 'base' + ls | grep "$@" } +function quiet() { + about 'what *does* this do?' + group 'base' + nohup "$@" &> /dev/null < /dev/null & +} + +function usage() { + about 'disk usage per directory, in Mac OS X and Linux' + param '1: directory name' + group 'base' + case $OSTYPE in + *'darwin'*) + du -hd 1 "$@" + ;; + *'linux'*) + du -h --max-depth=1 "$@" + ;; + esac +} + +# shellcheck disable=SC2144 # the glob matches only one file +if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" && + ! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then + # if user has installed todo plugin, skip this... + function t() { + about 'one thing todo' + param 'if not set, display todo item' + param '1: todo text' + if [[ "$*" == "" ]]; then + cat ~/.t + else + echo "$*" > ~/.t + fi + } +fi + +if _command_exists mkisofs; then + function mkiso() { + about 'creates iso from current dir in the parent dir (unless defined)' + param '1: ISO name' + param '2: dest/path' + param '3: src/path' + example 'mkiso' + example 'mkiso ISO-Name dest/path src/path' + group 'base' + + local isoname="${1:-${PWD##*/}}" + local destpath="${2:-../}" + local srcpath="${3:-${PWD}}" + + if [[ ! -f "${destpath%/}/${isoname}.iso" ]]; then + echo "writing ${isoname}.iso to ${destpath} from ${srcpath}" + mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath%/}/${isoname}.iso" "${srcpath}" + else + echo "${destpath%/}/${isoname}.iso already exists" + fi + } +fi + # useful for administrators and configs -function buf () -{ - about 'back up file with timestamp' - param 'filename' - group 'base' - local filename=$1 - local filetime=$(date +%Y%m%d_%H%M%S) - cp -a "${filename}" "${filename}_${filetime}" +function buf() { + about 'back up file with timestamp' + param 'filename' + group 'base' + local filename="${1?}" filetime + filetime=$(date +%Y%m%d_%H%M%S) + cp -a "${filename}" "${filename}_${filetime}" } -function del() { - about 'move files to hidden folder in tmp, that gets cleared on each reboot' - param 'file or folder to be deleted' - example 'del ./file.txt' - group 'base' - mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; -} +if ! _command_exists del; then + function del() { + about 'move files to hidden folder in tmp, that gets cleared on each reboot' + param 'file or folder to be deleted' + example 'del ./file.txt' + group 'base' + mkdir -p /tmp/.trash && mv "$@" /tmp/.trash + } +fi diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index e60d5542..7f6664e0 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -5,11 +5,11 @@ load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log load ../../lib/utilities load ../../lib/search -load ../../plugins/available/base.plugin cite _about _param _example _group _author _version load ../../lib/helpers +load ../../plugins/available/base.plugin function local_setup { setup_test_fixture diff --git a/test/lib/log.bats b/test/lib/log.bats index f4a04f0e..329386bd 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -3,10 +3,11 @@ load ../test_helper load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/appearance -load ../../plugins/available/base.plugin cite _about _param _example _group _author _version load ../../lib/log +load ../../lib/helpers +load ../../plugins/available/base.plugin @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 1def481e..6f1099cc 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -2,6 +2,8 @@ load ../test_helper load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +load ../../lib/log +load ../../lib/helpers load ../../plugins/available/base.plugin @test 'plugins base: ips()' { diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats old mode 100644 new mode 100755 index 9af49697..fda52b02 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -2,6 +2,8 @@ load ../test_helper load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +load "${BASH_IT}/lib/log.bash" +load "${BASH_IT}/lib/helpers.bash" cite _about _param _example _group _author _version From 3eed0f033fca8a6dd7687c9828880ef6ca20c6ff Mon Sep 17 00:00:00 2001 From: John D Pell <52194+gaelicWizard@users.noreply.github.com> Date: Tue, 28 Sep 2021 05:24:18 -0700 Subject: [PATCH 110/114] Lint: prepare `lib/utilities` for `shellcheck` (#1933) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib/utilities: shellcheck SC2059 * lib/utilities: fix `_bash-it-get-component-type-from-path()` Account for plugins with names that contain periods. * lib/utilities: fix `_bash-it-array-dedup()` Use fewer subprocesses and newline-delimited not space-delimited. * lib/utilities: fix `_bash-it-component-list()` Use fewer subprocesses and return newline-delimited, not space-delimited. * lib/utilities: fix `_bash-it-component-list-matching()` Use `sort -u` instead of `sort | uniq` * lib/utilities: fix `_bash-it-component-list-enabled()` Use fewer subprocesses, return newline-delimited instead of space-delimited, and use `sort -u` instead of `uniq | sort` * lib/utilities: fix `_bash-it-component-list-disabled()` Use fewer subprocesses, return newline-delimited instead of space-delimited, and use `sort -u` instead of `uniq | sort` * lib/utilities: fix `_bash-it-grep()` 1. Executing `'/usr/bin/grep'` does *not* return the path to grep... 2. use `type -p` instead of external binary `which`. 3. Simplify parameter definition. 4. Why was there a space after `%s`? * lib/utilities: use `_bash-it-grep` Alsö, lose a spurious `cat` * lib/utilities: lint `_bash-it-component-help` * lib/utilities: lint `_bash-it-component-cache-file()` * lib/utilities: `shfmt` My apologies to future `git blame` hunters ♥ * lib/helpers: fix `_bash-it-get-component-name-from-path()` Use `${BASH_IT_LOAD_PRIORITY_SEPARATOR}` --- clean_files.txt | 3 + lib/utilities.bash | 174 +++++++++++++++++++++++---------------------- 2 files changed, 92 insertions(+), 85 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8388bb52..420c6cc9 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -75,6 +75,9 @@ completion/available/vault.completion.bash completion/available/vuejs.completion.bash completion/available/wpscan.completion.bash +# libraries +lib/utilities.bash + # plugins # plugins/available/alias-completion.plugin.bash diff --git a/lib/utilities.bash b/lib/utilities.bash index e072b52d..84fa4d96 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # # A collection of reusable functions. @@ -6,22 +6,25 @@ # Generic utilies ########################################################################### -_bash-it-get-component-name-from-path() { - # filename without path - filename=${1##*/} - # filename without path or priority - filename=${filename##*---} - # filename without path, priority or extension - echo ${filename%.*.bash} +function _bash-it-get-component-name-from-path() { + local filename + # filename without path + filename="${1##*/}" + # filename without path or priority + filename="${filename##*${BASH_IT_LOAD_PRIORITY_SEPARATOR?}}" + # filename without path, priority or extension + echo "${filename%.*.bash}" } -_bash-it-get-component-type-from-path() { - # filename without path - filename=${1##*/} - # filename without path or priority - filename=${filename##*---} - # extension - echo ${filename} | cut -d '.' -f 2 +function _bash-it-get-component-type-from-path() { + local filename + # filename without path + filename="${1##*/}" + # filename without extension + filename="${filename%.bash}" + # extension without priority or name + filename="${filename##*.}" + echo "${filename}" } # This function searches an array for an exact match against the term passed @@ -43,96 +46,97 @@ _bash-it-get-component-type-from-path() { # contains pear! # # -_bash-it-array-contains-element() { - local e - for e in "${@:2}"; do - [[ "$e" == "$1" ]] && return 0 - done - return 1 +function _bash-it-array-contains-element() { + local e + for e in "${@:2}"; do + [[ "$e" == "$1" ]] && return 0 + done + return 1 } # Dedupe a simple array of words without spaces. -_bash-it-array-dedup() { - echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' ' +function _bash-it-array-dedup() { + local IFS=$'\n' + echo "$@" | tr ' ' '\n' | sort -u } # Outputs a full path of the grep found on the filesystem -_bash-it-grep() { - if [[ -z "${BASH_IT_GREP:-}" ]] ; then - export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')" - fi - printf "%s " "${BASH_IT_GREP}" +function _bash-it-grep() { + : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" + printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}" } - ########################################################################### # Component-specific functions (component is either an alias, a plugin, or a # completion). ########################################################################### -_bash-it-component-help() { - local component="$(_bash-it-pluralize-component "${1}")" - local file="$(_bash-it-component-cache-file "${component}")" - if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then - rm -f "${file}" 2>/dev/null - local func="_bash-it-${component}" - "${func}" | $(_bash-it-grep) -E ' \[' | cat > "${file}" - fi - cat "${file}" +function _bash-it-component-help() { + local component file func + component="$(_bash-it-pluralize-component "${1}")" + file="$(_bash-it-component-cache-file "${component}")" + if [[ ! -s "${file}" || -z "$(find "${file}" -mmin -300)" ]]; then + rm -f "${file}" 2> /dev/null + func="_bash-it-${component}" + "${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' > "${file}" + fi + cat "${file}" } -_bash-it-component-cache-file() { - local component=$(_bash-it-pluralize-component "${1}") - local file="${BASH_IT}/tmp/cache/${component}" - [[ -f "${file}" ]] || mkdir -p "${file%/*}" - printf "${file}" +function _bash-it-component-cache-file() { + local component file + component="$(_bash-it-pluralize-component "${1}")" + file="${BASH_IT?}/tmp/cache/${component}" + [[ -f "${file}" ]] || mkdir -p "${file%/*}" + printf '%s' "${file}" } -_bash-it-pluralize-component() { - local component="${1}" - local len=$(( ${#component} - 1 )) - # pluralize component name for consistency - [[ ${component:${len}:1} != 's' ]] && component="${component}s" - [[ ${component} == "alias" ]] && component="aliases" - printf ${component} +function _bash-it-pluralize-component() { + local component="${1}" + local -i len=$((${#component} - 1)) + # pluralize component name for consistency + [[ "${component:${len}:1}" != 's' ]] && component="${component}s" + [[ "${component}" == "alias" ]] && component="aliases" + printf '%s' "${component}" } -_bash-it-clean-component-cache() { - local component="$1" - local cache - local -a BASH_IT_COMPONENTS=(aliases plugins completions) - if [[ -z ${component} ]] ; then - for component in "${BASH_IT_COMPONENTS[@]}" ; do - _bash-it-clean-component-cache "${component}" - done - else - cache="$(_bash-it-component-cache-file ${component})" - if [[ -f "${cache}" ]] ; then - rm -f "${cache}" - fi - fi +function _bash-it-clean-component-cache() { + local component="$1" + local cache + local -a BASH_IT_COMPONENTS=(aliases plugins completions) + if [[ -z "${component}" ]]; then + for component in "${BASH_IT_COMPONENTS[@]}"; do + _bash-it-clean-component-cache "${component}" + done + else + cache="$(_bash-it-component-cache-file "${component}")" + if [[ -f "${cache}" ]]; then + rm -f "${cache}" + fi + fi } # Returns an array of items within each compoenent. -_bash-it-component-list() { - local component="$1" - _bash-it-component-help "${component}" | awk '{print $1}' | uniq | sort | tr '\n' ' ' +function _bash-it-component-list() { + local IFS=$'\n' component="$1" + _bash-it-component-help "${component}" | awk '{print $1}' | sort -u } -_bash-it-component-list-matching() { - local component="$1"; shift - local term="$1" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E -- "${term}" | awk '{print $1}' | sort | uniq +function _bash-it-component-list-matching() { + local component="$1" + shift + local term="$1" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -- "${term}" | awk '{print $1}' | sort -u } -_bash-it-component-list-enabled() { - local component="$1" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' ' +function _bash-it-component-list-enabled() { + local IFS=$'\n' component="$1" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | awk '{print $1}' | sort -u } -_bash-it-component-list-disabled() { - local component="$1" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' ' +function _bash-it-component-list-disabled() { + local IFS=$'\n' component="$1" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | awk '{print $1}' | sort -u } # Checks if a given item is enabled for a particular component/file-type. @@ -143,10 +147,10 @@ _bash-it-component-list-disabled() { # # Examples: # _bash-it-component-item-is-enabled alias git && echo "git alias is enabled" -_bash-it-component-item-is-enabled() { - local component="$1" - local item="$2" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s" +function _bash-it-component-item-is-enabled() { + local component="$1" + local item="$2" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s" } # Checks if a given item is disabled for a particular component/file-type. @@ -157,8 +161,8 @@ _bash-it-component-item-is-enabled() { # # Examples: # _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled" -_bash-it-component-item-is-disabled() { - local component="$1" - local item="$2" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s" +function _bash-it-component-item-is-disabled() { + local component="$1" + local item="$2" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s" } From ec075a404ace3e531ae9e1957fbd31e161fc89a0 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Tue, 28 Sep 2021 07:44:40 -0500 Subject: [PATCH 111/114] clean up pyenv plugin This commit cleans up the pyenv plugin to follow the newer conventions of the other *env plugins, as well as addresses the changes made to pyenv for PATH munging. --- plugins/available/pyenv.plugin.bash | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index dc8df3ad..05d28478 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -2,14 +2,33 @@ cite about-plugin about-plugin 'load pyenv, if you are using it' -export PYENV_ROOT="$HOME/.pyenv" -pathmunge "$PYENV_ROOT/bin" +# https://github.com/pyenv/pyenv -if _command_exists pyenv; then - eval "$(pyenv init - bash)" +# Load after basher +# BASH_IT_LOAD_PRIORITY: 260 + +# Don't modify the environment if we can't find the tool: +# - Check if in $PATH already +# - Check if installed manually to $PYENV_ROOT +# - Check if installed manually to $HOME +_command_exists pyenv \ + || [[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] \ + || [[ -x "$HOME/.pyenv/bin/pyenv" ]] \ + || return 0 + +# Set PYENV_ROOT, if not already set +export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}" + +# Add PYENV_ROOT/bin to PATH, if that's where it's installed +if ! _command_exists pyenv && [[ -x "$PYENV_ROOT/bin/pyenv" ]]; then + pathmunge "$PYENV_ROOT/bin" fi -#Load pyenv virtualenv if the virtualenv plugin is installed. +# Initialize pyenv +pathmunge "$PYENV_ROOT/shims" +eval "$(pyenv init - bash)" + +# Load pyenv virtualenv if the virtualenv plugin is installed. if pyenv virtualenv-init - &> /dev/null; then eval "$(pyenv virtualenv-init - bash)" fi From c360f0c7c5c30dfbd0f19e451bb101cfac4196a5 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 21 May 2021 17:47:44 +0300 Subject: [PATCH 112/114] plugins: Add ble.sh plugin --- clean_files.txt | 1 + plugins/available/blesh.plugin.bash | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 plugins/available/blesh.plugin.bash diff --git a/clean_files.txt b/clean_files.txt index 420c6cc9..da7e41bc 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -84,6 +84,7 @@ plugins/available/alias-completion.plugin.bash plugins/available/autojump.plugin.bash plugins/available/base.plugin.bash plugins/available/basher.plugin.bash +plugins/available/blesh.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/direnv.plugin.bash plugins/available/docker-machine.plugin.bash diff --git a/plugins/available/blesh.plugin.bash b/plugins/available/blesh.plugin.bash new file mode 100644 index 00000000..7b1ce74e --- /dev/null +++ b/plugins/available/blesh.plugin.bash @@ -0,0 +1,19 @@ +# shellcheck shell=bash +cite about-plugin +about-plugin 'load ble.sh, the Bash line editor!' + +if [[ ${BLE_VERSION-} ]]; then + _log_warning "ble.sh is already loaded!" + return +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" +else + _log_error "Could not find ble.sh in $_bash_it_ble_path" + _log_error "Please install using the following command:" + _log_error "git clone https://github.com/akinomyoga/ble.sh && make -C ble.sh install" +fi +unset _bash_it_ble_path From b7feb144041168607d640aa9c9e8c514531f538a Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Wed, 29 Sep 2021 18:06:42 -0500 Subject: [PATCH 113/114] skip go tests when go is not available --- test/plugins/go.plugin.bats | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index c53f359f..110699e8 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -4,50 +4,52 @@ load ../test_helper load ../../lib/helpers load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +# We test `go version` in each test to account for users with goenv and no system go. + @test 'ensure _bash-it-gopath-pathmunge is defined' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' load ../../plugins/available/go.plugin run type -t _bash-it-gopath-pathmunge assert_line 'function' } @test 'plugins go: single entry in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin" } @test 'plugins go: single entry in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin" } @test 'plugins go: single entry in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo\ bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin" } @test 'plugins go: multiple entries in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/bar/bin" } @test 'plugins go: multiple entries in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/foo bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo bar/bin" } @test 'plugins go: multiple entries in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/foo\ bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo\ bar/bin" From adab880f89aa0cf5bd4c24071c642a386dbd4c82 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 10 Oct 2021 23:50:39 +0300 Subject: [PATCH 114/114] ci: Bump go to 1.17 from 1.14 --- .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 f42c096b..3c7ba2ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.14 + go-version: 1.17 - name: Set up Python uses: actions/setup-python@v2 with: