by kingvash · 9y ago · 0 comments
function promptCommand()
{
LAST_STATUS=$?
# Set title of window to dir, then add new line to prompt.
PS1='\[\e]0;\w\a\]\n'
if [ $LAST_STATUS -eq 0 ]; then
((successes++))
PS1+='\[\033[1;32m\][$successes]'
else
successes=0
PS1+='\[\033[1;31m\][0 $LAST_STATUS]'
fi
PS1+='\[\033[0;32m\] '
PS1+='\w $(date +%H:%M) \$ \[\033[0m\]'
}
lastStatus=0
successes=-1
PROMPT_COMMAND="promptCommand"
My prompt: [0] /home/bar/g3 14:19 $ echo "boo"
boo
[1] /home/bar/g3 14:19 $In the former, if a result can't be found it will return `nil` but in the latter it expects the record to exist and so will raise an exception if it can't be found.
echo foo | grep bar | cat
is successful. Of course, this works for any command.Not to mention tar which is just impossible to get right on the first try.