Download:
child 66:584e8e0b08ee
parent 64:d5855dfb83d2
65:f9947eb0c34a
Anton Shestakov <engored@ya.ru>, Sat, 29 Nov 2014 13:38:16 +0800
Use upsearch for detecting if pwd is tracked

1 файлов изменено, 14 вставок(+), 19 удалений(-) [+]
.bash_prompt file | annotate | diff | comparison | revisions
--- a/.bash_prompt Wed Nov 12 21:39:50 2014 +0800
+++ b/.bash_prompt Sat Nov 29 13:38:16 2014 +0800
@@ -38,25 +38,16 @@
else
local PROMPT_COLOR="$G"
- # testing if current dir is a part of hg/git repo
- local TEST_DIR="$PWD"
-
- while true ; do
- [[ -d "$TEST_DIR/.hg" ]] && local HG_TRACKED=1 && break
- [[ -d "$TEST_DIR/.git" ]] && local GIT_TRACKED=1 && break
- [[ "$TEST_DIR" == '/' ]] && break
- TEST_DIR=$(dirname "$TEST_DIR")
- done
-
- local HG_INFO=
- if [[ $HG_TRACKED ]] ; then
- _set_hg_info
- fi
-
- local GIT_INFO=
- if [[ $GIT_TRACKED ]] ; then
- _set_git_info
- fi
+ case "$(_upsearch)" in
+ 'hg')
+ local HG_INFO=
+ _set_hg_info
+ ;;
+ 'git')
+ local GIT_INFO=
+ _set_git_info
+ ;;
+ esac
fi
if [[ $VIRTUAL_ENV ]] ; then
@@ -69,6 +60,10 @@
${PROMPT_COLOR}\\\$${RESET} "
}
+function _upsearch {
+ test "$PWD" == '/' && return || test -e '.hg' && echo 'hg' && return || test -e '.git' && echo 'git' && return || cd .. && _upsearch
+}
+
function _set_hg_info {
if [[ $USE_HG_PROMPT ]] ; then
local PROMPT_TEMPLATE="${P}{branch|quiet}{${Rd}{closed}}${P}☿{rev}{${B}+{tags|quiet|+}}{${Gd}*{bookmark}}{${R}{update}}{${G}+{rev|merge}}${R}{status|modified}${RESET}"