From 83fdc89ec194960a0ce72b2f4080614fcfe1a31a Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Sun, 6 Oct 2019 12:33:12 +0200 Subject: [PATCH 01/13] implement gitstatusd support --- bash_it.sh | 7 +++ template/bash_profile.template.bash | 6 +++ themes/base.theme.bash | 35 ++++++++++-- themes/githelpers.theme.bash | 84 +++++++++++++++++++++-------- 4 files changed, 105 insertions(+), 27 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index ab911019..e09c3ba7 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -121,5 +121,12 @@ if ! command -v reload &>/dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then esac fi +# If gitstatusd is requested for the current shell, launch it if the shell is interactive +if [[ "${SCM_GIT_USE_GITSTATUSD}" == "true" ]] && [[ "$SCM_CHECK" == "true" ]] && [[ $- == *i* ]]; then + test -z "${SCM_GIT_GITSTATUSD_LOC}" || SCM_GIT_GITSTATUSD_LOC="$HOME/gitstatus/gitstatus.plugin.sh" + source "${SCM_GIT_GITSTATUSD_LOC}" + gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 +fi + # Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 set +T diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index e7f92dd3..9e9e6b9d 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -32,6 +32,12 @@ export TODO="t" # Set this to false to turn off version control status checking within the prompt for all themes export SCM_CHECK=true +# when using Git, consider installing https://github.com/romkatv/gitstatus for faster status prompt +# enable it here if you wish, change the LOC variable if you did not choose the standard location in your home +#export SCM_GIT_USE_GITSTATUSD=true +#export SCM_GIT_GITSTATUSD_LOC="$HOME/gitstatus/gitstatus.plugin.sh" +# per default gitstatusd uses 2 times as many threads as CPU cores, you can change this here if you must +#export GITSTATUS_NUM_THREADS=8 # Set Xterm/screen/Tmux title with only a short hostname. # Uncomment this (or set SHORT_HOSTNAME to something else), diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 97bbee45..f92bd268 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -34,6 +34,8 @@ SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false} SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false} SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true} SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true} +SCM_GIT_USE_GITSTATUSD=${SCM_GIT_USE_GITSTATUSD:=false} +SCM_GIT_GITSTATUSD_LOC=${SCM_GIT_GITSTATUSD_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} SCM_GIT='git' SCM_GIT_CHAR='±' @@ -191,6 +193,15 @@ function git_prompt_minimal_info { } function git_prompt_vars { + if ${SCM_GIT_USE_GITSTATUSD}; then # use faster gitstatusd + gitstatus_query # call gitstatusd + if [[ -z ${VCS_STATUS_WORKDIR} ]] ; then # this var is guaranteed to exist if query was successful + SCM_GIT_GITSTATUSD_RAN=false + else + SCM_GIT_GITSTATUSD_RAN=true # use this in githelpers and below to choose gitstatusd output + fi + fi + if _git-branch &> /dev/null; then SCM_GIT_DETACHED="false" SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)$(_git-remote-info)" @@ -206,7 +217,12 @@ function git_prompt_vars { SCM_BRANCH="${detached_prefix}\$(_git-friendly-ref)" fi - IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)" + if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + commits_behind=${VCS_STATUS_COMMITS_BEHIND} + commits_ahead=${VCS_STATUS_COMMITS_AHEAD} + else + IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)" + fi if [[ "${commits_ahead}" -gt 0 ]]; then SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}" [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_ahead}" @@ -218,13 +234,23 @@ function git_prompt_vars { if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then local stash_count - stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')" + if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + stash_count=${VCS_STATUS_STASHES} + else + stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')" + fi [[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STASH_CHAR_PREFIX}${stash_count}${SCM_GIT_STASH_CHAR_SUFFIX}" fi SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} if ! _git-hide-status; then - IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)" + if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + untracked_count=${VCS_STATUS_NUM_UNTRACKED} + unstaged_count=${VCS_STATUS_NUM_UNSTAGED} + staged_count=${VCS_STATUS_NUM_STAGED} + else + IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)" + fi if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then SCM_DIRTY=1 if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; then @@ -236,12 +262,13 @@ function git_prompt_vars { fi fi + # no if for gitstatusd here, user extraction is not supported by it [[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)" SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "") + } function p4_prompt_vars { diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index 24c4b1f4..c31e1ff5 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -9,11 +9,19 @@ function _git-symbolic-ref { # same commit. _git-branch is used to explicitly choose the checked-out # branch. function _git-branch { - git symbolic-ref -q --short HEAD 2> /dev/null || return 1 + if [[ "${SCM_GIT_GITSTATUSD_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 { - git describe --tags --exact-match 2> /dev/null + if [[ "${SCM_GIT_GITSTATUSD_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 { @@ -21,12 +29,20 @@ function _git-commit-description { } function _git-short-sha { - git rev-parse --short HEAD + if [[ "${SCM_GIT_GITSTATUSD_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_GITSTATUSD_RAN}" == "true" ]]; then + _git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatusd + else _git-branch || _git-tag || _git-commit-description || _git-short-sha + fi } function _git-num-remotes { @@ -101,29 +117,51 @@ function _git-status-counts { } function _git-remote-info { - [[ "$(_git-upstream)" == "" ]] && return || true - [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true || 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)" + if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then # prompt handling only, reimplement because patching the routine below gets ugly + [[ "${VCS_STATUS_REMOTE_NAME}" == "" ]] && return || true + [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && local same_branch_name=true || true + local same_branch_name= + [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && same_branch_name=true + if [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]] || [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]]; then # no multiple remote support in gitstatusd + if [[ "${same_branch_name}" != "true" ]]; then + remote_info="\${VCS_STATUS_REMOTE_NAME}" + else + remote_info="${VCS_STATUS_REMOTE_NAME}/${VCS_STATUS_REMOTE_BRANCH}" + fi + elif [[ ${same_branch_name} != "true" ]]; then + remote_info="\${VCS_STATUS_REMOTE_BRANCH}" 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}" + if [[ -n "${remote_info}" ]];then + local branch_prefix + branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" # no support for gone remote branches in gitstatusd + echo "${branch_prefix}${remote_info}" + fi + else + [[ "$(_git-upstream)" == "" ]] && return || true + + [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true || 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 - echo "${branch_prefix}${remote_info}" fi } From feae99431a5b38095e3175f9e769437fb187143c Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Sun, 6 Oct 2019 14:10:49 +0200 Subject: [PATCH 02/13] implement feedback --- themes/base.theme.bash | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index f92bd268..92031860 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -36,6 +36,7 @@ SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true} SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true} SCM_GIT_USE_GITSTATUSD=${SCM_GIT_USE_GITSTATUSD:=false} SCM_GIT_GITSTATUSD_LOC=${SCM_GIT_GITSTATUSD_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} +SCM_GIT_GITSTATUSD_RAN=${SCM_GIT_GITSTATUSD_RAN:=false} SCM_GIT='git' SCM_GIT_CHAR='±' @@ -193,13 +194,10 @@ function git_prompt_minimal_info { } function git_prompt_vars { - if ${SCM_GIT_USE_GITSTATUSD}; then # use faster gitstatusd - gitstatus_query # call gitstatusd - if [[ -z ${VCS_STATUS_WORKDIR} ]] ; then # this var is guaranteed to exist if query was successful - SCM_GIT_GITSTATUSD_RAN=false - else - SCM_GIT_GITSTATUSD_RAN=true # use this in githelpers and below to choose gitstatusd output - fi + if ${SCM_GIT_USE_GITSTATUSD} && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then # use faster gitstatusd + SCM_GIT_GITSTATUSD_RAN=true # use this in githelpers and below to choose gitstatusd output + else + SCM_GIT_GITSTATUSD_RAN=false fi if _git-branch &> /dev/null; then From 3c0738ba4325997895a4fda2ed62916d8a9188d6 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Sun, 6 Oct 2019 17:23:18 +0200 Subject: [PATCH 03/13] fix expansion inconsistency --- themes/githelpers.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index c31e1ff5..2ee242df 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -127,7 +127,7 @@ function _git-remote-info { if [[ "${same_branch_name}" != "true" ]]; then remote_info="\${VCS_STATUS_REMOTE_NAME}" else - remote_info="${VCS_STATUS_REMOTE_NAME}/${VCS_STATUS_REMOTE_BRANCH}" + remote_info="\${VCS_STATUS_REMOTE_NAME}/\${VCS_STATUS_REMOTE_BRANCH}" fi elif [[ ${same_branch_name} != "true" ]]; then remote_info="\${VCS_STATUS_REMOTE_BRANCH}" From fb2e8549ad805c735d642947e81a9d2f4522ac95 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 19 Jun 2020 19:44:21 +0300 Subject: [PATCH 04/13] themes: Tidy base.theme and remove uneeded changes --- themes/base.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 92031860..fb362d78 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -265,8 +265,8 @@ function git_prompt_vars { SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "") + SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "") } function p4_prompt_vars { From 5d1403059112c5c72d79ec345525380cd49e0226 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 19 Jun 2020 19:45:45 +0300 Subject: [PATCH 05/13] plugins: Add gitstatud plugin --- bash_it.sh | 7 ------ plugins/available/gitstatusd.plugin.bash | 14 +++++++++++ template/bash_profile.template.bash | 4 +--- themes/base.theme.bash | 3 +-- themes/githelpers.theme.bash | 30 +++++++++++++----------- 5 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 plugins/available/gitstatusd.plugin.bash diff --git a/bash_it.sh b/bash_it.sh index e09c3ba7..ab911019 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -121,12 +121,5 @@ if ! command -v reload &>/dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then esac fi -# If gitstatusd is requested for the current shell, launch it if the shell is interactive -if [[ "${SCM_GIT_USE_GITSTATUSD}" == "true" ]] && [[ "$SCM_CHECK" == "true" ]] && [[ $- == *i* ]]; then - test -z "${SCM_GIT_GITSTATUSD_LOC}" || SCM_GIT_GITSTATUSD_LOC="$HOME/gitstatus/gitstatus.plugin.sh" - source "${SCM_GIT_GITSTATUSD_LOC}" - gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 -fi - # Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 set +T diff --git a/plugins/available/gitstatusd.plugin.bash b/plugins/available/gitstatusd.plugin.bash new file mode 100644 index 00000000..02794394 --- /dev/null +++ b/plugins/available/gitstatusd.plugin.bash @@ -0,0 +1,14 @@ +cite about-plugin +about-plugin 'speeds up your life by using gitstatusd for git status calculations. install from https://github.com/romkatv/gitstatus' + +[[ "$SCM_CHECK" == "true" ]] || return # No scm-check + +[[ $- == *i* ]] || return # non-interactive shell + +SCM_GIT_GITSTATUSD_LOC=${SCM_GIT_GITSTATUSD_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} +if [[ -f "${SCM_GIT_GITSTATUSD_LOC}" ]]; then + source "${SCM_GIT_GITSTATUSD_LOC}" + # Start the actual gitstatusd binary + gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 + export SCM_GIT_USE_GITSTATUSD=true +fi diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 9e9e6b9d..efafa8d9 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -32,9 +32,7 @@ export TODO="t" # Set this to false to turn off version control status checking within the prompt for all themes export SCM_CHECK=true -# when using Git, consider installing https://github.com/romkatv/gitstatus for faster status prompt -# enable it here if you wish, change the LOC variable if you did not choose the standard location in your home -#export SCM_GIT_USE_GITSTATUSD=true +# Set to actual location of gitstatusd if installed #export SCM_GIT_GITSTATUSD_LOC="$HOME/gitstatus/gitstatus.plugin.sh" # per default gitstatusd uses 2 times as many threads as CPU cores, you can change this here if you must #export GITSTATUS_NUM_THREADS=8 diff --git a/themes/base.theme.bash b/themes/base.theme.bash index fb362d78..26527659 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -35,7 +35,6 @@ SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false} SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true} SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true} SCM_GIT_USE_GITSTATUSD=${SCM_GIT_USE_GITSTATUSD:=false} -SCM_GIT_GITSTATUSD_LOC=${SCM_GIT_GITSTATUSD_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} SCM_GIT_GITSTATUSD_RAN=${SCM_GIT_GITSTATUSD_RAN:=false} SCM_GIT='git' @@ -194,7 +193,7 @@ function git_prompt_minimal_info { } function git_prompt_vars { - if ${SCM_GIT_USE_GITSTATUSD} && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then # use faster gitstatusd + if ${SCM_GIT_USE_GITSTATUSD} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then # use faster gitstatusd SCM_GIT_GITSTATUSD_RAN=true # use this in githelpers and below to choose gitstatusd output else SCM_GIT_GITSTATUSD_RAN=false diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index 2ee242df..fd5b3ce7 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -118,33 +118,35 @@ function _git-status-counts { function _git-remote-info { - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then # prompt handling only, reimplement because patching the routine below gets ugly - [[ "${VCS_STATUS_REMOTE_NAME}" == "" ]] && return || true - [[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && local same_branch_name=true || true + # prompt handling only, reimplement because patching the routine below gets ugly + if [[ "${SCM_GIT_GITSTATUSD_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 - if [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]] || [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]]; then # no multiple remote support in gitstatusd + # 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}" + remote_info="${VCS_STATUS_REMOTE_NAME}/${VCS_STATUS_REMOTE_BRANCH}" else - remote_info="\${VCS_STATUS_REMOTE_NAME}/\${VCS_STATUS_REMOTE_BRANCH}" + remote_info="${VCS_STATUS_REMOTE_NAME}" fi elif [[ ${same_branch_name} != "true" ]]; then - remote_info="\${VCS_STATUS_REMOTE_BRANCH}" + remote_info="${VCS_STATUS_REMOTE_BRANCH}" fi if [[ -n "${remote_info}" ]];then - local branch_prefix - branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" # no support for gone remote branches in gitstatusd + # 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 || true + else + [[ "$(_git-upstream)" == "" ]] && return - [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true || true + [[ "$(_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 [[ ("${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 From b95062192a241e5261e2008e0fed023bcff76620 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 19 Jun 2020 21:58:45 +0300 Subject: [PATCH 06/13] Add docs about gitstatusd in README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index adb783e6..314e77b8 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,13 @@ $ git config --global --add bash-it.hide-status 1 Setting this flag globally has the same effect as `SCM_CHECK=true`, but only for Git repos. +### Speed up git status calculations + +As an alternative to ignoring repo status entirely, you can try out the `gitstatusd` plugin. +This plugin speeds up all `git status` calculations by up to 10x times! + +**NOTE**: You will need to clone `gitstatus` repo from [here](https://github.com/romkatv/gitstatus). + ### Pass function renamed to passgen The Bash-it `pass` function has been renamed to `passgen` in order to avoid a naming conflict with the [pass password manager](https://www.passwordstore.org/). From 4f4bae95e42b1c7caab949aa44be711194679698 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 20 Jun 2020 14:11:00 +0300 Subject: [PATCH 07/13] tests: Fix search git test --- test/lib/search.bats | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/lib/search.bats b/test/lib/search.bats index a7c1a23f..60c06be2 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -39,7 +39,12 @@ function local_teardown { @test "search: git" { run _bash-it-search 'git' --no-color assert_line -n 0 ' aliases: git gitsvn ' - assert_line -n 1 ' plugins: autojump git git-subrepo jgitflow jump ' + assert_line -n 1 -p ' plugins:' + for plugin in "autojump" "git" "gitstatusd" "git-subrepo" "jgitflow" "jump" + do + echo $plugin + assert_line -n 1 -p $plugin + done assert_line -n 2 ' completions: git git_flow git_flow_avh ' } From bda85c36794dafbe0a6c063bfde29565dee30b09 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 20 Jun 2020 14:37:21 +0300 Subject: [PATCH 08/13] lib: Add on-disable-callback for plugins to use --- DEVELOPMENT.md | 5 +++++ lib/helpers.bash | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index ba9efe60..33276b71 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -43,3 +43,8 @@ For `aliases`, `plugins` and `completions`, the following rules are applied that Having the order based on a numeric priority in a common directory allows for more flexibility. While in general, aliases are loaded first (since their default priority is 150), it's possible to load some aliases after the plugins, or some plugins after completions by setting the items' load priority. This is more flexible than a fixed type-based order or a strict alphabetical order based on name. These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well. + +## Plugin Disable Callbacks + +Plugins can define a function that will be called when the plugin is being disabled. +The callback name should be `{PLUGIN_NAME}_on_disable`, you can see `gitstatus` for usage example. diff --git a/lib/helpers.bash b/lib/helpers.bash index e7ef15ba..9c4b3c43 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -318,6 +318,17 @@ _bash-it-describe () 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 gitstatusd' + _group 'lib' + + callback=$1_on_disable + _command_exists $callback && $callback +} + _disable-plugin () { _about 'disables bash_it plugin' @@ -326,6 +337,7 @@ _disable-plugin () _group 'lib' _disable-thing "plugins" "plugin" $1 + _on-disable-callback $1 } _disable-alias () From 1143bb8ddf0c35e3e6f565dd4a5e0add803742ea Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 20 Jun 2020 14:37:39 +0300 Subject: [PATCH 09/13] plugins: Add disable callback for gitstatusd --- plugins/available/gitstatusd.plugin.bash | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/available/gitstatusd.plugin.bash b/plugins/available/gitstatusd.plugin.bash index 02794394..0658fb1a 100644 --- a/plugins/available/gitstatusd.plugin.bash +++ b/plugins/available/gitstatusd.plugin.bash @@ -1,6 +1,15 @@ cite about-plugin about-plugin 'speeds up your life by using gitstatusd for git status calculations. install from https://github.com/romkatv/gitstatus' + +function gitstatusd_on_disable() { + about 'Destructor of gitstatusd plugin' + group 'gitstatusd' + + unset SCM_GIT_USE_GITSTATUSD + gitstatus_stop +} + [[ "$SCM_CHECK" == "true" ]] || return # No scm-check [[ $- == *i* ]] || return # non-interactive shell From 6294797986d86393b0c80c7c6d246713a978b550 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 20 Jun 2020 15:15:55 +0300 Subject: [PATCH 10/13] Rename SCM_GIT_GITSTATUSD_LOC to SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC --- plugins/available/gitstatusd.plugin.bash | 6 +++--- template/bash_profile.template.bash | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/available/gitstatusd.plugin.bash b/plugins/available/gitstatusd.plugin.bash index 0658fb1a..3551c6f9 100644 --- a/plugins/available/gitstatusd.plugin.bash +++ b/plugins/available/gitstatusd.plugin.bash @@ -14,9 +14,9 @@ function gitstatusd_on_disable() { [[ $- == *i* ]] || return # non-interactive shell -SCM_GIT_GITSTATUSD_LOC=${SCM_GIT_GITSTATUSD_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} -if [[ -f "${SCM_GIT_GITSTATUSD_LOC}" ]]; then - source "${SCM_GIT_GITSTATUSD_LOC}" +SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC=${SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} +if [[ -f "${SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC}" ]]; then + source "${SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC}" # Start the actual gitstatusd binary gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 export SCM_GIT_USE_GITSTATUSD=true diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index efafa8d9..6fa8e516 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -32,8 +32,8 @@ export TODO="t" # Set this to false to turn off version control status checking within the prompt for all themes export SCM_CHECK=true -# Set to actual location of gitstatusd if installed -#export SCM_GIT_GITSTATUSD_LOC="$HOME/gitstatus/gitstatus.plugin.sh" +# Set to actual location of gitstatusd.plugin.sh if installed +#export SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC="$HOME/gitstatus/gitstatus.plugin.sh" # per default gitstatusd uses 2 times as many threads as CPU cores, you can change this here if you must #export GITSTATUS_NUM_THREADS=8 From 3eac73f613a81cf4b13882317c9106f81fec592f Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 21 Jun 2020 12:54:53 +0300 Subject: [PATCH 11/13] plugins: Rename gitstatusd plugin to gitstatus --- README.md | 2 +- lib/helpers.bash | 2 +- plugins/available/gitstatus.plugin.bash | 23 +++++++++++++++++++++++ plugins/available/gitstatusd.plugin.bash | 23 ----------------------- template/bash_profile.template.bash | 6 +++--- test/lib/search.bats | 2 +- themes/base.theme.bash | 18 +++++++++--------- themes/githelpers.theme.bash | 12 ++++++------ 8 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 plugins/available/gitstatus.plugin.bash delete mode 100644 plugins/available/gitstatusd.plugin.bash diff --git a/README.md b/README.md index 314e77b8..a696894e 100644 --- a/README.md +++ b/README.md @@ -397,7 +397,7 @@ Setting this flag globally has the same effect as `SCM_CHECK=true`, but only for ### Speed up git status calculations -As an alternative to ignoring repo status entirely, you can try out the `gitstatusd` plugin. +As an alternative to ignoring repo status entirely, you can try out the `gitstatus` plugin. This plugin speeds up all `git status` calculations by up to 10x times! **NOTE**: You will need to clone `gitstatus` repo from [here](https://github.com/romkatv/gitstatus). diff --git a/lib/helpers.bash b/lib/helpers.bash index 9c4b3c43..f3bd2e0b 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -322,7 +322,7 @@ _on-disable-callback() { _about 'Calls the disabled plugin destructor, if present' _param '1: plugin name' - _example '$ _on-disable-callback gitstatusd' + _example '$ _on-disable-callback gitstatus' _group 'lib' callback=$1_on_disable diff --git a/plugins/available/gitstatus.plugin.bash b/plugins/available/gitstatus.plugin.bash new file mode 100644 index 00000000..d48d0569 --- /dev/null +++ b/plugins/available/gitstatus.plugin.bash @@ -0,0 +1,23 @@ +cite about-plugin +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' + + unset SCM_GIT_USE_GITSTATUS + gitstatus_stop +} + +[[ "$SCM_CHECK" == "true" ]] || return # No scm-check + +[[ $- == *i* ]] || return # non-interactive shell + +SCM_GIT_GITSTATUS_PLUGIN_SH_LOC=${SCM_GIT_GITSTATUS_PLUGIN_SH_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} +if [[ -f "${SCM_GIT_GITSTATUS_PLUGIN_SH_LOC}" ]]; then + source "${SCM_GIT_GITSTATUS_PLUGIN_SH_LOC}" + # Start the actual gitstatus binary + gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 + export SCM_GIT_USE_GITSTATUS=true +fi diff --git a/plugins/available/gitstatusd.plugin.bash b/plugins/available/gitstatusd.plugin.bash deleted file mode 100644 index 3551c6f9..00000000 --- a/plugins/available/gitstatusd.plugin.bash +++ /dev/null @@ -1,23 +0,0 @@ -cite about-plugin -about-plugin 'speeds up your life by using gitstatusd for git status calculations. install from https://github.com/romkatv/gitstatus' - - -function gitstatusd_on_disable() { - about 'Destructor of gitstatusd plugin' - group 'gitstatusd' - - unset SCM_GIT_USE_GITSTATUSD - gitstatus_stop -} - -[[ "$SCM_CHECK" == "true" ]] || return # No scm-check - -[[ $- == *i* ]] || return # non-interactive shell - -SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC=${SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} -if [[ -f "${SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC}" ]]; then - source "${SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC}" - # Start the actual gitstatusd binary - gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 - export SCM_GIT_USE_GITSTATUSD=true -fi diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 6fa8e516..40ac5c32 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -32,9 +32,9 @@ export TODO="t" # Set this to false to turn off version control status checking within the prompt for all themes export SCM_CHECK=true -# Set to actual location of gitstatusd.plugin.sh if installed -#export SCM_GIT_GITSTATUSD_PLUGIN_SH_LOC="$HOME/gitstatus/gitstatus.plugin.sh" -# per default gitstatusd uses 2 times as many threads as CPU cores, you can change this here if you must +# Set to actual location of gitstatus.plugin.sh if installed +#export SCM_GIT_GITSTATUS_PLUGIN_SH_LOC="$HOME/gitstatus/gitstatus.plugin.sh" +# per default gitstatus uses 2 times as many threads as CPU cores, you can change this here if you must #export GITSTATUS_NUM_THREADS=8 # Set Xterm/screen/Tmux title with only a short hostname. diff --git a/test/lib/search.bats b/test/lib/search.bats index 60c06be2..c7bda191 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -40,7 +40,7 @@ function local_teardown { run _bash-it-search 'git' --no-color assert_line -n 0 ' aliases: git gitsvn ' assert_line -n 1 -p ' plugins:' - for plugin in "autojump" "git" "gitstatusd" "git-subrepo" "jgitflow" "jump" + for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump" do echo $plugin assert_line -n 1 -p $plugin diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 26527659..61671b51 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -34,8 +34,8 @@ SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false} SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false} SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true} SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true} -SCM_GIT_USE_GITSTATUSD=${SCM_GIT_USE_GITSTATUSD:=false} -SCM_GIT_GITSTATUSD_RAN=${SCM_GIT_GITSTATUSD_RAN:=false} +SCM_GIT_USE_GITSTATUS=${SCM_GIT_USE_GITSTATUS:=false} +SCM_GIT_GITSTATUS_RAN=${SCM_GIT_GITSTATUS_RAN:=false} SCM_GIT='git' SCM_GIT_CHAR='±' @@ -193,10 +193,10 @@ function git_prompt_minimal_info { } function git_prompt_vars { - if ${SCM_GIT_USE_GITSTATUSD} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then # use faster gitstatusd - SCM_GIT_GITSTATUSD_RAN=true # use this in githelpers and below to choose gitstatusd output + if ${SCM_GIT_USE_GITSTATUS} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then # use faster gitstatus + SCM_GIT_GITSTATUS_RAN=true # use this in githelpers and below to choose gitstatus output else - SCM_GIT_GITSTATUSD_RAN=false + SCM_GIT_GITSTATUS_RAN=false fi if _git-branch &> /dev/null; then @@ -214,7 +214,7 @@ function git_prompt_vars { SCM_BRANCH="${detached_prefix}\$(_git-friendly-ref)" fi - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then commits_behind=${VCS_STATUS_COMMITS_BEHIND} commits_ahead=${VCS_STATUS_COMMITS_AHEAD} else @@ -231,7 +231,7 @@ function git_prompt_vars { if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then local stash_count - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then stash_count=${VCS_STATUS_STASHES} else stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')" @@ -241,7 +241,7 @@ function git_prompt_vars { SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} if ! _git-hide-status; then - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then untracked_count=${VCS_STATUS_NUM_UNTRACKED} unstaged_count=${VCS_STATUS_NUM_UNSTAGED} staged_count=${VCS_STATUS_NUM_STAGED} @@ -259,7 +259,7 @@ function git_prompt_vars { fi fi - # no if for gitstatusd here, user extraction is not supported by it + # no if for gitstatus here, user extraction is not supported by it [[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)" SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index fd5b3ce7..2d5829ff 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -9,7 +9,7 @@ function _git-symbolic-ref { # same commit. _git-branch is used to explicitly choose the checked-out # branch. function _git-branch { - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + 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 @@ -17,7 +17,7 @@ function _git-branch { } function _git-tag { - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + 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 @@ -29,7 +29,7 @@ function _git-commit-description { } function _git-short-sha { - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then echo ${VCS_STATUS_COMMIT:0:7} else git rev-parse --short HEAD @@ -38,8 +38,8 @@ function _git-short-sha { # Try the checked-out branch first to avoid collision with branches pointing to the same ref. function _git-friendly-ref { - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then - _git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatusd + 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 @@ -119,7 +119,7 @@ function _git-status-counts { function _git-remote-info { # prompt handling only, reimplement because patching the routine below gets ugly - if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then + 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= From d7aebe17a391331485021826603e08908ee13c2e Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 21 Jun 2020 14:10:14 +0300 Subject: [PATCH 12/13] plugins: Rename SCM_GIT_GITSTATUS_PLUGIN_SH_LOC to SCM_GIT_GITSTATUS_DIR Also fix the destructor in case plugin did not load as expected --- plugins/available/gitstatus.plugin.bash | 8 ++++---- template/bash_profile.template.bash | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/available/gitstatus.plugin.bash b/plugins/available/gitstatus.plugin.bash index d48d0569..8e6558cd 100644 --- a/plugins/available/gitstatus.plugin.bash +++ b/plugins/available/gitstatus.plugin.bash @@ -7,16 +7,16 @@ function gitstatus_on_disable() { group 'gitstatus' unset SCM_GIT_USE_GITSTATUS - gitstatus_stop + _command_exists gitstatus_stop && gitstatus_stop } [[ "$SCM_CHECK" == "true" ]] || return # No scm-check [[ $- == *i* ]] || return # non-interactive shell -SCM_GIT_GITSTATUS_PLUGIN_SH_LOC=${SCM_GIT_GITSTATUS_PLUGIN_SH_LOC:="$HOME/gitstatus/gitstatus.plugin.sh"} -if [[ -f "${SCM_GIT_GITSTATUS_PLUGIN_SH_LOC}" ]]; then - source "${SCM_GIT_GITSTATUS_PLUGIN_SH_LOC}" +: ${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 diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 40ac5c32..f8f4705f 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -32,8 +32,8 @@ export TODO="t" # Set this to false to turn off version control status checking within the prompt for all themes export SCM_CHECK=true -# Set to actual location of gitstatus.plugin.sh if installed -#export SCM_GIT_GITSTATUS_PLUGIN_SH_LOC="$HOME/gitstatus/gitstatus.plugin.sh" +# Set to actual location of gitstatus directory if installed +#export SCM_GIT_GITSTATUS_DIR="$HOME/gitstatus" # per default gitstatus uses 2 times as many threads as CPU cores, you can change this here if you must #export GITSTATUS_NUM_THREADS=8 From a697fd2c5321069c66496ca4c3204971dddd7e5d Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Mon, 22 Jun 2020 14:48:49 +0300 Subject: [PATCH 13/13] plugins: Tidy gitstatus plugin comments and code --- plugins/available/gitstatus.plugin.bash | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/available/gitstatus.plugin.bash b/plugins/available/gitstatus.plugin.bash index 8e6558cd..98df693e 100644 --- a/plugins/available/gitstatus.plugin.bash +++ b/plugins/available/gitstatus.plugin.bash @@ -1,7 +1,6 @@ cite about-plugin 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' @@ -10,12 +9,14 @@ function gitstatus_on_disable() { _command_exists gitstatus_stop && gitstatus_stop } -[[ "$SCM_CHECK" == "true" ]] || return # No scm-check +# No scm-check +[[ $SCM_CHECK == "true" ]] || return -[[ $- == *i* ]] || return # non-interactive shell +# non-interactive shell +[[ $- == *i* ]] || return -: ${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"} -if [[ -d "${SCM_GIT_GITSTATUS_DIR}" ]]; then +: "${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