I have a shell script that I run on a distant server, and I'd like the i3 window status to become urgent so that the workspace button becomes red. How can I achieve that ?
Answer
Many terminals can set the urgent flag on their windows if the bell character - \a
- is printed. So
me-runs-long-time.sh ; echo -e '\a'
Should do the trick. Remember that i3 will immediately remove the urgent flag when the window is focused or when it is already focused. So you can test if this works by running
sleep 3; echo -e '\a'
and immediately focusing another window.
Note: The terminal might need to be configured for this behavior:
For
rxvt-unicode
the resourceurgentOnBell
needs to be set toTrue
. Forxterm
it is the resourcebellIsUrgent
. You can set resources in~/.Xresources
or~/.Xdefaults
, depending on your distribution.XTerm*bellIsUrgent: True
URxvt.urgentOnBell: TrueEither run
xrdb ~/.Xresources
or restart your X session to enable the changes (for new terminals).For
termite
this can be enabled by setting theurgent_on_bell
option totrue
in its configuration -~/.config/termite/config
:[options]
urgent_on_bell = trueThis will immediately work on any new termite window.
Of course, the above solution depends on you remembering to append ; echo -e '\a'
every time. There are a few ways to automate this. For example:
An easy way out would be to just output
\a
at the appropriate time in the script itself. This of course requires write access and would need to be done for every script separately.If you use
zsh
, you could add the following to your~/.zshrc
(on the remote machine):# this may already be in your ~/.zshrc
autoload -Uz add-zsh-hook
# duration in seconds after which a bell should be sent
typeset -i LONGRUNTIME=60
# function to save time at which a command was started
save_starttime () {
starttime=$SECONDS
}
# function to print \a if the command took longer than LONGRUNTIME
set_longrunning_alert () {
if ((LONGRUNTIME > 0 && SECONDS - starttime >= LONGRUNTIME)); then
print "\a"
fi
}
# run save_starttime before a command is executed
add-zsh-hook preexec save_starttime
# run set_longrunning_alert after a command finishes (before the prompt)
add-zsh-hook precmd set_longrunning_alertThis will automatically print a bell character if a command took longer than one minute.
If you use
bash
you could use the following on the remote machine.PROMPT_COMMAND='echo -e "\a"'
This will run
echo -e "\a"
every time before the primary prompt is issued. While this will mark the window urgent after every command, it should not really be noticable in most cases because will not keep the urgent flag on focused windows.
If you use the settings for bash
or zsh
also on your local machine, you will also be notified in case of the SSH connection dying (in the case of zsh
only if it dies after LONGRUNTIME
seconds). Assuming of course that you start ssh
from your shell.
No comments:
Post a Comment