-
-
Save diffshare/3476383 to your computer and use it in GitHub Desktop.
my simplevcs prompt theme for zsh
This file contains hidden or 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
# Original Written by @cat_in_136 | |
# https://gist.github.com/3475756 | |
# Very Thanks! | |
# | |
# prompt_simplevcs_setup for zsh | |
# forked by @diffshare | |
# | |
# 2012-08-26 18:00 @diffshare | |
# * disable: svn hg | |
# * use add-zsh-hook | |
# * add: "unstage" and "stage" state | |
# * change form psvar[3] | |
# * check-for-changes: default true | |
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 false 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:-'true'} | |
autoload -Uz vcs_info | |
zstyle ':vcs_info:*' enable git | |
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 | |
zstyle ':vcs_info:git:*' unstagestr "<U>" | |
zstyle ':vcs_info:git:*' stagestr "<S>" | |
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 ) | |
add-zsh-hook precmd prompt_simplevcs_precmd | |
prompt_simplevcs_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 | |
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 | |
psvar[3]="<$psvar[3]>" | |
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