Last active
August 29, 2015 14:02
-
-
Save IQAndreas/5d22728244b6cbcf59b4 to your computer and use it in GitHub Desktop.
Displays the status of the previous command run from the terminal. Place somewhere inside of your `.bashrc` file. Result: http://i.stack.imgur.com/r7YwR.png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shows the exit value of the last executed command | |
function previous_command_status() | |
{ | |
local exit_code=$?; | |
case "$exit_code" in | |
0) printf "\033[1;4;32m%-${COLUMNS}s\033[00m" "Command successful";; | |
126) printf "\033[1;4;31m%-${COLUMNS}s\033[00m" "Permission problem or command is not an executable";; | |
127) printf "\033[1;4;31m%-${COLUMNS}s\033[00m" "Command not found";; | |
130) printf "\033[1;4;31m%-${COLUMNS}s\033[00m" "Script canceled";; | |
*) printf "\033[1;4;31m%-${COLUMNS}s\033[00m" "Command failed with exit code $exit_code";; | |
esac | |
return $exit_code; | |
} | |
PROMPT_COMMAND="previous_command_status" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still needs some ironing out. For example, it will display after you have run
clear
on the screen (which is a bit annoying) and it runs once when you first start the terminal instance, even if you haven't run a command yet.