Instead of waiting for long commands to finish one can easily get notifications when they are complete. The following procdure shows how to set his in fish shell.
Requirements: fish shell, notify-send, xdotool
- Add a new file
vi ~/.config/fish/functions/noti.fish
with the content below:
function fish_right_prompt
if test $CMD_DURATION
# Check if terminal window is hidden
if test (xdotool getactivewindow) -ne $WINDOWID
# Show notification if dration is more than 30 seconds
if test $CMD_DURATION -gt 30000
# Show duration of the last command in seconds
set duration (echo "$CMD_DURATION 1000" | awk '{printf "%.3fs", $1 / $2}')
notify-send (echo (history | head -1) returned $status after $duration)
end
end
end
end
- Add the following line at the end of
~/.config/fish/config.fish
to sourcenoti.fish
:
. ~/.config/fish/functions/noti.fish
Thanks for the gist. I created (Telert) to easily configure sound alerts, desktop popup, or even Telegram/Slack/Teams/Discord messages when a long-running command finishes. It also works in Python commands.
Setting it up is quick and easy
You can then use it with your long running commands in your script.
Telert will time the command and send a notification to the provider channel when it completes with the execution time and exit code.
https://github.com/navig-me/telert/