Skip to content

Instantly share code, notes, and snippets.

@cat-in-136
Created August 26, 2012 07:39
Show Gist options
  • Save cat-in-136/3475756 to your computer and use it in GitHub Desktop.
Save cat-in-136/3475756 to your computer and use it in GitHub Desktop.
my simplevcs prompt theme for zsh
# Written by @cat_in_136
#
prompt_simplevcs_help() {
cat <<'EOF'
This prompt is color-scheme-able. You can invoke it thus:
prompt simplevcs [<color1> [<color2> [<color3> [<color4> [<check4changes]]]]]
<color1> the right prompt color.
<color2> the left prompt color.
<color3> the right prompt color about VCS information.
<color4> the alternate color of <color3>.
<check4changes> specify true if you want to check for changes.
EOF
}
prompt_simplevcs_setup () {
local rpc=${1:-'blue'}
local lpc=${2:-${${SSH_CLIENT+'blue'}:-'default'}}
local vcspc=${3:-'green'}
local vcsapc=${4:-'red'}
local check4changes=${5:-'false'}
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git svn hg
zstyle ':vcs_info:*' formats "%s\n%b\n%c%u\n"
zstyle ':vcs_info:*' actionformats "%s\n%b\n%c%u\n%a"
zstyle ':vcs_info:(svn|bzr):*' branchformat '%b:r%r'
zstyle ':vcs_info:bzr:*' use-simple true
autoload -Uz is-at-least
if is-at-least 4.3.10; then
zstyle ':vcs_info:(hg*|git*):*' check-for-changes $check4changes
fi
PS1="%b%F{$lpc}[%U%n@%m%u]%B%(!.#.\$) %b%f"
PS2='%_> '
local rpc_spwd="%(7~,%-3~/.../%3~,%~)"
local vcs_branch="%2v%4(v|-%F{$vcsapc}%4v%F{$vcspc}|)"
local vcs_status="%3(v|%F{$vcsapc}%B%3v%b%F{$vcspc}|)"
local vcs_info="%F{$vcspc}($vcs_branch)$vcs_status"
RPROMPT="%b%F{$rpc}$rpc_spwd%1(v| $vcs_info|)%b%f"
prompt_opts=( cr percent )
precmd () {
LANG=C vcs_info
if [ -n "$vcs_info_msg_0_" ]; then
local -a vcsinfo
vcsinfo=( ${(s.\n.)vcs_info_msg_0_} )
psvar=(
$vcsinfo[1] # %s
$vcsinfo[2] # %b
$vcsinfo[3] # %c%u
$vcsinfo[4] # %a
)
if [[ "$vcsinfo[1]" = "git" ]]; then
local head="$(LANG=C git rev-parse --verify -q HEAD 2>/dev/null)"
if [[ $? -eq 0 ]]; then
if [[ -n "$head" ]]; then
local remotes_matches="$(LANG=C git rev-parse --remotes 2>/dev/null | grep $head)"
if [[ -n "$remotes_matches" ]]; then
:
else
psvar[3]+="P"
fi
fi
fi
fi
else
psvar=()
fi
}
preexec () { }
}
prompt_simplevcs_preview (){
prompt_preview_theme simplevcs
}
prompt_simplevcs_setup "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment