From b9e15351e1c40387fab55e720ebac7d017a6074a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 4 Jan 2022 14:22:03 -0800 Subject: [PATCH] plugins: clear and consistent log messages --- clean_files.txt | 7 +++ plugins/available/cht-sh.plugin.bash | 38 ++++++------ plugins/available/direnv.plugin.bash | 9 ++- plugins/available/fasd.plugin.bash | 9 ++- plugins/available/fzf.plugin.bash | 59 ++++++++++--------- plugins/available/go.plugin.bash | 10 ++-- plugins/available/goenv.plugin.bash | 23 ++++---- plugins/available/hub.plugin.bash | 7 ++- plugins/available/jenv.plugin.bash | 23 ++++---- plugins/available/less-pretty-cat.plugin.bash | 6 +- plugins/available/node.plugin.bash | 8 ++- plugins/available/nodenv.plugin.bash | 14 +++-- plugins/available/nvm.plugin.bash | 39 +++++------- plugins/available/percol.plugin.bash | 10 ++-- plugins/available/plenv.plugin.bash | 12 ++-- plugins/available/powerline.plugin.bash | 22 ++++--- plugins/available/pyenv.plugin.bash | 18 +++--- plugins/available/rbenv.plugin.bash | 11 ++-- plugins/available/ruby.plugin.bash | 8 ++- plugins/available/textmate.plugin.bash | 11 ++-- plugins/available/thefuck.plugin.bash | 11 ++-- plugins/available/zoxide.plugin.bash | 8 +-- 22 files changed, 203 insertions(+), 160 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index f4ab4b1969..7a750f7d80 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -91,10 +91,13 @@ plugins/available/autojump.plugin.bash plugins/available/base.plugin.bash plugins/available/basher.plugin.bash plugins/available/blesh.plugin.bash +plugins/available/cht.sh.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/direnv.plugin.bash plugins/available/dirs.plugin.bash plugins/available/docker-machine.plugin.bash +plugins/available/fasd.plugin.bash +plugins/available/fzf.plugin.bash plugins/available/gif.plugin.bash plugins/available/git-subrepo.plugin.bash plugins/available/git.plugin.bash @@ -107,6 +110,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/java.plugin.bash plugins/available/jekyll.plugin.bash +plugins/available/jenv.plugin.bash plugins/available/jump.plugin.bash plugins/available/latex.plugin.bash plugins/available/less-pretty-cat.plugin.bash @@ -114,10 +118,12 @@ plugins/available/man.plugin.bash plugins/available/nginx.plugin.bash plugins/available/node.plugin.bash plugins/available/nodenv.plugin.bash +plugins/available/nvm.plugin.bash plugins/available/osx-timemachine.plugin.bash plugins/available/osx.plugin.bash plugins/available/percol.plugin.bash plugins/available/plenv.plugin.bash +plugins/available/powerline.plugin.bash plugins/available/projects.plugin.bash plugins/available/proxy.plugin.bash plugins/available/pyenv.plugin.bash @@ -125,6 +131,7 @@ plugins/available/python.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash +plugins/available/thefuck.plugin.bash plugins/available/todo.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash diff --git a/plugins/available/cht-sh.plugin.bash b/plugins/available/cht-sh.plugin.bash index 63e3c9b74f..a64453b326 100644 --- a/plugins/available/cht-sh.plugin.bash +++ b/plugins/available/cht-sh.plugin.bash @@ -1,21 +1,25 @@ -cite about-plugin +# shellcheck shell=bash about-plugin 'Simplify `curl cht.sh/` to `cht.sh `' # Play nicely if user already installed cht.sh cli tool -if ! _command_exists cht.sh ; then - function cht.sh () { - about 'Executes a cht.sh curl query using the provided arguments' - param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]' - example '$ cht.sh :help' - example '$ cht.sh :list' - example '$ cht.sh tar' - example '$ cht.sh js "parse json"' - example '$ cht.sh python :learn' - example '$ cht.sh rust :list' - group 'cht-sh' - - # Separate arguments with '/', preserving spaces within them - local query=$(IFS=/ ; echo "$*") - curl "cht.sh/${query}" - } +if _binary_exists cht.sh ; then + _log_warning "You have already installed `cht.sh`, so it's safe to disable this plugin." + return 1 fi + +function cht.sh () { + about 'Executes a cht.sh curl query using the provided arguments' + param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]' + example '$ cht.sh :help' + example '$ cht.sh :list' + example '$ cht.sh tar' + example '$ cht.sh js "parse json"' + example '$ cht.sh python :learn' + example '$ cht.sh rust :list' + group 'cht-sh' + + # Separate arguments with '/', preserving spaces within them + local query + query=$(IFS=/ ; echo "$*") + curl "cht.sh/${query}" +} diff --git a/plugins/available/direnv.plugin.bash b/plugins/available/direnv.plugin.bash index 62788600be..fbbe1c30ec 100644 --- a/plugins/available/direnv.plugin.bash +++ b/plugins/available/direnv.plugin.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'load direnv, if you are using it: https://direnv.net/' -if _command_exists direnv; then - eval "$(direnv hook bash)" +if ! _binary_exists direnv; then + _log_warning "Could not find 'direnv'." + return 1 fi + +# shellcheck disable=SC1090 +source < <(direnv hook bash) diff --git a/plugins/available/fasd.plugin.bash b/plugins/available/fasd.plugin.bash index d507f5185e..9ae6439324 100644 --- a/plugins/available/fasd.plugin.bash +++ b/plugins/available/fasd.plugin.bash @@ -1,6 +1,9 @@ -cite about-plugin +# shellcheck shell=bash about-plugin 'load fasd, if you are using it' -_command_exists fasd || return +if ! _binary_exists fasd; then + _log_warning "Unable to locage 'fasd'." +fi -eval "$(fasd --init auto)" +# shellcheck disable=SC1090 +source < <(fasd --init auto) diff --git a/plugins/available/fzf.plugin.bash b/plugins/available/fzf.plugin.bash index 21182ac24f..99a4870780 100644 --- a/plugins/available/fzf.plugin.bash +++ b/plugins/available/fzf.plugin.bash @@ -1,42 +1,43 @@ -# Load after the system completion to make sure that the fzf completions are working -# BASH_IT_LOAD_PRIORITY: 375 - -cite about-plugin +# shellcheck shell=bash about-plugin 'load fzf, if you are using it' -if [ -r ~/.fzf.bash ] ; then - source ~/.fzf.bash -elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ] ; then - source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash +# shellcheck source-path=$HOME source-path=$HOME/.config/fzf disable=SC1090 disable=SC1091 +if [[ -r ~/.fzf.bash ]]; then + source ~/.fzf.bash +elif [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf.bash" ]]; then + source "${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf.bash" fi # No need to continue if the command is not present -_command_exists fzf || return +if ! _binary_exists fzf; then + _log_warning "${BASH_SOURCE[0]##*/}: unable to initialize without '$_' installed." + return 1 +fi -if [ -z ${FZF_DEFAULT_COMMAND+x} ] && _command_exists fd ; then - export FZF_DEFAULT_COMMAND='fd --type f' +if [[ -z ${FZF_DEFAULT_COMMAND+x} ]] && _command_exists fd; then + export FZF_DEFAULT_COMMAND='fd --type f' fi -fe() { - about "Open the selected file in the default editor" - group "fzf" - param "1: Search term" - example "fe foo" +function fe() { + about "Open the selected file in the default editor" + group "fzf" + param "1: Search term" + example "fe foo" - local IFS=$'\n' - local files - files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) - [[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}" + local IFS=$'\n' + local files + IFS=$'\n' read -ra files < <(fzf-tmux --query="$1" --multi --select-1 --exit-0) + [[ -n "${files[*]}" ]] && "${EDITOR:-${ALTERNATE_EDITOR:-nano}}" "${files[@]}" } -fcd() { - about "cd to the selected directory" - group "fzf" - param "1: Directory to browse, or . if omitted" - example "fcd aliases" +function fcd() { + about "cd to the selected directory" + group "fzf" + param "1: Directory to browse, or . if omitted" + example "fcd aliases" - local dir - dir=$(find ${1:-.} -path '*/\.*' -prune \ - -o -type d -print 2> /dev/null | fzf +m) && - cd "$dir" + local dir + dir=$(find "${1:-.}" -path '*/\.*' -prune \ + -o -type d -print 2> /dev/null | fzf +m) \ + && cd "$dir" || return } diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 5592a006a7..73ee0e425b 100644 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'go environment variables & path configuration' # Load after basher and goenv @@ -7,7 +6,10 @@ 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 +if ! _binary_exists go || ! go version &> /dev/null; then + _log_warning "Unable to locate a working 'go'." + return 1 +fi export GOROOT="${GOROOT:-$(go env GOROOT)}" export GOPATH="${GOPATH:-$(go env GOPATH)}" @@ -16,7 +18,7 @@ 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() { +function _bash-it-gopath-pathmunge() { _about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended' _group 'go' if [[ -z $GOPATH ]]; then @@ -29,7 +31,7 @@ _bash-it-gopath-pathmunge() { while [[ $i -gt 0 ]]; do i=$((i - 1)) if [[ -n "${paths[i]}" ]]; then - pathmunge "${paths[i]}/bin" + pathmunge "${paths[i]}/bin" || true # ignore failures fi done } diff --git a/plugins/available/goenv.plugin.bash b/plugins/available/goenv.plugin.bash index 17e4a0ffd3..124174e7b7 100644 --- a/plugins/available/goenv.plugin.bash +++ b/plugins/available/goenv.plugin.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'load goenv, if you are using it' # https://github.com/syndbg/goenv @@ -11,29 +10,31 @@ 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 +if ! _binary_exists goenv || ! [[ -n "${GOENV_ROOT:-}" && -x "$GOENV_ROOT/bin/goenv" ]] || ! [[ -x "$HOME/.goenv/bin/goenv" ]]; then + _log_warning "Unable to locate 'goenv'." + return 1 +fi # Set GOENV_ROOT, if not already set -export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}" +: "${GOENV_ROOT:=$HOME/.goenv}" +export GOENV_ROOT # Add GOENV_ROOT/bin to PATH, if that's where it's installed if ! _command_exists goenv && [[ -x "$GOENV_ROOT/bin/goenv" ]]; then pathmunge "$GOENV_ROOT/bin" fi -# Initialize goenv -eval "$(goenv init - bash)" +# shellcheck disable=SC1090 # Initialize goenv +source < <(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() { +function _bash-it-goenv-preexec() { GOENV_OLD_VERSION="$(goenv version-name)" } -_bash-it-goenv-precmd() { - if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then + +function _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 unset GOENV_OLD_VERSION diff --git a/plugins/available/hub.plugin.bash b/plugins/available/hub.plugin.bash index e9a8cbab48..6c73fb945c 100644 --- a/plugins/available/hub.plugin.bash +++ b/plugins/available/hub.plugin.bash @@ -1,7 +1,8 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'load hub, if you are using it' -if _command_exists hub; then - eval "$(hub alias -s)" +if ! _binary_exists hub; then + _log_warning "Unable to locate 'hub'." fi + +source < <(hub alias -s) diff --git a/plugins/available/jenv.plugin.bash b/plugins/available/jenv.plugin.bash index 773a992116..b59379bcf0 100644 --- a/plugins/available/jenv.plugin.bash +++ b/plugins/available/jenv.plugin.bash @@ -1,22 +1,23 @@ -cite about-plugin +# shellcheck shell=bash about-plugin 'load jenv, if you are using it' # Don't modify the environment if we can't find the tool: # - Check if in $PATH already # - Check if installed manually to $JENV_ROOT # - Check if installed manually to $HOME -_command_exists jenv || - [[ -n "$JENV_ROOT" && -x "$JENV_ROOT/bin/jenv" ]] || - [[ -x "$HOME/.jenv/bin/jenv" ]] || - return +if ! _binary_exists jenv && ! [[ -n "${JENV_ROOT:-}" && -x "$JENV_ROOT/bin/jenv" ]] && ! [[ -x "$HOME/.jenv/bin/jenv" ]]; then + _log_warning "Unable to locate 'jenv'." + return 1 +fi # Set JENV_ROOT, if not already set -export JENV_ROOT="${JENV_ROOT:-$HOME/.jenv}" +: "${JENV_ROOT:=$HOME/.jenv}" +export JENV_ROOT # Add JENV_ROOT/bin to PATH, if that's where it's installed -! _command_exists jenv && - [[ -x "$JENV_ROOT/bin/jenv" ]] && - pathmunge "$JENV_ROOT/bin" +if ! _command_exists jenv && [[ -x "$JENV_ROOT/bin/jenv" ]]; then + pathmunge "$JENV_ROOT/bin" +fi -# Initialize jenv -eval "$(jenv init - bash)" +# shellcheck disable=SC1090 # Initialize jenv +source < <(jenv init - bash) diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index 139e518819..7f8b78c6f8 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -1,8 +1,10 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'pygmentize instead of cat to terminal if possible' -_command_exists pygmentize || return +if ! _binary_exists pygmentize; then + _log_warning "${BASH_SOURCE[0]##*/}: unable to initialize without '$_' installed." + return 1 +fi # 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 diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 8bf876df24..cb5d582865 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,14 +1,16 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'Node.js helper functions' # Check that we have npm -_command_exists npm || return +if ! _binary_exists npm; then + _log_warning "Unable to locage 'npm'." + return 1 +fi # Ensure local modules are preferred in PATH pathmunge "./node_modules/.bin" "after" # If not using nodenv, ensure global modules are in PATH -if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then +if [[ "$(type -p npm)" != *"nodenv/shims"* ]]; then pathmunge "$(npm config get prefix)/bin" "after" fi diff --git a/plugins/available/nodenv.plugin.bash b/plugins/available/nodenv.plugin.bash index 262a57c399..d219a50a1a 100644 --- a/plugins/available/nodenv.plugin.bash +++ b/plugins/available/nodenv.plugin.bash @@ -1,10 +1,14 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'load nodenv, if you are using it' -export NODENV_ROOT="$HOME/.nodenv" -pathmunge "$NODENV_ROOT/bin" +if [[ -d "${NODENV_ROOT:=$HOME/.nodenv}/bin" ]]; then + export NODENV_ROOT + pathmunge "$NODENV_ROOT/bin" +fi -if _command_exists nodenv; then - eval "$(nodenv init - bash)" +if ! _binary_exists nodenv; then + _log_warning "Unable to locage 'nodenv'." fi + +# shellcheck disable=SC1090 +source < <(nodenv init - bash) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 0e6da5d8cf..a3f11be947 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -1,31 +1,24 @@ # shellcheck shell=bash -# -# BASH_IT_LOAD_PRIORITY: 225 -# +about-plugin 'node version manager configuration' + # Bash-it no longer bundles nvm, as this was quickly becoming outdated. # Please install nvm from https://github.com/creationix/nvm.git if you want to use it. -cite about-plugin -about-plugin 'node version manager configuration' +# BASH_IT_LOAD_PRIORITY: 225 -export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" -# This loads nvm -if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]] -then - source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" -else - [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" -fi +: "${NVM_DIR:=$HOME/.nvm}" +export NVM_DIR -if ! _command_exists nvm -then - function nvm() { - echo "Bash-it no longer bundles the nvm script. Please install the latest version from" - echo "" - echo "https://github.com/creationix/nvm.git" - echo "" - echo "if you want to use nvm. You can keep this plugin enabled once you have installed nvm." - } +# shellcheck disable=SC1091 # This loads nvm +if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX?}/nvm.sh" ]]; then + source "${BASH_IT_HOMEBREW_PREFIX?}/nvm.sh" +elif [[ -s "${NVM_DIR}/nvm.sh" ]]; then + source "${NVM_DIR}/nvm.sh" +fi - nvm +if ! _command_exists nvm; then + _log_warning "Bash-it no longer bundles the nvm script. Please install the latest version from + https://github.com/creationix/nvm.git" + _log_warning "if you want to use nvm. You can keep this plugin enabled once you have installed nvm." + return 1 fi diff --git a/plugins/available/percol.plugin.bash b/plugins/available/percol.plugin.bash index 027dfdc4af..3e27f5db23 100644 --- a/plugins/available/percol.plugin.bash +++ b/plugins/available/percol.plugin.bash @@ -1,9 +1,8 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'Search&Select history with percol' # Notice -## You have to upgrade bash to bash 4.x on Mac OS X. +## You have to upgrade bash to bash 4.x or higher ## http://stackoverflow.com/questions/16416195/how-do-i-upgrade-bash-in-mac-osx-mountain-lion-and-set-it-the-correct-path # Install @@ -13,12 +12,15 @@ about-plugin 'Search&Select history with percol' # Usage ## C-r to search&select from history -_command_exists percol || return +if ! _binary_exists percol; then + _log_warning "Unable to locate 'percol'." + return 1 +fi if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin." _log_warning "Your current Bash version is $BASH_VERSION." - return + return 1 fi function _replace_by_history() { diff --git a/plugins/available/plenv.plugin.bash b/plugins/available/plenv.plugin.bash index 79a9cf4964..822282ce84 100644 --- a/plugins/available/plenv.plugin.bash +++ b/plugins/available/plenv.plugin.bash @@ -1,8 +1,4 @@ # shellcheck shell=bash -# -# plugin for plenv - -cite about-plugin about-plugin 'plenv plugin for Perl' if [[ -d "${HOME}/.plenv/bin" ]]; then @@ -10,7 +6,9 @@ if [[ -d "${HOME}/.plenv/bin" ]]; then pathmunge "${HOME}/.plenv/bin" fi -if _command_exists plenv; then - # init plenv - eval "$(plenv init - bash)" +if ! _binary_exists plenv; then + _log_warning "Unable to locage 'plenv'." fi + +# shellcheck disable=SC1090 # init plenv +source < <(plenv init - bash) diff --git a/plugins/available/powerline.plugin.bash b/plugins/available/powerline.plugin.bash index 1927bf3e24..a4014ced5d 100644 --- a/plugins/available/powerline.plugin.bash +++ b/plugins/available/powerline.plugin.bash @@ -1,9 +1,11 @@ # shellcheck shell=bash - -cite about-plugin about-plugin 'enables powerline daemon' -_command_exists powerline-daemon || return +if ! _binary_exists powerline-daemon; then + _log_warning "Unable to locate '$_'." + return 1 +fi + powerline-daemon -q #the following should not be executed if bashit powerline themes in use @@ -12,8 +14,8 @@ case "$BASH_IT_THEME" in return ;; esac -POWERLINE_BASH_CONTINUATION=1 -POWERLINE_BASH_SELECT=1 +export POWERLINE_BASH_CONTINUATION=1 +export POWERLINE_BASH_SELECT=1 bashPowerlineInit="$(python -c \ "import os; \ import powerline;\ @@ -22,5 +24,11 @@ bashPowerlineInit="$(python -c \ 'bindings', \ 'bash', \ 'powerline.sh'))")" -[ -e $bashPowerlineInit ] || return -source $bashPowerlineInit + +if ! [[ -s ${bashPowerlineInit?} ]]; then + _log_warning "Failed to initialize 'powerline'." + return 1 +fi + +# shellcheck disable=SC1090 +source "${bashPowerlineInit?}" diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index 05d2847812..b0550948a1 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'load pyenv, if you are using it' # https://github.com/pyenv/pyenv @@ -11,13 +10,14 @@ 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 +if ! _binary_exists pyenv && ! [[ -n "${PYENV_ROOT:-}" && -x "$PYENV_ROOT/bin/pyenv" ]] && ! [[ -x "$HOME/.pyenv/bin/pyenv" ]]; then + _log_warning "Unable to locage 'pyenv'." + return 0 +fi # Set PYENV_ROOT, if not already set -export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}" +: "${PYENV_ROOT:=$HOME/.pyenv}" +export PYENV_ROOT # Add PYENV_ROOT/bin to PATH, if that's where it's installed if ! _command_exists pyenv && [[ -x "$PYENV_ROOT/bin/pyenv" ]]; then @@ -26,9 +26,11 @@ fi # Initialize pyenv pathmunge "$PYENV_ROOT/shims" -eval "$(pyenv init - bash)" +# shellcheck disable=SC1090 +source < <(pyenv init - bash) # Load pyenv virtualenv if the virtualenv plugin is installed. if pyenv virtualenv-init - &> /dev/null; then - eval "$(pyenv virtualenv-init - bash)" + # shellcheck disable=SC1090 + source < <(pyenv virtualenv-init - bash) fi diff --git a/plugins/available/rbenv.plugin.bash b/plugins/available/rbenv.plugin.bash index f3605f585c..ef20bd339b 100644 --- a/plugins/available/rbenv.plugin.bash +++ b/plugins/available/rbenv.plugin.bash @@ -1,10 +1,13 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'load rbenv, if you are using it' -export RBENV_ROOT="$HOME/.rbenv" +: "${RBENV_ROOT:=$HOME/.rbenv}" +export RBENV_ROOT pathmunge "$RBENV_ROOT/bin" -if _command_exists rbenv; then - eval "$(rbenv init - bash)" +if ! _binary_exists rbenv; then + _log_warning "Unable to locage 'rbenv'." + return 1 fi + +source < <(rbenv init - bash) diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index aed8daf8cd..c85f1cf216 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -1,13 +1,15 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'ruby and rubygems specific functions and settings' # Make commands installed with 'gem install --user-install' available # ~/.gem/ruby/${RUBY_VERSION}/bin/ -if _command_exists ruby && _command_exists gem; then - pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after +if ! _binary_exists ruby || ! _binary_exists gem; then + _log_warning "Unable to locate 'gem'." + return 1 fi +pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after + function remove_gem() { about 'removes installed gem' param '1: installed gem name' diff --git a/plugins/available/textmate.plugin.bash b/plugins/available/textmate.plugin.bash index 5c81f195ac..f688b5b2cb 100644 --- a/plugins/available/textmate.plugin.bash +++ b/plugins/available/textmate.plugin.bash @@ -1,9 +1,10 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'set textmate as a default editor' -if _command_exists mate; then - EDITOR="$(type -p mate) -w" - GIT_EDITOR="$EDITOR" - export EDITOR GIT_EDITOR +if ! _binary_exists mate; then + _log_warning "Unable to locage 'mate'." + return 1 fi + +EDITOR="$(type -p mate) -w" +export EDITOR diff --git a/plugins/available/thefuck.plugin.bash b/plugins/available/thefuck.plugin.bash index 242a77df22..b845e81275 100644 --- a/plugins/available/thefuck.plugin.bash +++ b/plugins/available/thefuck.plugin.bash @@ -1,9 +1,12 @@ -cite about-plugin +# shellcheck shell=bash about-plugin 'Initialization for fuck' # https://github.com/nvbn/thefuck -if _command_exists thefuck; then - # shellcheck disable=SC2046 - eval $(thefuck --alias) +if ! _binary_exists thefuck; then + _log_warning "Unable to locate 'thefuck'." + return 1 fi + +# shellcheck disable=SC1090 +source < <(thefuck --alias) diff --git a/plugins/available/zoxide.plugin.bash b/plugins/available/zoxide.plugin.bash index 5f9d634f59..339ddcbff7 100644 --- a/plugins/available/zoxide.plugin.bash +++ b/plugins/available/zoxide.plugin.bash @@ -1,9 +1,9 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'zoxide is a smarter cd command for your shell.' -if _command_exists zoxide; then - eval "$(zoxide init bash)" -else +if ! _binary_exists zoxide; then _log_error 'zoxide not found, please install it from https://github.com/ajeetdsouza/zoxide' + return 1 fi + +source < <(zoxide init bash)