diff options
author | Robby Russell <robby@planetargon.com> | 2013-12-02 22:49:08 -0800 |
---|---|---|
committer | Robby Russell <robby@planetargon.com> | 2013-12-02 22:49:08 -0800 |
commit | 3d6f9d78c5a2335751d2980919ef1a067dbda9e2 (patch) | |
tree | 5bed72d1de3057f9cade62313a31ecc53f4111fc /plugins/git-prompt/git-prompt.plugin.zsh | |
parent | 7f3e56f8d6fc354de6e665a739b2ab4ba4f84372 (diff) | |
parent | e5f77b8f0496e5915383f2f456f91a20f5ff4ace (diff) | |
download | zsh-3d6f9d78c5a2335751d2980919ef1a067dbda9e2.tar.gz zsh-3d6f9d78c5a2335751d2980919ef1a067dbda9e2.tar.bz2 zsh-3d6f9d78c5a2335751d2980919ef1a067dbda9e2.zip |
Merge pull request #306 from jtriley/git-prompt
add git-prompt plugin from olivierverdier/zsh-git-prompt
Diffstat (limited to 'plugins/git-prompt/git-prompt.plugin.zsh')
-rw-r--r-- | plugins/git-prompt/git-prompt.plugin.zsh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh new file mode 100644 index 000000000..01b8a88d9 --- /dev/null +++ b/plugins/git-prompt/git-prompt.plugin.zsh @@ -0,0 +1,60 @@ +# ZSH Git Prompt Plugin from: +# http://github.com/olivierverdier/zsh-git-prompt +# +export __GIT_PROMPT_DIR=$ZSH/plugins/git-prompt +# Initialize colors. +autoload -U colors +colors + +# Allow for functions in the prompt. +setopt PROMPT_SUBST + +## Enable auto-execution of functions. +typeset -ga preexec_functions +typeset -ga precmd_functions +typeset -ga chpwd_functions + +# Append git functions needed for prompt. +preexec_functions+='preexec_update_git_vars' +precmd_functions+='precmd_update_git_vars' +chpwd_functions+='chpwd_update_git_vars' + +## Function definitions +function preexec_update_git_vars() { + case "$2" in + git*) + __EXECUTED_GIT_COMMAND=1 + ;; + esac +} + +function precmd_update_git_vars() { + if [ -n "$__EXECUTED_GIT_COMMAND" ]; then + update_current_git_vars + unset __EXECUTED_GIT_COMMAND + fi +} + +function chpwd_update_git_vars() { + update_current_git_vars +} + +function update_current_git_vars() { + unset __CURRENT_GIT_STATUS + + local gitstatus="$__GIT_PROMPT_DIR/gitstatus.py" + _GIT_STATUS=`python ${gitstatus}` + __CURRENT_GIT_STATUS=("${(f)_GIT_STATUS}") +} + +function prompt_git_info() { + if [ -n "$__CURRENT_GIT_STATUS" ]; then + echo "(%{${fg[red]}%}$__CURRENT_GIT_STATUS[1]%{${fg[default]}%}$__CURRENT_GIT_STATUS[2]%{${fg[magenta]}%}$__CURRENT_GIT_STATUS[3]%{${fg[default]}%})" + fi +} + +# Set the prompt. +#PROMPT='%B%m%~%b$(prompt_git_info) %# ' +# for a right prompt: +#RPROMPT='%b$(prompt_git_info)' +RPROMPT='$(prompt_git_info)' |