Skip to content

Instantly share code, notes, and snippets.

@ekimekim
Created May 29, 2013 06:14
Show Gist options
  • Save ekimekim/5668284 to your computer and use it in GitHub Desktop.
Save ekimekim/5668284 to your computer and use it in GitHub Desktop.
A system for setting arbitrary watch commands to set a flag in your PS1.
# Prefixes current PS1 with a blank space
# This blank space changes to a ! character if any command
# given in the ALERTS array exits non-zero.
# (additionally, a ? character is an error state - this shouldn't happen)
# Tip: ALERTS may be appended to thusly: ALERTS+=('mycommand myarg')
# Note: Commands in ALERTS are run every time PS1 is printed.
# However, if any command fails (indicates an alert), no further commands will be run.
declare -a ALERTS[0]
alerts_check() {
for command in "${ALERTS[@]}"; do
if ! $command; then
echo -en '\b!'
return 1
fi
done
echo -en '\b '
return 0
}
PS1='?\[$(alerts_check)\]'"${PS1}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment