How to receive an alert when a terminal command has completed

Dustin Kirkland, Ubuntu Server developer, recently posted something very interesting on his blog: an "alias", which you can add to the .bashrc file so that when a process run from a terminal has finished its work, a notification bubble appears using NotifyOSD (that is, in the same way that a notification appears when a friend connects or similar).

Receiving these types of notifications can be very useful, especially when performing long and complex tasks in the terminal, such as compiling a program, etc. Surely if you use the terminal a lot, this tip will come in handy.

What to do

1. First, edit your ~ / .bashrc file:

gedit ~ / .bashrc

and paste the following line at the end of the file:

alias alert_helper = 'history | tail -n1 | sed -e "s / ^ s * [0-9] + s * //" -e "s /; s * alert $ //"'
alias alert = 'notify-send -i /usr/share/icons/gnome/32x32/apps/gnome-terminal.png "[$?] $ (alert_helper)"'

What it does is create an alias. An alias allows you to execute a long and complicated command by typing a simple word, easier to remember. Thus, executing this long and complicated command from the terminal, which would also take a long time to write, becomes a super easy task. In this specific case, what we did is tell the system that when we enter «; alert »at the end of any command, it alerts us when it finishes its execution.

2. Install libnotify-bin:

sudo apt-get install libnotify-bin

3. Finally, we make the "source" of the .bashrc:

source ~/.bashrc

Now, let's try it!

As I mentioned before, all you have to do is add «; alert »at the end of any command so that you will receive a notification (via NotifyOSD) when it completes.

For example, I wrote:

sleep 20; alert

So when you want to compile a program, I wrote:

make; alert

Via | WebUpd8


2 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Saito Mordraw said

    This is not only very interesting but very useful to me ... because the truth is that sometimes I forget that I had things running in the XD terminal

    Thank you very much for the input, to try it has been said!

    By the way, how good that you are back!

  2.   Spacegnulinux said

    Hello, I am writing to inform you that I have changed the url of the gnu / linux space that appears in your blogroll, I would like you to update it so that we can continue linking our blogs. The current url of GNU / Linux Space is http://www.espaciognulinux.comthank you and have a nice day