-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtrueline.sh
650 lines (602 loc) · 20.7 KB
/
trueline.sh
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# shellcheck disable=SC2155,SC2148
#---------+
# Helpers |
#---------+
_trueline_font_style() {
style="$1"
case "$style" in
bold)
style=1
;;
dim)
style=2
;;
italic)
style=3
;;
underlined)
style=4
;;
**)
style=22
;;
esac
style+="m"
echo "$style"
}
_trueline_content() {
fg_c="${TRUELINE_COLORS[$1]}"
bg_c="$2"
style="$(_trueline_font_style "$3")"
content="$4"
esc_seq_start="\["
esc_seq_end="\]"
if [[ -n "$5" ]] && [[ "$5" == "vi" ]]; then
esc_seq_start="\1"
esc_seq_end="\2"
fi
output="$esc_seq_start\033[0m\033[38;2;$fg_c;"
if [[ "$bg_c" != 'default_bg' ]]; then
bg_c="${TRUELINE_COLORS[$bg_c]}"
output+="48;2;$bg_c;"
fi
output+="$style$esc_seq_end$content$esc_seq_start\033[0m$esc_seq_end"
echo "$output"
}
_trueline_separator() {
if [[ -n "$_last_color" ]]; then
# Only add a separator if it's not the first section (and hence last
# color is set/defined)
if [[ -n "$1" ]]; then
local bg_color="$1"
fi
_trueline_content "$_last_color" "$bg_color" bold "${TRUELINE_SYMBOLS[segment_separator]}"
fi
}
_trueline_record_colors() {
local force="$4"
if [[ -z "$_first_color_fg" ]] || [[ -n "$force" ]]; then
_first_color_fg="$1"
_first_color_bg="$2"
_first_font_style="$3"
fi
_last_color="$2"
}
#----------+
# Segments |
#----------+
_trueline_is_root() {
if [[ "${EUID}" -eq 0 ]]; then
echo 'is_root'
fi
}
_trueline_ip_address() {
\ip route get 1 | tr -s ' ' | cut -d' ' -f7
}
_trueline_has_ssh() {
if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then
echo 'has_ssh'
fi
}
_trueline_user_segment() {
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local user="$USER"
local is_root="$(_trueline_is_root)"
if [[ -n "$is_root" ]]; then
if [[ -z "$user" ]]; then
user='root'
fi
fg_color=${TRUELINE_USER_ROOT_COLORS[0]}
bg_color=${TRUELINE_USER_ROOT_COLORS[1]}
fi
local has_ssh="$(_trueline_has_ssh)"
if [[ -n "$has_ssh" ]]; then
user="${TRUELINE_SYMBOLS[ssh]} $user"
fi
if [[ -n "$has_ssh" ]] || [[ "$TRUELINE_USER_ALWAYS_SHOW_HOSTNAME" = true ]]; then
user+="@"
if [ "$TRUELINE_USER_SHOW_IP_SSH" = true ]; then
user+="$(_trueline_ip_address)"
elif [ "$TRUELINE_USER_SHORTEN_HOSTNAME" = true ]; then
user+="$(hostname -s)"
else
user+="$HOSTNAME"
fi
fi
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " $user ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
}
_trueline_has_venv() {
printf "%s" "${VIRTUAL_ENV##*/}"
}
_trueline_venv_segment() {
local venv="$(_trueline_has_venv)"
if [[ -n "$venv" ]]; then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " ${TRUELINE_SYMBOLS[venv]} $venv ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_has_conda_env() {
printf "%s" "${CONDA_DEFAULT_ENV}"
}
_trueline_conda_env_segment() {
local conda_env="$(_trueline_has_conda_env)"
if [[ -n "$conda_env" ]]; then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " ${TRUELINE_SYMBOLS[venv]} $conda_env")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_has_aws_profile() {
printf "%s" "${AWS_PROFILE}"
}
_trueline_aws_profile_segment() {
local profile_aws="$(_trueline_has_aws_profile)"
if [[ -n "$profile_aws" ]]; then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " ${TRUELINE_SYMBOLS[aws_profile]} $profile_aws ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_has_git_branch() {
branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ "$?" -ne "128" ]]; then
printf "%s" "$branch"
else
printf "%s" ""
fi
}
_trueline_git_mod_files() {
nr_mod_files="$(git diff --name-only --diff-filter=M 2> /dev/null | wc -l | sed 's/^ *//')"
mod_files=''
if [[ ! "$nr_mod_files" -eq 0 ]]; then
mod_files="${TRUELINE_SYMBOLS[git_modified]} "
if [[ "$TRUELINE_GIT_SHOW_STATUS_NUMBERS" = true ]]; then
mod_files+="$nr_mod_files "
fi
fi
echo "$mod_files"
}
_trueline_git_behind_ahead() {
branch="$1"
upstream="$(git config --get branch."$branch".merge)"
if [[ -n $upstream ]]; then
nr_behind_ahead="$(git rev-list --count --left-right '@{upstream}...HEAD' 2> /dev/null)" || nr_behind_ahead=''
nr_behind="${nr_behind_ahead% *}"
nr_ahead="${nr_behind_ahead#* }"
git_behind_ahead=''
if [[ ! "$nr_behind" -eq 0 ]]; then
git_behind_ahead+="${TRUELINE_SYMBOLS[git_behind]} "
if [[ "$TRUELINE_GIT_SHOW_STATUS_NUMBERS" = true ]]; then
git_behind_ahead+="$nr_behind "
fi
fi
if [[ ! "$nr_ahead" -eq 0 ]]; then
git_behind_ahead+="${TRUELINE_SYMBOLS[git_ahead]} "
if [[ "$TRUELINE_GIT_SHOW_STATUS_NUMBERS" = true ]]; then
git_behind_ahead+="$nr_ahead "
fi
fi
echo "$git_behind_ahead"
fi
}
_trueline_git_remote_icon() {
remote=$(command git ls-remote --get-url 2> /dev/null)
remote_icon="${TRUELINE_SYMBOLS[git_branch]}"
if [[ "$remote" =~ "github" ]]; then
remote_icon="${TRUELINE_SYMBOLS[git_github]} "
elif [[ "$remote" =~ "bitbucket" ]]; then
remote_icon="${TRUELINE_SYMBOLS[git_bitbucket]} "
elif [[ "$remote" =~ "gitlab" ]]; then
remote_icon="${TRUELINE_SYMBOLS[git_gitlab]} "
elif [[ "$remote" =~ "codeberg" ]]; then
remote_icon="${TRUELINE_SYMBOLS[git_codeberg]} "
fi
if [[ -n "${remote_icon// /}" ]]; then
remote_icon=" $remote_icon "
fi
echo "$remote_icon"
}
_trueline_git_segment() {
local branch="$(_trueline_has_git_branch)"
if [[ -n $branch ]]; then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
local branch_icon="$(_trueline_git_remote_icon)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" "$branch_icon$branch ")"
local mod_files="$(_trueline_git_mod_files)"
if [[ -n "$mod_files" ]]; then
segment+="$(_trueline_content "$TRUELINE_GIT_MODIFIED_COLOR" "$bg_color" "$font_style" "$mod_files")"
fi
local behind_ahead="$(_trueline_git_behind_ahead "$branch")"
if [[ -n "$behind_ahead" ]]; then
segment+="$(_trueline_content "$TRUELINE_GIT_BEHIND_AHEAD_COLOR" "$bg_color" "$font_style" "$behind_ahead")"
fi
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_working_dir_segment() {
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
local wd_separator="${TRUELINE_SYMBOLS[working_dir_separator]}"
if [[ "$TRUELINE_WORKING_DIR_SPACE_BETWEEN_PATH_SEPARATOR" = true ]]; then
wd_separator=" $wd_separator "
fi
local p="${PWD/#$HOME/${TRUELINE_SYMBOLS[working_dir_home]}}"
local arr=
IFS='/' read -r -a arr <<< "$p"
local path_size="${#arr[@]}"
if [[ "$path_size" -eq 1 ]]; then
local path_="\[\033[1m\]${arr[0]:=/}"
elif [[ "$path_size" -eq 2 ]]; then
local path_="${arr[0]:=/}$wd_separator\[\033[1m\]${arr[+1]}"
else
if [[ "$path_size" -gt 3 ]]; then
if [[ "$TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS" = true ]]; then
p=$(echo "$p" | sed -r "s:([^/]{,$TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS_LENGTH})[^/]*/:\1/:g")
else
p="${TRUELINE_SYMBOLS[working_dir_folder]}/"$(echo "$p" | awk -F'/' '{n=NF; print $(n-2)"/"$(n-1)"/"$n}')
fi
fi
local curr=$(basename "$p")
p=$(dirname "$p")
local path_="${p//\//$wd_separator}$wd_separator\[\033[1m\]$curr"
if [[ "${p:0:1}" = '/' ]]; then
path_="/$path_"
fi
fi
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " $path_ ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
}
_trueline_bg_jobs_segment() {
# Note: We clear terminated foreground job information by first calling
# `jobs &>/dev/null' and then obtain the information of the currently running
# jobs by `jobs -p'.
local bg_jobs=$(
jobs &> /dev/null
jobs -p | wc -l | sed 's/^ *//'
)
if [[ ! "$bg_jobs" -eq 0 ]]; then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " ${TRUELINE_SYMBOLS[bg_jobs]} $bg_jobs ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_is_read_only() {
if [[ ! -w $PWD ]]; then
echo 'read_only'
fi
}
_trueline_read_only_segment() {
local read_only="$(_trueline_is_read_only)"
if [[ -n $read_only ]]; then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " ${TRUELINE_SYMBOLS[read_only]} ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_exit_status_segment() {
if [[ "$_exit_status" != 0 ]]; then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" "${TRUELINE_SYMBOLS[exit_status]} $_exit_status ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_newline_segment() {
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local is_root="$(_trueline_is_root)"
local newline_symbol="${TRUELINE_SYMBOLS[newline]}"
if [[ -n "$is_root" ]]; then
local newline_symbol="${TRUELINE_SYMBOLS[newline_root]}"
fi
local segment="$(_trueline_separator default_bg)"
segment+="\n"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" "$newline_symbol")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style" true
}
_trueline_vimode_cursor_shape() {
shape="$1"
case "$shape" in
under)
cursor_parameter=4
;;
vert)
cursor_parameter=6
;;
**)
cursor_parameter=2
;;
esac
# shellcheck disable=SC2028
echo "\1\e[$cursor_parameter q\2"
}
_trueline_vimode_segment() {
if [[ "$TRUELINE_SHOW_VIMODE" = true ]]; then
if [[ ! -o vi ]]; then
set -o vi
fi
local seg_separator=${TRUELINE_SYMBOLS[segment_separator]}
bind "set show-mode-in-prompt on"
local vimode_ins_fg=${TRUELINE_VIMODE_INS_COLORS_STYLE[0]}
local vimode_ins_bg=${TRUELINE_VIMODE_INS_COLORS_STYLE[1]}
local vimode_ins_font_style=${TRUELINE_VIMODE_INS_COLORS_STYLE[2]}
local segment="$(_trueline_content "$vimode_ins_fg" "$vimode_ins_bg" "$vimode_ins_font_style" " ${TRUELINE_SYMBOLS[vimode_ins]} " "vi")"
segment+="$(_trueline_content "$vimode_ins_bg" "$_first_color_bg" bold "$seg_separator" "vi")"
segment+="$(_trueline_vimode_cursor_shape "$TRUELINE_VIMODE_INS_CURSOR")"
bind "set vi-ins-mode-string $segment"
local vimode_cmd_fg=${TRUELINE_VIMODE_CMD_COLORS_STYLE[0]}
local vimode_cmd_bg=${TRUELINE_VIMODE_CMD_COLORS_STYLE[1]}
local vimode_cmd_font_style=${TRUELINE_VIMODE_CMD_COLORS_STYLE[2]}
segment="$(_trueline_content "$vimode_cmd_fg" "$vimode_cmd_bg" "$vimode_cmd_font_style" " ${TRUELINE_SYMBOLS[vimode_cmd]} " "vi")"
segment+="$(_trueline_content "$vimode_cmd_bg" "$_first_color_bg" bold "$seg_separator" "vi")"
segment+="$(_trueline_vimode_cursor_shape "$TRUELINE_VIMODE_CMD_CURSOR")"
bind "set vi-cmd-mode-string $segment"
# Switch to block cursor before executing a command
bind -m vi-insert 'RETURN: "\e\n"'
else
bind "set show-mode-in-prompt off"
fi
}
_trueline_cmd_duration_segment() {
function _trueline_format_time {
local T=$1
local D=$((T / 60 / 60 / 24))
local H=$((T / 60 / 60 % 24))
local M=$((T / 60 % 60))
local S=$((T % 60))
local result=""
((D > 0)) && result="${D}d "
((H > 0)) && result="${result}${H}h "
((M > 0)) && result="${result}${M}m "
((S > 0)) && result="${result}${S}s "
echo -e "${result}" | sed -e 's/[[:space:]]*$//'
}
function _trueline_timestamp_cleanup() {
command rm -f "$TRUELINE_TIMESTAMP_FILE" 2> /dev/null
}
trap _trueline_timestamp_cleanup EXIT
# PS0 gets expanded after a command is read (just before execution)
TRUELINE_TIMESTAMP_FILE="/tmp/trueline.user-${USER}.pid-$$.timestamp"
# shellcheck disable=SC2034,SC2016
PS0='$(date +%s > "$TRUELINE_TIMESTAMP_FILE")'
local duration=0
if [ -e "$TRUELINE_TIMESTAMP_FILE" ]; then
local end=$(date +%s)
local start=$(cat "$TRUELINE_TIMESTAMP_FILE")
duration="$((end - start))"
_trueline_timestamp_cleanup
fi
if ((duration > 0)); then
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
local elapsed="$(_trueline_format_time duration)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " ${TRUELINE_SYMBOLS[timer]}$elapsed ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
fi
}
_trueline_distro_icon_segment() {
case "$(grep ^ID= /etc/os-release)" in
*ubuntu*) distro_icon=" " ;;
*fedora*) distro_icon=" " ;;
*debian*) distro_icon=" " ;;
*arch*) distro_icon=" " ;;
*) distro_icon="${TRUELINE_SYMBOLS[distro_icon]} " ;;
esac
local fg_color="$1"
local bg_color="$2"
local font_style="$3"
local segment="$(_trueline_separator)"
segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " $distro_icon ")"
PS1+="$segment"
_trueline_record_colors "$fg_color" "$bg_color" "$font_style"
}
#-------------+
# PS1 and PS2 |
#-------------+
_trueline_continuation_prompt() {
PS2=$(_trueline_content "$_first_color_fg" "$_first_color_bg" "$_first_font_style" " ${TRUELINE_SYMBOLS[ps2]} ")
PS2+=$(_trueline_content "$_first_color_bg" default_bg bold "${TRUELINE_SYMBOLS[segment_separator]} ")
}
_trueline_prompt_command() {
local _exit_status="$?"
PS1=""
local segment_def=
for segment_def in "${TRUELINE_SEGMENTS[@]}"; do
local segment_name=$(echo "$segment_def" | cut -d ',' -f1)
local segment_fg=$(echo "$segment_def" | cut -d ',' -f2)
local segment_bg=$(echo "$segment_def" | cut -d ',' -f3)
local font_style=$(echo "$segment_def" | cut -d ',' -f4)
# Note: we cannot call within a subshell because global variables
# (such as _last_color) won't be passed along
'_trueline_'"$segment_name"'_segment' "$segment_fg" "$segment_bg" "$font_style"
done
_trueline_vimode_segment
PS1+=$(_trueline_content "$_last_color" default_bg bold "${TRUELINE_SYMBOLS[segment_separator]}")
PS1+=" " # non-breakable space
_trueline_continuation_prompt
unset _first_color_fg
unset _first_color_bg
unset _first_font_style
unset _last_color
# Note: we reset the exit status to the original value for the subsequent
# commands in PROMPT_COMMAND.
return "$_exit_status"
}
#---------------+
# Configuration |
#---------------+
declare -A TRUELINE_COLORS_DEFAULT=(
[black]='36;39;46' #24272e
[cursor_grey]='40;44;52' #282c34
[green]='152;195;121' #98c379
[grey]='171;178;191' #abb2bf
[light_blue]='97;175;239' #61afef
[mono]='130;137;151' #828997
[orange]='209;154;102' #d19a66
[purple]='198;120;221' #c678dd
[red]='224;108;117' #e06c75
[special_grey]='59;64;72' #3b4048
[white]='208;208;208' #d0d0d0
)
if [[ "${#TRUELINE_COLORS[@]}" -eq 0 ]]; then
declare -A TRUELINE_COLORS=()
fi
for i in "${!TRUELINE_COLORS_DEFAULT[@]}"; do
if [[ ! "${TRUELINE_COLORS["$i"]+exists}" ]]; then
TRUELINE_COLORS["$i"]="${TRUELINE_COLORS_DEFAULT["$i"]}"
fi
done
unset TRUELINE_COLORS_DEFAULT
if [[ "${#TRUELINE_SEGMENTS[@]}" -eq 0 ]]; then
declare -a TRUELINE_SEGMENTS=(
'user,black,white,bold'
'aws_profile,black,orange,bold'
'venv,black,purple,bold'
'conda_env,black,purple,bold'
'git,grey,special_grey,normal'
'working_dir,mono,cursor_grey,normal'
'read_only,black,orange,bold'
'bg_jobs,black,orange,bold'
'exit_status,black,red,bold'
# 'cmd_duration,black,grey,normal'
# 'newline,black,orange,bold'
# 'distro_icon,black,green,normal'
)
fi
declare -A TRUELINE_SYMBOLS_DEFAULT=(
[aws_profile]=''
[bg_jobs]=''
[distro_icon]=' '
[exit_status]=' '
[git_ahead]=''
[git_behind]=''
[git_bitbucket]=''
[git_branch]=''
[git_codeberg]=''
[git_github]=''
[git_gitlab]=''
[git_modified]=''
[newline]=' '
[newline_root]=' '
[ps2]='...'
[read_only]=''
[segment_separator]=''
[ssh]=''
[timer]=''
[venv]=''
[vimode_cmd]='N'
[vimode_ins]='I'
[working_dir_folder]=''
[working_dir_home]=''
[working_dir_separator]=''
)
if [[ "${#TRUELINE_SYMBOLS[@]}" -eq 0 ]]; then
declare -A TRUELINE_SYMBOLS=()
fi
for i in "${!TRUELINE_SYMBOLS_DEFAULT[@]}"; do
if [[ ! "${TRUELINE_SYMBOLS["$i"]+exists}" ]]; then
TRUELINE_SYMBOLS["$i"]="${TRUELINE_SYMBOLS_DEFAULT["$i"]}"
fi
done
unset TRUELINE_SYMBOLS_DEFAULT
# Vimode
if [[ -z "$TRUELINE_SHOW_VIMODE" ]]; then
TRUELINE_SHOW_VIMODE=false
fi
if [[ -z "$TRUELINE_VIMODE_INS_COLORS_STYLE" ]]; then
TRUELINE_VIMODE_INS_COLORS_STYLE=('black' 'light_blue' 'bold')
fi
if [[ -z "$TRUELINE_VIMODE_CMD_COLORS_STYLE" ]]; then
TRUELINE_VIMODE_CMD_COLORS_STYLE=('black' 'green' 'bold')
fi
if [[ -z "$TRUELINE_VIMODE_INS_CURSOR" ]]; then
TRUELINE_VIMODE_INS_CURSOR='vert'
fi
if [[ -z "$TRUELINE_VIMODE_CMD_CURSOR" ]]; then
TRUELINE_VIMODE_CMD_CURSOR='block'
fi
# Git
if [[ -z "$TRUELINE_GIT_SHOW_STATUS_NUMBERS" ]]; then
TRUELINE_GIT_SHOW_STATUS_NUMBERS=true
fi
if [[ -z "$TRUELINE_GIT_MODIFIED_COLOR" ]]; then
TRUELINE_GIT_MODIFIED_COLOR='red'
fi
if [[ -z "$TRUELINE_GIT_BEHIND_AHEAD_COLOR" ]]; then
TRUELINE_GIT_BEHIND_AHEAD_COLOR='purple'
fi
# User
if [[ -z "$TRUELINE_USER_ROOT_COLORS" ]]; then
TRUELINE_USER_ROOT_COLORS=('black' 'red')
fi
if [[ -z "$TRUELINE_USER_SHOW_IP_SSH" ]]; then
TRUELINE_USER_SHOW_IP_SSH=false
fi
if [[ -z "$TRUELINE_USER_ALWAYS_SHOW_HOSTNAME" ]]; then
TRUELINE_USER_ALWAYS_SHOW_HOSTNAME=false
fi
if [[ -z "$TRUELINE_USER_SHORTEN_HOSTNAME" ]]; then
TRUELINE_USER_SHORTEN_HOSTNAME=false
fi
# Working dir
if [[ -z "$TRUELINE_WORKING_DIR_SPACE_BETWEEN_PATH_SEPARATOR" ]]; then
TRUELINE_WORKING_DIR_SPACE_BETWEEN_PATH_SEPARATOR=true
fi
if [[ -z "$TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS" ]]; then
TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS=false
fi
if [[ -z "$TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS_LENGTH" ]]; then
TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS_LENGTH=1
fi
#----------------+
# PROMPT_COMMAND |
#----------------+
if ((BASH_VERSINFO[0] > 5 || BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1)); then
# Bash 5.1 and above supports the PROMPT_COMMAND array
PROMPT_COMMAND=${PROMPT_COMMAND-}
PROMPT_COMMAND+=(_trueline_prompt_command)
else
# shellcheck disable=SC2128,SC2178
PROMPT_COMMAND="_trueline_prompt_command${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi