Open ~/.bashrc
. Append export WINDOWID=...
in the header as follows:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
export WINDOWID=$(xdotool getactivewindow)
Locate alias alert
and change it as follows, prepending to PS1
:
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(dateutils.ddiff $(HISTTIMEFORMAT="%FT%T " history 1|cut -d\ -f3) $(date +%FT%T))" "$(HISTTIMEFORMAT= history 1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
PS1='$(if [ "$(xdotool getwindowfocus 2>/dev/null)" != "$WINDOWID" ]; then alert; fi)'"$PS1"
Install xdotool
:
sudo apt install xdotool
Test: open a new terminal session, execute sleep 5
, then switch to your web browser or any other window. You should see a system notification.