-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt_paradox_setup
121 lines (105 loc) · 3.76 KB
/
prompt_paradox_setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Load dependencies.
pmodload 'helper'
CURRENT_BG='NONE'
SEGMENT_SEPARATOR='⮀'
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && print -Pn $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}
function build_prompt {
# prompt_segment black default '%(1?;%{%F{red}%}✘ ;)%(!;%{%F{yellow}%}⚡ ;)%(1j;%{%F{cyan}%}%j⚙ ;)%{%F{blue}%}%n%{%F{red}%}@%{%F{green}%}%M'
prompt_segment blue black '%2~'
if $git_status; then
prompt_segment green black '${(e)git_info[prompt]}${git_info[status]}'
fi
prompt_end
}
start_time=$SECONDS
function prompt_paradox_preexec {
start_time=$SECONDS
}
function calc_elapsed_time {
if [[ $timer_result -ge 3600 ]]; then
let "timer_hours = $timer_result / 3600"
let "remainder = $timer_result % 3600"
let "timer_minutes = $remainder / 60"
let "timer_seconds = $remainder % 60"
print -P "%B%F{red}>>> elapsed time ${timer_hours}h${timer_minutes}m${timer_seconds}s%b"
elif [[ $timer_result -ge 60 ]]; then
let "timer_minutes = $timer_result / 60"
let "timer_seconds = $timer_result % 60"
print -P "%B%F{yellow}>>> elapsed time ${timer_minutes}m${timer_seconds}s%b"
elif [[ $timer_result -gt 10 ]]; then
print -P "%B%F{green}>>> elapsed time ${timer_result}s%b"
fi
}
function prompt_paradox_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
# Get Git repository information.
if (( $+functions[git-info] )); then
git_status=git-info
fi
timer_result=$(($SECONDS-$start_time))
if [[ $timer_result -gt 10 ]]; then
calc_elapsed_time
fi
start_time=$SECONDS
}
function prompt_paradox_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
# Load required functions.
autoload -Uz add-zsh-hook
# Add hook for calling git-info before each command.
add-zsh-hook preexec prompt_paradox_preexec
add-zsh-hook precmd prompt_paradox_precmd
zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b'
zstyle ':prezto:module:editor:info:keymap:primary' format '%B%F{blue}❯%f%b'
zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format '%F{red}♺%f'
zstyle ':prezto:module:editor:info:keymap:alternate' format '%B%F{red}❮%f%b'
zstyle ':prezto:module:git:info:action' format '! %s'
zstyle ':prezto:module:git:info:added' format '✚'
zstyle ':prezto:module:git:info:ahead' format '⬆'
zstyle ':prezto:module:git:info:behind' format '⬇'
zstyle ':prezto:module:git:info:branch' format '⭠ %b'
zstyle ':prezto:module:git:info:commit' format '➦ %.7c'
zstyle ':prezto:module:git:info:deleted' format '✖'
zstyle ':prezto:module:git:info:modified' format '✱'
zstyle ':prezto:module:git:info:position' format '%p'
zstyle ':prezto:module:git:info:renamed' format '➙'
zstyle ':prezto:module:git:info:stashed' format 's'
zstyle ':prezto:module:git:info:unmerged' format '═'
zstyle ':prezto:module:git:info:untracked' format '?'
zstyle ':prezto:module:git:info:keys' format \
'prompt' '$(coalesce "%b" "%p" "%c")%s' \
'status' ' %A%B%S%a%d%m%r%U%u'
# Define prompts.
PROMPT='%{%f%b%k%}$(build_prompt)
${editor_info[keymap]} '
RPROMPT='[%D{%L:%M:%S %p}]'
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
}
prompt_paradox_setup "$@"