dotfiles/zsh/theme.zsh

82 lines
2 KiB
Bash
Raw Normal View History

2018-08-23 17:25:14 +00:00
#!/usr/bin/env zsh
configure_dircolors() {
[[ -f ~/.dircolors ]] && eval "$(dircolors ~/.dircolors)"
[[ -z "$LS_COLORS" ]] && eval "$(dircolors -b)"
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
}
2019-08-06 12:20:57 +00:00
prompt_escape() {
echo "${@//'%'/%%}"
}
prompt_preexec_hook() {
typeset -gF _PROMPT_EXEC_START_TIME="$EPOCHREALTIME"
}
prompt_precmd_hook() {
if [[ -v _PROMPT_EXEC_START_TIME ]]; then
local -F duration="$((EPOCHREALTIME - _PROMPT_EXEC_START_TIME))"
unset _PROMPT_EXEC_START_TIME
if (( duration > 1 )); then
local -i t="$duration" d h m s
typeset -g _PROMPT_EXEC_TIME=""
d="$((t/60/60/24))"
h="$((t/60/60%24))"
m="$((t/60%60))"
s="$((t%60))"
(( d > 0 )) && _PROMPT_EXEC_TIME+="${d}d"
(( h > 0 )) && _PROMPT_EXEC_TIME+="${h}h"
(( m > 0 )) && _PROMPT_EXEC_TIME+="${m}m"
_PROMPT_EXEC_TIME+="${s}s"
else
unset _PROMPT_EXEC_TIME
fi
fi
}
2019-08-06 12:20:57 +00:00
prompt_vcs_info() {
if [[ $(command git rev-parse --is-inside-work-tree) != true ]]; then
return
fi
local branch="(no branches)" line
git branch | while IFS= read -r line; do
if [[ "$line" == "* "* ]]; then
branch="${line#\* }"
break
fi
done
print -n ' %F{blue}git:(%F{magenta}'"$(prompt_escape "$branch")"'%F{blue})%f'
}
setup_prompt() {
setopt nopromptbang promptcr promptsp promptpercent promptsubst
zmodload zsh/datetime
2019-08-04 17:22:07 +00:00
autoload -Uz add-zsh-hook
add-zsh-hook preexec prompt_preexec_hook
add-zsh-hook precmd prompt_precmd_hook
PROMPT='%F{8}┌─%f%B'
PROMPT+='%F{%(!.red.yellow)}%n%f'
PROMPT+=' at %F{${SSH_CONNECTION:+blue}${SSH_CONNECTION:-green}}%m%f'
PROMPT+=' in %F{cyan}%~%f'
2019-08-06 12:20:57 +00:00
PROMPT+='$(prompt_vcs_info 2>/dev/null)'
PROMPT+=' '
2019-08-06 12:20:57 +00:00
PROMPT+='${_PROMPT_EXEC_TIME:+" %F{yellow}$(prompt_escape "$_PROMPT_EXEC_TIME")%f"}'
PROMPT+='%(?.. %F{red}EXIT:%?%f)'
PROMPT+='%1(j. %F{blue}JOBS:%j%f.)'
PROMPT+=$'\n'
PROMPT+='%b%F{8}└─%f'
PROMPT+='%F{%(?.green.red)}%(!.#.\$)%f '
2019-07-29 12:30:37 +00:00
PROMPT2=' %_> '
}
2018-08-23 17:25:14 +00:00
configure_dircolors
setup_prompt