From 70f3b56dcc613d4937e3811c77d83bd9443a0dca Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 22 Oct 2021 11:15:41 -0700 Subject: [PATCH] `shfmt` --- aliases/available/git.aliases.bash | 6 +- aliases/available/vim.aliases.bash | 10 +- completion/available/composer.completion.bash | 3 +- completion/available/dart.completion.bash | 3 +- .../available/dmidecode.completion.bash | 3 +- completion/available/gem.completion.bash | 3 +- completion/available/knife.completion.bash | 34 +- completion/available/laravel.completion.bash | 3 +- completion/available/lerna.completion.bash | 3 +- completion/available/ngrok.completion.bash | 3 +- .../available/notify-send.completion.bash | 3 +- completion/available/pip.completion.bash | 3 +- completion/available/pip3.completion.bash | 3 +- completion/available/sdkman.completion.bash | 12 +- completion/available/vuejs.completion.bash | 3 +- completion/available/wpscan.completion.bash | 3 +- hooks/check-clean-files-txt.sh | 3 +- install.sh | 30 +- lib/helpers.bash | 1384 +++++++++-------- lib/log.bash | 60 +- lib/preview.bash | 22 +- lib/search.bash | 393 ++--- lib/utilities.bash | 48 +- lint_clean_files.sh | 8 +- .../available/alias-completion.plugin.bash | 3 +- plugins/available/base.plugin.bash | 42 +- .../available/cmd-returned-notify.plugin.bash | 6 +- plugins/available/dirs.plugin.bash | 108 +- plugins/available/git.plugin.bash | 45 +- plugins/available/go.plugin.bash | 7 +- plugins/available/goenv.plugin.bash | 14 +- plugins/available/history.plugin.bash | 15 +- plugins/available/jump.plugin.bash | 3 +- plugins/available/less-pretty-cat.plugin.bash | 6 +- plugins/available/percol.plugin.bash | 3 +- plugins/available/pyenv.plugin.bash | 8 +- plugins/available/ruby.plugin.bash | 3 +- plugins/available/xterm.plugin.bash | 15 +- scripts/reloader.bash | 73 +- test/test_helper.bash | 15 +- themes/90210/90210.theme.bash | 3 +- themes/agnoster/agnoster.theme.bash | 66 +- themes/atomic/atomic.theme.bash | 76 +- themes/axin/axin.theme.bash | 3 +- themes/bakke/bakke.theme.bash | 3 +- themes/barbuk/barbuk.theme.bash | 12 +- themes/base.theme.bash | 150 +- themes/binaryanomaly/binaryanomaly.theme.bash | 18 +- themes/bira/bira.theme.bash | 3 +- themes/bobby-python/bobby-python.theme.bash | 3 +- themes/bobby/bobby.theme.bash | 6 +- themes/brainy/brainy.theme.bash | 76 +- themes/brunton/brunton.theme.bash | 6 +- themes/candy/candy.theme.bash | 3 +- themes/command_duration.theme.bash | 12 +- themes/easy/easy.theme.bash | 3 +- themes/githelpers.theme.bash | 233 +-- themes/modern/modern.theme.bash | 9 +- themes/p4helpers.theme.bash | 24 +- themes/powerline/powerline.base.bash | 81 +- themes/pure/pure.theme.bash | 3 +- themes/purity/purity.theme.bash | 6 +- uninstall.sh | 33 +- 63 files changed, 1794 insertions(+), 1450 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 8cafa82b..08254dd5 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -194,11 +194,13 @@ case $OSTYPE in esac # functions -function gdv() { +function gdv() +{ git diff --ignore-all-space "$@" | vim -R - } -function get_default_branch() { +function get_default_branch() +{ if git branch | grep -q main; then echo main else diff --git a/aliases/available/vim.aliases.bash b/aliases/available/vim.aliases.bash index b426d270..91490f68 100644 --- a/aliases/available/vim.aliases.bash +++ b/aliases/available/vim.aliases.bash @@ -11,5 +11,11 @@ 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 -_command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } -_command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } +_command_exists mvim && function mvimt +{ + command mvim --remote-tab-silent "$@" || command mvim "$@" +} +_command_exists gvim && function gvimt +{ + command gvim --remote-tab-silent "$@" || command gvim "$@" +} diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index 176f0832..f5ea133d 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -2,7 +2,8 @@ cite "about-completion" about-completion "composer completion" -function __composer_completion() { +function __composer_completion() +{ local cur coms opts com words COMPREPLY=() _get_comp_words_by_ref -n : cur words diff --git a/completion/available/dart.completion.bash b/completion/available/dart.completion.bash index b7563443..c5a809a3 100644 --- a/completion/available/dart.completion.bash +++ b/completion/available/dart.completion.bash @@ -1,6 +1,7 @@ # shellcheck shell=bash -__dart_completion() { +__dart_completion() +{ # shellcheck disable=SC2155 local prev=$(_get_pword) # shellcheck disable=SC2155 diff --git a/completion/available/dmidecode.completion.bash b/completion/available/dmidecode.completion.bash index 4a884524..4c11c170 100644 --- a/completion/available/dmidecode.completion.bash +++ b/completion/available/dmidecode.completion.bash @@ -1,6 +1,7 @@ # shellcheck shell=bash -function __dmidecode_completion() { +function __dmidecode_completion() +{ # shellcheck disable=SC2155 local prev=$(_get_pword) # shellcheck disable=SC2155 diff --git a/completion/available/gem.completion.bash b/completion/available/gem.completion.bash index ab07a133..a4c34843 100644 --- a/completion/available/gem.completion.bash +++ b/completion/available/gem.completion.bash @@ -2,7 +2,8 @@ cite "about-completion" about-completion "gem completion" -__gem_completion() { +__gem_completion() +{ local cur=${COMP_WORDS[COMP_CWORD]} local prev=${COMP_WORDS[COMP_CWORD - 1]} case $prev in diff --git a/completion/available/knife.completion.bash b/completion/available/knife.completion.bash index 4b9950ed..4f632859 100644 --- a/completion/available/knife.completion.bash +++ b/completion/available/knife.completion.bash @@ -33,13 +33,15 @@ stat -c %Y /dev/null > /dev/null 2>&1 && _KAC_STAT_COMMAND="stat -c %Y" || _KAC_ # returns 0 iff the file whose path is given as 1st argument # exists and has last been modified in the last $2 seconds # returns 1 otherwise -_KAC_is_file_newer_than() { +_KAC_is_file_newer_than() +{ [ -f "$1" ] || return 1 [ $(($(date +%s) - $($_KAC_STAT_COMMAND "$1"))) -gt "$2" ] && return 1 || return 0 } # helper function for _KAC_get_and_regen_cache, see doc below -_KAC_regen_cache() { +_KAC_regen_cache() +{ local CACHE_NAME=$1 local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME" # shellcheck disable=SC2155 @@ -54,12 +56,14 @@ _KAC_regen_cache() { } # cached files can't have spaces in their names -_KAC_get_cache_name_from_command() { +_KAC_get_cache_name_from_command() +{ echo "${@/ /_SPACE_}" } # the reverse operation from the function above -_KAC_get_command_from_cache_name() { +_KAC_get_command_from_cache_name() +{ echo "${@/_SPACE_/ }" } @@ -68,7 +72,8 @@ _KAC_get_command_from_cache_name() { # 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() { +_KAC_get_and_regen_cache() +{ # the cache name can't have space in it local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@") local REGEN_CMD="_KAC_regen_cache $CACHE_NAME $*" @@ -83,15 +88,16 @@ _KAC_get_and_regen_cache() { # performs two things: first, deletes all obsolete temp files # then refreshes stale caches that haven't been called in a long time -_KAC_clean_cache() { +_KAC_clean_cache() +{ local FILE CMD # delete all obsolete temp files, could be lingering there for any kind of crash in the caching process for FILE in "$_KAC_CACHE_TMP_DIR"/*; do _KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" || rm -f "$FILE" done # refresh really stale caches - find "$_KNIFE_AUTOCOMPLETE_CACHE_DIR" -maxdepth 1 -type f -not -name '.*' \ - | while read -r FILE; do + find "$_KNIFE_AUTOCOMPLETE_CACHE_DIR" -maxdepth 1 -type f -not -name '.*' | + while read -r FILE; do _KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" && continue # first let's get the original command CMD=$(_KAC_get_command_from_cache_name "$(basename "$FILE")") @@ -109,14 +115,16 @@ _KAC_clean_cache() { ##################################### # returns all the possible knife sub-commands -_KAC_knife_commands() { +_KAC_knife_commands() +{ knife --help | grep -E "^knife" | sed -E 's/ \(options\)//g' } # rebuilds the knife base command currently being completed, and assigns it to $_KAC_CURRENT_COMMAND # additionnally, returns 1 iff the current base command is not complete, 0 otherwise # also sets $_KAC_CURRENT_COMMAND_NB_WORDS if the base command is complete -_KAC_get_current_base_command() { +_KAC_get_current_base_command() +{ local PREVIOUS="knife" local I=1 local CURRENT @@ -136,7 +144,8 @@ _KAC_get_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() { +_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") local CURRENT_ARG @@ -150,7 +159,8 @@ _KAC_get_current_arg_position() { } # the actual auto-complete function -_knife() { +_knife() +{ _KAC_get_and_regen_cache _KAC_knife_commands local RAW_LIST ITEM REGEN_CMD ARG_POSITION # shellcheck disable=SC2034 diff --git a/completion/available/laravel.completion.bash b/completion/available/laravel.completion.bash index 8f032568..728f9038 100644 --- a/completion/available/laravel.completion.bash +++ b/completion/available/laravel.completion.bash @@ -2,7 +2,8 @@ _command_exists laravel || return -function __laravel_completion() { +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=() diff --git a/completion/available/lerna.completion.bash b/completion/available/lerna.completion.bash index f83f1125..d380f59a 100644 --- a/completion/available/lerna.completion.bash +++ b/completion/available/lerna.completion.bash @@ -2,7 +2,8 @@ cite "about-completion" about-completion "lerna(javascript project manager tool) completion" -function __lerna_completion() { +function __lerna_completion() +{ local cur compls # The currently-being-completed word. diff --git a/completion/available/ngrok.completion.bash b/completion/available/ngrok.completion.bash index ca50a16f..57d50b8c 100644 --- a/completion/available/ngrok.completion.bash +++ b/completion/available/ngrok.completion.bash @@ -1,6 +1,7 @@ # shellcheck shell=bash -__ngrok_completion() { +__ngrok_completion() +{ # shellcheck disable=SC2155 local prev=$(_get_pword) # shellcheck disable=SC2155 diff --git a/completion/available/notify-send.completion.bash b/completion/available/notify-send.completion.bash index 676485f8..f8aaef29 100644 --- a/completion/available/notify-send.completion.bash +++ b/completion/available/notify-send.completion.bash @@ -1,6 +1,7 @@ # shellcheck shell=bash -function __notify-send_completions() { +function __notify-send_completions() +{ # shellcheck disable=SC2155 local curr=$(_get_cword) # shellcheck disable=SC2155 diff --git a/completion/available/pip.completion.bash b/completion/available/pip.completion.bash index f094d6ed..8456158d 100644 --- a/completion/available/pip.completion.bash +++ b/completion/available/pip.completion.bash @@ -8,7 +8,8 @@ # So that pip is in the system's path. _command_exists pip || return -function __bash_it_complete_pip() { +function __bash_it_complete_pip() +{ if _command_exists _pip_completion; then complete -o default -F _pip_completion pip _pip_completion "$@" diff --git a/completion/available/pip3.completion.bash b/completion/available/pip3.completion.bash index 34abc053..95a37546 100644 --- a/completion/available/pip3.completion.bash +++ b/completion/available/pip3.completion.bash @@ -8,7 +8,8 @@ # So that pip3 is in the system's path. _command_exists pip3 || return -function __bash_it_complete_pip3() { +function __bash_it_complete_pip3() +{ if _command_exists _pip_completion; then complete -o default -F _pip_completion pip3 _pip_completion "$@" diff --git a/completion/available/sdkman.completion.bash b/completion/available/sdkman.completion.bash index 2dc09088..16a031af 100644 --- a/completion/available/sdkman.completion.bash +++ b/completion/available/sdkman.completion.bash @@ -1,6 +1,7 @@ # shellcheck shell=bash -function _sdkman_complete() { +function _sdkman_complete() +{ local CANDIDATES local CANDIDATE_VERSIONS local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}" @@ -48,13 +49,15 @@ function _sdkman_complete() { return 0 } -function _sdkman_candidate_local_versions() { +function _sdkman_candidate_local_versions() +{ CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1") } -function _sdkman_candidate_all_versions() { +function _sdkman_candidate_all_versions() +{ candidate="$1" CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate") @@ -77,7 +80,8 @@ function _sdkman_candidate_all_versions() { } -function __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 751658f0..e2b776cf 100644 --- a/completion/available/vuejs.completion.bash +++ b/completion/available/vuejs.completion.bash @@ -1,6 +1,7 @@ # shellcheck shell=bash -__vuejs_completion() { +__vuejs_completion() +{ # shellcheck disable=SC2155 local prev=$(_get_pword) # shellcheck disable=SC2155 diff --git a/completion/available/wpscan.completion.bash b/completion/available/wpscan.completion.bash index 105468a3..c7c9f584 100644 --- a/completion/available/wpscan.completion.bash +++ b/completion/available/wpscan.completion.bash @@ -2,7 +2,8 @@ _command_exists wpscan || return -function __wpscan_completion() { +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=() diff --git a/hooks/check-clean-files-txt.sh b/hooks/check-clean-files-txt.sh index a37ee777..f2ffc1f5 100755 --- a/hooks/check-clean-files-txt.sh +++ b/hooks/check-clean-files-txt.sh @@ -7,7 +7,8 @@ if [ "$file" != "clean_files.txt" ]; then exit 1 fi -function compare_lines() { +function compare_lines() +{ prev="" while read -r line; do # Skip unimportant lines diff --git a/install.sh b/install.sh index 5d2f883e..831072db 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,8 @@ # bash-it installer # Show how to use this installer -function _bash-it_show_usage() { +function _bash-it_show_usage() +{ echo -e "\n$0 : Install bash-it" echo -e "Usage:\n$0 [arguments] \n" echo "Arguments:" @@ -16,7 +17,8 @@ function _bash-it_show_usage() { } # enable a thing -function _bash-it_load_one() { +function _bash-it_load_one() +{ file_type=$1 file_to_enable=$2 mkdir -p "$BASH_IT/${file_type}/enabled" @@ -30,7 +32,8 @@ function _bash-it_load_one() { } # Interactively enable several things -function _bash-it_load_some() { +function _bash-it_load_some() +{ file_type=$1 single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g") enable_func="_enable-$single_type" @@ -57,27 +60,31 @@ function _bash-it_load_some() { } # Back up existing profile -function _bash-it_backup() { - test -w "$HOME/$CONFIG_FILE" \ - && cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" \ - && echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m" +function _bash-it_backup() +{ + test -w "$HOME/$CONFIG_FILE" && + cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" && + echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m" } # Back up existing profile and create new one for bash-it -function _bash-it_backup_new() { +function _bash-it_backup_new() +{ _bash-it_backup sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE" echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m" } # Back up existing profile and append bash-it templates at the end -function _bash-it_backup_append() { +function _bash-it_backup_append() +{ _bash-it_backup (sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE" echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m" } -function _bash-it_check_for_backup() { +function _bash-it_check_for_backup() +{ if ! [[ -e "$HOME/$BACKUP_FILE" ]]; then return fi @@ -111,7 +118,8 @@ function _bash-it_check_for_backup() { fi } -function _bash-it_modify_config_files() { +function _bash-it_modify_config_files() +{ _bash-it_check_for_backup if [[ -z "${silent}" ]]; then diff --git a/lib/helpers.bash b/lib/helpers.bash index 94df885d..1031d171 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -12,72 +12,69 @@ BASH_IT_LOAD_PRIORITY_SEPARATOR="---" # sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file BASH_IT_SED_I_PARAMETERS=(-i) case "$OSTYPE" in - 'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "") + 'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "") ;; esac -function _command_exists () +function _command_exists() { - _about 'checks for existence of a command' - _param '1: command to check' - _param '2: (optional) log message to include when command not found' - _example '$ _command_exists ls && echo exists' - _group 'lib' - local msg="${2:-Command '$1' does not exist!}" - if type -t "$1" &> /dev/null - then - return 0 - else - _log_warning "$msg" - return 1 - fi + _about 'checks for existence of a command' + _param '1: command to check' + _param '2: (optional) log message to include when command not found' + _example '$ _command_exists ls && echo exists' + _group 'lib' + local msg="${2:-Command '$1' does not exist!}" + if type -t "$1" &> /dev/null; then + return 0 + else + _log_warning "$msg" + return 1 + fi } -function _binary_exists () +function _binary_exists() { - _about 'checks for existence of a binary' - _param '1: binary to check' - _param '2: (optional) log message to include when binary not found' - _example '$ _binary_exists ls && echo exists' - _group 'lib' - local msg="${2:-Binary '$1' does not exist!}" - if type -P "$1" &> /dev/null - then - return 0 - else - _log_warning "$msg" - return 1 - fi + _about 'checks for existence of a binary' + _param '1: binary to check' + _param '2: (optional) log message to include when binary not found' + _example '$ _binary_exists ls && echo exists' + _group 'lib' + local msg="${2:-Binary '$1' does not exist!}" + if type -P "$1" &> /dev/null; then + return 0 + else + _log_warning "$msg" + return 1 + fi } -function _completion_exists () +function _completion_exists() { - _about 'checks for existence of a completion' - _param '1: command to check' - _param '2: (optional) log message to include when completion is found' - _example '$ _completion_exists gh && echo exists' - _group 'lib' - local msg="${2:-Completion for '$1' already exists!}" - complete -p "$1" &> /dev/null && _log_warning "$msg" ; + _about 'checks for existence of a completion' + _param '1: command to check' + _param '2: (optional) log message to include when completion is found' + _example '$ _completion_exists gh && echo exists' + _group 'lib' + local msg="${2:-Completion for '$1' already exists!}" + complete -p "$1" &> /dev/null && _log_warning "$msg" } function _bash_it_homebrew_check() { - if _binary_exists 'brew' - then # Homebrew is installed - if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]] - then # variable isn't set + 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 true # Variable is set already, don't invoke `brew`. fi - else # Homebrew is not installed. + else # Homebrew is not installed. BASH_IT_HOMEBREW_PREFIX= # clear variable, if set to anything. - false # return failure if brew not installed. + false # return failure if brew not installed. fi } -function _make_reload_alias() { - echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" +function _make_reload_alias() +{ + echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" } # Alias for reloading aliases @@ -92,768 +89,785 @@ alias reload_completion="$(_make_reload_alias completion completion)" # shellcheck disable=SC2139 alias reload_plugins="$(_make_reload_alias plugin plugins)" -bash-it () +bash-it() { - about 'Bash-it help and maintenance' - param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] ' - param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)' - param '3: specific component [optional]' - example '$ bash-it show plugins' - example '$ bash-it help aliases' - example '$ bash-it enable plugin git [tmux]...' - example '$ bash-it disable alias hg [tmux]...' - example '$ bash-it migrate' - example '$ bash-it update' - example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]' - example '$ bash-it version' - example '$ bash-it reload' - example '$ bash-it restart' - example '$ bash-it doctor errors|warnings|all' - typeset verb=${1:-} - shift - typeset component=${1:-} - shift - typeset func + about 'Bash-it help and maintenance' + param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] ' + param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)' + param '3: specific component [optional]' + example '$ bash-it show plugins' + example '$ bash-it help aliases' + example '$ bash-it enable plugin git [tmux]...' + example '$ bash-it disable alias hg [tmux]...' + example '$ bash-it migrate' + example '$ bash-it update' + example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]' + example '$ bash-it version' + example '$ bash-it reload' + example '$ bash-it restart' + example '$ bash-it doctor errors|warnings|all' + typeset verb=${1:-} + shift + typeset component=${1:-} + shift + typeset func - case $verb in - show) - func=_bash-it-$component;; - enable) - func=_enable-$component;; - disable) - func=_disable-$component;; - help) - func=_help-$component;; - doctor) - func=_bash-it-doctor-$component;; - search) - _bash-it-search $component "$@" - return;; - update) - func=_bash-it-update-$component;; - migrate) - func=_bash-it-migrate;; - version) - func=_bash-it-version;; - restart) - func=_bash-it-restart;; - reload) - func=_bash-it-reload;; - *) - reference bash-it - return;; - esac + case $verb in + show) + func=_bash-it-$component + ;; + enable) + func=_enable-$component + ;; + disable) + func=_disable-$component + ;; + help) + func=_help-$component + ;; + doctor) + func=_bash-it-doctor-$component + ;; + search) + _bash-it-search $component "$@" + return + ;; + update) + func=_bash-it-update-$component + ;; + migrate) + func=_bash-it-migrate + ;; + version) + func=_bash-it-version + ;; + restart) + func=_bash-it-restart + ;; + reload) + func=_bash-it-reload + ;; + *) + reference bash-it + return + ;; + esac - # pluralize component if necessary - if ! _is_function $func; then - if _is_function ${func}s; then - func=${func}s - else - if _is_function ${func}es; then - func=${func}es - else - echo "oops! $component is not a valid option!" - reference bash-it - return - fi - fi - fi + # pluralize component if necessary + if ! _is_function $func; then + if _is_function ${func}s; then + func=${func}s + else + if _is_function ${func}es; then + func=${func}es + else + echo "oops! $component is not a valid option!" + reference bash-it + return + fi + fi + fi - if [ x"$verb" == x"enable" ] || [ x"$verb" == x"disable" ]; then - # Automatically run a migration if required - _bash-it-migrate + if [ x"$verb" == x"enable" ] || [ x"$verb" == x"disable" ]; then + # Automatically run a migration if required + _bash-it-migrate - for arg in "$@" - do - $func $arg - done + for arg in "$@"; do + $func $arg + done - if [ -n "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:-}" ]; then - _bash-it-reload - fi - else - $func "$@" - fi + if [ -n "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:-}" ]; then + _bash-it-reload + fi + else + $func "$@" + fi } -_is_function () +_is_function() { - _about 'sets $? to true if parameter is the name of a function' - _param '1: name of alleged function' - _group 'lib' - [ -n "$(LANG=C type -t $1 2>/dev/null | grep 'function')" ] + _about 'sets $? to true if parameter is the name of a function' + _param '1: name of alleged function' + _group 'lib' + [ -n "$(LANG=C type -t $1 2> /dev/null | grep 'function')" ] } -_bash-it-aliases () +_bash-it-aliases() { - _about 'summarizes available bash_it aliases' - _group 'lib' + _about 'summarizes available bash_it aliases' + _group 'lib' - _bash-it-describe "aliases" "an" "alias" "Alias" + _bash-it-describe "aliases" "an" "alias" "Alias" } -_bash-it-completions () +_bash-it-completions() { - _about 'summarizes available bash_it completions' - _group 'lib' + _about 'summarizes available bash_it completions' + _group 'lib' - _bash-it-describe "completion" "a" "completion" "Completion" + _bash-it-describe "completion" "a" "completion" "Completion" } -_bash-it-plugins () +_bash-it-plugins() { - _about 'summarizes available bash_it plugins' - _group 'lib' + _about 'summarizes available bash_it plugins' + _group 'lib' - _bash-it-describe "plugins" "a" "plugin" "Plugin" + _bash-it-describe "plugins" "a" "plugin" "Plugin" } -_bash-it-update-dev() { - _about 'updates Bash-it to the latest master' - _group 'lib' +_bash-it-update-dev() +{ + _about 'updates Bash-it to the latest master' + _group 'lib' - _bash-it-update- dev "$@" + _bash-it-update- dev "$@" } -_bash-it-update-stable() { - _about 'updates Bash-it to the latest tag' - _group 'lib' +_bash-it-update-stable() +{ + _about 'updates Bash-it to the latest tag' + _group 'lib' - _bash-it-update- stable "$@" + _bash-it-update- stable "$@" } -_bash-it_update_migrate_and_restart() { +_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." - echo "" - echo "Migrating your installation to the latest $2 version now..." - _bash-it-migrate - echo "" - echo "All done, enjoy!" - # 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 + _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." + echo "" + echo "Migrating your installation to the latest $2 version now..." + _bash-it-migrate + echo "" + echo "All done, enjoy!" + # 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 } -_bash-it-update-() { - _about 'updates Bash-it' - _param '1: What kind of update to do (stable|dev)' - _group 'lib' - - declare silent - for word in $@; do - if [[ ${word} == "--silent" || ${word} == "-s" ]]; then - silent=true - fi - done - - 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 - - if [ -z "$BASH_IT_REMOTE" ]; then - BASH_IT_REMOTE="origin" - fi - - git fetch $BASH_IT_REMOTE --tags &> /dev/null - - if [ -z "$BASH_IT_DEVELOPMENT_BRANCH" ]; then - BASH_IT_DEVELOPMENT_BRANCH="master" - fi - # Defaults to stable update - if [ -z "$1" ] || [ "$1" == "stable" ]; then - version="stable" - TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2> /dev/null) - - if [[ -z "$TARGET" ]]; then - echo "Can not find tags, so can not update to latest stable version..." - popd &> /dev/null - return - fi - else - version="dev" - TARGET=${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH} - fi - - declare revision - revision="HEAD..${TARGET}" - declare status - status="$(git rev-list ${revision} 2> /dev/null)" - declare revert - - if [[ -z "${status}" && ${version} == "stable" ]]; then - revision="${TARGET}..HEAD" - status="$(git rev-list ${revision} 2> /dev/null)" - revert=true - fi - - if [[ -n "${status}" ]]; then - if [[ $revert ]]; then - echo "Your version is a more recent development version ($(git log -1 --format=%h HEAD))" - echo "You can continue in order to revert and update to the latest stable version" - echo "" - log_color="%Cred" - fi - - for i in $(git rev-list --merges --first-parent ${revision}); do - num_of_lines=$(git log -1 --format=%B $i | awk 'NF' | wc -l) - if [ $num_of_lines -eq 1 ]; then - description="%s" - else - description="%b" - fi - git log --format="${log_color}%h: $description (%an)" -1 $i - done - echo "" - - if [[ $silent ]]; then - echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..." - _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_update_migrate_and_restart $TARGET $version - ;; - [nN]) - echo "Not updating…" - ;; - *) - echo -e "\033[91mPlease choose y or n.\033[m" - ;; - esac - fi - else - if [[ ${version} == "stable" ]]; then - echo "You're on the latest stable version. If you want to check out the latest 'dev' version, please run \"bash-it update dev\"" - else - echo "Bash-it is up to date, nothing to do!" - fi - fi - popd &> /dev/null -} - -_bash-it-migrate() { - _about 'migrates Bash-it configuration from a previous format to the current one' - _group 'lib' - - declare migrated_something - migrated_something=false - - for file_type in "aliases" "plugins" "completion" - do - for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")` - do - 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') - # Cut off the optional "250---" prefix and the suffix - typeset component_name=$(echo $ff | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g') - - migrated_something=true - - echo "Migrating $single_type $component_name." - - disable_func="_disable-$single_type" - enable_func="_enable-$single_type" - - $disable_func "$component_name" - $enable_func "$component_name" - done - done - - if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then - _bash-it-reload - fi - - if [ "$migrated_something" = "true" ]; then - echo "" - echo "If any migration errors were reported, please try the following: reload && bash-it migrate" - fi -} - -_bash-it-version() { - _about 'shows current Bash-it version' - _group 'lib' - - cd "${BASH_IT}" || return - - if [ -z "${BASH_IT_REMOTE:-}" ]; then - BASH_IT_REMOTE="origin" - fi - - BASH_IT_GIT_REMOTE=$(git remote get-url $BASH_IT_REMOTE) - BASH_IT_GIT_URL=${BASH_IT_GIT_REMOTE%.git} - if [[ "$BASH_IT_GIT_URL" == *"git@"* ]]; then - # Fix URL in case it is ssh based URL - BASH_IT_GIT_URL=${BASH_IT_GIT_URL/://} - BASH_IT_GIT_URL=${BASH_IT_GIT_URL/git@/https://} - fi - - current_tag=$(git describe --exact-match --tags 2> /dev/null) - - if [[ -z $current_tag ]]; then - BASH_IT_GIT_VERSION_INFO="$(git log --pretty=format:'%h on %aI' -n 1)" - TARGET=${BASH_IT_GIT_VERSION_INFO%% *} - echo "Version type: dev" - echo "Current git SHA: $BASH_IT_GIT_VERSION_INFO" - echo "Commit info: $BASH_IT_GIT_URL/commit/$TARGET" - else - TARGET=$current_tag - echo "Version type: stable" - echo "Current tag: $current_tag" - echo "Tag information: $BASH_IT_GIT_URL/releases/tag/$current_tag" - fi - - echo "Compare to latest: $BASH_IT_GIT_URL/compare/$TARGET...master" - - cd - &> /dev/null || return -} - -_bash-it-doctor() { - _about 'reloads a profile file with a BASH_IT_LOG_LEVEL set' - _param '1: BASH_IT_LOG_LEVEL argument: "errors" "warnings" "all"' - _group 'lib' - - BASH_IT_LOG_LEVEL=$1 - _bash-it-reload - unset BASH_IT_LOG_LEVEL -} - -_bash-it-doctor-all() { - _about 'reloads a profile file with error, warning and debug logs' - _group 'lib' - - _bash-it-doctor $BASH_IT_LOG_LEVEL_ALL -} - -_bash-it-doctor-warnings() { - _about 'reloads a profile file with error and warning logs' - _group 'lib' - - _bash-it-doctor $BASH_IT_LOG_LEVEL_WARNING -} - -_bash-it-doctor-errors() { - _about 'reloads a profile file with error logs' - _group 'lib' - - _bash-it-doctor $BASH_IT_LOG_LEVEL_ERROR -} - -_bash-it-doctor-() { - _about 'default bash-it doctor behavior, behaves like bash-it doctor all' - _group 'lib' - - _bash-it-doctor-all -} - -_bash-it-restart() { - _about 'restarts the shell in order to fully reload it' - _group 'lib' - - saved_pwd="${PWD}" - - case $OSTYPE in - darwin*) - init_file=.bash_profile - ;; - *) - init_file=.bashrc - ;; - esac - exec "${0/-/}" --rcfile <(echo "source \"$HOME/$init_file\"; cd \"$saved_pwd\"") -} - -_bash-it-reload() { - _about 'reloads a profile file' - _group 'lib' - - pushd "${BASH_IT}" &> /dev/null || return - - case $OSTYPE in - darwin*) - source ~/.bash_profile - ;; - *) - source ~/.bashrc - ;; - esac - - popd &> /dev/null || return -} - -_bash-it-describe () +_bash-it-update-() { - _about 'summarizes available bash_it components' - _param '1: subdirectory' - _param '2: preposition' - _param '3: file_type' - _param '4: column_header' - _example '$ _bash-it-describe "plugins" "a" "plugin" "Plugin"' + _about 'updates Bash-it' + _param '1: What kind of update to do (stable|dev)' + _group 'lib' - subdirectory="$1" - preposition="$2" - file_type="$3" - column_header="$4" + declare silent + for word in $@; do + if [[ ${word} == "--silent" || ${word} == "-s" ]]; then + silent=true + fi + done - typeset f - typeset enabled - printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description' - for f in "${BASH_IT}/$subdirectory/available/"*.bash - do - # Check for both the old format without the load priority, and the extended format with the priority - declare enabled_files enabled_file + 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 + + if [ -z "$BASH_IT_REMOTE" ]; then + BASH_IT_REMOTE="origin" + fi + + git fetch $BASH_IT_REMOTE --tags &> /dev/null + + if [ -z "$BASH_IT_DEVELOPMENT_BRANCH" ]; then + BASH_IT_DEVELOPMENT_BRANCH="master" + fi + # Defaults to stable update + if [ -z "$1" ] || [ "$1" == "stable" ]; then + version="stable" + TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2> /dev/null) + + if [[ -z "$TARGET" ]]; then + echo "Can not find tags, so can not update to latest stable version..." + popd &> /dev/null + return + fi + else + version="dev" + TARGET=${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH} + fi + + declare revision + revision="HEAD..${TARGET}" + declare status + status="$(git rev-list ${revision} 2> /dev/null)" + declare revert + + if [[ -z "${status}" && ${version} == "stable" ]]; then + revision="${TARGET}..HEAD" + status="$(git rev-list ${revision} 2> /dev/null)" + revert=true + fi + + if [[ -n "${status}" ]]; then + if [[ $revert ]]; then + echo "Your version is a more recent development version ($(git log -1 --format=%h HEAD))" + echo "You can continue in order to revert and update to the latest stable version" + echo "" + log_color="%Cred" + fi + + for i in $(git rev-list --merges --first-parent ${revision}); do + num_of_lines=$(git log -1 --format=%B $i | awk 'NF' | wc -l) + if [ $num_of_lines -eq 1 ]; then + description="%s" + else + description="%b" + fi + git log --format="${log_color}%h: $description (%an)" -1 $i + done + echo "" + + if [[ $silent ]]; then + echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..." + _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_update_migrate_and_restart $TARGET $version + ;; + [nN]) + echo "Not updating…" + ;; + *) + echo -e "\033[91mPlease choose y or n.\033[m" + ;; + esac + fi + else + if [[ ${version} == "stable" ]]; then + echo "You're on the latest stable version. If you want to check out the latest 'dev' version, please run \"bash-it update dev\"" + else + echo "Bash-it is up to date, nothing to do!" + fi + fi + popd &> /dev/null +} + +_bash-it-migrate() +{ + _about 'migrates Bash-it configuration from a previous format to the current one' + _group 'lib' + + declare migrated_something + migrated_something=false + + for file_type in "aliases" "plugins" "completion"; do + for f in $(sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")); do + 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') + # Cut off the optional "250---" prefix and the suffix + typeset component_name=$(echo $ff | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g') + + migrated_something=true + + echo "Migrating $single_type $component_name." + + disable_func="_disable-$single_type" + enable_func="_enable-$single_type" + + $disable_func "$component_name" + $enable_func "$component_name" + done + done + + if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then + _bash-it-reload + fi + + if [ "$migrated_something" = "true" ]; then + echo "" + echo "If any migration errors were reported, please try the following: reload && bash-it migrate" + fi +} + +_bash-it-version() +{ + _about 'shows current Bash-it version' + _group 'lib' + + cd "${BASH_IT}" || return + + if [ -z "${BASH_IT_REMOTE:-}" ]; then + BASH_IT_REMOTE="origin" + fi + + BASH_IT_GIT_REMOTE=$(git remote get-url $BASH_IT_REMOTE) + BASH_IT_GIT_URL=${BASH_IT_GIT_REMOTE%.git} + if [[ "$BASH_IT_GIT_URL" == *"git@"* ]]; then + # Fix URL in case it is ssh based URL + BASH_IT_GIT_URL=${BASH_IT_GIT_URL/://} + BASH_IT_GIT_URL=${BASH_IT_GIT_URL/git@/https://} + fi + + current_tag=$(git describe --exact-match --tags 2> /dev/null) + + if [[ -z $current_tag ]]; then + BASH_IT_GIT_VERSION_INFO="$(git log --pretty=format:'%h on %aI' -n 1)" + TARGET=${BASH_IT_GIT_VERSION_INFO%% *} + echo "Version type: dev" + echo "Current git SHA: $BASH_IT_GIT_VERSION_INFO" + echo "Commit info: $BASH_IT_GIT_URL/commit/$TARGET" + else + TARGET=$current_tag + echo "Version type: stable" + echo "Current tag: $current_tag" + echo "Tag information: $BASH_IT_GIT_URL/releases/tag/$current_tag" + fi + + echo "Compare to latest: $BASH_IT_GIT_URL/compare/$TARGET...master" + + cd - &> /dev/null || return +} + +_bash-it-doctor() +{ + _about 'reloads a profile file with a BASH_IT_LOG_LEVEL set' + _param '1: BASH_IT_LOG_LEVEL argument: "errors" "warnings" "all"' + _group 'lib' + + BASH_IT_LOG_LEVEL=$1 + _bash-it-reload + unset BASH_IT_LOG_LEVEL +} + +_bash-it-doctor-all() +{ + _about 'reloads a profile file with error, warning and debug logs' + _group 'lib' + + _bash-it-doctor $BASH_IT_LOG_LEVEL_ALL +} + +_bash-it-doctor-warnings() +{ + _about 'reloads a profile file with error and warning logs' + _group 'lib' + + _bash-it-doctor $BASH_IT_LOG_LEVEL_WARNING +} + +_bash-it-doctor-errors() +{ + _about 'reloads a profile file with error logs' + _group 'lib' + + _bash-it-doctor $BASH_IT_LOG_LEVEL_ERROR +} + +_bash-it-doctor-() +{ + _about 'default bash-it doctor behavior, behaves like bash-it doctor all' + _group 'lib' + + _bash-it-doctor-all +} + +_bash-it-restart() +{ + _about 'restarts the shell in order to fully reload it' + _group 'lib' + + saved_pwd="${PWD}" + + case $OSTYPE in + darwin*) + init_file=.bash_profile + ;; + *) + init_file=.bashrc + ;; + esac + exec "${0/-/}" --rcfile <(echo "source \"$HOME/$init_file\"; cd \"$saved_pwd\"") +} + +_bash-it-reload() +{ + _about 'reloads a profile file' + _group 'lib' + + pushd "${BASH_IT}" &> /dev/null || return + + case $OSTYPE in + darwin*) + source ~/.bash_profile + ;; + *) + source ~/.bashrc + ;; + esac + + popd &> /dev/null || return +} + +_bash-it-describe() +{ + _about 'summarizes available bash_it components' + _param '1: subdirectory' + _param '2: preposition' + _param '3: file_type' + _param '4: column_header' + _example '$ _bash-it-describe "plugins" "a" "plugin" "Plugin"' + + subdirectory="$1" + preposition="$2" + file_type="$3" + column_header="$4" + + typeset f + typeset enabled + printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description' + for f in "${BASH_IT}/$subdirectory/available/"*.bash; 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="${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) + 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 - enabled='x' - else - enabled=' ' - fi - printf "%-20s%-10s%s\n" "$(basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g')" " [$enabled]" "$(cat $f | metafor about-$file_type)" - done - printf '\n%s\n' "to enable $preposition $file_type, do:" - printf '%s\n' "$ bash-it enable $file_type <$file_type name> [$file_type name]... -or- $ bash-it enable $file_type all" - printf '\n%s\n' "to disable $preposition $file_type, do:" - printf '%s\n' "$ bash-it disable $file_type <$file_type name> [$file_type name]... -or- $ bash-it disable $file_type all" + if [ $enabled_files -gt 0 ]; then + enabled='x' + else + enabled=' ' + fi + printf "%-20s%-10s%s\n" "$(basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g')" " [$enabled]" "$(cat $f | metafor about-$file_type)" + done + printf '\n%s\n' "to enable $preposition $file_type, do:" + printf '%s\n' "$ bash-it enable $file_type <$file_type name> [$file_type name]... -or- $ bash-it enable $file_type all" + printf '\n%s\n' "to disable $preposition $file_type, do:" + printf '%s\n' "$ bash-it disable $file_type <$file_type name> [$file_type name]... -or- $ bash-it disable $file_type all" } _on-disable-callback() { - _about 'Calls the disabled plugin destructor, if present' - _param '1: plugin name' - _example '$ _on-disable-callback gitstatus' - _group 'lib' + _about 'Calls the disabled plugin destructor, if present' + _param '1: plugin name' + _example '$ _on-disable-callback gitstatus' + _group 'lib' - callback=$1_on_disable - _command_exists $callback && $callback + callback=$1_on_disable + _command_exists $callback && $callback } -_disable-plugin () +_disable-plugin() { - _about 'disables bash_it plugin' - _param '1: plugin name' - _example '$ disable-plugin rvm' - _group 'lib' + _about 'disables bash_it plugin' + _param '1: plugin name' + _example '$ disable-plugin rvm' + _group 'lib' - _disable-thing "plugins" "plugin" $1 - _on-disable-callback $1 + _disable-thing "plugins" "plugin" $1 + _on-disable-callback $1 } -_disable-alias () +_disable-alias() { - _about 'disables bash_it alias' - _param '1: alias name' - _example '$ disable-alias git' - _group 'lib' + _about 'disables bash_it alias' + _param '1: alias name' + _example '$ disable-alias git' + _group 'lib' - _disable-thing "aliases" "alias" $1 + _disable-thing "aliases" "alias" $1 } -_disable-completion () +_disable-completion() { - _about 'disables bash_it completion' - _param '1: completion name' - _example '$ disable-completion git' - _group 'lib' + _about 'disables bash_it completion' + _param '1: completion name' + _example '$ disable-completion git' + _group 'lib' - _disable-thing "completion" "completion" $1 + _disable-thing "completion" "completion" $1 } -_disable-thing () +_disable-thing() { - _about 'disables a bash_it component' - _param '1: subdirectory' - _param '2: file_type' - _param '3: file_entity' - _example '$ _disable-thing "plugins" "plugin" "ssh"' + _about 'disables a bash_it component' + _param '1: subdirectory' + _param '2: file_type' + _param '3: file_entity' + _example '$ _disable-thing "plugins" "plugin" "ssh"' - subdirectory="$1" - file_type="$2" - file_entity="$3" + subdirectory="$1" + file_type="$2" + file_entity="$3" - if [ -z "$file_entity" ]; then - reference "disable-$file_type" - return - fi + if [ -z "$file_entity" ]; then + reference "disable-$file_type" + return + fi - typeset f suffix - suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + typeset f suffix + suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') - if [ "$file_entity" = "all" ]; then - # Disable everything that's using the old structure - for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"` - do - rm "$f" - done + if [ "$file_entity" = "all" ]; then + # Disable everything that's using the old structure + for f in $(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"); do + rm "$f" + done - # Disable everything in the global "enabled" directory - for f in `compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"` - do - rm "$f" - done - else - typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1) - if [ -z "$plugin_global" ]; then - # Use a glob to search for both possible patterns - # 250---node.plugin.bash - # node.plugin.bash - # Either one will be matched by this glob - typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1) - if [ -z "$plugin" ]; then - printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." - return - fi - rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}" - else - rm "${BASH_IT}/enabled/${plugin_global##*/}" - fi - fi + # Disable everything in the global "enabled" directory + for f in $(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"); do + rm "$f" + done + else + typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2> /dev/null | head -1) + if [ -z "$plugin_global" ]; then + # Use a glob to search for both possible patterns + # 250---node.plugin.bash + # node.plugin.bash + # Either one will be matched by this glob + typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2> /dev/null | head -1) + if [ -z "$plugin" ]; then + printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." + return + fi + rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}" + else + rm "${BASH_IT}/enabled/${plugin_global##*/}" + fi + fi - _bash-it-clean-component-cache "${file_type}" + _bash-it-clean-component-cache "${file_type}" - printf '%s\n' "$file_entity disabled." + printf '%s\n' "$file_entity disabled." } -_enable-plugin () +_enable-plugin() { - _about 'enables bash_it plugin' - _param '1: plugin name' - _example '$ enable-plugin rvm' - _group 'lib' + _about 'enables bash_it plugin' + _param '1: plugin name' + _example '$ enable-plugin rvm' + _group 'lib' - _enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN + _enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN } -_enable-alias () +_enable-alias() { - _about 'enables bash_it alias' - _param '1: alias name' - _example '$ enable-alias git' - _group 'lib' + _about 'enables bash_it alias' + _param '1: alias name' + _example '$ enable-alias git' + _group 'lib' - _enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS + _enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS } -_enable-completion () +_enable-completion() { - _about 'enables bash_it completion' - _param '1: completion name' - _example '$ enable-completion git' - _group 'lib' + _about 'enables bash_it completion' + _param '1: completion name' + _example '$ enable-completion git' + _group 'lib' - _enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION + _enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION } -_enable-thing () +_enable-thing() { - cite _about _param _example - _about 'enables a bash_it component' - _param '1: subdirectory' - _param '2: file_type' - _param '3: file_entity' - _param '4: load priority' - _example '$ _enable-thing "plugins" "plugin" "ssh" "150"' + cite _about _param _example + _about 'enables a bash_it component' + _param '1: subdirectory' + _param '2: file_type' + _param '3: file_entity' + _param '4: load priority' + _example '$ _enable-thing "plugins" "plugin" "ssh" "150"' - subdirectory="$1" - file_type="$2" - file_entity="$3" - load_priority="$4" + subdirectory="$1" + file_type="$2" + file_entity="$3" + load_priority="$4" - if [ -z "$file_entity" ]; then - reference "enable-$file_type" - return - fi + if [ -z "$file_entity" ]; then + reference "enable-$file_type" + return + fi - if [ "$file_entity" = "all" ]; then - typeset f $file_type - for f in "${BASH_IT}/$subdirectory/available/"*.bash - do - to_enable=$(basename $f .$file_type.bash) - if [ "$file_type" = "alias" ]; then - to_enable=$(basename $f ".aliases.bash") - fi - _enable-thing $subdirectory $file_type $to_enable $load_priority - done - else - typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2>/dev/null | head -1) - if [ -z "$to_enable" ]; then - printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type." - return - fi + if [ "$file_entity" = "all" ]; then + typeset f $file_type + for f in "${BASH_IT}/$subdirectory/available/"*.bash; do + to_enable=$(basename $f .$file_type.bash) + if [ "$file_type" = "alias" ]; then + to_enable=$(basename $f ".aliases.bash") + fi + _enable-thing $subdirectory $file_type $to_enable $load_priority + done + else + typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2> /dev/null | head -1) + if [ -z "$to_enable" ]; then + printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type." + return + fi 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 - printf '%s\n' "$file_entity is already enabled." - return - fi + # 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 + printf '%s\n' "$file_entity is already enabled." + return + fi - typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1) - if [ ! -z "$enabled_plugin_global" ] ; then - printf '%s\n' "$file_entity is already enabled." - return - fi + typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2> /dev/null | head -1) + if [ ! -z "$enabled_plugin_global" ]; then + printf '%s\n' "$file_entity is already enabled." + return + fi - mkdir -p "${BASH_IT}/enabled" + mkdir -p "${BASH_IT}/enabled" - # Load the priority from the file if it present there - declare local_file_priority use_load_priority - local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }') - use_load_priority=${local_file_priority:-$load_priority} + # Load the priority from the file if it present there + declare local_file_priority use_load_priority + local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }') + use_load_priority=${local_file_priority:-$load_priority} - ln -s ../$subdirectory/available/$to_enable "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" - fi + ln -s ../$subdirectory/available/$to_enable "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" + fi - _bash-it-clean-component-cache "${file_type}" + _bash-it-clean-component-cache "${file_type}" - printf '%s\n' "$file_entity enabled with priority $use_load_priority." + printf '%s\n' "$file_entity enabled with priority $use_load_priority." } _help-completions() { - _about 'summarize all completions available in bash-it' - _group 'lib' + _about 'summarize all completions available in bash-it' + _group 'lib' - _bash-it-completions + _bash-it-completions } _help-aliases() { - _about 'shows help for all aliases, or a specific alias group' - _param '1: optional alias group' - _example '$ alias-help' - _example '$ alias-help git' + _about 'shows help for all aliases, or a specific alias group' + _param '1: optional alias group' + _example '$ alias-help' + _example '$ alias-help git' - if [ -n "$1" ]; then - case $1 in - custom) - alias_path='custom.aliases.bash' - ;; - *) - alias_path="available/$1.aliases.bash" - ;; - esac - cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/" - else - typeset f + if [ -n "$1" ]; then + case $1 in + custom) + alias_path='custom.aliases.bash' + ;; + *) + alias_path="available/$1.aliases.bash" + ;; + esac + cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/" + else + typeset f - for f in `sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")` - do - _help-list-aliases $f - done + for f in $(sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")); do + _help-list-aliases $f + done - if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ]; then - _help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash" - fi - fi + if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ]; then + _help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash" + fi + fi } -_help-list-aliases () +_help-list-aliases() { - typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g') - printf '\n\n%s:\n' "${file}" - # metafor() strips trailing quotes, restore them with sed.. - cat $1 | metafor alias | sed "s/$/'/" + typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g') + printf '\n\n%s:\n' "${file}" + # metafor() strips trailing quotes, restore them with sed.. + cat $1 | metafor alias | sed "s/$/'/" } _help-plugins() { - _about 'summarize all functions defined by enabled bash-it plugins' - _group 'lib' + _about 'summarize all functions defined by enabled bash-it plugins' + _group 'lib' - # display a brief progress message... - printf '%s' 'please wait, building help...' - typeset grouplist=$(mktemp -t grouplist.XXXXXX) - typeset func - for func in $(_typeset_functions) - do - typeset group="$(typeset -f $func | metafor group)" - if [ -z "$group" ]; then - group='misc' - fi - typeset about="$(typeset -f $func | metafor about)" - _letterpress "$about" $func >> $grouplist.$group - echo $grouplist.$group >> $grouplist - done - # clear progress message - printf '\r%s\n' ' ' - typeset group - typeset gfile - for gfile in $(cat $grouplist | sort | uniq) - do - printf '%s\n' "${gfile##*.}:" - cat $gfile - printf '\n' - rm $gfile 2> /dev/null - done | less - rm $grouplist 2> /dev/null + # display a brief progress message... + printf '%s' 'please wait, building help...' + typeset grouplist=$(mktemp -t grouplist.XXXXXX) + typeset func + for func in $(_typeset_functions); do + typeset group="$(typeset -f $func | metafor group)" + if [ -z "$group" ]; then + group='misc' + fi + typeset about="$(typeset -f $func | metafor about)" + _letterpress "$about" $func >> $grouplist.$group + echo $grouplist.$group >> $grouplist + done + # clear progress message + printf '\r%s\n' ' ' + typeset group + typeset gfile + for gfile in $(cat $grouplist | sort | uniq); do + printf '%s\n' "${gfile##*.}:" + cat $gfile + printf '\n' + rm $gfile 2> /dev/null + done | less + rm $grouplist 2> /dev/null } -_help-update () { - _about 'help message for update command' - _group 'lib' - - echo "Check for a new version of Bash-it and update it." -} - -_help-migrate () { - _about 'help message for migrate command' - _group 'lib' - - echo "Migrates internal Bash-it structure to the latest version in case of changes." - echo "The 'migrate' command is run automatically when calling 'update', 'enable' or 'disable'." -} - -all_groups () +_help-update() { - about 'displays all unique metadata groups' - group 'lib' + _about 'help message for update command' + _group 'lib' - typeset func - typeset file=$(mktemp -t composure.XXXX) - for func in $(_typeset_functions) - do - typeset -f $func | metafor group >> $file - done - cat $file | sort | uniq - rm $file + echo "Check for a new version of Bash-it and update it." } -if ! type pathmunge > /dev/null 2>&1 -then - function pathmunge () { - about 'prevent duplicate directories in you PATH variable' - group 'helpers' - example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH' - example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir' +_help-migrate() +{ + _about 'help message for migrate command' + _group 'lib' - if ! [[ $PATH =~ (^|:)$1($|:) ]] ; then - if [ "$2" = "after" ] ; then - export PATH=$PATH:$1 - else - export PATH=$1:$PATH - fi - fi - } + echo "Migrates internal Bash-it structure to the latest version in case of changes." + echo "The 'migrate' command is run automatically when calling 'update', 'enable' or 'disable'." +} + +all_groups() +{ + about 'displays all unique metadata groups' + group 'lib' + + typeset func + typeset file=$(mktemp -t composure.XXXX) + for func in $(_typeset_functions); do + typeset -f $func | metafor group >> $file + done + cat $file | sort | uniq + rm $file +} + +if ! type pathmunge > /dev/null 2>&1; then + function pathmunge() + { + about 'prevent duplicate directories in you PATH variable' + group 'helpers' + example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH' + example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir' + + if ! [[ $PATH =~ (^|:)$1($|:) ]]; then + if [ "$2" = "after" ]; then + export PATH=$PATH:$1 + else + export PATH=$1:$PATH + fi + fi + } 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() ( +function _bash-it-find-in-ancestor() +( about 'searches parents of the current directory for any of the specified file names' group 'helpers' param '*: names of files or folders to search for' diff --git a/lib/log.bash b/lib/log.bash index 6bc53a12..705c93e2 100644 --- a/lib/log.bash +++ b/lib/log.bash @@ -6,55 +6,55 @@ export BASH_IT_LOG_LEVEL_ALL=3 function _has_colors() { - # Check that stdout is a terminal - test -t 1 || return 1 + # Check that stdout is a terminal + test -t 1 || return 1 - ncolors=$(tput colors) - test -n "$ncolors" && test "$ncolors" -ge 8 || return 1 - return 0 + ncolors=$(tput colors) + test -n "$ncolors" && test "$ncolors" -ge 8 || return 1 + return 0 } function _log_general() { - about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix' - param '1: color of the message' - param '2: log level to print before the prefix' - param '3: message to log' - group 'log' + about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix' + param '1: color of the message' + param '2: log level to print before the prefix' + param '3: message to log' + group 'log' - message=$2${BASH_IT_LOG_PREFIX:-default: }$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() { - about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ALL' - param '1: message to log' - example '$ _log_debug "Loading plugin git..."' - group 'log' + about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ALL' + param '1: message to log' + example '$ _log_debug "Loading plugin git..."' + group 'log' - [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 - _log_general "${echo_green:-}" "DEBUG: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 + _log_general "${echo_green:-}" "DEBUG: " "$1" } function _log_warning() { - about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING' - param '1: message to log' - example '$ _log_warning "git binary not found, disabling git plugin..."' - group 'log' + about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING' + param '1: message to log' + example '$ _log_warning "git binary not found, disabling git plugin..."' + group 'log' - [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 - _log_general "${echo_yellow:-}" " WARN: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 + _log_general "${echo_yellow:-}" " WARN: " "$1" } function _log_error() { - about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR' - param '1: message to log' - example '$ _log_error "Failed to load git plugin..."' - group 'log' + about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR' + param '1: message to log' + example '$ _log_error "Failed to load git plugin..."' + group 'log' - [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 - _log_general "${echo_red:-}" "ERROR: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 + _log_general "${echo_red:-}" "ERROR: " "$1" } diff --git a/lib/preview.bash b/lib/preview.bash index 418839cd..9ed98190 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -1,19 +1,17 @@ -if [[ "${BASH_PREVIEW:-}" ]]; -then - unset BASH_PREVIEW #Prevent infinite looping - echo " +if [[ "${BASH_PREVIEW:-}" ]]; then + unset BASH_PREVIEW #Prevent infinite looping + echo " Previewing Bash-it Themes " - THEMES="$BASH_IT/themes/*/*.theme.bash" - for theme in $THEMES - do - BASH_IT_THEME=${theme%.theme.bash} - BASH_IT_THEME=${BASH_IT_THEME##*/} - echo " + THEMES="$BASH_IT/themes/*/*.theme.bash" + for theme in $THEMES; do + BASH_IT_THEME=${theme%.theme.bash} + BASH_IT_THEME=${BASH_IT_THEME##*/} + echo " $BASH_IT_THEME" - echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i - done + echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i + done fi diff --git a/lib/search.bash b/lib/search.bash index 58f98904..11794e8b 100644 --- a/lib/search.bash +++ b/lib/search.bash @@ -47,49 +47,51 @@ # completions: git # -_bash-it-search() { - _about 'searches for given terms amongst bash-it plugins, aliases and completions' - _param '1: term1' - _param '2: [ term2 ]...' - _example '$ _bash-it-search @git ruby -rvm rake bundler' +_bash-it-search() +{ + _about 'searches for given terms amongst bash-it plugins, aliases and completions' + _param '1: term1' + _param '2: [ term2 ]...' + _example '$ _bash-it-search @git ruby -rvm rake bundler' - [[ -z "$(type _bash-it-array-contains-element 2>/dev/null)" ]] && source "${BASH_IT}/lib/utilities.bash" + [[ -z "$(type _bash-it-array-contains-element 2> /dev/null)" ]] && source "${BASH_IT}/lib/utilities.bash" - local component - export BASH_IT_SEARCH_USE_COLOR=true - export BASH_IT_GREP=${BASH_IT_GREP:-$(which egrep)} - declare -a BASH_IT_COMPONENTS=(aliases plugins completions) + local component + export BASH_IT_SEARCH_USE_COLOR=true + export BASH_IT_GREP=${BASH_IT_GREP:-$(which egrep)} + declare -a BASH_IT_COMPONENTS=(aliases plugins completions) - if [[ -z "$*" ]] ; then - _bash-it-search-help - return 0 - fi + if [[ -z "$*" ]]; then + _bash-it-search-help + return 0 + fi - local -a args=() - for word in $@; do - if [[ ${word} == "--help" || ${word} == "-h" ]]; then - _bash-it-search-help - return 0 - elif [[ ${word} == "--refresh" || ${word} == "-r" ]]; then - _bash-it-clean-component-cache - elif [[ ${word} == "--no-color" || ${word} == '-c' ]]; then - export BASH_IT_SEARCH_USE_COLOR=false - else - args=(${args[@]} ${word}) - fi - done + local -a args=() + for word in $@; do + if [[ ${word} == "--help" || ${word} == "-h" ]]; then + _bash-it-search-help + return 0 + elif [[ ${word} == "--refresh" || ${word} == "-r" ]]; then + _bash-it-clean-component-cache + elif [[ ${word} == "--no-color" || ${word} == '-c' ]]; then + export BASH_IT_SEARCH_USE_COLOR=false + else + args=(${args[@]} ${word}) + fi + done - if [[ ${#args} -gt 0 ]]; then - for component in "${BASH_IT_COMPONENTS[@]}" ; do - _bash-it-search-component "${component}" "${args[@]}" - done - fi + if [[ ${#args} -gt 0 ]]; then + for component in "${BASH_IT_COMPONENTS[@]}"; do + _bash-it-search-component "${component}" "${args[@]}" + done + fi - return 0 + return 0 } -_bash-it-search-help() { - printf "${echo_normal} +_bash-it-search-help() +{ + printf "${echo_normal} ${echo_underline_yellow}USAGE${echo_normal} bash-it search [-|@]term1 [-|@]term2 ... \\ @@ -165,197 +167,208 @@ ${echo_underline_yellow}SUMMARY${echo_normal} " } -_bash-it-is-partial-match() { - local component="$1" - local term="$2" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E -i -q -- "${term}" +_bash-it-is-partial-match() +{ + local component="$1" + local term="$2" + _bash-it-component-help "${component}" | $(_bash-it-grep) -E -i -q -- "${term}" } -_bash-it-component-term-matches-negation() { - local match="$1"; shift - local negative - for negative in "$@"; do - [[ "${match}" =~ "${negative}" ]] && return 0 - done +_bash-it-component-term-matches-negation() +{ + local match="$1" + shift + local negative + for negative in "$@"; do + [[ "${match}" =~ "${negative}" ]] && return 0 + done - return 1 + return 1 } -_bash-it-search-component() { - local component="$1" - shift +_bash-it-search-component() +{ + local component="$1" + shift - _about 'searches for given terms amongst a given component' - _param '1: component type, one of: [ aliases | plugins | completions ]' - _param '2: term1 term2 @term3' - _param '3: [-]term4 [-]term5 ...' - _example '$ _bash-it-search-component aliases @git rake bundler -chruby' + _about 'searches for given terms amongst a given component' + _param '1: component type, one of: [ aliases | plugins | completions ]' + _param '2: term1 term2 @term3' + _param '3: [-]term4 [-]term5 ...' + _example '$ _bash-it-search-component aliases @git rake bundler -chruby' - # if one of the search terms is --enable or --disable, we will apply - # this action to the matches further ` down. - local component_singular action action_func - local -a search_commands=(enable disable) - for search_command in "${search_commands[@]}"; do - if $(_bash-it-array-contains-element "--${search_command}" "$@"); then - component_singular=${component} - component_singular=${component_singular/es/} # aliases -> alias - component_singular=${component_singular/ns/n} # plugins -> plugin + # if one of the search terms is --enable or --disable, we will apply + # this action to the matches further ` down. + local component_singular action action_func + local -a search_commands=(enable disable) + for search_command in "${search_commands[@]}"; do + if $(_bash-it-array-contains-element "--${search_command}" "$@"); then + component_singular=${component} + component_singular=${component_singular/es/} # aliases -> alias + component_singular=${component_singular/ns/n} # plugins -> plugin - action="${search_command}" - action_func="_${action}-${component_singular}" - break - fi - done + action="${search_command}" + action_func="_${action}-${component_singular}" + break + fi + done - local -a terms=($@) # passed on the command line + local -a terms=($@) # passed on the command line - unset exact_terms - unset partial_terms - unset negative_terms + unset exact_terms + unset partial_terms + unset negative_terms - local -a exact_terms=() # terms that should be included only if they match exactly - local -a partial_terms=() # terms that should be included if they match partially - local -a negative_terms=() # negated partial terms that should be excluded + local -a exact_terms=() # terms that should be included only if they match exactly + local -a partial_terms=() # terms that should be included if they match partially + local -a negative_terms=() # negated partial terms that should be excluded - unset component_list - local -a component_list=( $(_bash-it-component-list "${component}") ) - local term + unset component_list + local -a component_list=($(_bash-it-component-list "${component}")) + local term - for term in "${terms[@]}"; do - local search_term="${term:1}" - if [[ "${term:0:2}" == "--" ]] ; then - continue - elif [[ "${term:0:1}" == "-" ]] ; then - negative_terms=(${negative_terms[@]} "${search_term}") - elif [[ "${term:0:1}" == "@" ]] ; then - if $(_bash-it-array-contains-element "${search_term}" "${component_list[@]}"); then - exact_terms=(${exact_terms[@]} "${search_term}") - fi - else - partial_terms=(${partial_terms[@]} $(_bash-it-component-list-matching "${component}" "${term}") ) - fi - done + for term in "${terms[@]}"; do + local search_term="${term:1}" + if [[ "${term:0:2}" == "--" ]]; then + continue + elif [[ "${term:0:1}" == "-" ]]; then + negative_terms=(${negative_terms[@]} "${search_term}") + elif [[ "${term:0:1}" == "@" ]]; then + if $(_bash-it-array-contains-element "${search_term}" "${component_list[@]}"); then + exact_terms=(${exact_terms[@]} "${search_term}") + fi + else + partial_terms=(${partial_terms[@]} $(_bash-it-component-list-matching "${component}" "${term}")) + fi + done - local -a total_matches=( $(_bash-it-array-dedup ${exact_terms[@]} ${partial_terms[@]}) ) + local -a total_matches=($(_bash-it-array-dedup ${exact_terms[@]} ${partial_terms[@]})) - unset matches - declare -a matches=() - for match in ${total_matches[@]}; do - local include_match=true - if [[ ${#negative_terms[@]} -gt 0 ]]; then - ( _bash-it-component-term-matches-negation "${match}" "${negative_terms[@]}" ) && include_match=false - fi - ( ${include_match} ) && matches=(${matches[@]} "${match}") - done - _bash-it-search-result "${component}" "${action}" "${action_func}" "${matches[@]}" - unset matches final_matches terms + unset matches + declare -a matches=() + for match in ${total_matches[@]}; do + local include_match=true + if [[ ${#negative_terms[@]} -gt 0 ]]; then + (_bash-it-component-term-matches-negation "${match}" "${negative_terms[@]}") && include_match=false + fi + (${include_match}) && matches=(${matches[@]} "${match}") + done + _bash-it-search-result "${component}" "${action}" "${action_func}" "${matches[@]}" + unset matches final_matches terms } -_bash-it-search-result() { - local component="$1"; shift - local action="$1"; shift - local action_func="$1"; shift - local -a matches=($@) +_bash-it-search-result() +{ + local component="$1" + shift + local action="$1" + shift + local action_func="$1" + shift + local -a matches=($@) - local color_component color_enable color_disable color_off + local color_component color_enable color_disable color_off - color_sep=':' + color_sep=':' - ( ${BASH_IT_SEARCH_USE_COLOR} ) && { - color_component='\e[1;34m' - color_enable='\e[1;32m' - suffix_enable='' - suffix_disable='' - color_disable='\e[0;0m' - color_off='\e[0;0m' - } + (${BASH_IT_SEARCH_USE_COLOR}) && { + color_component='\e[1;34m' + color_enable='\e[1;32m' + suffix_enable='' + suffix_disable='' + color_disable='\e[0;0m' + color_off='\e[0;0m' + } - ( ${BASH_IT_SEARCH_USE_COLOR} ) || { - color_component='' - suffix_enable=' ✓ ︎' - suffix_disable=' ' - color_enable='' - color_disable='' - color_off='' - } + (${BASH_IT_SEARCH_USE_COLOR}) || { + color_component='' + suffix_enable=' ✓ ︎' + suffix_disable=' ' + color_enable='' + color_disable='' + color_off='' + } - local match - local modified=0 + local match + local modified=0 - if [[ "${#matches[@]}" -gt 0 ]] ; then - printf "${color_component}%13s${color_sep} ${color_off}" "${component}" + if [[ "${#matches[@]}" -gt 0 ]]; then + printf "${color_component}%13s${color_sep} ${color_off}" "${component}" - for match in "${matches[@]}"; do - local enabled=0 - ( _bash-it-component-item-is-enabled "${component}" "${match}" ) && enabled=1 + for match in "${matches[@]}"; do + local enabled=0 + (_bash-it-component-item-is-enabled "${component}" "${match}") && enabled=1 - local match_color compatible_action suffix opposite_suffix + local match_color compatible_action suffix opposite_suffix - (( ${enabled} )) && { - match_color=${color_enable} - suffix=${suffix_enable} - opposite_suffix=${suffix_disable} - compatible_action="disable" - } + ((${enabled})) && { + match_color=${color_enable} + suffix=${suffix_enable} + opposite_suffix=${suffix_disable} + compatible_action="disable" + } - (( ${enabled} )) || { - match_color=${color_disable} - suffix=${suffix_disable} - opposite_suffix=${suffix_enable} - compatible_action="enable" - } + ((${enabled})) || { + match_color=${color_disable} + suffix=${suffix_disable} + opposite_suffix=${suffix_enable} + compatible_action="enable" + } - local m="${match}${suffix}" - local len - len=${#m} + local m="${match}${suffix}" + local len + len=${#m} - printf " ${match_color}${match}${suffix}" # print current state - if [[ "${action}" == "${compatible_action}" ]]; then - if [[ ${action} == "enable" && ${BASH_IT_SEARCH_USE_COLOR} == false ]]; then - _bash-it-flash-term ${len} "${match}${suffix}" - else - _bash-it-erase-term ${len} - fi - modified=1 - result=$(${action_func} ${match}) - local temp="color_${compatible_action}" - match_color=${!temp} - _bash-it-rewind ${len} - printf "${match_color}${match}${opposite_suffix}" - fi + printf " ${match_color}${match}${suffix}" # print current state + if [[ "${action}" == "${compatible_action}" ]]; then + if [[ ${action} == "enable" && ${BASH_IT_SEARCH_USE_COLOR} == false ]]; then + _bash-it-flash-term ${len} "${match}${suffix}" + else + _bash-it-erase-term ${len} + fi + modified=1 + result=$(${action_func} ${match}) + local temp="color_${compatible_action}" + match_color=${!temp} + _bash-it-rewind ${len} + printf "${match_color}${match}${opposite_suffix}" + fi - printf "${color_off}" - done + printf "${color_off}" + done - [[ ${modified} -gt 0 ]] && _bash-it-clean-component-cache ${component} - printf "\n" - fi + [[ ${modified} -gt 0 ]] && _bash-it-clean-component-cache ${component} + printf "\n" + fi } -_bash-it-rewind() { - local len="$1" - printf "\033[${len}D" +_bash-it-rewind() +{ + local len="$1" + printf "\033[${len}D" } -_bash-it-flash-term() { - local len="$1" - local match="$2" - local delay=0.1 - local color +_bash-it-flash-term() +{ + local len="$1" + local match="$2" + local delay=0.1 + local color - for color in ${text_black} ${echo_bold_blue} ${bold_yellow} ${bold_red} ${echo_bold_green} ; do - sleep ${delay} - _bash-it-rewind "${len}" - printf "${color}${match}" - done + for color in ${text_black} ${echo_bold_blue} ${bold_yellow} ${bold_red} ${echo_bold_green}; do + sleep ${delay} + _bash-it-rewind "${len}" + printf "${color}${match}" + done } -_bash-it-erase-term() { - local len="$1" - _bash-it-rewind ${len} - for a in {0..30}; do - [[ ${a} -gt ${len} ]] && break - printf "%.*s" $a " " - sleep 0.05 - done +_bash-it-erase-term() +{ + local len="$1" + _bash-it-rewind ${len} + for a in {0..30}; do + [[ ${a} -gt ${len} ]] && break + printf "%.*s" $a " " + sleep 0.05 + done } diff --git a/lib/utilities.bash b/lib/utilities.bash index 1f249b98..ab7d1caa 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -6,7 +6,8 @@ # Generic utilies ########################################################################### -function _bash-it-get-component-name-from-path() { +function _bash-it-get-component-name-from-path() +{ local filename # filename without path filename="${1##*/}" @@ -16,7 +17,8 @@ function _bash-it-get-component-name-from-path() { echo "${filename%.*.bash}" } -function _bash-it-get-component-type-from-path() { +function _bash-it-get-component-type-from-path() +{ local filename # filename without path filename="${1##*/}" @@ -46,7 +48,8 @@ function _bash-it-get-component-type-from-path() { # contains pear! # # -function _bash-it-array-contains-element() { +function _bash-it-array-contains-element() +{ local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0 @@ -55,18 +58,21 @@ function _bash-it-array-contains-element() { } # Dedupe an array (without embedded newlines). -function _bash-it-array-dedup() { +function _bash-it-array-dedup() +{ printf '%s\n' "$@" | sort -u } # Outputs a full path of the grep found on the filesystem -function _bash-it-grep() { +function _bash-it-grep() +{ : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}" } # Runs `grep` with extended regular expressions -function _bash-it-egrep() { +function _bash-it-egrep() +{ : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" "${BASH_IT_GREP:-/usr/bin/grep}" -E "$@" } @@ -76,7 +82,8 @@ function _bash-it-egrep() { # completion). ########################################################################### -function _bash-it-component-help() { +function _bash-it-component-help() +{ local component file func component="$(_bash-it-pluralize-component "${1}")" file="$(_bash-it-component-cache-file "${component}")" @@ -87,7 +94,8 @@ function _bash-it-component-help() { cat "${file}" } -function _bash-it-component-cache-file() { +function _bash-it-component-cache-file() +{ local component file component="$(_bash-it-pluralize-component "${1?${FUNCNAME[0]}: component name required}")" file="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${component}" @@ -95,7 +103,8 @@ function _bash-it-component-cache-file() { printf '%s' "${file}" } -function _bash-it-pluralize-component() { +function _bash-it-pluralize-component() +{ local component="${1}" local -i len=$((${#component} - 1)) # pluralize component name for consistency @@ -104,7 +113,8 @@ function _bash-it-pluralize-component() { printf '%s' "${component}" } -function _bash-it-clean-component-cache() { +function _bash-it-clean-component-cache() +{ local component="$1" local cache local -a BASH_IT_COMPONENTS=(aliases plugins completions) @@ -121,24 +131,28 @@ function _bash-it-clean-component-cache() { } # Returns an array of items within each compoenent. -function _bash-it-component-list() { +function _bash-it-component-list() +{ local IFS=$'\n' component="$1" _bash-it-component-help "${component}" | awk '{print $1}' | sort -u } -function _bash-it-component-list-matching() { +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 } -function _bash-it-component-list-enabled() { +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 } -function _bash-it-component-list-disabled() { +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 } @@ -151,7 +165,8 @@ function _bash-it-component-list-disabled() { # # Examples: # _bash-it-component-item-is-enabled alias git && echo "git alias is enabled" -function _bash-it-component-item-is-enabled() { +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" @@ -165,7 +180,8 @@ function _bash-it-component-item-is-enabled() { # # Examples: # _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled" -function _bash-it-component-item-is-disabled() { +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" diff --git a/lint_clean_files.sh b/lint_clean_files.sh index 26650b16..642b8415 100755 --- a/lint_clean_files.sh +++ b/lint_clean_files.sh @@ -7,10 +7,10 @@ # # shellcheck disable=SC2002 # Prefer 'cat' for cleaner script mapfile -t FILES < <( - cat clean_files.txt \ - | grep -v -E '^\s*$' \ - | grep -v -E '^\s*#' \ - | xargs -n1 -I{} find "{}" -type f + cat clean_files.txt | + grep -v -E '^\s*$' | + grep -v -E '^\s*#' | + xargs -n1 -I{} find "{}" -type f ) # We clear the BASH_IT variable to help the shellcheck checker diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index eb368d93..58bd8f3c 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -17,7 +17,8 @@ about-plugin 'Automatic completion of aliases' # 4) Custom scripts # Automatically add completion for all aliases to commands having completion functions -function alias_completion { +function alias_completion +{ local namespace="alias_completion" local tmp_file completion_loader alias_name alias_tokens line completions local alias_arg_words new_completion compl_func compl_wrapper diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 6490ab88..858d7d94 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -2,7 +2,8 @@ cite about-plugin about-plugin 'miscellaneous tools' -function ips() { +function ips() +{ about 'display all ip addresses for this host' group 'base' if _command_exists ifconfig; then @@ -14,7 +15,8 @@ function ips() { fi } -function down4me() { +function down4me() +{ about 'checks whether a website is down for you, or everybody' param '1: website url' example '$ down4me http://www.google.com' @@ -22,7 +24,8 @@ function down4me() { curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' } -function myip() { +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/") @@ -35,7 +38,8 @@ function myip() { echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}" } -function pickfrom() { +function pickfrom() +{ about 'picks random line from file' param '1: filename' example '$ pickfrom /usr/share/dict/words' @@ -50,7 +54,8 @@ function pickfrom() { head -n "$n" "$file" | tail -1 } -function passgen() { +function passgen() +{ about 'generates random password from dictionary words' param 'optional integer length' param 'if unset, defaults to 4' @@ -72,7 +77,8 @@ if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then fi if _command_exists markdown && _command_exists browser; then - function pmdown() { + function pmdown() + { about 'preview markdown file in a browser' param '1: markdown file' example '$ pmdown README.md' @@ -82,7 +88,8 @@ if _command_exists markdown && _command_exists browser; then } fi -function mkcd() { +function mkcd() +{ about 'make one or more directories and cd into the last one' param 'one or more directories to create' example '$ mkcd foo' @@ -94,19 +101,22 @@ function mkcd() { } # shellcheck disable=SC2010 -function lsgrep() { +function lsgrep() +{ about 'search through directory contents with grep' group 'base' ls | grep "$@" } -function quiet() { +function quiet() +{ about 'what *does* this do?' group 'base' nohup "$@" &> /dev/null < /dev/null & } -function usage() { +function usage() +{ about 'disk usage per directory, in Mac OS X and Linux' param '1: directory name' group 'base' @@ -124,7 +134,8 @@ function usage() { 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() { + function t() + { about 'one thing todo' param 'if not set, display todo item' param '1: todo text' @@ -137,7 +148,8 @@ if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" && fi if _command_exists mkisofs; then - function mkiso() { + function mkiso() + { about 'creates iso from current dir in the parent dir (unless defined)' param '1: ISO name' param '2: dest/path' @@ -160,7 +172,8 @@ if _command_exists mkisofs; then fi # useful for administrators and configs -function buf() { +function buf() +{ about 'back up file with timestamp' param 'filename' group 'base' @@ -170,7 +183,8 @@ function buf() { } if ! _command_exists del; then - function del() { + 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' diff --git a/plugins/available/cmd-returned-notify.plugin.bash b/plugins/available/cmd-returned-notify.plugin.bash index d9be5e4e..6f91bca3 100644 --- a/plugins/available/cmd-returned-notify.plugin.bash +++ b/plugins/available/cmd-returned-notify.plugin.bash @@ -2,13 +2,15 @@ cite about-plugin about-plugin 'Alert (BEL) when process ends after a threshold of seconds' -precmd_return_notification() { +precmd_return_notification() +{ export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)})) [[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a" export LAST_COMMAND_TIME= } -preexec_return_notification() { +preexec_return_notification() +{ [[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s) } diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index 2c1adf7a..c95c931a 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -31,77 +31,87 @@ alias pu="pushd" # Pop current location alias po="popd" -function dirs-help() { - about 'directory navigation alias usage' - group 'dirs' +function dirs-help() +{ + about 'directory navigation alias usage' + group 'dirs' - echo "Directory Navigation Alias Usage" - echo - echo "Use the power of directory stacking to move" - echo "between several locations with ease." - echo - echo "d : Show directory stack." - echo "po : Remove current location from stack." - echo "pc : Adds current location to stack." - echo "pu : Adds given location to stack." - echo "1 : Change to stack location 1." - echo "2 : Change to stack location 2." - echo "3 : Change to stack location 3." - echo "4 : Change to stack location 4." - echo "5 : Change to stack location 5." - echo "6 : Change to stack location 6." - echo "7 : Change to stack location 7." - echo "8 : Change to stack location 8." - echo "9 : Change to stack location 9." + echo "Directory Navigation Alias Usage" + echo + echo "Use the power of directory stacking to move" + echo "between several locations with ease." + echo + echo "d : Show directory stack." + echo "po : Remove current location from stack." + echo "pc : Adds current location to stack." + echo "pu : Adds given location to stack." + echo "1 : Change to stack location 1." + echo "2 : Change to stack location 2." + echo "3 : Change to stack location 3." + echo "4 : Change to stack location 4." + echo "5 : Change to stack location 5." + echo "6 : Change to stack location 6." + echo "7 : Change to stack location 7." + echo "8 : Change to stack location 8." + echo "9 : Change to stack location 9." } # Add bookmarking functionality # Usage: -if [ ! -f ~/.dirs ]; then # if doesn't exist, create it - touch ~/.dirs +if [ ! -f ~/.dirs ]; then # if doesn't exist, create it + touch ~/.dirs else - source ~/.dirs + source ~/.dirs fi alias L='cat ~/.dirs' # Goes to destination dir, otherwise stay in the dir -G () { - about 'goes to destination dir' - param '1: directory' - example '$ G ..' - group 'dirs' +G() +{ + about 'goes to destination dir' + param '1: directory' + example '$ G ..' + group 'dirs' - cd "${1:-${PWD}}" ; + cd "${1:-${PWD}}" } -S () { - about 'save a bookmark' - param '1: bookmark name' - example '$ S mybkmrk' - group 'dirs' +S() +{ + about 'save a bookmark' + param '1: bookmark name' + example '$ S mybkmrk' + group 'dirs' - [[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; } + [[ $# -eq 1 ]] || { + echo "${FUNCNAME[0]} function requires 1 argument" + return 1 + } - sed "/$@/d" ~/.dirs > ~/.dirs1; - \mv ~/.dirs1 ~/.dirs; - echo "$@"=\""${PWD}"\" >> ~/.dirs; - source ~/.dirs ; + sed "/$@/d" ~/.dirs > ~/.dirs1 + \mv ~/.dirs1 ~/.dirs + echo "$@"=\""${PWD}"\" >> ~/.dirs + source ~/.dirs } -R () { - about 'remove a bookmark' - param '1: bookmark name' - example '$ R mybkmrk' - group 'dirs' +R() +{ + about 'remove a bookmark' + param '1: bookmark name' + example '$ R mybkmrk' + group 'dirs' - [[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; } + [[ $# -eq 1 ]] || { + echo "${FUNCNAME[0]} function requires 1 argument" + return 1 + } - sed "/$@/d" ~/.dirs > ~/.dirs1; - \mv ~/.dirs1 ~/.dirs; + sed "/$@/d" ~/.dirs > ~/.dirs1 + \mv ~/.dirs1 ~/.dirs } -alias U='source ~/.dirs' # Update bookmark stack +alias U='source ~/.dirs' # Update bookmark stack # Set the Bash option so that no '$' is required when using the above facility shopt -s cdable_vars diff --git a/plugins/available/git.plugin.bash b/plugins/available/git.plugin.bash index 3a130955..1b70aa05 100644 --- a/plugins/available/git.plugin.bash +++ b/plugins/available/git.plugin.bash @@ -3,7 +3,8 @@ cite about-plugin about-plugin 'git helper functions' # shellcheck disable=SC2016 -function git_remote { +function git_remote +{ about 'adds remote $GIT_HOSTING:$1 to current repo' group "git" @@ -11,7 +12,8 @@ function git_remote { git remote add origin "${GIT_HOSTING}:${1}".git } -function git_first_push { +function git_first_push +{ about 'push into origin refs/heads/master' group 'git' @@ -19,7 +21,8 @@ function git_first_push { git push origin master:refs/heads/master } -function git_pub() { +function git_pub() +{ about 'publishes current branch to remote origin' group 'git' BRANCH=$(git rev-parse --abbrev-ref HEAD) @@ -28,7 +31,8 @@ function git_pub() { git push -u origin "${BRANCH}" } -function git_revert() { +function git_revert() +{ about 'applies changes to HEAD that revert all changes after this commit' group 'git' @@ -38,25 +42,29 @@ function git_revert() { git reset --hard } -function git_rollback() { +function git_rollback() +{ about 'resets the current HEAD to this commit' group 'git' - function is_clean() { + function is_clean() + { if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then echo "Your branch is dirty, please commit your changes" kill -INT $$ fi } - function commit_exists() { + function commit_exists() + { if git rev-list --quiet "${1:?}"; then echo "Commit ${1} does not exist" kill -INT $$ fi } - function keep_changes() { + function keep_changes() + { 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 @@ -105,7 +113,8 @@ function git_rollback() { fi } -function git_remove_missing_files() { +function git_remove_missing_files() +{ about "git rm's missing files" group 'git' @@ -113,7 +122,8 @@ function git_remove_missing_files() { } # Adds files to git's exclude file (same as .gitignore) -function local-ignore() { +function local-ignore() +{ about 'adds file or path to git exclude file' param '1: file or path fragment to ignore' group 'git' @@ -121,7 +131,8 @@ function local-ignore() { } # get a quick overview for your git repo -function git_info() { +function git_info() +{ about 'overview for your git repo' group 'git' @@ -158,7 +169,8 @@ function git_info() { fi } -function git_stats { +function git_stats +{ about 'display stats per author' group 'git' @@ -203,7 +215,8 @@ function git_stats { fi } -function gittowork() { +function gittowork() +{ about 'Places the latest .gitignore file for a given project type in the current directory, or concatenates onto an existing .gitignore' group 'git' param '1: the language/type of the project, used for determining the contents of the .gitignore file' @@ -224,7 +237,8 @@ function gittowork() { fi } -function gitignore-reload() { +function gitignore-reload() +{ about 'Empties the git cache, and readds all files not blacklisted by .gitignore' group 'git' example '$ gitignore-reload' @@ -274,7 +288,8 @@ function gitignore-reload() { fi } -function git-changelog() { +function git-changelog() +{ # --------------------------------------------------------------- # ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 | # --------------------------------------------------------------- diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 5592a006..d9a8c0ae 100644 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -7,7 +7,9 @@ about-plugin 'go environment variables & path configuration' # Test `go version` because goenv creates shim scripts that will be found in PATH # but do not always resolve to a working install. -{ _command_exists go && go version &> /dev/null; } || return 0 +{ + _command_exists go && go version &> /dev/null +} || return 0 export GOROOT="${GOROOT:-$(go env GOROOT)}" export GOPATH="${GOPATH:-$(go env GOPATH)}" @@ -16,7 +18,8 @@ export GOPATH="${GOPATH:-$(go env GOPATH)}" # might be managed differently, we add each path's /bin folder to PATH using pathmunge, # while preserving ordering. # e.g. GOPATH=foo:bar -> PATH=foo/bin:bar/bin -_bash-it-gopath-pathmunge() { +_bash-it-gopath-pathmunge() +{ _about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended' _group 'go' if [[ -z $GOPATH ]]; then diff --git a/plugins/available/goenv.plugin.bash b/plugins/available/goenv.plugin.bash index 17e4a0ff..d14ab196 100644 --- a/plugins/available/goenv.plugin.bash +++ b/plugins/available/goenv.plugin.bash @@ -11,10 +11,10 @@ about-plugin 'load goenv, if you are using it' # - Check if in $PATH already # - Check if installed manually to $GOENV_ROOT # - Check if installed manually to $HOME -_command_exists goenv \ - || [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] \ - || [[ -x "$HOME/.goenv/bin/goenv" ]] \ - || return 0 +_command_exists goenv || + [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] || + [[ -x "$HOME/.goenv/bin/goenv" ]] || + return 0 # Set GOENV_ROOT, if not already set export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}" @@ -29,10 +29,12 @@ 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() { +_bash-it-goenv-preexec() +{ GOENV_OLD_VERSION="$(goenv version-name)" } -_bash-it-goenv-precmd() { +_bash-it-goenv-precmd() +{ if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then exec env -u PATH -u GOROOT -u GOPATH -u GOENV_OLD_VERSION "${0/-/}" --login fi diff --git a/plugins/available/history.plugin.bash b/plugins/available/history.plugin.bash index 08ca8de6..3bfb7a9c 100644 --- a/plugins/available/history.plugin.bash +++ b/plugins/available/history.plugin.bash @@ -11,7 +11,8 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups} # resize history to 100x the default (500) export HISTSIZE=${HISTSIZE:-50000} -top-history() { +top-history() +{ about 'print the name and count of the most commonly run tools' if [[ -n $HISTTIMEFORMAT ]]; then @@ -23,16 +24,16 @@ top-history() { unset HISTTIMEFORMAT fi - history \ - | awk '{ + history | + awk '{ a[$2]++ }END{ for(i in a) printf("%s\t%s\n", a[i], i) - }' \ - | sort --reverse --numeric-sort \ - | head \ - | column \ + }' | + sort --reverse --numeric-sort | + head | + column \ --table \ --table-columns 'Command Count,Command Name' \ --output-separator ' | ' diff --git a/plugins/available/jump.plugin.bash b/plugins/available/jump.plugin.bash index 1713d1b7..b1c1592f 100644 --- a/plugins/available/jump.plugin.bash +++ b/plugins/available/jump.plugin.bash @@ -3,7 +3,8 @@ cite about-plugin about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding' -function __init_jump() { +function __init_jump() +{ if _command_exists jump; then eval "$(jump shell bash "${JUMP_OPTS[@]}")" fi diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index 139e5188..f285018d 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -6,7 +6,8 @@ _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() { +function ccat() +{ 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' @@ -14,7 +15,8 @@ function ccat() { pygmentize -f 256 -O style="${BASH_IT_CCAT_STYLE:-default}" -g "$@" } -function cless() { +function cless() +{ about 'pigments the files passed in and passes to less for pagination' param '*: the files to paginate with less' example 'cless mysite/manage.py' diff --git a/plugins/available/percol.plugin.bash b/plugins/available/percol.plugin.bash index 027dfdc4..abc8d46b 100644 --- a/plugins/available/percol.plugin.bash +++ b/plugins/available/percol.plugin.bash @@ -21,7 +21,8 @@ if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then return fi -function _replace_by_history() { +function _replace_by_history() +{ local HISTTIMEFORMAT= # Ensure we can parse history properly #TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}" local l diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index 05d28478..6f6c9b0e 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -11,10 +11,10 @@ about-plugin 'load pyenv, if you are using it' # - 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 +_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}" diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index aed8daf8..ce5cc9c2 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -8,7 +8,8 @@ if _command_exists ruby && _command_exists gem; then pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after fi -function remove_gem() { +function remove_gem() +{ about 'removes installed gem' param '1: installed gem name' group 'ruby' diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index b8747a25..1fd648c0 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -2,7 +2,8 @@ cite about-plugin about-plugin 'automatically set your xterm title with host and location info' -_short-dirname() { +_short-dirname() +{ local dir_name="${PWD/~/\~}" if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then echo "${dir_name##*/}" @@ -11,7 +12,8 @@ _short-dirname() { fi } -_short-command() { +_short-command() +{ local input_command="$*" if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then echo "${input_command%% *}" @@ -20,16 +22,19 @@ _short-command() { fi } -set_xterm_title() { +set_xterm_title() +{ local title="${1:-}" echo -ne "\033]0;${title}\007" } -precmd_xterm_title() { +precmd_xterm_title() +{ set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}" } -preexec_xterm_title() { +preexec_xterm_title() +{ set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" } diff --git a/scripts/reloader.bash b/scripts/reloader.bash index 4bc24941..4fc6fa33 100755 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -3,50 +3,53 @@ BASH_IT_LOG_PREFIX="core: reloader: " function _set-prefix-based-on-path() { - filename=$(_bash-it-get-component-name-from-path "$1") - extension=$(_bash-it-get-component-type-from-path "$1") + 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: " + BASH_IT_LOG_PREFIX="$extension: $filename: " } if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then - _bash_it_config_type="" + _bash_it_config_type="" - case $1 in - alias|completion|plugin) - _bash_it_config_type=$1 - _log_debug "Loading enabled $1 components..." ;; - ''|*) - _log_debug "Loading all enabled components..." ;; - esac + case $1 in + alias | completion | plugin) + _bash_it_config_type=$1 + _log_debug "Loading enabled $1 components..." + ;; + '' | *) + _log_debug "Loading all enabled components..." + ;; + esac - for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do - if [ -e "${_bash_it_config_file}" ]; then - _set-prefix-based-on-path "${_bash_it_config_file}" - _log_debug "Loading component..." - # shellcheck source=/dev/null - source $_bash_it_config_file - else - echo "Unable to read ${_bash_it_config_file}" > /dev/stderr - fi - done + for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do + if [ -e "${_bash_it_config_file}" ]; then + _set-prefix-based-on-path "${_bash_it_config_file}" + _log_debug "Loading component..." + # shellcheck source=/dev/null + source $_bash_it_config_file + else + echo "Unable to read ${_bash_it_config_file}" > /dev/stderr + fi + done fi if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then - case $2 in - aliases|completion|plugins) - _log_warning "Using legacy enabling for $2, please update your bash-it version and migrate" - for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")); do - if [[ -e "$_bash_it_config_file" ]]; then - _set-prefix-based-on-path "${_bash_it_config_file}" - _log_debug "Loading component..." - # shellcheck source=/dev/null - source "$_bash_it_config_file" - else - echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr - fi - done ;; - esac + case $2 in + aliases | completion | plugins) + _log_warning "Using legacy enabling for $2, please update your bash-it version and migrate" + for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")); do + if [[ -e "$_bash_it_config_file" ]]; then + _set-prefix-based-on-path "${_bash_it_config_file}" + _log_debug "Loading component..." + # shellcheck source=/dev/null + source "$_bash_it_config_file" + else + echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr + fi + done + ;; + esac fi unset _bash_it_config_file diff --git a/test/test_helper.bash b/test/test_helper.bash index 8d92e89c..1f19d1fa 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -22,11 +22,13 @@ load "${TEST_DEPS_DIR}/bats-file/load.bash" # support 'plumbing' metadata cite _about _param _example _group _author _version -local_setup() { +local_setup() +{ true } -local_teardown() { +local_teardown() +{ true } @@ -34,7 +36,8 @@ local_teardown() { # fresh and isolated Bash-it directory. This is done to avoid # messing with your own Bash-it source directory. # If you need this, call it in your .bats file's `local_setup` function. -setup_test_fixture() { +setup_test_fixture() +{ mkdir -p "$BASH_IT" lib_directory="$(cd "$(dirname "$0")" && pwd)" local src_topdir="$lib_directory/../../../.." @@ -66,7 +69,8 @@ setup_test_fixture() { export BASH_IT_TEST_HOME="$TEST_TEMP_DIR" } -setup() { +setup() +{ # The `temp_make` function from "bats-file" requires the tralston/bats-file fork, # since the original ztombol/bats-file's `temp_make` does not work on macOS. TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')" @@ -96,7 +100,8 @@ setup() { local_setup } -teardown() { +teardown() +{ local_teardown rm -rf "${BASH_IT_TEST_DIR}" diff --git a/themes/90210/90210.theme.bash b/themes/90210/90210.theme.bash index 3db3f17b..0c14d495 100644 --- a/themes/90210/90210.theme.bash +++ b/themes/90210/90210.theme.bash @@ -13,7 +13,8 @@ GIT_THEME_PROMPT_PREFIX=" ${green}|" GIT_THEME_PROMPT_SUFFIX="${green}|" # Nicely formatted terminal prompt -function prompt_command() { +function prompt_command() +{ 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}\$ " } diff --git a/themes/agnoster/agnoster.theme.bash b/themes/agnoster/agnoster.theme.bash index 20c184f3..cf1cf855 100644 --- a/themes/agnoster/agnoster.theme.bash +++ b/themes/agnoster/agnoster.theme.bash @@ -70,7 +70,8 @@ PROMPT_DIRTRIM=2 # bash4 and above ###################################################################### DEBUG=0 -debug() { +debug() +{ if [[ ${DEBUG} -ne 0 ]]; then echo >&2 -e "$@" fi @@ -87,7 +88,8 @@ RIGHT_SEPARATOR='' LEFT_SUBSEG='' RIGHT_SUBSEG='' -text_effect() { +text_effect() +{ case "$1" in reset) echo 0 ;; bold) echo 1 ;; @@ -98,7 +100,8 @@ text_effect() { # to add colors, see # http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux # under the "256 (8-bit) Colors" section, and follow the example for orange below -fg_color() { +fg_color() +{ case "$1" in black) echo 30 ;; red) echo 31 ;; @@ -112,7 +115,8 @@ fg_color() { esac } -bg_color() { +bg_color() +{ case "$1" in black) echo 40 ;; red) echo 41 ;; @@ -129,7 +133,8 @@ bg_color() { # TIL: declare is global not local, so best use a different name # for codes (mycodes) as otherwise it'll clobber the original. # this changes from BASH v3 to BASH v4. -ansi() { +ansi() +{ local seq declare -a mycodes=("${!1}") @@ -147,14 +152,16 @@ ansi() { # PR="$PR\[\033[${seq}m\]" } -ansi_single() { +ansi_single() +{ echo -ne '\[\033['"$1"'m\]' } # Begin a segment # Takes two arguments, background and foreground. Both can be omitted, # rendering default background/foreground. -prompt_segment() { +prompt_segment() +{ local bg fg declare -a codes @@ -196,7 +203,8 @@ prompt_segment() { } # End the prompt, closing any open segments -prompt_end() { +prompt_end() +{ if [[ -n $CURRENT_BG ]]; then declare -a codes=("$(text_effect reset)" "$(fg_color "$CURRENT_BG")") PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR" @@ -207,7 +215,8 @@ prompt_end() { } ### virtualenv prompt -prompt_virtualenv() { +prompt_virtualenv() +{ if [[ -n $VIRTUAL_ENV ]]; then color=cyan prompt_segment $color "$PRIMARY_FG" @@ -220,7 +229,8 @@ prompt_virtualenv() { # Each component will draw itself, and hide itself if no information needs to be shown # Context: user@hostname (who am I and where am I) -prompt_context() { +prompt_context() +{ local user="${USER:-${LOGNAME:?}}" if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then @@ -230,17 +240,20 @@ prompt_context() { # prints history followed by HH:MM, useful for remembering what # we did previously -prompt_histdt() { +prompt_histdt() +{ prompt_segment black default "\! [\A]" } -git_status_dirty() { +git_status_dirty() +{ dirty=$(git status -s 2> /dev/null | tail -n 1) [[ -n $dirty ]] && echo " ●" } # Git: branch/detached head, dirty status -prompt_git() { +prompt_git() +{ local ref dirty if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then ZSH_THEME_GIT_PROMPT_DIRTY='±' @@ -256,7 +269,8 @@ prompt_git() { } # Dir: current working directory -prompt_dir() { +prompt_dir() +{ prompt_segment blue black '\w' } @@ -264,7 +278,8 @@ prompt_dir() { # - was there an error # - am I root # - are there background jobs? -prompt_status() { +prompt_status() +{ local symbols symbols=() [[ $RETVAL -ne 0 ]] && symbols+=("$(ansi_single "$(fg_color red)")✘") @@ -280,12 +295,14 @@ prompt_status() { # requires setting prompt_foo to use PRIGHT vs PR # doesn't quite work per above -rightprompt() { +rightprompt() +{ printf "%*s" $COLUMNS "$PRIGHT" } # quick right prompt I grabbed to test things. -__command_rprompt() { +__command_rprompt() +{ local times=n=$COLUMNS tz for tz in ZRH:Europe/Zurich PIT:US/Eastern \ MTV:US/Pacific TOK:Asia/Tokyo; do @@ -299,7 +316,8 @@ __command_rprompt() { # PROMPT_COMMAND=__command_rprompt # this doens't wrap code in \[ \] -ansi_r() { +ansi_r() +{ local seq declare -a mycodes2=("${!1}") @@ -320,7 +338,8 @@ ansi_r() { # Begin a segment on the right # Takes two arguments, background and foreground. Both can be omitted, # rendering default background/foreground. -prompt_right_segment() { +prompt_right_segment() +{ local bg fg declare -a codes @@ -383,7 +402,8 @@ prompt_right_segment() { # (add-hook 'comint-preoutput-filter-functions # 'dirtrack-filter-out-pwd-prompt t t))) -prompt_emacsdir() { +prompt_emacsdir() +{ # no color or other setting... this will be deleted per above PR="DIR \w DIR$PR" } @@ -391,7 +411,8 @@ prompt_emacsdir() { ###################################################################### ## Main prompt -build_prompt() { +build_prompt() +{ [[ -n ${AG_EMACS_DIR+x} ]] && prompt_emacsdir prompt_status #[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt @@ -407,7 +428,8 @@ build_prompt() { # this doesn't work... new model: create a prompt via a PR variable and # use that. -set_bash_prompt() { +set_bash_prompt() +{ RETVAL=$? PR="" PRIGHT="" diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 03dc9e95..3326fab0 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -29,7 +29,8 @@ Face="\342\230\273" ## Parsers ## ############# -____atomic_top_left_parse() { +____atomic_top_left_parse() +{ ifs_old="${IFS}" IFS="|" read -r -a args <<< "$@" @@ -44,7 +45,8 @@ ____atomic_top_left_parse() { _TOP_LEFT+="" } -____atomic_top_right_parse() { +____atomic_top_right_parse() +{ ifs_old="${IFS}" IFS="|" read -r -a args <<< "$@" @@ -61,7 +63,8 @@ ____atomic_top_right_parse() { ((__SEG_AT_RIGHT += 1)) } -____atomic_bottom_parse() { +____atomic_bottom_parse() +{ ifs_old="${IFS}" IFS="|" read -r -a args <<< "$@" @@ -70,7 +73,8 @@ ____atomic_bottom_parse() { [ ${#args[1]} -gt 0 ] && _BOTTOM+=" " } -____atomic_top() { +____atomic_top() +{ _TOP_LEFT="" _TOP_RIGHT="" __TOP_RIGHT_LEN=0 @@ -96,7 +100,8 @@ ____atomic_top() { printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}" } -____atomic_bottom() { +____atomic_bottom() +{ _BOTTOM="" for seg in $___ATOMIC_BOTTOM; do info="$(___atomic_prompt_"${seg}")" @@ -109,7 +114,8 @@ ____atomic_bottom() { ## Segments ## ############## -___atomic_prompt_user_info() { +___atomic_prompt_user_info() +{ color=$white box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}" info="${IYellow}\u${IRed}@${IGreen}\h" @@ -117,14 +123,16 @@ ___atomic_prompt_user_info() { printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}" } -___atomic_prompt_dir() { +___atomic_prompt_dir() +{ color=${IRed} box="[|]${normal}" info="\w" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___atomic_prompt_scm() { +___atomic_prompt_scm() +{ [ "${THEME_SHOW_SCM}" != "true" ] && return color=$bold_green box="${Line}[${IWhite}$(scm_char)] " @@ -132,7 +140,8 @@ ___atomic_prompt_scm() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___atomic_prompt_python() { +___atomic_prompt_python() +{ [ "${THEME_SHOW_PYTHON}" != "true" ] && return color=$bold_yellow box="[|]" @@ -140,7 +149,8 @@ ___atomic_prompt_python() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}" } -___atomic_prompt_ruby() { +___atomic_prompt_ruby() +{ [ "${THEME_SHOW_RUBY}" != "true" ] && return color=$bold_white box="[|]" @@ -148,16 +158,18 @@ ___atomic_prompt_ruby() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}" } -___atomic_prompt_todo() { - [ "${THEME_SHOW_TODO}" != "true" ] \ - || [ -z "$(which todo.sh)" ] && return +___atomic_prompt_todo() +{ + [ "${THEME_SHOW_TODO}" != "true" ] || + [ -z "$(which todo.sh)" ] && return color=$bold_white box="[|]" info="t:$(todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }')" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}" } -___atomic_prompt_clock() { +___atomic_prompt_clock() +{ [ "${THEME_SHOW_CLOCK}" != "true" ] && return color=$THEME_CLOCK_COLOR box="[|]" @@ -165,10 +177,11 @@ ___atomic_prompt_clock() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___atomic_prompt_battery() { - ! _command_exists battery_percentage \ - || [ "${THEME_SHOW_BATTERY}" != "true" ] \ - || [ "$(battery_percentage)" = "no" ] && return +___atomic_prompt_battery() +{ + ! _command_exists battery_percentage || + [ "${THEME_SHOW_BATTERY}" != "true" ] || + [ "$(battery_percentage)" = "no" ] && return batp=$(battery_percentage) if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then @@ -186,13 +199,15 @@ ___atomic_prompt_battery() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___atomic_prompt_exitcode() { +___atomic_prompt_exitcode() +{ [ "${THEME_SHOW_EXITCODE}" != "true" ] && return color=$bold_purple [ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}" } -___atomic_prompt_char() { +___atomic_prompt_char() +{ color=$white prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}" if [ "${THEME_SHOW_SUDO}" == "true" ]; then @@ -207,19 +222,22 @@ ___atomic_prompt_char() { ## cli ## ######### -__atomic_show() { +__atomic_show() +{ typeset _seg=${1:-} shift export "THEME_SHOW_${_seg}"=true } -__atomic_hide() { +__atomic_hide() +{ typeset _seg=${1:-} shift export "THEME_SHOW_${_seg}"=false } -_atomic_completion() { +_atomic_completion() +{ local cur _action actions segments COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" @@ -239,7 +257,8 @@ _atomic_completion() { return 0 } -atomic() { +atomic() +{ typeset action=${1:-} shift typeset segs=${*:-} @@ -303,16 +322,19 @@ ___ATOMIC_BOTTOM=${___ATOMIC_BOTTOM:-"char"} ## Prompt ## ############ -__atomic_ps1() { +__atomic_ps1() +{ printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}" } -__atomic_ps2() { +__atomic_ps2() +{ color=$bold_white printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}" } -_atomic_prompt() { +_atomic_prompt() +{ exitcode="$?" PS1="$(__atomic_ps1)" diff --git a/themes/axin/axin.theme.bash b/themes/axin/axin.theme.bash index 7e90aded..116abbf4 100644 --- a/themes/axin/axin.theme.bash +++ b/themes/axin/axin.theme.bash @@ -29,7 +29,8 @@ else RESET="\033[m" fi -function prompt_command() { +function prompt_command() +{ PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]@ \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\[$SCM_THEME_PROMPT_PREFIX\]$(clock_prompt) \[$PURPLE\]$(scm_prompt_info) \n\$ \[$RESET\]" } diff --git a/themes/bakke/bakke.theme.bash b/themes/bakke/bakke.theme.bash index d7bfbbe8..90ba0a76 100644 --- a/themes/bakke/bakke.theme.bash +++ b/themes/bakke/bakke.theme.bash @@ -15,7 +15,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|" RVM_THEME_PROMPT_PREFIX="|" RVM_THEME_PROMPT_SUFFIX="|" -function prompt_command() { +function prompt_command() +{ #PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} " #PS1="\n${purple}\h: ${reset_color} ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " #PS1="\n${cyan}\h: ${reset_color} ${yellow}\w\n${red}$(scm_char)${red}$(scm_prompt_info) ${green}→${reset_color} " diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index b614d148..15d9834a 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -41,7 +41,8 @@ SCM_THEME_BRANCH_TRACK_PREFIX="${normal} ⤏ ${cyan}" SCM_THEME_CURRENT_USER_PREFFIX='  ' SCM_GIT_SHOW_CURRENT_USER=false -function _git-uptream-remote-logo { +function _git-uptream-remote-logo +{ [[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" local remote remote_domain @@ -59,12 +60,14 @@ function _git-uptream-remote-logo { esac } -function git_prompt_info { +function git_prompt_info +{ git_prompt_vars echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX" } -function _exit-code { +function _exit-code +{ if [[ "$1" -ne 0 ]]; then exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}" else @@ -72,7 +75,8 @@ function _exit-code { fi } -function _prompt { +function _prompt +{ local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration= command_duration=$(_command_duration) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index f9f5190d..4b9f3a02 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -91,7 +91,8 @@ RBFU_THEME_PROMPT_SUFFIX='|' : "${HG_EXE:=$SCM_HG}" : "${SVN_EXE:=$SCM_SVN}" -function _bash_it_appearance_scm_init() { +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)" @@ -108,7 +109,8 @@ function _bash_it_appearance_scm_init() { } _bash_it_appearance_scm_init -function scm { +function scm +{ if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then @@ -130,7 +132,8 @@ function scm { fi } -scm_prompt() { +scm_prompt() +{ local CHAR CHAR="$(scm_char)" local format=${SCM_PROMPT_FORMAT:-'[%s%s]'} @@ -141,7 +144,8 @@ scm_prompt() { fi } -function scm_prompt_char { +function scm_prompt_char +{ if [[ -z $SCM ]]; then scm; fi if [[ $SCM == "$SCM_GIT" ]]; then SCM_CHAR=$SCM_GIT_CHAR @@ -156,7 +160,8 @@ function scm_prompt_char { fi } -function scm_prompt_vars { +function scm_prompt_vars +{ scm scm_prompt_char SCM_DIRTY=0 @@ -167,19 +172,22 @@ function scm_prompt_vars { [[ $SCM == "$SCM_SVN" ]] && svn_prompt_vars && return } -function scm_prompt_info { +function scm_prompt_info +{ scm scm_prompt_char scm_prompt_info_common } -function scm_prompt_char_info { +function scm_prompt_char_info +{ scm_prompt_char echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" scm_prompt_info_common } -function scm_prompt_info_common { +function scm_prompt_info_common +{ SCM_DIRTY=0 SCM_STATE='' @@ -195,12 +203,19 @@ function scm_prompt_info_common { fi # TODO: consider adding minimal status information for hg and svn - { [[ ${SCM} == "${SCM_P4}" ]] && p4_prompt_info && return; } || true - { [[ ${SCM} == "${SCM_HG}" ]] && hg_prompt_info && return; } || true - { [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true + { + [[ ${SCM} == "${SCM_P4}" ]] && p4_prompt_info && return + } || true + { + [[ ${SCM} == "${SCM_HG}" ]] && hg_prompt_info && return + } || true + { + [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return + } || true } -function terraform_workspace_prompt { +function terraform_workspace_prompt +{ if _command_exists terraform; then if [ -d .terraform ]; then echo -e "$(terraform workspace show 2> /dev/null)" @@ -208,13 +223,15 @@ function terraform_workspace_prompt { fi } -function active_gcloud_account_prompt { +function active_gcloud_account_prompt +{ if _command_exists gcloud; then echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)" fi } -function git_prompt_minimal_info { +function git_prompt_minimal_info +{ SCM_STATE=${SCM_THEME_PROMPT_CLEAN} _git-hide-status && return @@ -232,7 +249,8 @@ function git_prompt_minimal_info { echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" } -function git_prompt_vars { +function git_prompt_vars +{ if ${SCM_GIT_USE_GITSTATUS} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then # we can use faster gitstatus # use this variable in githelpers and below to choose gitstatus output @@ -310,7 +328,8 @@ function git_prompt_vars { SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo "") } -function p4_prompt_vars { +function p4_prompt_vars +{ IFS=$'\t' read -r \ opened_count non_default_changes default_count \ add_file_count edit_file_count delete_file_count \ @@ -330,7 +349,8 @@ function p4_prompt_vars { SCM_SUFFIX=${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} } -function svn_prompt_vars { +function svn_prompt_vars +{ if [[ -n $(svn status | head -c1 2> /dev/null) ]]; then SCM_DIRTY=1 SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} @@ -351,7 +371,8 @@ function svn_prompt_vars { # - lets say we cd into ~/Projects/Foo/Bar # - .hg is located in ~/Projects/Foo/.hg # - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo -function get_hg_root { +function get_hg_root +{ local CURRENT_DIR="${PWD}" while [[ "${CURRENT_DIR:-/}" != "/" ]]; do @@ -364,7 +385,8 @@ function get_hg_root { done } -function hg_prompt_vars { +function hg_prompt_vars +{ if [[ -n $(hg status 2> /dev/null) ]]; then SCM_DIRTY=1 SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} @@ -394,7 +416,8 @@ function hg_prompt_vars { fi } -function nvm_version_prompt { +function nvm_version_prompt +{ local node if _is_function nvm; then node=$(nvm current 2> /dev/null) @@ -403,11 +426,13 @@ function nvm_version_prompt { fi } -function node_version_prompt { +function node_version_prompt +{ echo -e "$(nvm_version_prompt)" } -function rvm_version_prompt { +function rvm_version_prompt +{ if which rvm &> /dev/null; then rvm=$(rvm-prompt) || return if [ -n "$rvm" ]; then @@ -416,7 +441,8 @@ function rvm_version_prompt { fi } -function rbenv_version_prompt { +function rbenv_version_prompt +{ if which rbenv &> /dev/null; then rbenv=$(rbenv version-name) || return rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}" @@ -426,13 +452,15 @@ function rbenv_version_prompt { fi } -function rbfu_version_prompt { +function rbfu_version_prompt +{ if [[ $RBFU_RUBY_VERSION ]]; then echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}" fi } -function chruby_version_prompt { +function chruby_version_prompt +{ if _is_function chruby; then if _is_function chruby_auto; then chruby_auto @@ -447,43 +475,51 @@ function chruby_version_prompt { fi } -function ruby_version_prompt { +function ruby_version_prompt +{ if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)" fi } -function k8s_context_prompt { +function k8s_context_prompt +{ echo -e "$(kubectl config current-context 2> /dev/null)" } -function k8s_namespace_prompt { +function k8s_namespace_prompt +{ echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)" } -function virtualenv_prompt { +function virtualenv_prompt +{ if [[ -n "$VIRTUAL_ENV" ]]; then virtualenv=$(basename "$VIRTUAL_ENV") echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" fi } -function condaenv_prompt { +function condaenv_prompt +{ if [[ $CONDA_DEFAULT_ENV ]]; then echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}" fi } -function py_interp_prompt { +function py_interp_prompt +{ py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}" } -function python_version_prompt { +function python_version_prompt +{ echo -e "$(virtualenv_prompt)$(condaenv_prompt)$(py_interp_prompt)" } -function git_user_info { +function git_user_info +{ # support two or more initials, set by 'git pair' plugin SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%') # if `user.initials` weren't set, attempt to extract initials from `user.name` @@ -491,7 +527,8 @@ function git_user_info { [[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX" } -function clock_char { +function clock_char +{ CLOCK_CHAR=${THEME_CLOCK_CHAR:-"⌚"} CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"} SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"} @@ -501,7 +538,8 @@ function clock_char { fi } -function clock_prompt { +function clock_prompt +{ CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"} CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"} [ -z "$THEME_SHOW_CLOCK" ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"} @@ -513,44 +551,52 @@ function clock_prompt { fi } -function user_host_prompt { +function user_host_prompt +{ if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}" fi } # backwards-compatibility -function git_prompt_info { +function git_prompt_info +{ _git-hide-status && return git_prompt_vars echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" } -function p4_prompt_info() { +function p4_prompt_info() +{ p4_prompt_vars echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}" } -function svn_prompt_info { +function svn_prompt_info +{ svn_prompt_vars echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" } -function hg_prompt_info() { +function hg_prompt_info() +{ hg_prompt_vars echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}" } -function scm_char { +function scm_char +{ scm_prompt_char echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" } -function prompt_char { +function prompt_char +{ scm_char } -function battery_char { +function battery_char +{ if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then echo -e "${bold_red:-}$(battery_percentage)%" fi @@ -558,7 +604,8 @@ function battery_char { if ! _command_exists battery_charge; then # if user has installed battery plugin, skip this... - function battery_charge() { + function battery_charge() + { # no op echo -n } @@ -567,13 +614,15 @@ fi # The battery_char function depends on the presence of the battery_percentage function. # If battery_percentage is not defined, then define battery_char as a no-op. if ! _command_exists battery_percentage; then - function battery_char() { + function battery_char() + { # no op echo -n } fi -function aws_profile { +function aws_profile +{ if [[ $AWS_DEFAULT_PROFILE ]]; then echo -e "${AWS_DEFAULT_PROFILE}" else @@ -581,7 +630,8 @@ function aws_profile { fi } -function __check_precmd_conflict() { +function __check_precmd_conflict() +{ local f for f in "${precmd_functions[@]}"; do if [[ "${f}" == "${1}" ]]; then @@ -591,7 +641,8 @@ function __check_precmd_conflict() { return 1 } -function safe_append_prompt_command { +function safe_append_prompt_command +{ local prompt_re if [ "${__bp_imported:-missing}" == "defined" ]; then @@ -619,7 +670,8 @@ function safe_append_prompt_command { fi } -function _save-and-reload-history() { +function _save-and-reload-history() +{ local autosave=${1:-0} [[ $autosave -eq 1 ]] && history -a && history -c && history -r } diff --git a/themes/binaryanomaly/binaryanomaly.theme.bash b/themes/binaryanomaly/binaryanomaly.theme.bash index c4488c4c..e5b02f0c 100644 --- a/themes/binaryanomaly/binaryanomaly.theme.bash +++ b/themes/binaryanomaly/binaryanomaly.theme.bash @@ -3,7 +3,8 @@ # shellcheck disable=SC2154 #TODO: fix these all. # Detect whether a reboot is required -function show_reboot_required() { +function show_reboot_required() +{ if [ -n "$_bf_prompt_reboot_info" ]; then if [ -f /var/run/reboot-required ]; then printf "Reboot required!" @@ -12,7 +13,8 @@ function show_reboot_required() { } # Set different host color for local and remote sessions -function set_host_color() { +function set_host_color() +{ # Detect if connection is through SSH if [[ -n $SSH_CLIENT ]]; then printf '%s' "${lime_yellow}" @@ -22,7 +24,8 @@ function set_host_color() { } # Set different username color for users and root -function set_user_color() { +function set_user_color() +{ case $(id -u) in 0) printf '%s' "${red}" @@ -36,7 +39,8 @@ function set_user_color() { # 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 -function set_custom_colors() { +function set_custom_colors() +{ dark_grey="\[$(tput setaf 8)\]" light_grey="\[$(tput setaf 248)\]" @@ -47,11 +51,13 @@ function set_custom_colors() { powder_blue="\[$(tput setaf 153)\]" } -__ps_time() { +__ps_time() +{ printf '%s' "$(clock_prompt)${normal}\n" } -function prompt_command() { +function prompt_command() +{ ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n" ps_username="$(set_user_color)\u${normal}" diff --git a/themes/bira/bira.theme.bash b/themes/bira/bira.theme.bash index 7db03000..75957ac6 100644 --- a/themes/bira/bira.theme.bash +++ b/themes/bira/bira.theme.bash @@ -16,7 +16,8 @@ else user_host="${bold_green}\u@\h${normal}${reset_color}" fi -function prompt_command() { +function prompt_command() +{ local current_dir=" ${bold_blue}\w${normal}${reset_color}" PS1="╭─${user_host}${current_dir}$(virtualenv_prompt)$(scm_prompt_info)\n╰─${bold}\\$ ${normal}" } diff --git a/themes/bobby-python/bobby-python.theme.bash b/themes/bobby-python/bobby-python.theme.bash index ebb3eab0..69c828a9 100644 --- a/themes/bobby-python/bobby-python.theme.bash +++ b/themes/bobby-python/bobby-python.theme.bash @@ -14,7 +14,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|" CONDAENV_THEME_PROMPT_SUFFIX="|" -function prompt_command() { +function prompt_command() +{ PS1="\n${yellow}$(python_version_prompt) " # Name of virtual env followed by python version PS1+="${purple}\h " PS1+="${reset_color}in " diff --git a/themes/bobby/bobby.theme.bash b/themes/bobby/bobby.theme.bash index 98d2cd8d..bff30f86 100644 --- a/themes/bobby/bobby.theme.bash +++ b/themes/bobby/bobby.theme.bash @@ -15,7 +15,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|" RVM_THEME_PROMPT_PREFIX="|" RVM_THEME_PROMPT_SUFFIX="|" -__bobby_clock() { +__bobby_clock() +{ printf '%s' "$(clock_prompt) " if [ "${THEME_SHOW_CLOCK_CHAR}" == "true" ]; then @@ -23,7 +24,8 @@ __bobby_clock() { fi } -function prompt_command() { +function prompt_command() +{ PS1="\n$(battery_char) $(__bobby_clock)" PS1+="${yellow}$(ruby_version_prompt) " PS1+="${purple}\h " diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index e1c36175..b107c59a 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -9,7 +9,8 @@ ## Parsers ## ############# -____brainy_top_left_parse() { +____brainy_top_left_parse() +{ ifs_old="${IFS}" IFS="|" read -r -a args <<< "$@" @@ -24,7 +25,8 @@ ____brainy_top_left_parse() { _TOP_LEFT+=" " } -____brainy_top_right_parse() { +____brainy_top_right_parse() +{ ifs_old="${IFS}" IFS="|" read -r -a args <<< "$@" @@ -41,7 +43,8 @@ ____brainy_top_right_parse() { ((__SEG_AT_RIGHT += 1)) } -____brainy_bottom_parse() { +____brainy_bottom_parse() +{ ifs_old="${IFS}" IFS="|" read -r -a args <<< "$@" @@ -50,7 +53,8 @@ ____brainy_bottom_parse() { [ ${#args[1]} -gt 0 ] && _BOTTOM+=" " } -____brainy_top() { +____brainy_top() +{ _TOP_LEFT="" _TOP_RIGHT="" __TOP_RIGHT_LEN=0 @@ -76,7 +80,8 @@ ____brainy_top() { printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}" } -____brainy_bottom() { +____brainy_bottom() +{ _BOTTOM="" for seg in $___BRAINY_BOTTOM; do info="$(___brainy_prompt_"${seg}")" @@ -89,7 +94,8 @@ ____brainy_bottom() { ## Segments ## ############## -___brainy_prompt_user_info() { +___brainy_prompt_user_info() +{ color=$bold_blue if [ "${THEME_SHOW_SUDO}" == "true" ]; then if sudo -vn 1> /dev/null 2>&1; then @@ -105,14 +111,16 @@ ___brainy_prompt_user_info() { fi } -___brainy_prompt_dir() { +___brainy_prompt_dir() +{ color=$bold_yellow box="[|]" info="\w" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___brainy_prompt_scm() { +___brainy_prompt_scm() +{ [ "${THEME_SHOW_SCM}" != "true" ] && return color=$bold_green box="$(scm_char) " @@ -120,7 +128,8 @@ ___brainy_prompt_scm() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___brainy_prompt_python() { +___brainy_prompt_python() +{ [ "${THEME_SHOW_PYTHON}" != "true" ] && return color=$bold_yellow box="[|]" @@ -128,7 +137,8 @@ ___brainy_prompt_python() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}" } -___brainy_prompt_ruby() { +___brainy_prompt_ruby() +{ [ "${THEME_SHOW_RUBY}" != "true" ] && return color=$bold_white box="[|]" @@ -136,16 +146,18 @@ ___brainy_prompt_ruby() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}" } -___brainy_prompt_todo() { - [ "${THEME_SHOW_TODO}" != "true" ] \ - || [ -z "$(which todo.sh)" ] && return +___brainy_prompt_todo() +{ + [ "${THEME_SHOW_TODO}" != "true" ] || + [ -z "$(which todo.sh)" ] && return color=$bold_white box="[|]" info="t:$(todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }')" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}" } -___brainy_prompt_clock() { +___brainy_prompt_clock() +{ [ "${THEME_SHOW_CLOCK}" != "true" ] && return color=$THEME_CLOCK_COLOR box="[|]" @@ -153,10 +165,11 @@ ___brainy_prompt_clock() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_purple}" "${box}" } -___brainy_prompt_battery() { - ! _command_exists battery_percentage \ - || [ "${THEME_SHOW_BATTERY}" != "true" ] \ - || [ "$(battery_percentage)" = "no" ] && return +___brainy_prompt_battery() +{ + ! _command_exists battery_percentage || + [ "${THEME_SHOW_BATTERY}" != "true" ] || + [ "$(battery_percentage)" = "no" ] && return info=$(battery_percentage) color=$bold_green @@ -173,13 +186,15 @@ ___brainy_prompt_battery() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___brainy_prompt_exitcode() { +___brainy_prompt_exitcode() +{ [ "${THEME_SHOW_EXITCODE}" != "true" ] && return color=$bold_purple [ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}" } -___brainy_prompt_char() { +___brainy_prompt_char() +{ color=$bold_white prompt_char="${__BRAINY_PROMPT_CHAR_PS1}" printf "%s|%s" "${color}" "${prompt_char}" @@ -189,19 +204,22 @@ ___brainy_prompt_char() { ## cli ## ######### -__brainy_show() { +__brainy_show() +{ typeset _seg=${1:-} shift export "THEME_SHOW_${_seg}"=true } -__brainy_hide() { +__brainy_hide() +{ typeset _seg=${1:-} shift export "THEME_SHOW_${_seg}"=false } -_brainy_completion() { +_brainy_completion() +{ local cur _action actions segments COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" @@ -221,7 +239,8 @@ _brainy_completion() { return 0 } -brainy() { +brainy() +{ typeset action=${1:-} shift typeset segs=${*:-} @@ -284,16 +303,19 @@ ___BRAINY_BOTTOM=${___BRAINY_BOTTOM:-"exitcode char"} ## Prompt ## ############ -__brainy_ps1() { +__brainy_ps1() +{ printf "%s%s%s" "$(____brainy_top)" "$(____brainy_bottom)" "${normal}" } -__brainy_ps2() { +__brainy_ps2() +{ color=$bold_white printf "%s%s%s" "${color}" "${__BRAINY_PROMPT_CHAR_PS2} " "${normal}" } -_brainy_prompt() { +_brainy_prompt() +{ exitcode="$?" PS1="$(__brainy_ps1)" diff --git a/themes/brunton/brunton.theme.bash b/themes/brunton/brunton.theme.bash index 166fcc84..ef62ed50 100644 --- a/themes/brunton/brunton.theme.bash +++ b/themes/brunton/brunton.theme.bash @@ -11,13 +11,15 @@ SCM_GIT_CHAR="${bold_green}±${normal}" SCM_SVN_CHAR="${bold_cyan}⑆${normal}" SCM_HG_CHAR="${bold_red}☿${normal}" -is_vim_shell() { +is_vim_shell() +{ if [ -n "$VIMRUNTIME" ]; then echo "[${cyan}vim shell${normal}]" fi } -prompt() { +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/candy/candy.theme.bash b/themes/candy/candy.theme.bash index 7753e934..32152b79 100644 --- a/themes/candy/candy.theme.bash +++ b/themes/candy/candy.theme.bash @@ -2,7 +2,8 @@ # shellcheck disable=SC2034 # Expected behavior for themes. # shellcheck disable=SC2154 #TODO: fix these all. -function prompt_command() { +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/command_duration.theme.bash b/themes/command_duration.theme.bash index cf91785c..c5bc712d 100644 --- a/themes/command_duration.theme.bash +++ b/themes/command_duration.theme.bash @@ -1,7 +1,8 @@ # shellcheck shell=bash if [ -z "$BASH_IT_COMMAND_DURATION" ] || [ "$BASH_IT_COMMAND_DURATION" != true ]; then - _command_duration() { + _command_duration() + { echo -n } return @@ -16,17 +17,20 @@ COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'} trap _command_duration_delete_temp_file EXIT HUP INT TERM -_command_duration_delete_temp_file() { +_command_duration_delete_temp_file() +{ if [[ -f "$COMMAND_DURATION_FILE" ]]; then rm -f "$COMMAND_DURATION_FILE" fi } -_command_duration_pre_exec() { +_command_duration_pre_exec() +{ date +%s.%1N > "$COMMAND_DURATION_FILE" } -_command_duration() { +_command_duration() +{ local command_duration command_start current_time local minutes seconds deciseconds local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds diff --git a/themes/easy/easy.theme.bash b/themes/easy/easy.theme.bash index 7e2e3389..c47c9ce7 100644 --- a/themes/easy/easy.theme.bash +++ b/themes/easy/easy.theme.bash @@ -7,7 +7,8 @@ SCM_THEME_PROMPT_SUFFIX="${bold_green} ] " SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" -prompt_command() { +prompt_command() +{ if [ "$(whoami)" = root ]; then cursor_color="${bold_red}" user_color="${green}" diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index ba089392..6b19e6d7 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -1,99 +1,114 @@ #!/usr/bin/env bash -function _git-symbolic-ref { - git symbolic-ref -q HEAD 2> /dev/null +function _git-symbolic-ref +{ + git symbolic-ref -q HEAD 2> /dev/null } # When on a branch, this is often the same as _git-commit-description, # but this can be different when two branches are pointing to the # same commit. _git-branch is used to explicitly choose the checked-out # branch. -function _git-branch { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - test -n "${VCS_STATUS_LOCAL_BRANCH}" && echo "${VCS_STATUS_LOCAL_BRANCH}" || return 1 - else - git symbolic-ref -q --short HEAD 2> /dev/null || return 1 - fi +function _git-branch +{ + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then + test -n "${VCS_STATUS_LOCAL_BRANCH}" && echo "${VCS_STATUS_LOCAL_BRANCH}" || return 1 + else + git symbolic-ref -q --short HEAD 2> /dev/null || return 1 + fi } -function _git-tag { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - test -n "${VCS_STATUS_TAG}" && echo "${VCS_STATUS_TAG}" - else - git describe --tags --exact-match 2> /dev/null - fi +function _git-tag +{ + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then + test -n "${VCS_STATUS_TAG}" && echo "${VCS_STATUS_TAG}" + else + git describe --tags --exact-match 2> /dev/null + fi } -function _git-commit-description { - git describe --contains --all 2> /dev/null +function _git-commit-description +{ + git describe --contains --all 2> /dev/null } -function _git-short-sha { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - echo ${VCS_STATUS_COMMIT:0:7} - else - git rev-parse --short HEAD - fi +function _git-short-sha +{ + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then + echo ${VCS_STATUS_COMMIT:0:7} + else + git rev-parse --short HEAD + fi } # Try the checked-out branch first to avoid collision with branches pointing to the same ref. -function _git-friendly-ref { - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - _git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatus - else - _git-branch || _git-tag || _git-commit-description || _git-short-sha - fi +function _git-friendly-ref +{ + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then + _git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatus + else + _git-branch || _git-tag || _git-commit-description || _git-short-sha + fi } -function _git-num-remotes { - git remote | wc -l +function _git-num-remotes +{ + git remote | wc -l } -function _git-upstream { - local ref - ref="$(_git-symbolic-ref)" || return 1 - git for-each-ref --format="%(upstream:short)" "${ref}" +function _git-upstream +{ + local ref + ref="$(_git-symbolic-ref)" || return 1 + git for-each-ref --format="%(upstream:short)" "${ref}" } -function _git-upstream-remote { - local upstream - upstream="$(_git-upstream)" || return 1 +function _git-upstream-remote +{ + local upstream + upstream="$(_git-upstream)" || return 1 - local branch - branch="$(_git-upstream-branch)" || return 1 - echo "${upstream%"/${branch}"}" + local branch + branch="$(_git-upstream-branch)" || return 1 + echo "${upstream%"/${branch}"}" } -function _git-upstream-branch { - local ref - ref="$(_git-symbolic-ref)" || return 1 +function _git-upstream-branch +{ + local ref + ref="$(_git-symbolic-ref)" || return 1 - # git versions < 2.13.0 do not support "strip" for upstream format - # regex replacement gives the wrong result for any remotes with slashes in the name, - # so only use when the strip format fails. - git for-each-ref --format="%(upstream:strip=3)" "${ref}" 2> /dev/null || git for-each-ref --format="%(upstream)" "${ref}" | sed -e "s/.*\/.*\/.*\///" + # git versions < 2.13.0 do not support "strip" for upstream format + # regex replacement gives the wrong result for any remotes with slashes in the name, + # so only use when the strip format fails. + git for-each-ref --format="%(upstream:strip=3)" "${ref}" 2> /dev/null || git for-each-ref --format="%(upstream)" "${ref}" | sed -e "s/.*\/.*\/.*\///" } -function _git-upstream-behind-ahead { - git rev-list --left-right --count "$(_git-upstream)...HEAD" 2> /dev/null +function _git-upstream-behind-ahead +{ + git rev-list --left-right --count "$(_git-upstream)...HEAD" 2> /dev/null } -function _git-upstream-branch-gone { - [[ "$(git status -s -b | sed -e 's/.* //')" == "[gone]" ]] +function _git-upstream-branch-gone +{ + [[ "$(git status -s -b | sed -e 's/.* //')" == "[gone]" ]] } -function _git-hide-status { - [[ "$(git config --get bash-it.hide-status)" == "1" ]] +function _git-hide-status +{ + [[ "$(git config --get bash-it.hide-status)" == "1" ]] } -function _git-status { - local git_status_flags= - [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true - git status --porcelain ${git_status_flags} 2> /dev/null +function _git-status +{ + local git_status_flags= + [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true + git status --porcelain ${git_status_flags} 2> /dev/null } -function _git-status-counts { - _git-status | awk ' +function _git-status-counts +{ + _git-status | awk ' BEGIN { untracked=0; unstaged=0; @@ -116,60 +131,62 @@ function _git-status-counts { }' } -function _git-remote-info { +function _git-remote-info +{ - # prompt handling only, reimplement because patching the routine below gets ugly - if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - [[ "${VCS_STATUS_REMOTE_NAME}" == "" ]] && return - [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && local same_branch_name=true - local same_branch_name= - [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && same_branch_name=true - # no multiple remote support in gitstatusd - if [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" || "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]]; then - if [[ "${same_branch_name}" != "true" ]]; then - remote_info="${VCS_STATUS_REMOTE_NAME}/${VCS_STATUS_REMOTE_BRANCH}" - else - remote_info="${VCS_STATUS_REMOTE_NAME}" - fi - elif [[ ${same_branch_name} != "true" ]]; then - remote_info="${VCS_STATUS_REMOTE_BRANCH}" - fi - if [[ -n "${remote_info}" ]];then - # no support for gone remote branches in gitstatusd - local branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" - echo "${branch_prefix}${remote_info}" - fi - else - [[ "$(_git-upstream)" == "" ]] && return + # prompt handling only, reimplement because patching the routine below gets ugly + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then + [[ "${VCS_STATUS_REMOTE_NAME}" == "" ]] && return + [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && local same_branch_name=true + local same_branch_name= + [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && same_branch_name=true + # no multiple remote support in gitstatusd + if [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" || "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]]; then + if [[ "${same_branch_name}" != "true" ]]; then + remote_info="${VCS_STATUS_REMOTE_NAME}/${VCS_STATUS_REMOTE_BRANCH}" + else + remote_info="${VCS_STATUS_REMOTE_NAME}" + fi + elif [[ ${same_branch_name} != "true" ]]; then + remote_info="${VCS_STATUS_REMOTE_BRANCH}" + fi + if [[ -n "${remote_info}" ]]; then + # no support for gone remote branches in gitstatusd + local branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" + echo "${branch_prefix}${remote_info}" + fi + else + [[ "$(_git-upstream)" == "" ]] && return - [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true - local same_branch_name= - [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true - if [[ ("${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" && "$(_git-num-remotes)" -ge 2) || - "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then - if [[ "${same_branch_name}" != "true" ]]; then - remote_info="\$(_git-upstream)" - else - remote_info="$(_git-upstream-remote)" - fi - elif [[ ${same_branch_name} != "true" ]]; then - remote_info="\$(_git-upstream-branch)" - fi - if [[ -n "${remote_info}" ]];then - local branch_prefix - if _git-upstream-branch-gone; then - branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}" - else - branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" - fi - echo "${branch_prefix}${remote_info}" - fi - fi + [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true + local same_branch_name= + [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true + if [[ ("${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" && "$(_git-num-remotes)" -ge 2) || + "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then + if [[ "${same_branch_name}" != "true" ]]; then + remote_info="\$(_git-upstream)" + else + remote_info="$(_git-upstream-remote)" + fi + elif [[ ${same_branch_name} != "true" ]]; then + remote_info="\$(_git-upstream-branch)" + fi + if [[ -n "${remote_info}" ]]; then + local branch_prefix + if _git-upstream-branch-gone; then + branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}" + else + branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" + fi + echo "${branch_prefix}${remote_info}" + fi + fi } # Unused by bash-it, present for API compatibility -function git_status_summary { - awk ' +function git_status_summary +{ + awk ' BEGIN { untracked=0; unstaged=0; diff --git a/themes/modern/modern.theme.bash b/themes/modern/modern.theme.bash index eadb0762..ca9fc6e2 100644 --- a/themes/modern/modern.theme.bash +++ b/themes/modern/modern.theme.bash @@ -22,13 +22,15 @@ esac PS3=">> " -is_vim_shell() { +is_vim_shell() +{ if [ -n "$VIMRUNTIME" ]; then echo "[${cyan}vim shell${normal}]" fi } -detect_venv() { +detect_venv() +{ python_venv="" # Detect python venv if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then @@ -38,7 +40,8 @@ detect_venv() { fi } -prompt() { +prompt() +{ SCM_PROMPT_FORMAT='[%s][%s]' retval=$? if [[ retval -ne 0 ]]; then diff --git a/themes/p4helpers.theme.bash b/themes/p4helpers.theme.bash index 27a777ac..df36a904 100644 --- a/themes/p4helpers.theme.bash +++ b/themes/p4helpers.theme.bash @@ -1,18 +1,20 @@ #!/usr/bin/env bash -function _p4-opened { - timeout 2.0s p4 opened -s 2> /dev/null +function _p4-opened +{ + timeout 2.0s p4 opened -s 2> /dev/null } -function _p4-opened-counts { - # Return the following counts seperated by tabs: - # - count of opened files - # - count of pending changesets (other than defaults) - # - count of files in the default changeset - # - count of opened files in add mode - # - count of opened files in edit mode - # - count of opened files in delete mode - _p4-opened | awk ' +function _p4-opened-counts +{ + # Return the following counts seperated by tabs: + # - count of opened files + # - count of pending changesets (other than defaults) + # - count of files in the default changeset + # - count of opened files in add mode + # - count of opened files in edit mode + # - count of opened files in delete mode + _p4-opened | awk ' BEGIN { opened=0; type_array["edit"]=0; diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 7da15cfd..09257cad 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -5,7 +5,8 @@ # Define this here so it can be used by all of the Powerline themes THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} -function set_color() { +function set_color() +{ set +u if [[ "${1}" != "-" ]]; then fg="38;5;${1}" @@ -17,7 +18,8 @@ function set_color() { echo -e "\[\033[${fg}${bg}m\]" } -function __powerline_user_info_prompt() { +function __powerline_user_info_prompt() +{ local user_info="" local color=${USER_INFO_THEME_PROMPT_COLOR} @@ -43,7 +45,8 @@ function __powerline_user_info_prompt() { [[ -n "${user_info}" ]] && echo "${user_info}|${color}" } -function __powerline_terraform_prompt() { +function __powerline_terraform_prompt() +{ local terraform_workspace="" if [ -d .terraform ]; then @@ -52,21 +55,24 @@ function __powerline_terraform_prompt() { fi } -function __powerline_gcloud_prompt() { +function __powerline_gcloud_prompt() +{ local active_gcloud_account="" active_gcloud_account="$(active_gcloud_account_prompt)" [[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR}" } -function __powerline_node_prompt() { +function __powerline_node_prompt() +{ local node_version="" node_version="$(node_version_prompt)" [[ -n "${node_version}" ]] && echo "${NODE_CHAR}${node_version}|${NODE_THEME_PROMPT_COLOR}" } -function __powerline_ruby_prompt() { +function __powerline_ruby_prompt() +{ local ruby_version="" if _command_exists rvm; then @@ -78,7 +84,8 @@ function __powerline_ruby_prompt() { [[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}" } -function __powerline_k8s_context_prompt() { +function __powerline_k8s_context_prompt() +{ local kubernetes_context="" if _command_exists kubectl; then @@ -88,7 +95,8 @@ 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() { +function __powerline_k8s_namespace_prompt() +{ local kubernetes_namespace="" if _command_exists kubectl; then @@ -98,7 +106,8 @@ function __powerline_k8s_namespace_prompt() { [[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR}" } -function __powerline_python_venv_prompt() { +function __powerline_python_venv_prompt() +{ set +u local python_venv="" @@ -112,7 +121,8 @@ function __powerline_python_venv_prompt() { [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}" } -function __powerline_scm_prompt() { +function __powerline_scm_prompt() +{ local color="" local scm_prompt="" @@ -141,23 +151,28 @@ function __powerline_scm_prompt() { fi } -function __powerline_cwd_prompt() { +function __powerline_cwd_prompt() +{ echo "\w|${CWD_THEME_PROMPT_COLOR}" } -function __powerline_hostname_prompt() { +function __powerline_hostname_prompt() +{ echo "${SHORT_HOSTNAME:-$(hostname -s)}|${HOST_THEME_PROMPT_COLOR}" } -function __powerline_wd_prompt() { +function __powerline_wd_prompt() +{ echo "\W|${CWD_THEME_PROMPT_COLOR}" } -function __powerline_clock_prompt() { +function __powerline_clock_prompt() +{ echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}" } -function __powerline_battery_prompt() { +function __powerline_battery_prompt() +{ local color="" battery_status battery_status="$(battery_percentage 2> /dev/null)" @@ -176,25 +191,29 @@ function __powerline_battery_prompt() { fi } -function __powerline_in_vim_prompt() { +function __powerline_in_vim_prompt() +{ if [[ -n "$VIMRUNTIME" ]]; then echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}" fi } -function __powerline_aws_profile_prompt() { +function __powerline_aws_profile_prompt() +{ if [[ -n "${AWS_PROFILE}" ]]; then echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}" fi } -function __powerline_in_toolbox_prompt() { +function __powerline_in_toolbox_prompt() +{ if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}" fi } -function __powerline_shlvl_prompt() { +function __powerline_shlvl_prompt() +{ if [[ "${SHLVL}" -gt 1 ]]; then local prompt="${SHLVL_THEME_PROMPT_CHAR}" local level=$((SHLVL - 1)) @@ -202,7 +221,8 @@ function __powerline_shlvl_prompt() { fi } -function __powerline_dirstack_prompt() { +function __powerline_dirstack_prompt() +{ if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then local depth=$((${#DIRSTACK[@]} - 1)) local prompt="${DIRSTACK_THEME_PROMPT_CHAR}" @@ -213,21 +233,25 @@ function __powerline_dirstack_prompt() { fi } -function __powerline_history_number_prompt() { +function __powerline_history_number_prompt() +{ echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR}" } -function __powerline_command_number_prompt() { +function __powerline_command_number_prompt() +{ echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}" } -function __powerline_duration_prompt() { +function __powerline_duration_prompt() +{ local duration duration=$(_command_duration) [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}" } -function __powerline_left_segment() { +function __powerline_left_segment() +{ local params IFS="|" read -ra params <<< "${1}" local pad_before_segment=" " @@ -257,15 +281,18 @@ function __powerline_left_segment() { ((SEGMENTS_AT_LEFT += 1)) } -function __powerline_left_last_segment_padding() { +function __powerline_left_last_segment_padding() +{ LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}" } -function __powerline_last_status_prompt() { +function __powerline_last_status_prompt() +{ [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}" } -function __powerline_prompt_command() { +function __powerline_prompt_command() +{ local last_status="$?" ## always the first local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash index 99476f4a..21398245 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -20,7 +20,8 @@ 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:' -pure_prompt() { +pure_prompt() +{ ps_host="${bold_blue}\h${normal}" ps_user="${green}\u${normal}" ps_user_mark="${green} $ ${normal}" diff --git a/themes/purity/purity.theme.bash b/themes/purity/purity.theme.bash index 22a3fbfb..38664935 100644 --- a/themes/purity/purity.theme.bash +++ b/themes/purity/purity.theme.bash @@ -16,7 +16,8 @@ STATUS_THEME_PROMPT_BAD="${bold_red}❯${reset_color}${normal} " STATUS_THEME_PROMPT_OK="${bold_green}❯${reset_color}${normal} " PURITY_THEME_PROMPT_COLOR="${PURITY_THEME_PROMPT_COLOR:=$blue}" -venv_prompt() { +venv_prompt() +{ python_venv="" # Detect python venv if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then @@ -27,7 +28,8 @@ venv_prompt() { [[ -n "${python_venv}" ]] && echo "${python_venv}" } -function prompt_command() { +function prompt_command() +{ 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)" diff --git a/uninstall.sh b/uninstall.sh index 17712610..19542732 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,31 +1,30 @@ #!/usr/bin/env bash -if [ -z "$BASH_IT" ]; -then - BASH_IT="$HOME/.bash_it" +if [ -z "$BASH_IT" ]; then + BASH_IT="$HOME/.bash_it" fi case $OSTYPE in - darwin*) - CONFIG_FILE=.bash_profile - ;; - *) - CONFIG_FILE=.bashrc - ;; + darwin*) + CONFIG_FILE=.bash_profile + ;; + *) + CONFIG_FILE=.bashrc + ;; esac BACKUP_FILE=$CONFIG_FILE.bak if [ ! -e "$HOME/$BACKUP_FILE" ]; then - echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2 + echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2 - test -w "$HOME/$CONFIG_FILE" && - mv "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.uninstall" && - echo -e "\033[0;32mMoved your $HOME/$CONFIG_FILE to $HOME/$CONFIG_FILE.uninstall.\033[0m" + test -w "$HOME/$CONFIG_FILE" && + mv "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.uninstall" && + echo -e "\033[0;32mMoved your $HOME/$CONFIG_FILE to $HOME/$CONFIG_FILE.uninstall.\033[0m" else - test -w "$HOME/$BACKUP_FILE" && - cp -a "$HOME/$BACKUP_FILE" "$HOME/$CONFIG_FILE" && - rm "$HOME/$BACKUP_FILE" && - echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" + test -w "$HOME/$BACKUP_FILE" && + cp -a "$HOME/$BACKUP_FILE" "$HOME/$CONFIG_FILE" && + rm "$HOME/$BACKUP_FILE" && + echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" fi echo ""