Skip to content

Instantly share code, notes, and snippets.

@IQAndreas
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IQAndreas/5d22728244b6cbcf59b4 to your computer and use it in GitHub Desktop.
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
# 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"
@IQAndreas
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment