Sample Header Ad - 728x90

Monitor exit code in tmux

10 votes
1 answer
1841 views
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.
Asked by user (367 rep)
Sep 2, 2015, 04:48 AM
Last activity: Jul 9, 2020, 07:23 AM