Created
February 13, 2010 23:08
-
-
Save julian7/303717 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setopt prompt_subst | |
chpwd_functions=('__set_current_git_branch' ${chpwd_functions:#__set_current_git_branch}) | |
preexec_functions=('__force_update_git_vars' ${precmd_functions:#__force_update_git_vars}) | |
precmd_functions=('__update_git_vars' ${precmd_functions:#__update_git_vars}) | |
function __force_update_git_vars() { | |
case "$1" in | |
*git*) | |
# delay setting prompt until next precmd hook | |
export __update_git_vars=1 | |
;; | |
esac | |
} | |
function __update_git_vars() { | |
if test -n "$__update_git_vars"; then | |
__set_current_git_branch | |
unset __update_git_vars | |
fi | |
} | |
function __set_current_git_branch() { | |
export __CURRENT_GIT_BRANCH="$(git branch --no-color 2>/dev/null | sed -n 's/^\* \(.*\)/\1/p')" | |
} | |
function __git_prompt_info() { | |
if [ -n "$__CURRENT_GIT_BRANCH" ]; then | |
printf "$1" "$__CURRENT_GIT_BRANCH" | |
fi | |
} | |
export __update_git_vars=1 | |
#export PROMPT='%n@%m:%c$(__git_prompt_info " [%s]")%# ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment