--- a/.bash_prompt Thu Sep 04 20:26:57 2014 +0900
+++ b/.bash_prompt Fri Sep 05 02:02:01 2014 +0900
[[ "$TEST_DIR" == '/' ]] && break
TEST_DIR=$(dirname "$TEST_DIR")
- if [[ $HG_TRACKED && $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}"
- local HG_INFO=" $(hg prompt $PROMPT_TEMPLATE)"
+ if [[ $HG_TRACKED ]] ; then
- if [[ $HG_TRACKED && ! $USE_HG_PROMPT ]] ; then
- local SUM=$(LC_ALL=C hg sum 2>/dev/null)
- local PARENTS=($(grep -Po '(?<=parent: ).*(?=:)' <<< "$SUM"))
- local BRANCH=$(grep -Po '(?<=branch: ).*$' <<< "$SUM")
- local COMMIT=$(grep -Po '(?<=commit: ).*$' <<< "$SUM")
- local UPDATE=$(grep -Po '(?<=update: ).*$' <<< "$SUM")
- local REV=${PARENTS[0]}
- local MERGEREV=${PARENTS[1]}
- BRANCH=${BRANCH/default/}
- [ -z "$MERGEREV" ] || MERGEREV="+$MERGEREV"
- *added*|*modified*|*deleted*)
- local HG_INFO=" ${P}${BRANCH}☿${REV}${R}${UPDATE}${G}${MERGEREV}${R}${COMMIT}${RESET}"
if [[ $GIT_TRACKED ]] ; then
- local GIT_STATUS=$(LC_ALL=C git status 2>/dev/null)
- local GIT_BRANCH=$(grep -Po '(?<=On branch ).*$' <<< "$GIT_STATUS")
- local GIT_REV=$(LC_ALL=C git rev-parse --short HEAD 2>/dev/null)
- if [[ $GIT_STATUS == *'Your branch is behind'* ]] ; then
- [[ $GIT_STATUS =~ behind[^$'\n']+([0-9]+)' 'commit ]] && GIT_BEHIND+=${BASH_REMATCH[1]}
- if [[ $GIT_STATUS == *'Your branch is ahead'* ]] ; then
- [[ $GIT_STATUS =~ ahead[^$'\n']+([0-9]+)' 'commit ]] && GIT_AHEAD+=${BASH_REMATCH[1]}
- if [[ $GIT_STATUS == *'Changes to be committed'* ]] ; then
- if [[ $GIT_STATUS == *'Changes not staged'* ]] ; then
- local GIT_UNSTAGED="$P?"
- local GIT_INFO=" ${G}${GIT_BRANCH}±${GIT_REV}${GIT_BEHIND}${GIT_AHEAD}${GIT_STAGED}${GIT_UNSTAGED}${RESET}"
${PROMPT_COLOR}\\\$${RESET} "
+ 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}"
+ HG_INFO=" $(hg prompt $PROMPT_TEMPLATE)"
+ local SUM=$(LC_ALL=C hg sum 2>/dev/null)
+ local PARENTS=($(grep -Po '(?<=parent: ).*(?=:)' <<< "$SUM"))
+ local BRANCH=$(grep -Po '(?<=branch: ).*$' <<< "$SUM")
+ local COMMIT=$(grep -Po '(?<=commit: ).*$' <<< "$SUM")
+ local UPDATE=$(grep -Po '(?<=update: ).*$' <<< "$SUM")
+ local REV=${PARENTS[0]}
+ local MERGEREV=${PARENTS[1]}
+ BRANCH=${BRANCH/default/}
+ [ -z "$MERGEREV" ] || MERGEREV="+$MERGEREV"
+ *added*|*modified*|*deleted*)
+ HG_INFO=" ${P}${BRANCH}☿${REV}${R}${UPDATE}${G}${MERGEREV}${R}${COMMIT}${RESET}"
+function _set_git_info {
+ local STATUS=$(LC_ALL=C git status 2>/dev/null)
+ local BRANCH=$(grep -Po '(?<=On branch ).*$' <<< "$STATUS")
+ local REV=$(LC_ALL=C git rev-parse --short HEAD 2>/dev/null)
+ if [[ $STATUS == *'Your branch is behind'* ]] ; then
+ [[ $STATUS =~ behind[^$'\n']+([0-9]+)' 'commit ]] && BEHIND+=${BASH_REMATCH[1]}
+ if [[ $STATUS == *'Your branch is ahead'* ]] ; then
+ [[ $STATUS =~ ahead[^$'\n']+([0-9]+)' 'commit ]] && AHEAD+=${BASH_REMATCH[1]}
+ if [[ $STATUS == *'Changes to be committed'* ]] ; then
+ if [[ $STATUS == *'Changes not staged'* ]] ; then
+ GIT_INFO=" ${G}${BRANCH}±${P}${REV}${BEHIND}${AHEAD}${STAGED}${UNSTAGED}${RESET}"
# first find prompt in hgrc, then check it's actually enabled
if grep -w '^prompt' ~/.hgrc &>/dev/null && hg help prompt &>/dev/null ; then