forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spaceship.zsh-theme
534 lines (451 loc) · 18.1 KB
/
spaceship.zsh-theme
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
#
# Spaceship ZSH Theme
#
# Author: Denys Dovhan, denysdovhan.com
# License: MIT
# https://github.com/denysdovhan/spaceship-zsh-theme
# ------------------------------------------------------------------------------
# CONFIGURATION
# The default configuration that can be overridden in .zshrc
# ------------------------------------------------------------------------------
# ORDER
if [ ! -n "$SPACESHIP_PROMPT_ORDER" ]; then
SPACESHIP_PROMPT_ORDER=(
time
user
host
dir
git
venv
pyenv
exec_time
line_sep
jobs
exit_code
char
)
fi
# PROMPT
SPACESHIP_PROMPT_SYMBOL="${SPACESHIP_PROMPT_SYMBOL:="➜"}"
SPACESHIP_PROMPT_ADD_NEWLINE="${SPACESHIP_PROMPT_ADD_NEWLINE:=true}"
SPACESHIP_PROMPT_SEPARATE_LINE="${SPACESHIP_PROMPT_SEPARATE_LINE:=true}"
SPACESHIP_PROMPT_PREFIXES_SHOW="${SPACESHIP_PROMPT_PREFIXES_SHOW:=true}"
SPACESHIP_PROMPT_SUFFIXES_SHOW="${SPACESHIP_PROMPT_SUFFIXES_SHOW:=true}"
SPACESHIP_PROMPT_DEFAULT_PREFIX="${SPACESHIP_PROMPT_DEFAULT_PREFIX:="via "}"
SPACESHIP_PROMPT_DEFAULT_SUFFIX="${SPACESHIP_PROMPT_DEFAULT_SUFFIX:=" "}"
# TIME
SPACESHIP_TIME_SHOW="${SPACESHIP_TIME_SHOW:=true}"
SPACESHIP_TIME_PREFIX="${SPACESHIP_TIME_PREFIX:="at "}"
SPACESHIP_TIME_SUFFIX="${SPACESHIP_TIME_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_TIME_FORMAT="${SPACESHIP_TIME_FORMAT:=false}"
SPACESHIP_TIME_12HR="${SPACESHIP_TIME_12HR:=false}"
SPACESHIP_TIME_COLOR="${SPACESHIP_TIME_COLOR:="yellow"}"
# USER
SPACESHIP_USER_SHOW="${SPACESHIP_USER_SHOW:=true}"
SPACESHIP_USER_PREFIX="${SPACESHIP_USER_PREFIX:="with "}"
SPACESHIP_USER_SUFFIX="${SPACESHIP_USER_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_USER_COLOR="${SPACESHIP_USER_COLOR:="yellow"}"
SPACESHIP_USER_COLOR_ROOT="${SPACESHIP_USER_COLOR_ROOT:="red"}"
# HOST
SPACESHIP_HOST_SHOW="${SPACESHIP_HOST_SHOW:=true}"
SPACESHIP_HOST_PREFIX="${SPACESHIP_HOST_PREFIX:="at "}"
SPACESHIP_HOST_SUFFIX="${SPACESHIP_HOST_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_HOST_COLOR="${SPACESHIP_HOST_COLOR:="green"}"
# DIR
SPACESHIP_DIR_SHOW="${SPACESHIP_DIR_SHOW:=true}"
SPACESHIP_DIR_PREFIX="${SPACESHIP_DIR_PREFIX:="in "}"
SPACESHIP_DIR_SUFFIX="${SPACESHIP_DIR_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_DIR_TRUNC="${SPACESHIP_DIR_TRUNC:=3}"
SPACESHIP_DIR_COLOR="${SPACESHIP_DIR_COLOR:="cyan"}"
# GIT
SPACESHIP_GIT_SHOW="${SPACESHIP_GIT_SHOW:=true}"
SPACESHIP_GIT_PREFIX="${SPACESHIP_GIT_PREFIX:="on "}"
SPACESHIP_GIT_SUFFIX="${SPACESHIP_GIT_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_GIT_SYMBOL="${SPACESHIP_GIT_SYMBOL:=" "}"
# GIT BRANCH
SPACESHIP_GIT_BRANCH_SHOW="${SPACESHIP_GIT_BRANCH_SHOW:=true}"
SPACESHIP_GIT_BRANCH_PREFIX="${SPACESHIP_GIT_BRANCH_PREFIX:="$SPACESHIP_GIT_SYMBOL"}"
SPACESHIP_GIT_BRANCH_SUFFIX="${SPACESHIP_GIT_BRANCH_SUFFIX:=""}"
SPACESHIP_GIT_BRANCH_COLOR="${SPACESHIP_GIT_BRANCH_COLOR:="magenta"}"
# GIT STATUS
SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW:=true}"
SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX:=" ["}"
SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX:="]"}"
SPACESHIP_GIT_STATUS_COLOR="${SPACESHIP_GIT_STATUS_COLOR:="red"}"
SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED:="?"}"
SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED:="+"}"
SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED:="!"}"
SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED:="»"}"
SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED:="✘"}"
SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED:="$"}"
SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED:="="}"
SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD:="⇡"}"
SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND:="⇣"}"
SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED:="⇕"}"
# VENV
SPACESHIP_VENV_SHOW="${SPACESHIP_VENV_SHOW:=true}"
SPACESHIP_VENV_PREFIX="${SPACESHIP_VENV_PREFIX:="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}"
SPACESHIP_VENV_SUFFIX="${SPACESHIP_VENV_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_VENV_COLOR="${SPACESHIP_VENV_COLOR:="blue"}"
# PYENV
SPACESHIP_PYENV_SHOW="${SPACESHIP_PYENV_SHOW:=true}"
SPACESHIP_PYENV_PREFIX="${SPACESHIP_PYENV_PREFIX:="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}"
SPACESHIP_PYENV_SUFFIX="${SPACESHIP_PYENV_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_PYENV_SYMBOL="${SPACESHIP_PYENV_SYMBOL:="🐍 "}"
SPACESHIP_PYENV_COLOR="${SPACESHIP_PYENV_COLOR:="yellow"}"
# EXECUTION TIME
SPACESHIP_EXEC_TIME_SHOW="${SPACESHIP_EXEC_TIME_SHOW:=true}"
SPACESHIP_EXEC_TIME_PREFIX="${SPACESHIP_EXEC_TIME_PREFIX:="took "}"
SPACESHIP_EXEC_TIME_SUFFIX="${SPACESHIP_EXEC_TIME_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_EXEC_TIME_COLOR="${SPACESHIP_EXEC_TIME_COLOR:="yellow"}"
SPACESHIP_EXEC_TIME_ELAPSED="${SPACESHIP_EXEC_TIME_ELAPSED:=2}"
# JOBS
SPACESHIP_JOBS_SHOW="${SPACESHIP_JOBS_SHOW:=true}"
SPACESHIP_JOBS_PREFIX="${SPACESHIP_JOBS_PREFIX:=""}"
SPACESHIP_JOBS_SUFFIX="${SPACESHIP_JOBS_SUFFIX:=" "}"
SPACESHIP_JOBS_SYMBOL="${SPACESHIP_JOBS_SYMBOL:="✦"}"
SPACESHIP_JOBS_COLOR="${SPACESHIP_JOBS_COLOR:="blue"}"
# EXIT CODE
SPACESHIP_EXIT_CODE_SHOW="${SPACESHIP_EXIT_CODE_SHOW:=false}"
SPACESHIP_EXIT_CODE_PREFIX="${SPACESHIP_EXIT_CODE_PREFIX:=""}"
SPACESHIP_EXIT_CODE_SUFFIX="${SPACESHIP_EXIT_CODE_SUFFIX:=" "}"
SPACESHIP_EXIT_CODE_SYMBOl="${SPACESHIP_EXIT_CODE_SYMBOl:="✘"}"
SPACESHIP_EXIT_CODE_COLOR="${SPACESHIP_EXIT_CODE_COLOR:="red"}"
# ------------------------------------------------------------------------------
# HELPERS
# Helpers for common used actions
# ------------------------------------------------------------------------------
# Check if command exists in $PATH
# USAGE:
# _exists <command>
_exists() {
command -v $1 > /dev/null 2>&1
}
# Check if the current directory is in a Git repository.
# USAGE:
# _is_git
_is_git() {
command git rev-parse --is-inside-work-tree &>/dev/null
}
# Draw prompt section (bold is used as default)
# USAGE:
# _prompt_section <color> [prefix] <content> [suffix]
SPACESHIP_OPENED=false # Internal variable for checking if prompt is opened
_prompt_section() {
local color prefix content suffix
[[ -n $1 ]] && color="%F{$1}" || color="%f"
[[ -n $2 ]] && prefix="$2" || prefix=""
[[ -n $3 ]] && content="$3" || content=""
[[ -n $4 ]] && suffix="$4" || suffix=""
[[ -z $3 && -z $4 ]] && content=$2 prefix=''
echo -n "%{%B%}" # set bold
if [[ $SPACESHIP_OPENED == true ]] && [[ $SPACESHIP_PROMPT_PREFIXES_SHOW == true ]]; then
echo -n "$prefix"
fi
SPACESHIP_OPENED=true
echo -n "%{%b%}" # unset bold
echo -n "%{%B$color%}" # set color
echo -n "$content" # section content
echo -n "%{%b%f%}" # unset color
echo -n "%{%B%}" # reset bold, if it was diabled before
if [[ $SPACESHIP_PROMPT_SUFFIXES_SHOW == true ]]; then
echo -n "$suffix"
fi
echo -n "%{%b%}" # unset bold
}
# Print message backward compatibility warning
# USAGE:
# _deprecate <deprecated> <actual>
_deprecated() {
[[ -n $1 && -n $2 ]] || return
local deprecated=$1 actual=$2 b=$bold_color r=$reset_color
local deprecated_value=${(P)deprecated} # the value of variable name $deprecated
[[ -n $deprecated_value ]] || return
echo "${b}\$$deprecated${r} is deprecated. Use ${b}\$$actual${r} instead."
}
# Display seconds in human readable fromat
# Based on http://stackoverflow.com/a/32164707/3859566
# USAGE:
# _displaytime <seconds>
_displaytime() {
local T=$1
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
[[ $D > 0 ]] && printf '%dd ' $D
[[ $H > 0 ]] && printf '%dh ' $H
[[ $M > 0 ]] && printf '%dm ' $M
printf '%ds' $S
}
# ------------------------------------------------------------------------------
# HOOKS
# ZSH hooks for advanced actions
# ------------------------------------------------------------------------------
# Execution time start
spaceship_exec_time_preexec_hook() {
[[ $SPACESHIP_EXEC_TIME_SHOW == false ]] && return
SPACESHIP_EXEC_TIME_start=$(date +%s)
}
# Execution time end
spaceship_exec_time_precmd_hook() {
[[ $SPACESHIP_EXEC_TIME_SHOW == false ]] && return
[[ -n $SPACESHIP_EXEC_TIME_duration ]] && unset SPACESHIP_EXEC_TIME_duration
[[ -z $SPACESHIP_EXEC_TIME_start ]] && return
local SPACESHIP_EXEC_TIME_stop=$(date +%s)
SPACESHIP_EXEC_TIME_duration=$(( $SPACESHIP_EXEC_TIME_stop - $SPACESHIP_EXEC_TIME_start ))
unset SPACESHIP_EXEC_TIME_start
}
# ------------------------------------------------------------------------------
# SECTIONS
# The parts the prompt consists of
# ------------------------------------------------------------------------------
# TIME
spaceship_time() {
[[ $SPACESHIP_TIME_SHOW == false ]] && return
local time_str
if [[ $SPACESHIP_TIME_FORMAT != false ]]; then
time_str="${SPACESHIP_TIME_FORMAT}"
elif [[ $SPACESHIP_TIME_12HR == true ]]; then
time_str="%D{%r}"
else
time_str="%D{%T}"
fi
_prompt_section \
"$SPACESHIP_TIME_COLOR" \
"$SPACESHIP_TIME_PREFIX" \
"$time_str" \
"$SPACESHIP_TIME_SUFFIX"
}
# USER
# If user is root, then paint it in red. Otherwise, just print in yellow.
spaceship_user() {
[[ $SPACESHIP_USER_SHOW == false ]] && return
if [[ $LOGNAME != $USER ]] || [[ $UID == 0 ]] || [[ -n $SSH_CONNECTION ]]; then
local user_color
if [[ $USER == 'root' ]]; then
user_color=$SPACESHIP_USER_COLOR_ROOT
else
user_color="$SPACESHIP_USER_COLOR"
fi
_prompt_section \
"$user_color" \
"$SPACESHIP_USER_PREFIX" \
'%n' \
"$SPACESHIP_USER_SUFFIX"
fi
}
# HOST
# If there is an ssh connections, current machine name.
spaceship_host() {
[[ $SPACESHIP_HOST_SHOW == false ]] && return
[[ -n $SSH_CONNECTION ]] || return
_prompt_section \
"$SPACESHIP_HOST_COLOR" \
"$SPACESHIP_HOST_PREFIX" \
'%m' \
"$SPACESHIP_HOST_SUFFIX"
}
# DIR
# Current directory. Return only three last items of path
spaceship_dir() {
[[ $SPACESHIP_DIR_SHOW == false ]] && return
_prompt_section \
"$SPACESHIP_DIR_COLOR" \
"$SPACESHIP_DIR_PREFIX" \
"%${SPACESHIP_DIR_TRUNC}~" \
"$SPACESHIP_DIR_SUFFIX"
}
# GIT BRANCH
# Show current git brunch using git_current_status from Oh-My-Zsh
spaceship_git_branch() {
[[ $SPACEHIP_GIT_BRANCH_SHOW == false ]] && return
_is_git || return
_prompt_section \
"$SPACESHIP_GIT_BRANCH_COLOR" \
"$SPACESHIP_GIT_BRANCH_PREFIX$(git_current_branch)$SPACESHIP_GIT_BRANCH_SUFFIX"
}
# GIT STATUS
# Check if current dir is a git repo, set up ZSH_THEME_* variables
# and show git status using git_prompt_status from Oh-My-Zsh
# Reference:
# https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/git.zsh
spaceship_git_status() {
[[ $SPACESHIP_GIT_STATUS_SHOW == false ]] && return
_is_git || return
ZSH_THEME_GIT_PROMPT_UNTRACKED=$SPACESHIP_GIT_STATUS_UNTRACKED
ZSH_THEME_GIT_PROMPT_ADDED=$SPACESHIP_GIT_STATUS_ADDED
ZSH_THEME_GIT_PROMPT_MODIFIED=$SPACESHIP_GIT_STATUS_MODIFIED
ZSH_THEME_GIT_PROMPT_RENAMED=$SPACESHIP_GIT_STATUS_RENAMED
ZSH_THEME_GIT_PROMPT_DELETED=$SPACESHIP_GIT_STATUS_DELETED
ZSH_THEME_GIT_PROMPT_STASHED=$SPACESHIP_GIT_STATUS_STASHED
ZSH_THEME_GIT_PROMPT_UNMERGED=$SPACESHIP_GIT_STATUS_UNMERGED
ZSH_THEME_GIT_PROMPT_AHEAD=$SPACESHIP_GIT_STATUS_AHEAD
ZSH_THEME_GIT_PROMPT_BEHIND=$SPACESHIP_GIT_STATUS_BEHIND
ZSH_THEME_GIT_PROMPT_DIVERGED=$SPACESHIP_GIT_STATUS_DIVERGED
local git_status="$(git_prompt_status)"
if [[ -n $git_status ]]; then
# Status prefixes are colorized
_prompt_section \
"$SPACESHIP_GIT_STATUS_COLOR" \
"$SPACESHIP_GIT_STATUS_PREFIX$git_status$SPACESHIP_GIT_STATUS_SUFFIX"
fi
}
# GIT
# Show both git branch and git status:
# spaceship_git_branch
# spaceship_git_status
spaceship_git() {
[[ $SPACESHIP_GIT_SHOW == false ]] && return
local git_branch="$(spaceship_git_branch)" git_status="$(spaceship_git_status)"
[[ -z $git_branch ]] && return
_prompt_section \
'white' \
"$SPACESHIP_GIT_PREFIX" \
"${git_branch}${git_status}" \
"$SPACESHIP_GIT_SUFFIX"
}
# VENV
# Show current virtual environment (Python).
spaceship_venv() {
[[ $SPACESHIP_VENV_SHOW == false ]] && return
# Check if the current directory running via Virtualenv
[ -n "$VIRTUAL_ENV" ] && _exists deactivate || return
_prompt_section \
"$SPACESHIP_VENV_COLOR" \
"$SPACESHIP_VENV_PREFIX" \
"$(basename $VIRTUAL_ENV)" \
"$SPACESHIP_VENV_SUFFIX"
}
# PYENV
# Show current version of pyenv python, including system.
spaceship_pyenv() {
[[ $SPACESHIP_PYENV_SHOW == false ]] && return
# Show NVM status only for Python-specific folders
[[ -f requirements.txt ]] || [[ -n *.py(#qN) ]] || return
_exists pyenv || return # Do nothing if pyenv is not installed
local pyenv_status=${$(pyenv version-name 2>/dev/null)//:/ }
_prompt_section \
"$SPACESHIP_PYENV_COLOR" \
"$SPACESHIP_PYENV_PREFIX" \
"${SPACESHIP_PYENV_SYMBOL}${pyenv_status}" \
"$SPACESHIP_PYENV_SUFFIX"
}
# EXECUTION TIME
# Execution time of the last command.
spaceship_exec_time() {
[[ $SPACESHIP_EXEC_TIME_SHOW == false ]] && return
if [[ $SPACESHIP_EXEC_TIME_duration -ge $SPACESHIP_EXEC_TIME_ELAPSED ]]; then
_prompt_section \
"$SPACESHIP_EXEC_TIME_COLOR" \
"$SPACESHIP_EXEC_TIME_PREFIX" \
"$(_displaytime $SPACESHIP_EXEC_TIME_duration)" \
"$SPACESHIP_EXEC_TIME_SUFFIX"
fi
}
# JOBS
# Show icon if there's a working jobs in the background
spaceship_jobs() {
[[ $SPACESHIP_JOBS_SHOW == false ]] && return
local jobs_amount=$(jobs -l | wc -l | xargs)
[[ $jobs_amount -gt 0 ]] || return
[[ $jobs_amount -eq 1 ]] && jobs_amount=''
_prompt_section \
"$SPACESHIP_JOBS_COLOR" \
"$SPACESHIP_JOBS_PREFIX" \
"${SPACESHIP_JOBS_SYMBOL}${jobs_amount}" \
"$SPACESHIP_JOBS_SUFFIX"
}
# EXIT CODE
# Show exit code of last statement
spaceship_exit_code() {
[[ $SPACESHIP_EXIT_CODE_SHOW == false || $RETVAL == 0 ]] && return
_prompt_section \
"$SPACESHIP_EXIT_CODE_COLOR" \
"$SPACESHIP_EXIT_CODE_PREFIX" \
"${SPACESHIP_EXIT_CODE_SYMBOl}$RETVAL" \
"$SPACESHIP_EXIT_CODE_SUFFIX"
}
# LINE SEPARATOR
# Should it write prompt in two lines or not?
spaceship_line_sep() {
[[ $SPACESHIP_PROMPT_SEPARATE_LINE == true ]] && echo -n "$NEWLINE"
}
# PROMPT CHARACTER
# Paint $PROMPT_SYMBOL in red if previous command was fail and
# paint in green if everything was OK.
spaceship_char() {
_prompt_section "%(?.green.red)" "${SPACESHIP_PROMPT_SYMBOL} "
}
# ------------------------------------------------------------------------------
# BACKWARD COMPATIBILITY WARNINGS
# Show deprecation messages for options that are set, but not supported
# ------------------------------------------------------------------------------
# PROMPT
_deprecated SPACESHIP_PROMPT_TRUNC SPACESHIP_DIR_TRUNC
# PREFIXES
_deprecated SPACEHIP_PREFIX_SHOW SPACESHIP_PROMPT_PREFIXES_SHOW
_deprecated SPACESHIP_PREFIX_TIME SPACESHIP_TIME_PREFIX
_deprecated SPACESHIP_PREFIX_USER SPACESHIP_USER_PREFIX
_deprecated SPACESHIP_PREFIX_HOST SPACESHIP_HOST_PREFIX
_deprecated SPACESHIP_PREFIX_DIR SPACESHIP_DIR_PREFIX
_deprecated SPACESHIP_PREFIX_GIT SPACESHIP_GIT_PREFIX
_deprecated SPACESHIP_PREFIX_ENV_DEFAULT SPACESHIP_PROMPT_DEFAULT_PREFIX
_deprecated SPACESHIP_PREFIX_VENV SPACESHIP_VENV_PREFIX
_deprecated SPACESHIP_PREFIX_PYENV SPACESHIP_PYENV_PREFIX
# GIT
_deprecated SPACESHIP_GIT_COLOR SPACESHIP_GIT_BRANCH_COLOR
_deprecated SPACESHIP_GIT_UNCOMMITTED SPACESHIP_GIT_STATUS_ADDED
_deprecated SPACESHIP_GIT_UNTRACKED SPACESHIP_GIT_STATUS_UNTRACKED
_deprecated SPACESHIP_GIT_UNSTAGED SPACESHIP_GIT_STATUS_MODIFIED
_deprecated SPACESHIP_GIT_STASHED SPACESHIP_GIT_STATUS_STASHED
_deprecated SPACESHIP_GIT_UNPULLED SPACESHIP_GIT_STATUS_BEHIND
_deprecated SPACESHIP_GIT_UNPUSHED SPACESHIP_GIT_STATUS_AHEAD
# ------------------------------------------------------------------------------
# MAIN
# An entry point of prompt
# ------------------------------------------------------------------------------
# Compose whole prompt from smaller parts
spaceship_prompt() {
# Retirve exit code of last command to use in exit_code
# Must be captured before any other command in prompt is executed
RETVAL=$?
# Option EXTENDED_GLOB is set locally to force filename generation on
# argument to conditions, i.e. allow usage of explicit glob qualifier (#q).
# See the description of filename generation in
# http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html
setopt EXTENDED_GLOB LOCAL_OPTIONS
# Should it add a new line before the prompt?
[[ $SPACESHIP_PROMPT_ADD_NEWLINE == true ]] && echo -n "$NEWLINE"
# Execute all parts
for section in $SPACESHIP_PROMPT_ORDER; do
spaceship_$section
done
}
# PS2 - continuation interactive prompt
spaceship_ps2() {
_prompt_section "yellow" $SPACESHIP_PROMPT_SYMBOL
}
# Setup required environment variables
# All preparation before drawing prompt should be done here
spaceship_setup() {
autoload -Uz add-zsh-hook
# Add exec_time hooks
add-zsh-hook preexec spaceship_exec_time_preexec_hook
add-zsh-hook precmd spaceship_exec_time_precmd_hook
# Disable python virtualenv environment prompt prefix
VIRTUAL_ENV_DISABLE_PROMPT=true
# Expose Spaceship to environment variables
PROMPT='$(spaceship_prompt)'
PS2='$(spaceship_ps2)'
# LSCOLORS
# Online editor: https://geoff.greer.fm/lscolors/
export LSCOLORS="Gxfxcxdxbxegedabagacab"
export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:ow=0;41:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:*.patch=00;34:*.o=00;32:*.so=01;35:*.ko=01;31:*.la=00;33'
# Zsh to use the same colors as ls
# Link: http://superuser.com/a/707567
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
}
# Entry point
# Pass all arguments to the spaceship_setup function
spaceship_setup "$@"