From 4c0a51aee25238f8db32271a51958f2cf358ef80 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 15 Jul 2019 09:31:16 -0300 Subject: [PATCH] Optimize SCM checks --- themes/base.theme.bash | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 430fb60d..e172dd0c 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -79,15 +79,20 @@ RBENV_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' +GIT_EXE=`which git 2> /dev/null || true` +P4_EXE=`which p4 2> /dev/null || true` +HG_EXE=`which hg 2> /dev/null || true` +SVN_EXE=`which svn 2> /dev/null || true` + function scm { if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE - elif [[ -f .git/HEAD ]] && which git &> /dev/null; then SCM=$SCM_GIT - elif which git &> /dev/null && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT - elif which p4 &> /dev/null && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM=$SCM_P4 - elif [[ -d .hg ]] && which hg &> /dev/null; then SCM=$SCM_HG - elif which hg &> /dev/null && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG - elif [[ -d .svn ]] && which svn &> /dev/null; then SCM=$SCM_SVN - elif which svn &> /dev/null && [[ -n "$(svn info --show-item wc-root 2>/dev/null)" ]]; then SCM=$SCM_SVN + elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT + elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT + elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM=$SCM_P4 + elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG + elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG + elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then SCM=$SCM_SVN + elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2>/dev/null)" ]]; then SCM=$SCM_SVN else SCM=$SCM_NONE fi } @@ -503,4 +508,4 @@ function safe_append_prompt_command { function _save-and-reload-history() { local autosave=${1:-0} [[ $autosave -eq 1 ]] && history -a && history -c && history -r -} \ No newline at end of file +}