2011-03-26 18:33:59 +11:00
|
|
|
autoload zsh/terminfo
|
|
|
|
|
|
|
|
pr_reset="%f%u%k%s%b" # reset all codes
|
|
|
|
|
|
|
|
if [ "$terminfo[colors]" -eq 256 ]; then
|
|
|
|
pr_red="%F{52}"
|
|
|
|
pr_blue="%F{25}"
|
|
|
|
pr_green="%F{28}"
|
|
|
|
pr_grey="%F{59}"
|
|
|
|
else
|
|
|
|
if [ "$terminfo[colors]" -eq 8 ]; then
|
|
|
|
pr_red="%F{red}"
|
|
|
|
pr_blue="%F{blue}"
|
|
|
|
pr_green="%F{green}"
|
|
|
|
pr_grey="%B%F{black}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# VCS configuration
|
|
|
|
autoload vcs_info
|
|
|
|
zstyle ':vcs_info:*' enable git hg svn
|
|
|
|
zstyle ':vcs_info:*' get-revision true
|
2011-06-08 07:39:08 +10:00
|
|
|
zstyle ':vcs_info:*' formats "(%s) %b@%6>>%i%<<…" "%r"
|
|
|
|
zstyle ':vcs_info:*' actionformats "(%s) %b@%6>>%i%<<…|%U%a%%u"
|
2011-03-26 18:33:59 +11:00
|
|
|
zstyle ':vcs_info:*' branchformat "%b:%r"
|
|
|
|
zstyle ':vcs_info:hg*:*' use-simple true
|
|
|
|
zstyle ':vcs_info:svn:*' formats "(%s) %b:r%i" "%r"
|
|
|
|
zstyle ':vcs_info:svn:*' branchformat "%b"
|
|
|
|
|
2011-06-20 03:30:37 +10:00
|
|
|
# TODO:
|
|
|
|
# - Don't lose / at beginning of path if not in home dir
|
|
|
|
# - Discover root of repo based on full path, not basename (to avoid underlining multiple path components)
|
2011-03-26 18:33:59 +11:00
|
|
|
function prompt_pwd() {
|
|
|
|
local repo="$vcs_info_msg_1_"
|
|
|
|
|
|
|
|
parts=(${(s:/:)${${PWD}/#${HOME}/\~}})
|
|
|
|
|
|
|
|
i=0
|
|
|
|
while (( i++ < ${#parts} )); do
|
|
|
|
part="$parts[i]"
|
|
|
|
if [[ "$part" == "$repo" ]]; then
|
|
|
|
# if this part of the path represents the repo,
|
|
|
|
# underline it, and skip truncating the component
|
|
|
|
parts[i]="%U$part%u"
|
2010-06-30 14:54:06 +10:00
|
|
|
else
|
2011-03-26 18:33:59 +11:00
|
|
|
# Shorten the path as long as it isn't the last piece
|
|
|
|
if [[ "$parts[${#parts}]" != "$part" ]]; then
|
|
|
|
parts[i]="$part[1,1]"
|
|
|
|
fi
|
2010-06-30 14:54:06 +10:00
|
|
|
fi
|
2011-03-26 18:33:59 +11:00
|
|
|
done
|
2010-06-30 14:54:06 +10:00
|
|
|
|
2011-03-26 18:33:59 +11:00
|
|
|
echo "${(j:/:)parts}"
|
2010-06-30 14:54:06 +10:00
|
|
|
}
|
|
|
|
|
2011-03-26 18:33:59 +11:00
|
|
|
function precmd {
|
|
|
|
vcs_info
|
2010-06-30 14:54:06 +10:00
|
|
|
|
2011-03-26 18:33:59 +11:00
|
|
|
local cwd="$pr_blue`prompt_pwd`$pr_reset"
|
|
|
|
local char="%0(?.$pr_green.$pr_red)♪$pr_reset"
|
2011-03-26 18:51:24 +11:00
|
|
|
local time="$pr_grey⌚ %*$pr_reset"
|
2011-10-25 00:45:03 +11:00
|
|
|
|
|
|
|
local ruby
|
|
|
|
which rvm-prompt &>/dev/null && ruby="❖ `rvm-prompt`"
|
|
|
|
which rbenv &>/dev/null && ruby="❖ `rbenv version-name`"
|
2011-03-26 18:33:59 +11:00
|
|
|
|
|
|
|
local user_at_host
|
|
|
|
if [[ "$USER" != "bjeanes" ]]; then
|
|
|
|
user_at_host="$USER"
|
|
|
|
|
|
|
|
if [[ "$user" == "root" ]] then
|
2011-03-27 10:46:21 +11:00
|
|
|
user_at_host="$pr_red$user_at_host$pr_reset"
|
2010-06-30 14:54:06 +10:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-03-26 18:33:59 +11:00
|
|
|
if [[ -n "$SSH_TTY" ]]; then
|
|
|
|
user_at_host+="$pr_blue@`hostname -s`$pr_reset"
|
2010-06-30 14:54:06 +10:00
|
|
|
fi
|
2011-03-26 18:33:59 +11:00
|
|
|
|
|
|
|
local rev="$pr_grey$vcs_info_msg_0_$pr_reset"
|
2011-03-26 18:51:24 +11:00
|
|
|
rev="${rev/\(git\)/±}"
|
|
|
|
rev="${rev/\(hg\)/☿}"
|
|
|
|
rev="${rev/\(svn\)/↯}"
|
2011-03-26 18:33:59 +11:00
|
|
|
|
|
|
|
local left right
|
|
|
|
left=($user_at_host $cwd $char)
|
2011-10-25 00:45:03 +11:00
|
|
|
right=($rev $ruby $time)
|
2011-03-26 18:33:59 +11:00
|
|
|
|
|
|
|
PS1="$left [ "
|
|
|
|
RPS1="] $right"
|
2010-06-30 14:54:06 +10:00
|
|
|
}
|
|
|
|
|
2011-03-26 18:33:59 +11:00
|
|
|
|