6

elementaryOS has the following feature to notify the user of a finished terminal process.

Is it possible to use this feature in Ubuntu?

enter image description here

Figure 1: Example of eOS terminal notification

orschiro
  • 13,317
  • 17
  • 87
  • 161
  • 1
    I guess it should not be hard. You can use something like sudo apt-get update && notify-send Task "sudo apt-get update" and adapt it to your needings. – dadexix86 Mar 22 '16 at 07:41
  • Dear @dadexix86, thank you for this "manual" solution. Below answers, however, provide a more automated way which I prefer. – orschiro Mar 23 '16 at 15:00

3 Answers3

9

What you want most probably already is available via your ~/.bashrc courtesy this and this:

Note: this assumes you have libnotify-bin installed. If it isn't, just run sudo apt-get install libnotify-bin to get it.

Check that your ~/.bashrc has lines like this:

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "Task finished" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

Note that "Task finished" isn't present in the original code.

So, in your specific example, you'll run

sudo apt-get update; alert

If you want the notification to remain on-screen a little longer, use -t 3000 (in milliseconds). Or, if you want the notification to display until you dismiss it, use --urgency=critical.

Here's what I see:

OSD alert

DK Bose
  • 42,548
  • 23
  • 127
  • 221
3

undistract-me provides notifications for terminal commands that take longer than 10 seconds to complete.

  1. sudo apt install undistract-me
  2. echo 'source /etc/profile.d/undistract-me.sh' >> ~/.bashrc
orschiro
  • 13,317
  • 17
  • 87
  • 161
2

You can set $PROMPT_COMMAND to trigger a notify-send command upon a command's completion in ~/.bashrc:

PROMPT_COMMAND='notify-send --icon=/usr/share/icons/Adwaita/256x256/apps/utilities-terminal.png "Task finished" "$(history | sed -n "\$s/^  [0-9]\+  //p")"'

enter image description here

The caveat is this can become pretty annoying soon, because it will send a notification each time a command is run.

kos
  • 35,891