Created
December 23, 2011 18:51
-
-
Save cowboy/1515055 to your computer and use it in GitHub Desktop.
Bash: an $? exit code var that clears itself when <enter> is pressed and no command is run.
This file contains hidden or 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
| # Maintain a per-execution call stack. | |
| prompt_stack=() | |
| trap 'prompt_stack=("${prompt_stack[@]}" "$BASH_COMMAND")' DEBUG | |
| function prompt_command() { | |
| prompt_exit_code=$? | |
| # If the first command in the stack is prompt_command, no command was run. | |
| # Set exit_code to 0 and reset the stack. | |
| [[ "${prompt_stack[0]}" == "prompt_command" ]] && prompt_exit_code=0 | |
| prompt_stack=() | |
| } | |
| PROMPT_COMMAND="prompt_command" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment