forked from liquidprompt/liquidprompt
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquidprompt
executable file
·5151 lines (4425 loc) · 166 KB
/
liquidprompt
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
################################################################################
# LIQUID PROMPT
# An intelligent and non-intrusive prompt for Bash and zsh
################################################################################
# shellcheck shell=bash
_LP_VERSION=(2 2 0 rc 2)
# Licensed under the AGPL version 3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:https://www.gnu.org/licenses/>.
# See the README.md file for a summary of features.
# Issue #161: do not load if not an interactive shell
# Do not exit if '--no-activate' flag was passed, as it overrides this check
# shellcheck disable=SC2268
[ "x${-##*i}" = "x$-" ] || [ -z "${TERM-}" ] || [ "x${TERM-}" = xdumb ] || [ "x${TERM-}" = xunknown ] && [ "x${1-}" != "x--no-activate" ] && return
if test -n "${BASH_VERSION-}"; then
# Check for recent enough version of bash.
if (( ${BASH_VERSINFO[0]:-0} < 3 || ( ${BASH_VERSINFO[0]:-0} == 3 && ${BASH_VERSINFO[1]:-0} < 2 ) )); then
echo "liquidprompt: Bash version $BASH_VERSION not supported" >&2
return
fi
_LP_SHELL_bash=1
_LP_SHELL_zsh=0
_LP_OPEN_ESC="\["
_LP_CLOSE_ESC="\]"
_LP_MARK_SYMBOL='$'
_LP_FIRST_INDEX=0
_LP_PERCENT='%' # must be escaped on zsh
# shellcheck disable=SC1003
_LP_BACKSLASH='\\' # must be escaped on bash
# Escape the given strings
# Must be used for all strings injected in PS1 that may comes from remote sources,
# like $PWD, VCS branch names...
__lp_escape() {
ret="${1//\\/\\\\}"
if shopt -q promptvars ; then
ret="${ret//\$/\\\$}"
ret="${ret//\`/\\\`}"
fi
}
__lp_strip_escapes() {
ret="$1"
while [[ "$ret" == *"$_LP_OPEN_ESC"* ]]; do
ret="${ret%%"$_LP_OPEN_ESC"*}${ret#*"$_LP_CLOSE_ESC"}"
done
ret="${ret//\\\\/\\}"
if shopt -q promptvars ; then
ret="${ret//\\\$/\$}"
ret="${ret//\\\`/\`}"
fi
}
elif test -n "${ZSH_VERSION-}" ; then
# Check for recent enough version of zsh.
if (( ${ZSH_VERSION:0:1} < 5 )); then
echo "liquidprompt: Zsh version $ZSH_VERSION not supported" >&2
return
fi
_LP_SHELL_bash=0
_LP_SHELL_zsh=1
_LP_OPEN_ESC="%{"
_LP_CLOSE_ESC="%}"
_LP_MARK_SYMBOL='%%'
if [[ -o ksh_arrays ]]; then
_LP_FIRST_INDEX=0
else
_LP_FIRST_INDEX=1
fi
_LP_PERCENT='%%'
# shellcheck disable=SC1003
_LP_BACKSLASH='\'
__lp_escape() {
ret="${1//\\/\\\\}"
ret="${ret//\%/%%}"
if [[ -o promptbang ]]; then
ret="${ret//!/!!}"
fi
if [[ -o promptsubst ]]; then
ret="${ret//\$/\\\$}"
ret="${ret//\`/\\\`}"
fi
}
__lp_strip_escapes() {
# shellcheck disable=SC2296
ret="${(S)1//"${_LP_OPEN_ESC}"*"${_LP_CLOSE_ESC}"}"
ret="${ret//\\\\/\\}"
ret="${ret//\%\%/%}"
if [[ -o promptbang ]]; then
ret="${ret//!!/!}"
fi
if [[ -o promptsubst ]]; then
ret="${ret//\\\$/\$}"
ret="${ret//\\\`/\`}"
fi
}
else
echo "liquidprompt: shell not supported" >&2
return
fi
__lp_use_bash_preexec() {
# If https://github.com/rcaloras/bash-preexec is present, we can (and should, because it interferes with
# PROMPT_COMMAND and DEBUG) use the zsh-hook like behavior it provides.
[[ "${__bp_imported-}" == "defined" ]]
}
__lp_array_contains() {
local target="$1"
shift
for element; do
if [[ $element == "$target" ]]; then
return 0
fi
done
return 1
}
###############
# OS specific #
###############
# LP_OS detection, default to Linux
case "$(uname)" in
FreeBSD) LP_OS=FreeBSD ;;
DragonFly) LP_OS=FreeBSD ;;
OpenBSD) LP_OS=OpenBSD ;;
Darwin) LP_OS=Darwin ;;
SunOS) LP_OS=SunOS ;;
*) LP_OS=Linux ;;
esac
_lp_os() {
# Fine-grained OS detection: arch, family, kernel, distrib, version.
(( LP_ENABLE_OS )) || return 2
# Output variables:
lp_os_arch=
lp_os_family=
lp_os_kernel=
lp_os_distrib=
lp_os_version=
local uname_sm kernel
# Get the kernel (and possibly the arch).
if (( LP_ENABLE_OS_ARCH )); then
# We can get the arch along, with a single subshell.
uname_sm="$(uname -s -m)"
IFS=' ' read -r kernel lp_os_arch <<<"$uname_sm"
else # In any case, we need to know the kernel.
kernel="$(uname -s)"
fi
if (( LP_ENABLE_OS_KERNEL
|| LP_ENABLE_OS_FAMILY
|| LP_ENABLE_OS_DISTRIB
|| LP_ENABLE_OS_VERSION )); then
case "$kernel" in
FreeBSD)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=BSD; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=FreeBSD; fi
;;
DragonFly)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=BSD; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=DragonFly; fi
;;
OpenBSD)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=BSD; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=OpenBSD; fi
;;
Darwin)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=BSD; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=Darwin; fi
;;
SunOS)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=UNIX; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=SunOS; fi
;;
CYGWIN*)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=Windows; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=Cygwin; fi
;;
MSYS*)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=Windows; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=MSYS; fi
;;
MINGW*)
if (( LP_ENABLE_OS_FAMILY )); then lp_os_family=Windows; fi
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=MinGW; fi
;;
Linux)
if (( LP_ENABLE_OS_KERNEL )); then lp_os_kernel=Linux; fi
if (( LP_ENABLE_OS_FAMILY )); then
if [[ "$kernel" == "Linux" ]]; then
osfamily="$(uname -o)"
if [[ "$osfamily" == "Android" ]]; then
lp_os_family=Android
return
fi # Android
fi # Linux
lp_os_family=GNU
fi
# TODO parse HOME_URL and add an hyperlink.
if (( LP_ENABLE_OS_DISTRIB && LP_ENABLE_OS_VERSION )); then
if _lp_grep_fields "/etc/os-release" "=" "ID" "VERSION_CODENAME"; then
lp_os_distrib=${lp_grep_fields[_LP_FIRST_INDEX+0]-}
lp_os_version=${lp_grep_fields[_LP_FIRST_INDEX+1]-}
fi
elif (( LP_ENABLE_OS_DISTRIB )); then
if _lp_grep_fields "/etc/os-release" "=" "ID"; then
lp_os_distrib=${lp_grep_fields[_LP_FIRST_INDEX+0]-}
fi
elif (( LP_ENABLE_OS_VERSION )); then
if _lp_grep_fields "/etc/os-release" "=" "VERSION_CODENAME"; then
lp_os_version=${lp_grep_fields[_LP_FIRST_INDEX+0]-}
fi
fi
;;
esac
fi
if [[ -z "${lp_os_arch}${lp_os_family}${lp_os_kernel}${lp_os_distrib}${lp_os_version}" ]]; then
return 1
fi
}
_lp_os_color() {
# Substitute lp_os_* names with icons/colored strings (from LP_MARK_OS),
# or hash colored versions.
# Join everything with LP_MARK_OS_SEP.
lp_os_color=
local lp_os_arch lp_os_family lp_os_kernel lp_os_distrib lp_os_version
_lp_os || return "$?"
local lp_substitute lp_hash_color lp_join
local active
active=()
for value in \
"$lp_os_arch" "$lp_os_family" "$lp_os_kernel" "$lp_os_distrib" "$lp_os_version"; do
if [[ -n "$value" ]]; then
if _lp_substitute "$value" "${LP_MARK_OS[@]}"; then
active+=("$lp_substitute")
elif _lp_hash_color "$value"; then
active+=("$lp_hash_color")
else
active+=("$value")
fi
fi
done
if [[ ${#active} -gt 0 ]]; then
_lp_join "$LP_MARK_OS_SEP" "${active[@]}"
lp_os_color="$lp_join"
else
return 1
fi
}
#################
# CONFIGURATION #
#################
# Return true if the current Liquid Prompt version is greater than or equal to the specified version.
# Return 1 if minor or less version difference, 2 if major difference.
_lp_version_greatereq() { # major, minor, [patch], [string], [number]
local major="$1" minor="$2" patch="${3-}" string="${4-}" number="${5-}"
if (( major > _LP_VERSION[_LP_FIRST_INDEX+0] )); then
return 2
elif (( major == _LP_VERSION[_LP_FIRST_INDEX+0] )); then
if (( minor > _LP_VERSION[_LP_FIRST_INDEX+1] )); then
return 1
elif (( minor == _LP_VERSION[_LP_FIRST_INDEX+1] )) && [[ -n $patch ]]; then
if (( patch > _LP_VERSION[_LP_FIRST_INDEX+2] )); then
return 1
elif (( patch == _LP_VERSION[_LP_FIRST_INDEX+2] )) && [[ -n $string && -n $number ]]; then
if [[ $string == "${_LP_VERSION[_LP_FIRST_INDEX+3]}" ]]; then
if (( number > _LP_VERSION[_LP_FIRST_INDEX+4] )); then
return 1
fi
elif [[ ${_LP_VERSION[_LP_FIRST_INDEX+3]} == "alpha" || \
( ${_LP_VERSION[_LP_FIRST_INDEX+3]} == "beta" && \
$string == "rc" ) ]]; then
return 1
fi
fi
fi
fi
return 0
}
# Load the user configuration and setup defaults.
# shellcheck disable=SC2034
__lp_source_config() {
local lp_terminal_format af_color='' ab_color=''
# Colors: variables are local so they will have a value only
# during config loading and will not conflict with other values
# with the same names defined by the user outside the config.
local BOLD="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${_LP_CLOSE_ESC}"
# Foreground colors
__lp_foreground_color 0
local BLACK="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local BOLD_GRAY="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 1
local RED="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local BOLD_RED="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 0
__lp_background_color 1
local WARN_RED="${_LP_OPEN_ESC}${af_color}${ab_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 7
local CRIT_RED="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${ab_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 3
local DANGER_RED="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${ab_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 2
local GREEN="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local BOLD_GREEN="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 3
local YELLOW="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local BOLD_YELLOW="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 4
local BLUE="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local BOLD_BLUE="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 5
local PURPLE="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local MAGENTA="${PURPLE}"
local PINK="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
local BOLD_PURPLE="${PINK}"
local BOLD_MAGENTA="${PINK}"
__lp_foreground_color 6
local CYAN="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local BOLD_CYAN="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
__lp_foreground_color 7
local WHITE="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
local BOLD_WHITE="${_LP_OPEN_ESC}${_LP_TI_BOLD-}${af_color}${_LP_CLOSE_ESC}"
# NO_COL is special: it will be used at runtime, not just during config loading
NO_COL="${_LP_OPEN_ESC}${_LP_TI_RESET-}${_LP_CLOSE_ESC}"
# compute the hash of the hostname and get the corresponding number in
# [1-6] (red,green,yellow,blue,purple or cyan)
local lp_hostname_hash
__lp_hostname_hash
__lp_foreground_color "$(( 1 + lp_hostname_hash % 6 ))"
LP_COLOR_HOST_HASH="${_LP_OPEN_ESC}${af_color}${_LP_CLOSE_ESC}"
# Default values (globals)
LP_TIME_FORMAT=${LP_TIME_FORMAT:-"%H:%M:%S"}
LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75}
LP_DISK_THRESHOLD=${LP_DISK_THRESHOLD:-102400} # 100 MiB in KiB
LP_DISK_THRESHOLD_PERC=${LP_DISK_THRESHOLD_PERC:-10} # 10% or less
LP_DISK_PRECISION=${LP_DISK_PRECISION:-2}
LP_RAM_THRESHOLD=${LP_RAM_THRESHOLD:-102400} # 100 MiB in KiB
LP_RAM_THRESHOLD_PERC=${LP_RAM_THRESHOLD_PERC:-10} # 10% or less
LP_RAM_PRECISION=${LP_RAM_PRECISION:-2}
LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-0.60}
LP_LOAD_CAP=${LP_LOAD_CAP:-2.0}
LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-60}
LP_WIFI_STRENGTH_THRESHOLD=${LP_WIFI_STRENGTH_THRESHOLD:-40}
LP_RUNTIME_THRESHOLD=${LP_RUNTIME_THRESHOLD:-2}
LP_RUNTIME_BELL_THRESHOLD=${LP_RUNTIME_BELL_THRESHOLD:-10}
LP_PATH_LENGTH=${LP_PATH_LENGTH:-35}
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
LP_PATH_CHARACTER_KEEP=${LP_PATH_CHARACTER_KEEP:-3}
LP_PATH_METHOD=${LP_PATH_METHOD:-truncate_chars_from_path_left}
LP_PATH_VCS_ROOT=${LP_PATH_VCS_ROOT:-1}
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
LP_HOSTNAME_METHOD=${LP_HOSTNAME_METHOD:-short}
LP_USER_ALWAYS=${LP_USER_ALWAYS:-1}
LP_ALWAYS_DISPLAY_VALUES=${LP_ALWAYS_DISPLAY_VALUES:-1}
LP_DISPLAY_VALUES_AS_PERCENTS=${LP_DISPLAY_VALUES_AS_PERCENTS:-0}
LP_PS1=${LP_PS1:-""}
LP_PS1_PREFIX=${LP_PS1_PREFIX:-""}
LP_PS1_POSTFIX=${LP_PS1_POSTFIX:-""}
LP_DELIMITER_KUBECONTEXT_SUFFIX=${LP_DELIMITER_KUBECONTEXT_SUFFIX:-""}
LP_DELIMITER_KUBECONTEXT_PREFIX=${LP_DELIMITER_KUBECONTEXT_PREFIX:-""}
LP_ENV_VARS=( ${LP_ENV_VARS[@]+"${LP_ENV_VARS[@]}"} )
LP_ENABLE_DISPLAY=${LP_ENABLE_DISPLAY:-1}
LP_ENABLE_CHROOT=${LP_ENABLE_CHROOT:-1}
LP_ENABLE_MULTIPLEXER=${LP_ENABLE_MULTIPLEXER:-1}
LP_ENABLE_PERM=${LP_ENABLE_PERM:-1}
LP_ENABLE_SHORTEN_PATH=${LP_ENABLE_SHORTEN_PATH:-1}
LP_ENABLE_PROXY=${LP_ENABLE_PROXY:-1}
LP_ENABLE_ENV_VARS=${LP_ENABLE_ENV_VARS:-1}
LP_ENABLE_TEMP=${LP_ENABLE_TEMP:-1}
LP_ENABLE_JOBS=${LP_ENABLE_JOBS:-1}
LP_ENABLE_DETACHED_SESSIONS=${LP_ENABLE_DETACHED_SESSIONS:-1}
LP_ENABLE_LOAD=${LP_ENABLE_LOAD:-1}
LP_ENABLE_BATT=${LP_ENABLE_BATT:-1}
LP_ENABLE_RAM=${LP_ENABLE_RAM:-1}
LP_ENABLE_DISK=${LP_ENABLE_DISK:-0}
LP_ENABLE_GIT=${LP_ENABLE_GIT:-1}
LP_ENABLE_SVN=${LP_ENABLE_SVN:-1}
LP_ENABLE_FOSSIL=${LP_ENABLE_FOSSIL:-1}
LP_ENABLE_HG=${LP_ENABLE_HG:-1}
LP_HG_COMMAND=${LP_HG_COMMAND:-hg}
LP_ENABLE_BZR=${LP_ENABLE_BZR:-1}
LP_ENABLE_VCS_REMOTE=${LP_ENABLE_VCS_REMOTE:-0}
LP_ENABLE_TIME=${LP_ENABLE_TIME:-0}
LP_TIME_ANALOG=${LP_TIME_ANALOG:-0}
LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-1}
LP_ENABLE_RUNTIME_BELL=${LP_ENABLE_RUNTIME_BELL:-0}
LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1}
LP_ENABLE_NODE_VENV=${LP_ENABLE_NODE_VENV:-0}
LP_ENABLE_RUBY_VENV=${LP_ENABLE_RUBY_VENV:-1}
LP_RUBY_RVM_PROMPT_OPTIONS=( ${LP_RUBY_RVM_PROMPT_OPTIONS[@]+"${LP_RUBY_RVM_PROMPT_OPTIONS[@]}"} )
[[ ${#LP_RUBY_RVM_PROMPT_OPTIONS[@]} == 0 ]] && LP_RUBY_RVM_PROMPT_OPTIONS=(i v g s)
LP_ENABLE_PERL_VENV=${LP_ENABLE_PERL_VENV:-1}
LP_ENABLE_TERRAFORM=${LP_ENABLE_TERRAFORM:-0}
LP_ENABLE_CONTAINER=${LP_ENABLE_CONTAINER:-0}
LP_ENABLE_SCLS=${LP_ENABLE_SCLS:-1}
LP_ENABLE_AWS_PROFILE=${LP_ENABLE_AWS_PROFILE:-1}
LP_ENABLE_MODULES=${LP_ENABLE_MODULES:-1}
LP_ENABLE_MODULES_VERSIONS=${LP_ENABLE_MODULES_VERSIONS:-1}
LP_ENABLE_MODULES_HASHCOLOR=${LP_ENABLE_MODULES_HASHCOLOR:-0}
LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0}
LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0}
LP_ENABLE_SCREEN_TITLE=${LP_ENABLE_SCREEN_TITLE:-0}
LP_ENABLE_TITLE_COMMAND=${LP_ENABLE_TITLE_COMMAND:-1}
LP_ENABLE_TMUX_TITLE_PANES=${LP_ENABLE_TMUX_TITLE_PANES:-1}
LP_ENABLE_SSH_COLORS=${LP_ENABLE_SSH_COLORS:-0}
LP_DISABLED_VCS_PATHS=( ${LP_DISABLED_VCS_PATHS[@]+"${LP_DISABLED_VCS_PATHS[@]}"} )
LP_TEMP_SYSFS_IGNORE_FILES=( ${LP_TEMP_SYSFS_IGNORE_FILES[@]+"${LP_TEMP_SYSFS_IGNORE_FILES[@]}"} )
LP_ENABLE_SUDO=${LP_ENABLE_SUDO:-0}
LP_ENABLE_COLOR=${LP_ENABLE_COLOR:-1}
LP_ENABLE_ERROR=${LP_ENABLE_ERROR:-1}
LP_ENABLE_ERROR_MEANING=${LP_ENABLE_ERROR_MEANING:-0}
LP_ENABLE_ERROR_MEANING_EXTENDED=${LP_ENABLE_ERROR_MEANING_EXTENDED:-0}
LP_ENABLE_DIRSTACK=${LP_ENABLE_DIRSTACK:-0}
LP_ENABLE_KUBECONTEXT=${LP_ENABLE_KUBECONTEXT:-0}
LP_ENABLE_KUBE_NAMESPACE=${LP_ENABLE_KUBE_NAMESPACE:-0}
LP_ENABLE_CMAKE=${LP_ENABLE_CMAKE:-0}
LP_ENABLE_SHLVL=${LP_ENABLE_SHLVL:-1}
LP_SHLVL_THRESHOLD=${LP_SHLVL_THRESHOLD:-2}
LP_ENABLE_WIFI_STRENGTH=${LP_ENABLE_WIFI_STRENGTH:-0}
LP_ENABLE_OS=${LP_ENABLE_OS:-0}
LP_ENABLE_OS_ARCH=${LP_ENABLE_OS_ARCH:-0}
LP_ENABLE_OS_FAMILY=${LP_ENABLE_OS_FAMILY:-0}
LP_ENABLE_OS_KERNEL=${LP_ENABLE_OS_KERNEL:-1}
LP_ENABLE_OS_DISTRIB=${LP_ENABLE_OS_DISTRIB:-0}
LP_ENABLE_OS_VERSION=${LP_ENABLE_OS_VERSION:-1}
LP_ENABLE_HYPERLINKS=${LP_ENABLE_HYPERLINKS:-0}
LP_ENABLE_PATH=${LP_ENABLE_PATH:-1}
LP_HIDE_EMPTY_ERROR=${LP_HIDE_EMPTY_ERROR:-1}
LP_MARK_DEFAULT="${LP_MARK_DEFAULT:-$_LP_MARK_SYMBOL}"
LP_MARK_BATTERY="${LP_MARK_BATTERY:-"⌁"}"
LP_MARK_ADAPTER="${LP_MARK_ADAPTER:-"⏚"}"
LP_MARK_LOAD="${LP_MARK_LOAD:-"⌂"}"
LP_MARK_TEMP="${LP_MARK_TEMP:-"θ"}"
LP_MARK_PROXY="${LP_MARK_PROXY:-"↥"}"
LP_MARK_ENV_VARS_OPEN="${LP_MARK_ENV_VARS_OPEN:-"("}"
LP_MARK_ENV_VARS_SEP="${LP_MARK_ENV_VARS_SEP:-" "}"
LP_MARK_ENV_VARS_CLOSE="${LP_MARK_ENV_VARS_CLOSE:-")"}"
LP_MARK_HG="${LP_MARK_HG:-"☿"}"
LP_MARK_SVN="${LP_MARK_SVN:-"‡"}"
LP_MARK_GIT="${LP_MARK_GIT:-"±"}"
LP_MARK_VCSH="${LP_MARK_VCSH:-"|"}"
LP_MARK_FOSSIL="${LP_MARK_FOSSIL:-"⌘"}"
LP_MARK_BZR="${LP_MARK_BZR:-"⚯"}"
LP_MARK_DISABLED="${LP_MARK_DISABLED:-"⌀"}"
LP_MARK_UNTRACKED="${LP_MARK_UNTRACKED:-"*"}"
LP_MARK_STASH="${LP_MARK_STASH:-"+"}"
LP_MARK_VCS_REMOTE="${LP_MARK_VCS_REMOTE:-"⭚"}"
LP_MARK_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN:-"["}"
LP_MARK_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE:-"]"}"
LP_MARK_MULTIPLEXER_OPEN="${LP_MARK_MULTIPLEXER_OPEN:-"$LP_MARK_BRACKET_OPEN"}"
LP_MARK_MULTIPLEXER_CLOSE="${LP_MARK_MULTIPLEXER_CLOSE:-"$LP_MARK_BRACKET_CLOSE"}"
LP_MARK_SHORTEN_PATH="${LP_MARK_SHORTEN_PATH:-" … "}"
LP_MARK_PREFIX="${LP_MARK_PREFIX:-" "}"
LP_MARK_PERM="${LP_MARK_PERM:-":"}"
LP_MARK_DIRSTACK="${LP_MARK_DIRSTACK:-"⚞"}"
LP_MARK_SHLVL="${LP_MARK_SHLVL:-"└"}"
LP_MARK_WIFI="${LP_MARK_WIFI:-"📶"}"
LP_MARK_DEV_OPEN="${LP_MARK_DEV_OPEN:-"<"}"
LP_MARK_DEV_CLOSE="${LP_MARK_DEV_CLOSE:-">"}"
LP_MARK_DEV_MID="${LP_MARK_DEV_MID:-"|"}"
LP_MARK_MODULES_OPEN="${LP_MARK_MODULES_OPEN:-""}"
LP_MARK_MODULES_SEP="${LP_MARK_MODULES_SEP:-":"}"
LP_MARK_MODULES_CLOSE="${LP_MARK_MODULES_CLOSE:-""}"
LP_MARK_CMAKE="${LP_MARK_CMAKE:-":"}"
LP_MARK_KUBECONTEXT=${LP_MARK_KUBECONTEXT:-"⎈"}
LP_MARK_JOBS_SEPARATOR="${LP_MARK_JOBS_SEPARATOR:-"/"}"
LP_MARK_OS_SEP=${LP_MARK_OS_SEP:-"/"}
LP_MARK_OS=( ${LP_MARK_OS[@]+"${LP_MARK_OS[@]}"} )
LP_MARK_DISK="${LP_MARK_DISK:-"🖴 "}"
LP_MARK_RAM="${LP_MARK_RAM:-"M"}"
LP_COLOR_CMAKE_DEBUG=${LP_COLOR_CMAKE_DEBUG:-$MAGENTA}
LP_COLOR_CMAKE_RWDI=${LP_COLOR_CMAKE_RWDI:-$BLUE}
LP_COLOR_CMAKE_RELEASE=${LP_COLOR_CMAKE_RELEASE:-$CYAN}
LP_COLOR_PATH=${LP_COLOR_PATH:-$NO_COL}
lp_terminal_format 8 -1 0 0 -1
LP_COLOR_PATH_SEPARATOR=${LP_COLOR_PATH_SEPARATOR:-$lp_terminal_format}
LP_COLOR_PATH_SHORTENED=${LP_COLOR_PATH_SHORTENED:-$lp_terminal_format}
lp_terminal_format -1 -1 1 0
LP_COLOR_PATH_VCS_ROOT=${LP_COLOR_PATH_VCS_ROOT:-$lp_terminal_format}
LP_COLOR_PATH_LAST_DIR=${LP_COLOR_PATH_LAST_DIR:-$lp_terminal_format}
LP_COLOR_PATH_ROOT=${LP_COLOR_PATH_ROOT:-$BOLD_YELLOW}
LP_COLOR_PROXY=${LP_COLOR_PROXY:-$BOLD_BLUE}
LP_COLOR_ENV_VARS_UNSET=${LP_COLOR_ENV_VARS_UNSET:-$BLUE}
LP_COLOR_ENV_VARS_SET=${LP_COLOR_ENV_VARS_SET:-$BOLD_BLUE}
LP_COLOR_JOB_D=${LP_COLOR_JOB_D:-$YELLOW}
LP_COLOR_JOB_R=${LP_COLOR_JOB_R:-$BOLD_YELLOW}
LP_COLOR_JOB_Z=${LP_COLOR_JOB_Z:-$BOLD_YELLOW}
LP_COLOR_ERR=${LP_COLOR_ERR:-$PURPLE}
LP_COLOR_ERR_MEANING=${LP_COLOR_ERR_MEANING:-$LP_COLOR_ERR}
LP_COLOR_MARK=${LP_COLOR_MARK:-$BOLD}
LP_COLOR_MARK_ROOT=${LP_COLOR_MARK_ROOT:-$BOLD_RED}
LP_COLOR_MARK_SUDO=${LP_COLOR_MARK_SUDO:-$LP_COLOR_MARK_ROOT}
LP_COLOR_USER_LOGGED=${LP_COLOR_USER_LOGGED:-""}
LP_COLOR_USER_ALT=${LP_COLOR_USER_ALT:-$BOLD}
LP_COLOR_USER_ROOT=${LP_COLOR_USER_ROOT:-$BOLD_YELLOW}
LP_COLOR_HOST=${LP_COLOR_HOST:-""}
LP_COLOR_SSH=${LP_COLOR_SSH:-$BLUE}
LP_COLOR_SU=${LP_COLOR_SU:-$BOLD_YELLOW}
LP_COLOR_TELNET=${LP_COLOR_TELNET:-$WARN_RED}
LP_COLOR_X11_ON=${LP_COLOR_X11_ON:-$GREEN}
LP_COLOR_X11_OFF=${LP_COLOR_X11_OFF:-$YELLOW}
LP_COLOR_WRITE=${LP_COLOR_WRITE:-$GREEN}
LP_COLOR_NOWRITE=${LP_COLOR_NOWRITE:-$RED}
LP_COLOR_UP=${LP_COLOR_UP:-$GREEN}
LP_COLOR_COMMITS=${LP_COLOR_COMMITS:-$YELLOW}
LP_COLOR_COMMITS_BEHIND=${LP_COLOR_COMMITS_BEHIND:-$BOLD_RED}
LP_COLOR_CHANGES=${LP_COLOR_CHANGES:-$RED}
LP_COLOR_DIFF=${LP_COLOR_DIFF:-$PURPLE}
LP_COLOR_CHARGING_ABOVE=${LP_COLOR_CHARGING_ABOVE:-$GREEN}
LP_COLOR_CHARGING_UNDER=${LP_COLOR_CHARGING_UNDER:-$YELLOW}
LP_COLOR_DISCHARGING_ABOVE=${LP_COLOR_DISCHARGING_ABOVE:-$YELLOW}
LP_COLOR_DISCHARGING_UNDER=${LP_COLOR_DISCHARGING_UNDER:-$RED}
LP_COLOR_TIME=${LP_COLOR_TIME:-$BLUE}
LP_COLOR_IN_MULTIPLEXER=${LP_COLOR_IN_MULTIPLEXER:-$BOLD_BLUE}
LP_COLOR_RUNTIME=${LP_COLOR_RUNTIME:-$YELLOW}
LP_COLOR_VIRTUALENV=${LP_COLOR_VIRTUALENV:-$CYAN}
LP_COLOR_NODE_VENV=${LP_COLOR_NODE_VENV:-$LP_COLOR_VIRTUALENV}
LP_COLOR_RUBY_VENV=${LP_COLOR_RUBY_VENV:-$LP_COLOR_VIRTUALENV}
LP_COLOR_PERL_VENV=${LP_COLOR_PERL_VENV:-$LP_COLOR_VIRTUALENV}
LP_COLOR_TERRAFORM=${LP_COLOR_TERRAFORM:-$PINK}
LP_COLOR_CONTAINER=${LP_COLOR_CONTAINER:-$BOLD_BLUE}
LP_COLOR_DIRSTACK=${LP_COLOR_DIRSTACK:-$BOLD_YELLOW}
LP_COLOR_KUBECONTEXT=${LP_COLOR_KUBECONTEXT:-$CYAN}
LP_COLOR_AWS_PROFILE=${LP_COLOR_AWS_PROFILE:-$YELLOW}
LP_COLOR_MODULES=${LP_COLOR_MODULES:-$BLUE}
LP_COLOR_SHLVL=${LP_COLOR_SHLVL:-$BOLD_GREEN}
LP_COLOR_DISK=${LP_COLOR_DISK:-$BOLD_RED}
LP_COLOR_DISK_UNITS=${LP_COLOR_DISK_UNITS:-$RED}
LP_COLOR_RAM=${LP_COLOR_RAM:-$BOLD_RED}
LP_COLOR_RAM_UNITS=${LP_COLOR_RAM_UNITS:-$RED}
LP_COLORMAP=( ${LP_COLORMAP[@]+"${LP_COLORMAP[@]}"} )
if [[ ${#LP_COLORMAP[@]} == 0 ]]; then
LP_COLORMAP=(
"" # 0
"$GREEN" # 1
"$BOLD_GREEN" # 2
"$YELLOW" # 3
"$BOLD_YELLOW" # 4
"$RED" # 5
"$BOLD_RED" # 6
"$WARN_RED" # 7
"$CRIT_RED" # 8
"$DANGER_RED" # 9
)
fi
# For mocking tests.
_LP_LINUX_POWERSUPPLY_PATH="/sys/class/power_supply"
_LP_LINUX_WIRELESS_FILE="/proc/net/wireless"
_LP_AIRPORT_BIN="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
_LP_LINUX_RAM_FILE="/proc/meminfo"
_LP_BSD_RAM_FILE="/var/run/dmesg.boot"
if (( _LP_SHELL_zsh )); then
setopt local_options nullglob
fi
_LP_LINUX_TEMPERATURE_FILES=(
/sys/class/hwmon/hwmon*/temp*_input
# CentOS has an intermediate /device directory:
/sys/class/hwmon/hwmon*/device/temp*_input
/sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_input
# Older, fallback option
/sys/class/thermal/thermal_zone*/temp
)
# Debugging flags
LP_DEBUG_TIME=${LP_DEBUG_TIME:-0}
if [[ ${1-} == --no-config ]]; then
shift
else
# Default config file may be the XDG standard ~/.config/liquidpromptrc,
# but heirloom dotfile has priority.
local -a configfiles
configfiles=("$HOME/.liquidpromptrc" "${XDG_CONFIG_HOME:-"$HOME/.config"}/liquidpromptrc")
# trailing ":" is so that ${search#*:} always removes something
local configfile search="${XDG_CONFIG_DIRS:-/etc/xdg}:"
while [[ -n "$search" ]]; do
configfiles+=("${search%%:*}/liquidpromptrc")
search="${search#*:}"
done
configfiles+=("/etc/liquidpromptrc")
for configfile in "${configfiles[@]}"; do
if [[ -f "$configfile" ]]; then
# shellcheck source=/dev/null
source "$configfile"
break
fi
done
fi
for file in "$@"; do
# shellcheck disable=SC1090
. "$file"
done
# Deprecations and compatibility shims
if [[ -n "${LP_DISABLED_VCS_PATH-}" ]]; then
echo "liquidprompt: LP_DISABLED_VCS_PATH is deprecated. Update your config to use LP_DISABLED_VCS_PATHS array." >&2
(( _LP_SHELL_zsh )) && setopt local_options && setopt sh_word_split
local _path IFS=:
for _path in $LP_DISABLED_VCS_PATH; do
LP_DISABLED_VCS_PATHS+=("$_path")
done
fi
# FIXME Delete this code in version 1.11
if [[ -n "${LP_COLORMAP_1-}" ]]; then
echo "liquidprompt: LP_COLORMAP_x variables are deprecated. Update your theme to use LP_COLORMAP array." >&2
LP_COLORMAP=(
"$LP_COLORMAP_0"
"$LP_COLORMAP_1"
"$LP_COLORMAP_2"
"$LP_COLORMAP_3"
"$LP_COLORMAP_4"
"$LP_COLORMAP_5"
"$LP_COLORMAP_6"
"$LP_COLORMAP_7"
"$LP_COLORMAP_8"
"$LP_COLORMAP_9"
)
unset LP_COLORMAP_0 LP_COLORMAP_1 LP_COLORMAP_2 LP_COLORMAP_3 LP_COLORMAP_4 \
LP_COLORMAP_5 LP_COLORMAP_6 LP_COLORMAP_7 LP_COLORMAP_8 LP_COLORMAP_9
fi
if [[ -n ${LP_PATH_DEFAULT-} ]]; then
echo "liquidprompt: LP_PATH_DEFAULT is deprecated. Update your config to set LP_PATH_METHOD." >&2
if (( ! LP_ENABLE_SHORTEN_PATH )); then
# There is just no elegant way to handle this. Fallback to the old way with basic formatting support.
_lp_path_format() {
lp_path=$LP_PATH_DEFAULT
lp_path_format="${LP_COLOR_PATH}${lp_path}${NO_COL}"
}
fi
fi
if [[ -n ${PROMPT_DIRTRIM-} ]] && (( ! LP_ENABLE_SHORTEN_PATH )); then
echo "liquidprompt: PROMPT_DIRTRIM support is deprecated. Update your config to set
LP_PATH_METHOD='truncate_chars_from_path_left' instead." >&2
# This does mostly the same thing, but with our formatting.
LP_ENABLE_SHORTEN_PATH=1
LP_PATH_METHOD="truncate_chars_from_path_left"
LP_PATH_KEEP=1
fi
if [[ $LP_PATH_KEEP == "-1" ]]; then
echo "liquidprompt: LP_PATH_KEEP set to '-1' is deprecated. Update your config to set
LP_PATH_METHOD='truncate_to_last_dir' instead." >&2
LP_PATH_METHOD="truncate_to_last_dir"
fi
if [[ ${LP_ENABLE_FQDN-} == 1 ]]; then
echo "liquidprompt: LP_ENABLE_FQDN is deprecated. Update your config to set LP_HOSTNAME_METHOD=full
or LP_HOSTNAME_METHOD=fqdn instead." >&2
LP_HOSTNAME_METHOD="full"
fi
if [[ -n ${LP_PERCENTS_ALWAYS-} ]]; then
echo "liquidprompt: LP_PERCENTS_ALWAYS is deprecated. Update your config to set LP_ALWAYS_DISPLAY_VALUES and LP_DISPLAY_VALUES_AS_PERCENTS instead." >&2
LP_ALWAYS_DISPLAY_VALUES=${LP_PERCENTS_ALWAYS}
LP_DISPLAY_VALUES_AS_PERCENTS=${LP_PERCENTS_ALWAYS}
fi
}
# Initialize features based on the user config.
# shellcheck disable=SC2120
lp_activate() {
if (( _LP_SHELL_bash )); then
complete -F __lp_theme_bash_complete lp_theme
else # zsh
# For ZSH, autoload required functions
autoload -Uz add-zsh-hook
# Enable the autocomplete if the autocomplete system is initialized.
__lp_is_function compdef && compdef __lp_theme_zsh_complete lp_theme
fi
# Disable hooks that we don't need if features will be disabled.
__lp_disable_hooks
# TermInfo feature detection
_lp_af_colors=() _lp_ab_colors=()
__lp_foreground_color() { return 2 ; }
__lp_background_color() { return 2 ; }
# TODO handle this case better. With no colors, no need for any escaping
if ! command -v tput >/dev/null; then
echo "liquidprompt: 'tput' not available; will not be able to format terminal" >&2
LP_ENABLE_COLOR=0
else
_LP_TI_RESET="$( { tput sgr0 || tput me ; } 2>/dev/null )"
_LP_TI_BOLD="$( { tput bold || tput md ; } 2>/dev/null )"
_LP_TI_UNDERLINE="$( { tput smul || tput us ; } 2>/dev/null )"
_LP_TI_COLORS="$( tput colors 2>/dev/null )"
_LP_TI_COLORS=${_LP_TI_COLORS:-8}
_LP_TI_BELL="$( { tput bel || tput bl ; } 2>/dev/null )"
if tput setaf 0 >/dev/null 2>&1; then
__lp_foreground_color() { af_color="${_lp_af_colors[$1+1]:=$(tput setaf "$1")}"; }
elif tput AF 0 >/dev/null 2>&1; then
# FreeBSD
__lp_foreground_color() { af_color="${_lp_af_colors[$1+1]:=$(tput AF "$1")}"; }
elif tput AF 0 0 0 >/dev/null 2>&1; then
# OpenBSD
__lp_foreground_color() { af_color="${_lp_af_colors[$1+1]:=$(tput AF "$1" 0 0)}"; }
else
echo "liquidprompt: terminal '${TERM-}' does not support foreground colors" >&2
fi
if tput setab 0 >/dev/null 2>&1; then
__lp_background_color() { ab_color="${_lp_ab_colors[$1+1]:=$(tput setab "$1")}"; }
elif tput AB 0 >/dev/null 2>&1; then
# FreeBSD
__lp_background_color() { ab_color="${_lp_ab_colors[$1+1]:=$(tput AB "$1")}"; }
elif tput AB 0 0 0 >/dev/null 2>&1; then
# OpenBSD
__lp_background_color() { ab_color="${_lp_ab_colors[$1+1]:=$(tput AB "$1" 0 0)}"; }
else
echo "liquidprompt: terminal '${TERM-}' does not support background colors" >&2
fi
fi
# If tput doesn't exist or lookup failed, still try to send bell
_LP_TI_BELL=${_LP_TI_BELL:-$'\a'}
__lp_source_config "$@"
# Disable feature if the tool is not installed
_lp_require_tool()
{
# zsh does not allow quoting here.
# shellcheck disable=SC1105,SC2086
(( LP_ENABLE_$1 )) && { command -v "$2" >/dev/null || eval "LP_ENABLE_$1=0" ; }
}
_lp_require_tool TIME date
_lp_require_tool GIT git
_lp_require_tool SVN svn
_lp_require_tool FOSSIL fossil
_lp_require_tool HG "$LP_HG_COMMAND"
_lp_require_tool BZR bzr
_lp_require_tool CMAKE cmake
_lp_require_tool DISK df
_LP_ENABLED_VCSS=()
(( LP_ENABLE_GIT )) && _LP_ENABLED_VCSS+=(git)
(( LP_ENABLE_SVN )) && _LP_ENABLED_VCSS+=(svn)
(( LP_ENABLE_HG )) && _LP_ENABLED_VCSS+=(hg)
(( LP_ENABLE_BZR )) && _LP_ENABLED_VCSS+=(bzr)
if [[ "$LP_OS" = Darwin ]]; then
_lp_require_tool BATT pmset
_lp_require_tool RAM vm_stat
elif (( LP_ENABLE_BATT )); then
__lp_battery_detect || LP_ENABLE_BATT=0
fi
_lp_require_tool KUBECONTEXT kubectl
_lp_require_tool TERRAFORM terraform
unset -f _lp_require_tool
_LP_ENABLE_PREEXEC=$((
LP_ENABLE_RUNTIME \
|| LP_ENABLE_RUNTIME_BELL \
|| LP_ENABLE_TITLE_COMMAND \
|| LP_HIDE_EMPTY_ERROR \
))
# LP_ENABLE_RUBY_VENV depends either from rvm or rbenv. Thus we cannot
# directly use _lp_require_tool for it.
# Also, to avoid to check twice which is the current ruby virtual env
# program in use, we set here an internal variable holding its name if we
# detect one of them.
if (( LP_ENABLE_RUBY_VENV )) ; then
if command -v rvm-prompt >/dev/null ; then
_LP_RUBY_VENV_PROGRAM=rvm
elif command -v rbenv >/dev/null ; then
_LP_RUBY_VENV_PROGRAM=rbenv
else
LP_ENABLE_RUBY_VENV=0
fi
fi
if (( LP_ENABLE_PERL_VENV )) ; then
if command -v perlbrew >/dev/null ; then
_LP_PERL_VENV_PROGRAM=perlbrew
elif command -v plenv >/dev/null ; then
_LP_PERL_VENV_PROGRAM=plenv
else
LP_ENABLE_PERL_VENV=0
fi
fi
if (( LP_ENABLE_DETACHED_SESSIONS )); then
command -v screen >/dev/null ; _LP_ENABLE_SCREEN=$(( ! $? ))
command -v tmux >/dev/null ; _LP_ENABLE_TMUX=$(( ! $? ))
fi
# Use standard path symbols inside Midnight Commander
[[ -n "${MC_SID-}" ]] && LP_ENABLE_SHORTEN_PATH=0
# If we are running in a terminal multiplexer, special title escapes
if _lp_multiplexer --internal; then
(( LP_ENABLE_TITLE = LP_ENABLE_TITLE && LP_ENABLE_SCREEN_TITLE ))
if (( LP_ENABLE_TMUX_TITLE_PANES )) && [[ $lp_multiplexer == tmux ]]; then
LP_TITLE_OPEN=$'\E]2'
else
LP_TITLE_OPEN=$'\Ek'
fi
LP_TITLE_CLOSE=$'\E\\'
else
LP_TITLE_OPEN=$'\E]0;'
LP_TITLE_CLOSE=$'\a'
fi
[[ "_${TERM-}" == _linux* ]] && LP_ENABLE_TITLE=0
# Can not show title command if the title feature is disabled.
(( LP_ENABLE_TITLE )) || LP_ENABLE_TITLE_COMMAND=0
# update_terminal_cwd is a shell function available on MacOS X Lion that
# will update an icon of the directory displayed in the title of the terminal
# window.
# See http:https://hints.macworld.com/article.php?story=20110722211753852
if [[ "${TERM_PROGRAM-}" == Apple_Terminal ]] && command -v update_terminal_cwd >/dev/null; then
_LP_TERM_UPDATE_DIR=update_terminal_cwd
# Remove "update_terminal_cwd; " that has been add by Apple in /et/bashrc.
# See issue #196
PROMPT_COMMAND="${PROMPT_COMMAND//update_terminal_cwd; /}"
else
_LP_TERM_UPDATE_DIR=:
fi
###############
# Who are we? #
###############
_lp_user
local -i user="$?"
if (( user < 2 )); then # if user is not root
# "sudo -n" is only supported from sudo 1.7.0
if (( LP_ENABLE_SUDO )); then
if command -v sudo >/dev/null \
&& LC_MESSAGES=C sudo -V \
| GREP_OPTIONS='' \grep -qE '^Sudo version (1(\.([789]\.|[1-9][0-9])|[0-9])|[2-9])'; then
# If user can run any command without password input.
# This command does not invalidate credentials.
if \sudo -nvk 2>/dev/null; then
_LP_SUDO_NOPASSWORD=1
else
_LP_SUDO_NOPASSWORD=0
fi
else
LP_ENABLE_SUDO=0
fi
fi
if (( user == 1 )); then
LP_COLOR_USER=$LP_COLOR_USER_ALT
else
LP_COLOR_USER=$LP_COLOR_USER_LOGGED
fi
else # root!
LP_ENABLE_SUDO=0
if (( ! LP_ENABLE_VCS_ROOT )); then
LP_DISABLED_VCS_PATHS=("/")
fi
LP_MARK_DEFAULT='#'
LP_COLOR_MARK=$LP_COLOR_MARK_ROOT
LP_COLOR_PATH=$LP_COLOR_PATH_ROOT
LP_COLOR_USER=$LP_COLOR_USER_ROOT
fi
#################
# Where are we? #
#################
if (( LP_ENABLE_TEMP )); then
# Try each _lp_temp method
# If no function worked, disable the feature
__lp_temp_detect || LP_ENABLE_TEMP=0
fi
if (( LP_ENABLE_LOAD )); then
# Find and save the number of CPUs
__lp_cpu_count
# Convert load config values into usable integers.
local ret
# if load threshold does not have a period in it.
if [[ -z ${LP_LOAD_THRESHOLD//[!\.]} ]]; then
# This is an old value, no need to convert
_LP_LOAD_THRESHOLD=$LP_LOAD_THRESHOLD
else
__lp_floating_scale "$LP_LOAD_THRESHOLD" 100
_LP_LOAD_THRESHOLD=$ret
fi
__lp_floating_scale "$LP_LOAD_CAP" 100
_LP_LOAD_CAP=$ret
fi
if [[ -n ${_LP_THEME_ACTIVATE_FUNCTION-} ]]; then
# Reactivate current theme
"$_LP_THEME_ACTIVATE_FUNCTION"
prompt_on
else
# Set default theme if no theme set
lp_theme default
fi
}
#####################
# Utility Functions #
#####################
# Remove all colors and escape characters of the given string and return a pure text
# Deprecated since v2.1.
_lp_as_text() {
# Remove all terminal sequences that we wrapped with $_LP_OPEN_ESC and
# $_LP_CLOSE_ESC.
local ret
__lp_strip_escapes "$1"
printf '%s' "$ret"
}
# Store $2 (or $?) as a true/false value in variable named $1
# Deprecated since v2.0.
_lp_bool() {
local res="${2:-$?}"