Skip to content

Commit 83e3044

Browse files
committed
[small-prompt] terminal check: workaround for color with sudo + meaningful and shorter names
1 parent d304927 commit 83e3044

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

unix/small-prompt/prompt.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,24 @@ setup_PS1() {
8484

8585

8686
# tweaks
87+
[[ ! -v TERM || "$TERM" == dummy ]] && return # terminal is too stupid
88+
8789
local rever=0 rgb=0 light=0 basic=0 short=0
8890

89-
[[ ! -v TERM || "$TERM" == dummy ]] && return # terminal is too stupid
90-
[[ "$TERM" != xterm* ]] && basic=1
91-
[[ -v KONSOLE_VERSION ]] && rgb=1
92-
[[ -v XTERM_VERSION ]] && { rever=1; basic=1; }
93-
[[ -v TERM_PROGRAM || -v TERMINAL_EMULATOR || -v KATE_PID ]] && short=1
94-
[[ -v TERM_PROGRAM || -v TERMINAL_EMULATOR ]] && light=1
91+
check_term() {
92+
# sudo -> env vars will be cleared without -E option
93+
local -n sudo=SUDO_UID konsole=KONSOLE_VERSION xterm=XTERM_VERSION \
94+
vscode=TERM_PROGRAM idea=TERMINAL_EMULATOR kate=KATE_PID
95+
96+
[[ "$TERM" != xterm* || -v xterm ]] && basic=1
97+
[[ -v xterm ]] && rever=1
98+
[[ -v konsole || -v sudo ]] && rgb=1
99+
[[ -v xterm || -v vscode || -v idea ]] && rgb=0
100+
[[ -v vscode || -v idea || -v kate ]] && short=1
101+
[[ -v vscode || -v idea ]] && light=1
102+
}
103+
check_term
104+
unset -f check_term
95105

96106
if ((rever)); then
97107
C[fdwhi]='30'

0 commit comments

Comments
 (0)