forked from agnoster/agnoster-zsh-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
katernet-zsh-theme.zsh
514 lines (487 loc) · 19.1 KB
/
katernet-zsh-theme.zsh
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# Katernet zsh prompt theme
# Adapted from spaceship-prompt https://github.com/denysdovhan/spaceship-prompt and agnoster https://github.com/agnoster/agnoster-zsh-theme
# Depedency: https://github.com/katernet/dotfiles
#PROMPT_CONTEXT=y # Prompt context - y: User@Host u: User o: Other user r: Remote context
#PROMPT_CLOCK=y # Prompt clock - y: 24H clock 12: 12H clock
#PROMPT_HISTLINE=y # Prompt history line number
PROMPT_BOLD=y # Bold prompt
#PROMPT_PREFIX=y # Prompt section prefixes
PROMPT_ICONS=y # Prompt glyph icons
#PROMPT_OS=y # Show OS icon - Arch, BSD, Linux, macOS
#PROMPT_NEWLINE=y # Show a new line after the prompt
PROMPT_TRANSIENT=y # Transient prompt - Trim previous prompts
PROMPT_TRANSIENTOPT=(newline clock hist) # Transient prompt options
PROMPT_DIR=y # Dir opts - trim: Trim pwd path [dependency] c: Current dir y: Full path
#PROMPT_DIRRESUME=y # [Depedency] Resume last dir from dirstack at login
PROMPT_DIRLOCK=y # Prompt dir lock icon for unwriteable folders
#PROMPT_DIRCOLOR=default # Dir color - Use 'default' for stock color
#PROMPT_CHAR=❯ # Custom prompt character
#PROMPT_CHARCOL=green # Custom prompt character color
#PROMPT_DOCKER=y # Docker module
#PROMPT_GITVCS=y # [Depedency] Git vcs async module
#PROMPT_VENV=y # [Depedency] Python virtualenv
PROMPT_TITLES=y # Prompt theme tab titles
#PROMPT_CLOCKTICK=y # Ticking clock (minor bugs)
#PROMPT_CLOCKEXE=y # Refresh clock after command (use without ticking clock)
PROMPT_EXIT=y # Prompt error color
PROMPT_EXITRESET=y # Async timer to reset prompt error color after 5s
#PROMPT_MOTD=y # [Depedency] Message of the day at login
#PROMPT_MOTDOPT=(greeting quote todo) # [Depedency] MOTD Opts: help, (neo/fast)fetch, hostinfo, greeting, quote, todo
#PROMPT_BOTTOM=y # Set the prompt at the bottom of the Terminal
#PROMPT_COMPILE=y # [Depedency] Compile zsh config files and compdump for fast load
#PROMPT_ZHELP=xman # [Depedency] Use Apple x-man-page - macOS only
#RPROMPT_OFF=y # Switch off right prompt
#RPROMPT_CLOCK=y # Right prompt clock
RPROMPT_CMDTIME=y # Right prompt command time
#RPROMPT_HISTLINE=y # Right prompt history line number
RPROMPT_DOCKER=y # Right prompt docker module
#RPROMPT_GITVCS=y # [Depedency] Right prompt git vcs module
RPROMPT_JOBS=y # Right prompt background job status
RPROMPT_EXITCODE=y # Right prompt exit code
RPROMPT_EXITSIG=y # Right prompt exit signal
# Begin a section
# If foreground argument is omitted, renders default foreground.
prompt_section() {
local fg
[ "$1" ] && fg="%F{$1}" || fg="%f"
[ "$PROMPT_BOLD" ] && print -n "%B"
if [[ "$3" && "$PROMPT_PREFIX" ]]; then
[ "$3" = "dir" ] && print -n "%F{default}in %f"
[ "$3" = "docker" ] && print -n "%F{default}on %f"
[ "$3" = "git" ] && print -n "%F{default}on %f"
[ "$3" = "os" ] && print -n "%F{default}on %f"
fi
print -n "%{$fg%}"
[ "$2" ] && print -n "$2 "
[[ "$PROMPT_PREFIX" && "$3" == "context" ]] && print -n "%F{default}at %f"
[ "$PROMPT_BOLD" ] && print -n "%b"
}
# Begin an rprompt section
prompt_rsection() {
local fg
[ "$1" ] && fg="%F{$1}" || fg="%f"
[ "$PROMPT_BOLD" ] && print -n "%B"
if [[ "$3" && "$PROMPT_PREFIX" ]]; then
[ "$3" = "docker" ] && print -n "%F{default} on%f"
[ "$3" = "git" ] && print -n "%F{default} on%f"
fi
print -n "%{$fg%}"
[ "$2" ] && print -n " $2"
[ "$PROMPT_BOLD" ] && print -n "%b"
}
# End the prompt closing open sections and set the prompt symbol
prompt_end() {
[ -z "$PROMPT_CHARCOLOR" ] && local PROMPT_CHARCOLOR=default
if [ $SHLVL -gt 1 ]; then # Subshell level
local L
[ "$PROMPT_CHAR" ] && lvlicon="$PROMPT_CHAR" || lvlicon=">"
for i in {1..$SHLVL}; do
L+="$lvlicon"
done
[ $i -gt 4 ] && L="$i${lvlicon}"
PROMPT_SYMBOL="%(!.# .$L )"
elif [[ "$PROMPT_ICONS" && "$incognito" && "$ghostmode" ]]; then # Incognito ghost mode
PROMPT_SYMBOL="$ghosticon"
else
[ "$PROMPT_CHAR" ] && PROMPT_SYMBOL="%(!.# .$PROMPT_CHAR) " || PROMPT_SYMBOL='%# '
fi
[[ "$PROMPT_NEWLINE" && $# -eq 0 ]] && print -n '\n' # New line prompt
if [[ "$PROMPT_EXIT" && $exitcode -eq 0 ]] || [[ -z "$PROMPT_EXIT" ]] || [ -z "$errprompt" ]; then
print -n "%F{${PROMPT_CHARCOLOR}}$PROMPT_SYMBOL%f"
elif [[ "$PROMPT_EXIT" && $exitcode -gt 0 ]]; then
print -n "%F{9}$PROMPT_SYMBOL%f"
fi
}
# User and hostname
prompt_context() {
[ "$PROMPT_CONTEXT" = 'u' ] && prompt_section default '%n' # User
[ "$PROMPT_CONTEXT" = 'm' ] && prompt_section default '%m' # Machine
[[ "$PROMPT_PREFIX" && "$PROMPT_CONTEXT" = 'y' ]] && prompt_section default '%n' context && prompt_section default '%m' # User at Host
[[ "$PROMPT_CONTEXT" = 'y' && -z "$PROMPT_PREFIX" ]] && prompt_section default '%n@%m' # User@Host
[[ "$PROMPT_CONTEXT" =~ 'o' && "$USER" != "$DEFAULTUSER" ]] && prompt_section default '%n' # Other user
[[ "$PROMPT_CONTEXT" =~ 'r' && "$SSH_CLIENT" ]] && prompt_section default '%n@%m' # Remote SSH: User@Host
}
# Current directory
prompt_dir() {
local dirargs=()
[[ -w "${PWD}" || -z "$PROMPT_DIRLOCK" ]] && unset lockicon # Dir writable
[[ ! -w "${PWD}" && -z "$PROMPT_DIRLOCK" ]] && PROMPT_DIRCOLOR="$PROMPT_DARKGRAY" # Dir unwriteable
if [ "$PROMPT_DIR" = trim ]; then
dirargs+=($PROMPT_DIRCOLOR "$(trm)${lockicon}") # trm function from fpath
elif [ "$PROMPT_DIR" = y ]; then
dirargs+=($PROMPT_DIRCOLOR "%~${lockicon}")
elif [ "$PROMPT_DIR" = c ]; then
dirargs+=($PROMPT_DIRCOLOR "%c${lockicon}")
fi
[[ "$PROMPT_CONTEXT" && -z "$VIRTUAL_ENV" ]] && dirargs+=(dir)
prompt_section "${dirargs[@]}"
}
# OS icon
prompt_os() {
local osicon
[[ "$PROMPT_OS" && "$PROMPT_ICONS" ]] || return
[[ "$OSTYPE" = darwin* ]] && osicon="\ue711" # Apple
[[ "$OSTYPE" = linux* ]] && osicon="\ue712" # Tux
[[ "$OSTYPE" = *bsd* || "$OSTYPE" = dragonfly* ]] && osicon="\uf30c" # BSD
[[ "$OSTYPE" = linux* && "$PROMPT_OS" = 'arch' ]] && osicon="\uf303" # Arch
[[ "$OSTYPE" = darwin* && "$PROMPT_OS" = 'finder' ]] && osicon="\uf535" # Mac Finder
[[ "$OSTYPE" = darwin* && "$PROMPT_OS" = 'command' ]] && osicon="\ufb32" # Mac command
prompt_section default "$osicon" os
}
# Clock
prompt_clock() {
if [[ "$PROMPT_CLOCK" && -z "$RPROMPT_CLOCK" ]] || [[ "$1" = 'transient' ]]; then
local newday=${(%):-%D{%a}}
if [[ "$newday" != "$dayofweek" ]]; then # Day of week changed (dayofweek from prompt_precmd)
unset newday
prompt_section "$PROMPT_MEDGRAY" '%D{%a %X}' # %X : Time based on locale
else
prompt_section "$PROMPT_MEDGRAY" '%D{%X}' # %X : Time based on locale
fi
fi
}
# History line
prompt_hist() {
if [[ "$PROMPT_HISTLINE" && -z "$RPROMPT_HISTLINE" ]] || [[ "$1" = 'transient' ]]; then
[ "$incognito" ] && return
prompt_section "$PROMPT_MEDGRAY2" "%h"
fi
}
# Python virtual environment status
prompt_venv() {
[ "$PROMPT_VENV" ] || return
if [ "$VIRTUAL_ENV" ]; then
local venvargs=()
[ -z "$PROMPT_DIRCOLOR" ] && local PROMPT_DIRCOLOR="$PROMPT_STEELBLUE"
venvargs+=($PROMPT_DIRCOLOR "(${VIRTUAL_ENV##*/})")
[ "$PROMPT_CONTEXT" ] && venvargs+=(dir)
prompt_section "${venvargs[@]}"
fi
}
# Docker machine context
prompt_dockercontext() {
local docker_remote_context
if [ $DOCKER_MACHINE_NAME ]; then
docker_remote_context="$DOCKER_MACHINE_NAME"
elif [ $DOCKER_HOST ]; then
# Remove protocol (tcp://) and port number from displayed Docker host
local parstring=${DOCKER_HOST#*//}
docker_remote_context=${parstring%:*}
fi
[ -z $docker_remote_context ] && return
print -n "${docker_remote_context}"
}
# Docker
prompt_docker() {
(($+commands[docker])) || return
[[ "$PROMPT_DOCKER" || "$RPROMPT_DOCKER" ]] || return
[[ -n "$RPROMPT_DOCKER" && ${funcstack[2]} = "prompt_build" ]] && return # Respect module position choice
[[ -z "$RPROMPT_DOCKER" && ${funcstack[2]} = "prompt_rbuild" ]] && return
# Better support for docker environment vars: https://docs.docker.com/compose/reference/envvars/
local compose_exists=false
if [ "$COMPOSE_FILE" ]; then
# Use COMPOSE_PATH_SEPARATOR or colon as default
local separator=${COMPOSE_PATH_SEPARATOR:-":"}
# COMPOSE_FILE may have several filenames separated by colon, test all of them
local filenames=("${(@ps/$separator/)COMPOSE_FILE}")
for filename in $filenames; do
if [[ ! -f $filename ]]; then
compose_exists=false
break
fi
compose_exists=true
done
# Must return if COMPOSE_FILE is present but invalid
[ "$compose_exists" = false ] && return
fi
local docker_context="$(prompt_dockercontext)" PROMPT_SECTIONFN
# Show Docker status only for Docker-specific folders or when connected to external host
[[ "$compose_exists" == true || -f Dockerfile || -f docker-compose.yml || -f /.dockerenv || $docker_context ]] || return
[ "$RPROMPT_DOCKER" ] && PROMPT_SECTIONFN="prompt_rsection" || PROMPT_SECTIONFN="prompt_section" # Set prompt section
$PROMPT_SECTIONFN $PROMPT_LIGHTBLUE "${dockericon}[${docker_context}]" docker
}
# VCS module status
prompt_vcs() {
(( $+commands[git] )) || return
[[ "$PROMPT_GITVCS" || "$RPROMPT_GITVCS" ]] || return
[ $UID -eq 0 ] && return # No git prompt for root user
[[ -n "$RPROMPT_GITVCS" && ${funcstack[2]} = "prompt_build" ]] && return # Respect module prompt choice
[[ -z "$RPROMPT_GITVCS" && ${funcstack[2]} = "prompt_rbuild" ]] && return
local PROMPT_SECTIONFN
[ "$RPROMPT_GITVCS" ] && PROMPT_SECTIONFN="prompt_rsection" || PROMPT_SECTIONFN="prompt_section" # Set prompt section
[ "${vcs_info_msg_0_}" ] && $PROMPT_SECTIONFN default "${vcs_info_msg_0_}" git
}
# Status for clock, cmd time, history line, job status, exit code.
prompt_status() {
local symbols=()
# Exit code
if [ "$RPROMPT_EXITCODE" ] && [ "$exitcode" -gt 0 ]; then
[ "$RPROMPT_EXITSIG" ] && prompt_exitsig
symbols+=("%F{$PROMPT_RED}${exiticon}${exitcode}%f")
fi
# Cmd time
if [[ "$RPROMPT_CMDTIME" && -z "$nocmdtime" ]]; then # nocmdtime set in prompt_accept-line
prompt_humantime $timer_result # timer_result set in prompt_precmd
[ "$PROMPT_PREFIX" ] && local prefix="took " || local prefix=$clockicon
[[ "$timer_result" -ge 5 && "$timer_result" -lt 15 ]] && symbols+=("%F{$PROMPT_MEDGRAY}${prefix}$humant")
[[ "$timer_result" -ge 15 && "$timer_result" -lt 30 ]] && symbols+=("%F{$PROMPT_MEDGRAY}${prefix}%F{$PROMPT_ORANGE}$humant") # Orange time
[[ "$timer_result" -ge 30 ]] && symbols+=("%F{$PROMPT_MEDGRAY}${prefix}%F{$PROMPT_RED}$humant") # Red time
fi
# History line
[[ "$RPROMPT_HISTLINE" && $BUFFER && -z "$incognito" ]] && symbols+=("%F{$PROMPT_MEDGRAY2}%h%f")
# Clock
if [[ "$RPROMPT_CLOCK" ]]; then
local rnewday=${(%):-%D{%a}}
if [[ "$rnewday" != "$dayofweek" ]]; then # Day of week changed
local RPROMPT_CLOCKDAY="$rnewday"
unset rnewday
symbols+=("%F{$PROMPT_MEDGRAY}$RPROMPT_CLOCKDAY %D{%X}%f")
else
symbols+=("%F{$PROMPT_MEDGRAY}%D{%X}%f")
fi
fi
# Jobs
if [ "$RPROMPT_JOBS" ]; then
if [ "$PROMPT_ICONS" ]; then
[ "$jobnum" -eq 1 ] && symbols+=("%F{$PROMPT_LIGHTGRAY}${jobicon}%f") # 1 job
[ "$jobnum" -gt 1 ] && symbols+=("%F{$PROMPT_LIGHTGRAY}${jobsicon}%f") # >1 job
else
[ "$jobnum" -gt 0 ] && symbols+=("%F{$PROMPT_LIGHTGRAY}${jobnum}%f")
fi
fi
[ "${symbols[*]}" ] && prompt_rsection default "${symbols[*]}" || :
}
# Convert time to a human readable format
# Adapted from https://github.com/sindresorhus/pretty-time-zsh
prompt_humantime() {
typeset -g humant
local human total_seconds=$1
local days=$(( total_seconds / 60 / 60 / 24 ))
local hours=$(( total_seconds / 60 / 60 % 24 ))
local minutes=$(( total_seconds / 60 % 60 ))
local seconds=$(( total_seconds % 60 ))
(( days > 0 )) && human+="${days}d "
(( hours > 0 )) && human+="${hours}h "
(( minutes > 0 )) && human+="${minutes}m "
human+="${seconds}s"
humant=$human
}
# Return exit code names. If no match, then use exit code number.
prompt_exitsig() {
case $exitcode in
-1) exitcode="FATAL(-1)" ;;
1) exitcode="WARN(1)" ;;
2) exitcode="BUILTINMISUSE(2)" ;;
19) exitcode="STOP(19)" ;;
20) exitcode="TSTP(20)" ;;
21) exitcode="TTIN(21)" ;;
22) exitcode="TTOU(22)" ;;
126) exitcode="CCANNOTINVOKE(126)" ;;
127) exitcode="CNOTFOUND(127)" ;;
129) exitcode="HUP(129)" ;;
130) exitcode="INT(130)" ;;
131) exitcode="QUIT(131)" ;;
132) exitcode="ILL(132)" ;;
134) exitcode="ABRT(134)" ;;
136) exitcode="FPE(136)" ;;
137) exitcode="KILL(137)" ;;
139) exitcode="SEGV(139)" ;;
141) exitcode="PIPE(141)" ;;
143) exitcode="TERM(143)" ;;
esac
}
# Reset prompt error color
prompt_exitreset() {
unset errprompt
read -r exitreset <&$1 # Read fd
# Reset prompt unless a condition is met
[[ $WIDGET == *(complete|delete|list|search|statusline)* ]] || [[ "$_lastcomp[insert]" =~ "^automenu$|^menu:" \
|| $statusline || "$paste" || "$__searching" || "$dm" ]] \
|| { zle && builtin zle reset-prompt }
exec {1}<&- # Close fd
zle -F $1 # Close handler
}
# Custom accept-line function to assist with prompt tasks
prompt_acceptline() {
# Handle prompt vars
[ "$paste" ] && unset paste
[ "$timer_result" ] && unset timer_result
[ "$__searching" ] && unset __searching
[ "$errprompt" ] && unset errprompt
[ "$nocmdtime" ] && unset nocmdtime
[ "$dm" ] && unset dm
# Show histline or executed time on previous buffer
[[ "$RPROMPT_HISTLINE" || "$PROMPT_CLOCKEXE" && -z "$PROMPT_TRANSIENT" ]] && zle .reset-prompt
# Blacklist commands from CMDTIME
local prog="(hist|[ht,t]op|fe|fd|fh|fkill|suroot|oa|dm)"
local head="(micro|m |nano|vi|vim|man|ssh|tmux|wtch)*"
local tail="*(fzf|less|more)"
[[ $BUFFER =~ ${prog} || $BUFFER = ${~head} || $BUFFER = ${~tail} ]] && typeset -g nocmdtime='y'
# Run builtin accept-line
zle .accept-line
}
# Transient prompt
# Adapted from https://www.zsh.org/mla/users/2019/msg00633.html
prompt_transient() {
if [ "$PROMPT_TRANSIENT" ]; then
emulate -L zsh
[[ $CONTEXT == start ]] || return 0
while true; do
# Start regular line editor
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1] # Re-enable bracketed paste
zle .recursive-edit
local -i ret=$?
# If we received EOT exit the shell
[[ $ret == 0 && $KEYS == $'\4' ]] || break
[[ -o ignore_eof ]] || exit 0
done
local TPS1
local oldPS1=$PS1
# Sections for transient prompt
if [ $BUFFER ]; then # Show only on prompts with executed buffers
[[ "$PROMPT_TRANSIENTOPT" =~ 'clock' ]] && TPS1+='$(prompt_clock transient)'
[[ "$PROMPT_TRANSIENTOPT" =~ 'hist' ]] && TPS1+='$(prompt_hist transient)'
fi
TPS1+='$(prompt_end)'
PS1="$TPS1"
# Line editor is finished - shorten the prompt
zle .reset-prompt
PS1="${tnewline}$oldPS1"
[ "$tnewline" ] && unset tnewline
if (( ret )); then # Ctrl-C
zle .send-break
else # Enter
zle .accept-line
fi
return ret
fi
}
# Prompt schedule to tick clock
# Adapted from https://www.zsh.org/mla/users/2007/msg00946.html
prompt_sched() {
local sched_exitcode=$?
local -i i=${"${(@)zsh_scheduled_events#*:*:}"[(I)schedprompt]}
emulate -L zsh
((i)) && sched -$i
# Reset prompt unless a condition is met - Adapted from https://stackoverflow.com/a/42982148
[[ $WIDGET == *(complete|delete|list|search|statusline)* ]] || [[ "$_lastcomp[insert]" =~ "^automenu$|^menu:" \
|| $statusline || "$paste" || "$__searching" || "$dm" ]] \
|| { zle && builtin zle reset-prompt }
sched +1 prompt_sched # 1s schedule
return $sched_exitcode # Restore prompt exit code
}
# Evaluate command
prompt_preexec() {
typeset -ghi nextcmd lastcmd
((nextcmd++)) # Next command initiated
[ "$RPROMPT_CMDTIME" ] && typeset -g timer_sec=${timer_sec:-$EPOCHSECONDS} # Start command timer
}
# Execute before next prompt
prompt_precmd() {
typeset -g exitcode=$? # Store cmd exit code
typeset -g jobnum=$#jobstates # Store number of jobs
[ "$exitcode" -gt 0 ] && errprompt='on'
[[ "$PROMPT_CLOCK" || "$RPROMPT_CLOCK" || "$PROMPT_TRANSIENTOPT" =~ "clock" ]] && \
typeset -g dayofweek=${(%):-%D{%a}} # Store day of week
((nextcmd==lastcmd)) && unset exitcode nextcmd lastcmd || ((lastcmd=nextcmd)) # Unset exitcode on next buffer
# Command time
if [[ "$RPROMPT_CMDTIME" && $timer_sec ]]; then
local timer_diff
((timer_diff=EPOCHREALTIME-timer_sec))
typeset -g timer_result=${timer_diff%.*} # Remove decimals
unset timer_sec
fi
# Start async timer for error prompt color reset
if [[ "$PROMPT_EXIT" && "$PROMPT_EXITRESET" ]]; then
if [ "$errprompt" = 'on' ]; then
exec {FD1}< <(zselect -t 500) # Initialize file descriptor and fork timer - 5s
zle -F $FD1 prompt_exitreset # Handle input from fd
fi
fi
# Tab and window title
# 1: tab 2: window
if [ "$PROMPT_TITLES" ]; then
local context
[ "$PROMPT_CONTEXT" = 'u' ] && context='%n: '
[ "$PROMPT_CONTEXT" = 'm' ] && context='%m: '
[ "$PROMPT_CONTEXT" = 'y' ] && context='%n@%m: '
[[ "$PROMPT_CONTEXT" == 'o' && "$USER" != "$DEFAULTUSER" ]] && context='%n: '
[[ "$PROMPT_CONTEXT" == 'r' && "$SSH_CLIENT" ]] && context='%n%m: '
[ "$UID" = 0 ] && print -Pn "\e]1;# ${context}%c\a" || print -Pn "\e]1;${context}%c\a"
print -Pn "\e]2;${context}%c ${ZSH_ARGZERO}\a"
fi
}
# Build prompt
prompt_build() {
prompt_clock
prompt_hist
prompt_context
prompt_os
prompt_venv
prompt_dir
prompt_docker
prompt_vcs
prompt_end
}
# Build rprompt
prompt_rbuild() {
[ "$RPROMPT_OFF" ] && return || :
prompt_docker
prompt_vcs
prompt_status
}
# Setup the things
prompt_setup() {
# Defines and hooks
autoload -Uz add-zsh-hook colors && colors
add-zsh-hook preexec prompt_preexec
add-zsh-hook precmd prompt_precmd
zle -N accept-line prompt_acceptline
zle-line-init() { key_start ; prompt_transient }
zle-line-finish() key_end
zle -N zle-line-init
zle -N zle-line-finish
# Prompt colors
typeset -g PROMPT_RED=160
typeset -g PROMPT_ORANGE=166
typeset -g PROMPT_LIGHTBLUE=39
typeset -g PROMPT_STEELBLUE=75
typeset -g PROMPT_LIGHTGRAY=252
typeset -g PROMPT_MEDGRAY=249
typeset -g PROMPT_MEDGRAY2=246
typeset -g PROMPT_DARKGRAY=244
# Glyphs
if [[ "$PROMPT_ICONS" && -z "$SSH_CLIENT" ]]; then
typeset -g lockicon=" \uf023" # padlock
typeset -g clockicon="\uf017 " # clock
typeset -g exiticon="\u21aa" # arrow
typeset -g jobicon="\uf013" # cog
typeset -g jobsicon="\uf085" # cogs
typeset -g dockericon="\uf308 " # whale
typeset -g ghosticon="\uf79f " # ghost
fi
# Settings and utilities
ZLE_RPROMPT_INDENT=0 # Set right prompt margin to 0
[ "$PROMPT_BOTTOM" ] && tput cup $LINES # Pin prompt to bottom of terminal
[ "$PROMPT_VENV" ] && chpwd_functions+=(avenv) # Add python auto venv to chpwd
[ "$PROMPT_EXITRESET" ] && zmodload zsh/zselect # Load timer module
[[ "$PROMPT_CLOCK" || "$RPROMPT_CMDTIME" || "$PROMPT_MOTD" ]] && zmodload zsh/datetime # Load time module
[[ "$PROMPT_ICONS" && $SSH_TTY ]] && unset PROMPT_ICONS # No glyph icons in an SSH session
[ -z "$PROMPT_DIRCOLOR" ] && typeset -g PROMPT_DIRCOLOR="$PROMPT_STEELBLUE" # Default dir color
if [[ "$PROMPT_TRANSIENT" && "$PROMPT_TRANSIENTOPT" =~ 'newline' ]]; then # New line after transient prompt
typeset -g tnewline=$'\n'
fi
if [ "$PROMPT_CLOCKTICK" ] && [[ "$PROMPT_CLOCK" || "$RPROMPT_CLOCK" ]]; then # Schedule tick clock function
prompt_sched
fi
# Refresh background job number
TRAPCHLD() {
if [ "$RPROMPT_JOBS" ]; then
jobnum=$#jobstates
zle && builtin zle reset-prompt
fi
}
PROMPT='$(prompt_build)'
RPROMPT='$(prompt_rbuild)'
}
prompt_setup "$@"