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 "${@//'%'/%%}"
|
|
|
|
}
|
|
|
|
|
2019-07-13 18:35:34 +00:00
|
|
|
prompt_preexec_hook() {
|
2019-08-04 08:42:18 +00:00
|
|
|
typeset -gF _PROMPT_EXEC_START_TIME="$EPOCHREALTIME"
|
2019-07-13 18:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prompt_precmd_hook() {
|
|
|
|
if [[ -v _PROMPT_EXEC_START_TIME ]]; then
|
2019-08-04 08:42:18 +00:00
|
|
|
local -F duration="$((EPOCHREALTIME - _PROMPT_EXEC_START_TIME))"
|
2019-07-13 18:35:34 +00:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2019-07-13 18:35:34 +00:00
|
|
|
setup_prompt() {
|
|
|
|
setopt nopromptbang promptcr promptsp promptpercent promptsubst
|
|
|
|
|
2019-08-04 08:42:18 +00:00
|
|
|
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
|
2019-07-13 18:35:34 +00:00
|
|
|
|
|
|
|
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)'
|
2019-07-13 18:35:34 +00:00
|
|
|
PROMPT+=' '
|
2019-08-06 12:20:57 +00:00
|
|
|
PROMPT+='${_PROMPT_EXEC_TIME:+" %F{yellow}$(prompt_escape "$_PROMPT_EXEC_TIME")%f"}'
|
2019-07-13 18:35:34 +00:00
|
|
|
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=' %_> '
|
2019-07-13 18:35:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 17:25:14 +00:00
|
|
|
configure_dircolors
|
2019-07-13 18:35:34 +00:00
|
|
|
setup_prompt
|