6

Is there a way to update tmux window attributes based on command exit status? Similar to activity monitoring, I would like the title to change color when a command exits, say, green for success and red for failure. I've hacked something together using PROMPT_COMMAND (which goes in ~/.bashrc), but it's not entirely satisfactory. It doesn't play well with activity monitoring (i.e. the red/green can't be seen unless activity monitoring is disabled) and the color change is sticky; it maintains state after you visit the window instead of returning to the default like other tmux monitoring does.

function set_color_from_return_code {
  local bg_color=$([ $? == 0 ] && echo "green" || echo "red")
  tmux set-window-option -t${TMUX_PANE} window-status-bg $bg_color # &> /dev/null
}
PROMPT_COMMAND="set_color_from_return_code"

Edit: Specifically, I'm using tmux as the backend for byobu, so I'm adding the byobu tag, as a byobu-specific solution is fine by me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.