2011-03-26 18:33:59 +11:00
|
|
|
pr_reset="%f%u%k%s%b" # reset all codes
|
|
|
|
|
2013-03-10 16:41:24 +11:00
|
|
|
pr_red="%F{red}"
|
|
|
|
pr_blue="%F{blue}"
|
|
|
|
pr_green="%F{green}"
|
|
|
|
pr_grey="%B%F{black}"
|
|
|
|
|
|
|
|
if [ "$(tput colors 2>/dev/null)" -eq 256 ]; then
|
2011-03-26 18:33:59 +11:00
|
|
|
pr_red="%F{52}"
|
2017-04-02 10:18:23 +10:00
|
|
|
pr_blue="%F{33}"
|
2011-03-26 18:33:59 +11:00
|
|
|
pr_green="%F{28}"
|
|
|
|
pr_grey="%F{59}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# VCS configuration
|
|
|
|
autoload vcs_info
|
|
|
|
zstyle ':vcs_info:*' enable git hg svn
|
|
|
|
zstyle ':vcs_info:*' get-revision true
|
2011-10-25 00:59:32 +11:00
|
|
|
zstyle ':vcs_info:*' formats "(%s) %b@%6>>%i%<<…" "%r" "%R" "%S"
|
2011-06-08 07:39:08 +10:00
|
|
|
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:
|
2011-10-25 00:59:32 +11:00
|
|
|
# - Discover root of repo based on full path, not basename (to avoid underlining multiple path components) ($vcs_info_msg_2_)
|
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-10-25 01:04:55 +11:00
|
|
|
local prompt_path="${(j:/:)parts}"
|
|
|
|
if [ "$parts[1]" != "~" ]; then
|
|
|
|
prompt_path="/$prompt_path"
|
|
|
|
fi
|
|
|
|
echo "$prompt_path"
|
2010-06-30 14:54:06 +10:00
|
|
|
}
|
|
|
|
|
2011-10-25 04:19:20 +11:00
|
|
|
|
|
|
|
function prompt_pwd_new() {
|
|
|
|
local parts path part cwd i=0
|
|
|
|
typeset -L path
|
|
|
|
|
|
|
|
|
|
|
|
parts=(${(s:/:)${${PWD}/#${HOME}/\~}})
|
|
|
|
|
|
|
|
while (( i++ < ${#parts} )); do
|
|
|
|
part="$parts[i]"
|
|
|
|
|
|
|
|
if [[ "$part" == "~" ]]; then
|
|
|
|
path="$part"
|
|
|
|
else
|
|
|
|
# This check is broken because LHS is collapsed, RHS is expanded
|
|
|
|
if [[ "$path/$part" == "${vcs_info_msg_2_/#${HOME}/~}" ]]; then
|
|
|
|
part="%U$part%u"
|
|
|
|
elif [[ "$parts[${#parts}]" != "$part" ]]; then
|
|
|
|
part="$part[1,1]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
path="$path/$part"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
# else
|
|
|
|
# # Shorten the path as long as it isn't the last piece
|
|
|
|
# if [[ "$parts[${#parts}]" != "$part" ]]; then
|
|
|
|
# parts[i]="$part[1,1]"
|
|
|
|
# fi
|
|
|
|
# fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$path"
|
|
|
|
}
|
|
|
|
|
2015-08-07 15:18:26 +10:00
|
|
|
function default_precmd {
|
|
|
|
if [ -z $INSIDE_EMACS ]; then
|
|
|
|
vcs_info
|
|
|
|
|
|
|
|
local cwd="$pr_blue`prompt_pwd`$pr_reset"
|
|
|
|
local char="%0(?.$pr_green.$pr_red)♪$pr_reset"
|
|
|
|
# local time="$pr_grey⌚ %*$pr_reset"
|
|
|
|
|
|
|
|
local ruby
|
|
|
|
ruby="$(current_ruby)"
|
|
|
|
[ "x$ruby" != "x" ] && ruby="❖ $ruby"
|
|
|
|
|
|
|
|
local rev="$pr_grey$vcs_info_msg_0_$pr_reset"
|
|
|
|
rev="${rev/\(git\)/±}"
|
|
|
|
rev="${rev/\(hg\)/☿}"
|
|
|
|
rev="${rev/\(svn\)/↯}"
|
|
|
|
|
|
|
|
local left right
|
|
|
|
left=($(user_at_host) $cwd $char)
|
|
|
|
right=($rev $ruby $time)
|
|
|
|
|
|
|
|
PS1="$left "
|
|
|
|
RPS1=" $right"
|
|
|
|
else
|
|
|
|
PS1="$ "
|
|
|
|
RPS1=""
|
|
|
|
fi
|
|
|
|
}
|
2011-03-26 18:33:59 +11:00
|
|
|
|
2015-08-07 15:18:26 +10:00
|
|
|
function precmd {
|
|
|
|
default_precmd
|
2010-06-30 14:54:06 +10:00
|
|
|
}
|