zsh/prompt_fresh_setup

46 lines
939 B
Bash

prompt_fresh_setup() {
autoload -U add-zsh-hook
add-zsh-hook precmd prompt_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
PS1="«$user» "
# TODO: PS2
# TODO: PS3
# TODO: PS4
# TODO: RPS1
prompt_opts=(cr subst percent)
}
prompt_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"
visible_length() { echo $(( ${#${(S%%)1//(\%(KF1]|)\{*\}|\%[Bbkf])}} )) }
local length=`visible_length "$line$result"`
print -P "$line${(l:COLUMNS - $length - 1:: :)}$result"
}
prompt_fresh_setup "$@"
# vim:ft=zsh