Day two: not much to do here, so I made a fun prompt script.

This commit is contained in:
John McCardle 2022-02-08 23:17:50 -05:00
parent 0e95423877
commit e132105cc3
2 changed files with 37 additions and 0 deletions

31
day2_exitcodeprompt.sh Normal file
View File

@ -0,0 +1,31 @@
#!/bin/bash
#
# Day 2 - Generate Inventory
# "Pimp my prompt" with the return value of the last command.
# source this from ~/.bashrc or similar to modify PS1 to show the return value of previous command.
# Use the "demojify" command to restore your previous prompt after sourcing.
PS1OLD=$PS1
exitprompt ()
{
ERROR="$?"
if [ "$ERROR" -eq 0 ]
then
COLORCODE=32 # foreground green
EMOJI="🙂"
else
COLORCODE=31 # foreground red
EMOJI="🙁"
fi
echo -e "\e[${COLORCODE}m${ERROR}${EMOJI}\e[0m"
}
demojify ()
{
PS1=$PS1OLD
}
PS1="$PS1 \$(exitprompt)$ "

6
test_error.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# Returns a non-zero exit code on purpose to test the day 2 error prompt.
exit 42