Different prompt mark for different VCS (±, ☿, ‡)

± for git directories, ☿ for mercurial, ‡ for svn.
Thus, do not display the now useless letter prefix before the branch name.
Refactor the smart mark function.
This commit is contained in:
nojhan 2012-08-10 14:40:50 +02:00
parent 8fd5c95409
commit 0943eb67a9
2 changed files with 21 additions and 20 deletions

View File

@ -24,7 +24,7 @@ in a git repository on a server, at branch "myb":
A liquid prompt displaying everything may look like this: A liquid prompt displaying everything may look like this:
`⌁24% ⌂42% 3d/2&/1z [user@server:~/ … /code/liquidprompt]↥ master(+10/-5,3) 125 ± ` `⌁24% ⌂42% 3d/2&/1z [user@server:~/ … /code/liquidprompt]↥ master(+10/-5,3) 125 ± `
It displays: It displays:
@ -52,7 +52,8 @@ there is changes, in yellow if there is pending commits to push;
* the number of added/deleted lines, if changes have been made and the number * the number of added/deleted lines, if changes have been made and the number
of pending commits, if any; of pending commits, if any;
* the error code of the last command, if it has failed in some way; * the error code of the last command, if it has failed in some way;
* a smart mark: ± for VCS directories, $ for simple user, a red # for root. * a smart mark: ± for git directories, ☿ for mercurial, ‡ for svn, $ for simple
user, a red # for root.
You can temporarily deactivate the liquid prompt and come back to your previous You can temporarily deactivate the liquid prompt and come back to your previous
one by typing `prompt_off`. Use `prompt_on` to bring it back. one by typing `prompt_off`. Use `prompt_on` to bring it back.

View File

@ -502,7 +502,7 @@ __git_branch_color()
ret="${GREEN}${branch}${NO_COL}" # nothing to commit or push ret="${GREEN}${branch}${NO_COL}" # nothing to commit or push
fi fi
fi fi
echo -ne "$ret" echo -ne "$ret"
fi fi
} }
@ -532,7 +532,7 @@ __hg_branch_color()
else else
ret="${RED}${branch}${NO_COL}" # changes to commit ret="${RED}${branch}${NO_COL}" # changes to commit
fi fi
echo -ne "$ret" echo -ne "$ret"
fi fi
} }
@ -573,7 +573,7 @@ __svn_branch_color()
else else
ret="${RED}${branch}${NO_COL}(${YELLOW}$commits${NO_COL})" # changes to commit ret="${RED}${branch}${NO_COL}(${YELLOW}$commits${NO_COL})" # changes to commit
fi fi
echo -ne "$ret" echo -ne "$ret"
fi fi
} }
@ -675,24 +675,24 @@ __load_color()
# DESIGN # # DESIGN #
########## ##########
# Set the prompt mark to ± if VCS, # if root and else $ # Set the prompt mark to ± if git, to ☿ if mercurial, to ‡ if subversion
# FIXME use the mercury unicode char for mercurial # to # if root and else $
__smart_mark() __smart_mark()
{ {
if [[ "$EUID" -ne "0" ]] local COL=${BOLD_FG}
then if [[ "$EUID" -eq "0" ]] ; then
if [[ ! -z $(__git_branch) ]] || [[ ! -z $(__hg_branch) ]] || [[ ! -z $(__svn_branch) ]] ; then COL=${BOLD_RED}
echo -ne "${BOLD_FG}±${NO_COL}"
else
echo -ne "${BOLD_FG}\\\$${NO_COL}"
fi
else
if [[ ! -z $(__git_branch) ]] || [[ ! -z $(__hg_branch) ]] || [[ ! -z $(__svn_branch) ]] ; then
echo -ne "${BOLD_RED}±${NO_COL}"
else
echo -ne "${BOLD_RED}#${NO_COL}"
fi fi
local mark="\\\$"
if [[ ! -z $(__git_branch) ]] ; then
mark="±"
elif [[ ! -z $(__hg_branch) ]] ; then
mark="☿"
elif [[ ! -z $(__svn_branch) ]] ; then
mark="‡"
fi fi
echo -ne "${COL}${mark}${NO_COL}"
} }
# insert a space on the right # insert a space on the right