Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created December 23, 2011 18:51
Show Gist options
  • Select an option

  • Save cowboy/1515055 to your computer and use it in GitHub Desktop.

Select an option

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.
# 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