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

2
  • 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, 2016 at 7:41
  • Dear @dadexix86, thank you for this "manual" solution. Below answers, however, provide a more automated way which I prefer.
    – orschiro
    Mar 23, 2016 at 15:00

3 Answers 3

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

4
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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.