uudruid74 Posted November 1, 2014 Report Share Posted November 1, 2014 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) LC_ICON="$LC_NAME" #- fix up name to icon mapping case $LC_NAME in Terminal) LC_ICON="gnome-terminal" ;; esac notify-send -i "$LC_ICON" "Task Complete in $LC_NAME" "$LC_TASK" } testWindow() { if [ -z "$LC_XWINDOWID" ]; then return 0; fi if [ "$(xdotool getactivewindow)" != "$LC_XWINDOWID" ]; then sendNotify fi } PROMPT_COMMAND="testWindow" 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. Enjoy! Link to comment Share on other sites More sharing options...
Recommended Posts