From 3573275c5d1df27a82f4f3e28c9ba226de724f34 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 25 Jan 2022 22:29:55 -0800 Subject: [PATCH] plugin/gitstatus: `shellcheck` --- clean_files.txt | 1 + plugins/available/gitstatus.plugin.bash | 48 +++++++++++++++---------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 686c3883..2e569655 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -104,6 +104,7 @@ plugins/available/fzf.plugin.bash plugins/available/gif.plugin.bash plugins/available/git-subrepo.plugin.bash plugins/available/git.plugin.bash +plugins/available/gitstatus.plugin.bash plugins/available/go.plugin.bash plugins/available/goenv.plugin.bash plugins/available/history-eternal.plugin.bash diff --git a/plugins/available/gitstatus.plugin.bash b/plugins/available/gitstatus.plugin.bash index 9df65a82..e71c7e50 100644 --- a/plugins/available/gitstatus.plugin.bash +++ b/plugins/available/gitstatus.plugin.bash @@ -1,26 +1,36 @@ -cite about-plugin +# shellcheck shell=bash about-plugin 'speeds up your life by using gitstatus for git status calculations. install from https://github.com/romkatv/gitstatus' -function gitstatus_on_disable() { - about 'Destructor of gitstatus plugin' - group 'gitstatus' +: "${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"}" +if [[ ! -d "${SCM_GIT_GITSTATUS_DIR}" ]] && _bash_it_homebrew_check; then + SCM_GIT_GITSTATUS_DIR="${BASH_IT_HOMEBREW_PREFIX?}/opt/gitstatus" +fi - unset SCM_GIT_USE_GITSTATUS - _command_exists gitstatus_stop && gitstatus_stop +function gitstatus_on_disable() { + about 'Destructor of gitstatus plugin' + group 'gitstatus' + + unset SCM_GIT_USE_GITSTATUS + _command_exists gitstatus_stop && gitstatus_stop } -# No scm-check -[[ $SCM_CHECK == "true" ]] || return +function _bash-it-component-plugin-callback-on-init-gitstatus() { + # No scm-check + [[ ${SCM_CHECK?} == "true" ]] || return -# non-interactive shell -[[ $- == *i* ]] || return + # non-interactive shell + [[ $- == *i* ]] || return -: "${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"}" -if [[ -d ${SCM_GIT_GITSTATUS_DIR} ]]; then - source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh" - # Start the actual gitstatus binary - gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 - export SCM_GIT_USE_GITSTATUS=true -else - _log_warning "Could not find gitstatus directory in ${SCM_GIT_GITSTATUS_DIR}. Please specify directory location using SCM_GIT_GITSTATUS_DIR." -fi + if [[ -d "${SCM_GIT_GITSTATUS_DIR?}" ]]; then + # shellcheck source-path=$HOME/gitstatus disable=SC1091 + source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh" + # Start the actual gitstatus binary + gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 + export SCM_GIT_USE_GITSTATUS=true + else + _log_warning "Could not find gitstatus directory in ${SCM_GIT_GITSTATUS_DIR}. Please specify directory location using SCM_GIT_GITSTATUS_DIR." + return 1 + fi +} + +_bash-it-component-plugin-callback-on-init-gitstatus