Created
May 31, 2012 20:13
-
-
Save kljensen/2845911 to your computer and use it in GitHub Desktop.
Kyle's zsh prompt (pilfered from others)
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
autoload -Uz vcs_info | |
zstyle ':vcs_info:*' check-for-changes true | |
zstyle ':vcs_info:*' enable git svn hg | |
### git: Show marker (T) if there are untracked files in repository | |
# Make sure you have added staged to your 'formats': %c | |
function +vi-git-untracked(){ | |
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \ | |
git status --porcelain | grep '??' &> /dev/null ; then | |
# This will show the marker if there are any untracked files in repo. | |
# If instead you want to show the marker only if there are untracked | |
# files in $PWD, use: | |
#[[ -n $(git ls-files --others --exclude-standard) ]] ; then | |
hook_com[unstaged]+='%B%F{magenta}?%f%b' | |
fi | |
} | |
### git: Show +N/-N when your local branch is ahead-of or behind remote HEAD. | |
# Make sure you have added misc to your 'formats': %m | |
function +vi-git-aheadbehind() { | |
local ahead behind | |
local -a gitstatus | |
# for git prior to 1.7 | |
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l) | |
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l | sed "s/ //g") | |
(( $ahead )) && gitstatus+=( "%B%F{blue}+${ahead}%f%b" ) | |
# for git prior to 1.7 | |
# behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l) | |
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l | sed "s/ //g") | |
(( $behind )) && gitstatus+=( "%B%F{red}-${behind}%f%b" ) | |
hook_com[misc]+=${(j::)gitstatus} | |
} | |
### git: Show remote branch name for remote-tracking branches | |
# Make sure you have added staged to your 'formats': %b | |
function +vi-git-remotebranch() { | |
local remote | |
# Are we on a remote-tracking branch? | |
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \ | |
--symbolic-full-name 2>/dev/null)/refs\/remotes\/} | |
# The first test will show a tracking branch whenever there is one. The | |
# second test, however, will only show the remote branch's name if it | |
# differs from the local one. | |
#if [[ -n ${remote} ]] ; then | |
if [[ -n ${remote} && ${remote#*/} != ${hook_com[branch]} ]] ; then | |
hook_com[branch]="${hook_com[branch]}(%F{cyan}${remote}%f)" | |
fi | |
} | |
function precmd { | |
pyenv="py:sys" | |
rbenv="rb:sys" | |
if [ -n "${VIRTUAL_ENV+x}" ]; then | |
# You should probably set export VIRTUAL_ENV_DISABLE_PROMPT=1 | |
# somewhere else, otherwise virtualenv will mess w/ your prompt. | |
pyenv=`basename $VIRTUAL_ENV` | |
pyenv="py:$pyenv" | |
fi | |
# Test if we're in an rvm environment | |
if [ -n "${MY_RUBY_HOME+x}" ]; then | |
rbenv=`basename $GEM_HOME` | |
rbenv="rb:$rbenv" | |
fi | |
venv="" | |
venv="${pyenv} ${rbenv}" | |
# zstyle ':vcs_info:git*' formats "%{$fg[blue]%}%b%{$reset_color%} %{$fg[red]%}%m%u%c%{$reset_color%}" | |
# zstyle ':vcs_info:*' stagedstr "%{$fg[green]%}S●%{$reset_color%}" | |
# zstyle ':vcs_info:*' unstagedstr "%{$fg[red]%}U●%{$reset_color%}" | |
zstyle ':vcs_info:git*' formats "%{$fg[blue]%}%b%{$reset_color%} %m%u%c%{$reset_color%}" | |
zstyle ':vcs_info:*' stagedstr '%B%F{green}$%f%b' | |
zstyle ':vcs_info:*' unstagedstr '%B%F{yellow}!%f%b' | |
zstyle ':vcs_info:*' formats '%c%u%b%m ' | |
zstyle ':vcs_info:*' actionformats '%c%u%b%m %B%s-%a%%b ' | |
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-aheadbehind git-remotebranch | |
vcs_info | |
if [ x"$vcs_info_msg_0_" = x ]; then | |
PR_APM='%%' | |
else | |
PR_APM='$vcs_info_msg_0_' | |
fi | |
local TERMWIDTH | |
(( TERMWIDTH = ${COLUMNS} - 1 )) | |
### | |
# Truncate the path if it's too long. | |
PR_FILLBAR="" | |
PR_PWDLEN="" | |
local promptsize=${#${(%):---(%n@%m)---()--}} | |
local promptsize=${#${(%):---($venv)---()--}} | |
local pwdsize=${#${(%):-%~}} | |
if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then | |
((PR_PWDLEN=$TERMWIDTH - $promptsize)) | |
else | |
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}" | |
fi | |
} | |
setopt extended_glob | |
preexec () { | |
if [[ "$TERM" == "screen" ]]; then | |
local CMD=${1[(wr)^(*=*|sudo|-*)]} | |
echo -n "\ek$CMD\e\\" | |
fi | |
} | |
setprompt () { | |
### | |
# Need this so the prompt will work. | |
setopt prompt_subst | |
### | |
# See if we can use colors. | |
autoload colors zsh/terminfo | |
if [[ "$terminfo[colors]" -ge 8 ]]; then | |
colors | |
fi | |
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do | |
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}' | |
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}' | |
(( count = $count + 1 )) | |
done | |
PR_NO_COLOUR="%{$terminfo[sgr0]%}" | |
### | |
# See if we can use extended characters to look nicer. | |
typeset -A altchar | |
set -A altchar ${(s..)terminfo[acsc]} | |
PR_SET_CHARSET="%{$terminfo[enacs]%}" | |
PR_SHIFT_IN="%{$terminfo[smacs]%}" | |
PR_SHIFT_OUT="%{$terminfo[rmacs]%}" | |
PR_HBAR=${altchar[q]:--} | |
PR_ULCORNER=${altchar[l]:--} | |
PR_LLCORNER=${altchar[m]:--} | |
PR_LRCORNER=${altchar[j]:--} | |
PR_URCORNER=${altchar[k]:--} | |
### | |
# Decide if we need to set titlebar text. | |
case $TERM in | |
xterm*) | |
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}' | |
;; | |
screen) | |
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}' | |
;; | |
*) | |
PR_TITLEBAR='' | |
;; | |
esac | |
### | |
# Decide whether to set a screen title | |
if [[ "$TERM" == "screen" ]]; then | |
PR_STITLE=$'%{\ekzsh\e\\%}' | |
else | |
PR_STITLE='' | |
fi | |
### | |
# Finally, the prompt. | |
# $PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@%m\ | |
PROMPT=' | |
$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\ | |
$PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ | |
$PR_MAGENTA${(e)venv}$PR_MAGENTA\ | |
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ | |
$PR_MAGENTA%$PR_PWDLEN<...<%~%<<\ | |
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\ | |
$PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ | |
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\ | |
$PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@%m\ | |
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_NO_COLOUR ' | |
RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ | |
$PR_YELLOW\ | |
${(e)PR_APM}\ | |
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR' | |
PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\ | |
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR ' | |
} | |
setprompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment