zsh/prompt_fresh_setup

50 lines
963 B
Bash

visible_length() {
echo $(( ${#${(S%%)1//(\%(KF1]|)\{*\}|\%[Bbkf])}} ))
}
prompt_fresh_setup() {
autoload -U add-zsh-hook
add-zsh-hook precmd fresh_precmd
if [ "$USERNAME" = "root" ]; then
local user="%{%F{9}%}%n%{%f%}"
else
local user="%{%F{35}%}%n%{%f%}"
fi
if [ "$SSH_CONNECTION" != "" ]; then
local user="%{%F{35}%}$user%{%f%}@%{%F{244}%}%M%{%f%}"
fi
local length=`visible_length "$user"`
PS1="«$user» "
PS2="${(l:$length + 1:: :)}» "
# TODO: RPS1
prompt_opts=(cr sp subst percent)
}
fresh_precmd() {
local exit_code=$?
if [[ $exit_code -ne 0 ]]; then
local result="%{%B%F{1}%}$exit_code%{%f%b%}"
fi
local time_stamp="%{%F{244}%}%D{%H:%M:%S}%{%f%}"
local directory="%{%F{37}%}%~%{%f%}"
# TODO: git status
local line="$time_stamp $directory"
local length=`visible_length "$line$result"`
print -P "$line${(l:COLUMNS - $length - 1:: :)}$result"
}
prompt_fresh_setup "$@"
# vim:ft=zsh