Last active
July 18, 2021 09:21
-
-
Save vmarkovtsev/4faef97d2498a2102c4fda7ad467185f to your computer and use it in GitHub Desktop.
Shell notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# apt install xdotool dateutils | |
# if "history" outputs a whitespace on the left, change -f3 to -f4 | |
# insert at the bottom: | |
# Add an "alert" alias for long running commands. Use like so: | |
# sleep 10; alert | |
alias alert='notify-send --urgency=low -t 5000 -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" -a ! -z "$WINDOWID" ]; then alert; fi)'"$PS1" | |
if [ $TERM != "linux" ]; then | |
export WINDOWID=$(xdotool getactivewindow 2>/dev/null) | |
while [ $(xdotool getwindowpid $WINDOWID 2>/dev/null) != $PPID ]; do | |
sleep 0.25 | |
export WINDOWID=$(xdotool getactivewindow 2>/dev/null) | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment