Skip to content

Commit f277854

Browse files
committed
Show last exit status
1 parent e476910 commit f277854

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ PROMPT_COMMAND="__prompt $color_prompt yes"
3030
When the user is root:
3131

3232
![When root](screen3.png)
33+
34+
When the last exit status iz not zero:
35+
36+
![Non-zero exit status](screen4.png)

prompt.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function __prompt() {
2+
local -r last_exit_code=$?
23
local -r use_color=$1
34
local -r show_host=${2:-no}
45

@@ -56,9 +57,18 @@ function __prompt() {
5657
fi
5758
fi
5859

60+
local error_mark=''
61+
if [ "$last_exit_code" -ne 0 ]; then
62+
if [ "$use_color" = yes ]; then
63+
error_mark="${C_BOLD_RED}!${C_NONE}"
64+
else
65+
error_mark='!'
66+
fi
67+
fi
68+
5969
if [ "$use_color" = yes ]; then
60-
PS1="╭─${C_WHITE}\t${C_NONE} \${debian_chroot:+(\$debian_chroot)}${C_USER}\u${C_NONE}${host}: ${C_BOLD_YELLOW}\w${C_NONE}${git_prompt}\n╰─${C_BOLD_PURPLE}\$${C_NONE} "
70+
PS1="╭─${C_WHITE}\t${C_NONE} \${debian_chroot:+(\$debian_chroot)}${C_USER}\u${C_NONE}${host}: ${C_BOLD_YELLOW}\w${C_NONE}${git_prompt}\n╰─${error_mark}${C_BOLD_PURPLE}\$${C_NONE} "
6171
else
62-
PS1="╭─\t \${debian_chroot:+(\$debian_chroot)}\u${host}: \w${git_prompt}\n╰─\$ "
72+
PS1="╭─\t \${debian_chroot:+(\$debian_chroot)}\u${host}: \w${git_prompt}\n╰─${error_mark}\$ "
6373
fi
6474
}

screen4.png

17.9 KB
Loading

0 commit comments

Comments
 (0)