This repository has been archived on 2024-03-13. You can view files and clone it, but cannot push or open issues or pull requests.
2022-02-09 04:17:50 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
2022-02-09 04:22:57 +00:00
|
|
|
# Day 2 - Exit Code PS1 prompt
|
2022-02-09 04:17:50 +00:00
|
|
|
# "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
|
2022-02-09 04:22:57 +00:00
|
|
|
echo -e "\e[${COLORCODE}m${ERROR} ${EMOJI} \e[0m"
|
2022-02-09 04:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
demojify ()
|
|
|
|
{
|
|
|
|
PS1=$PS1OLD
|
|
|
|
}
|
|
|
|
|
2022-02-09 04:22:57 +00:00
|
|
|
PS1="\$(exitprompt)\n$PS1"
|
2022-02-09 04:17:50 +00:00
|
|
|
|