Jump to content
Read the Funtoo Newsletter: Summer 2023 ×

Command Complete Notification

Recommended Posts

Ever need to know when a long emerge or some other command was finally finished after you went off and started something else?  Well, here is a script you can add to your .bashrc (or source it from your .bashrc) to do exactly that.  Due to some odd race behavior, it will be inactive until you use ls, cd, or n (n just activates it).  This was necessary because your .bashrc finishes running before the terminal window actually displays on screen.  If you use session management and your shell moves from one GUI window to another, the ls, cd, or n commands all ensure that the correct window is watched.  It only notifies if the shell window isn't on top.

#- This is to display notifications when you aren't watching the window
export DISPLAY=":0"
alias ls='LC_XWINDOWID=`xdotool getactivewindow`; ls --color=auto'
alias cd='LC_XWINDOWID=`xdotool getactivewindow`; cd'
alias n='LC_XWINDOWID=`xdotool getactivewindow`'

sendNotify() {
  LC_TASK=$(history 1 | cut -c 8-)
  LC_NAME=$(xdotool getwindowname $LC_XWINDOWID)
  #- fix up name to icon mapping
  case $LC_NAME in
        Terminal)       LC_ICON="gnome-terminal" ;;
  notify-send -i "$LC_ICON" "Task Complete in $LC_NAME" "$LC_TASK"

testWindow() {
  if [ -z "$LC_XWINDOWID" ]; then
     return 0;
  if [ "$(xdotool getactivewindow)" != "$LC_XWINDOWID" ]; then

FYI - you can add -t 10000 to the notify-send line to keep the notification up for a much longer duration (or an even greater value).  You can always close the notification manually.   So .. however long you want the timeout if the default isn't enough.



Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...