Undistract-me, you get a notification when finishing a terminal command

undistract me about

In the next article we are going to take a look at a utility called Undistract-me. This script we will display a warning when the commands are completed that we are running in the terminal. This can be useful when after launching a command we start working on something else. With it we will not need to constantly check the terminal to see if the command has been completed or not. The Undistract-me utility will notify us when a long-running command completes. Will work on Arch Linux, Debian, Ubuntu and other derivatives.

This utility will come in handy when you are not disciplined enough to sit back and watch the commands run. The script we displays a prompt on desktop when long run commands finish, so that we can dedicate our time to something other than looking at the terminal while the commands reach the end.

Install Undistract-me

Undistract-me is available in the default Debian repositories and their variants, like Ubuntu. I have tested it on Ubuntu 17.10. Anyone who wants to can consult the source code of this script on the page by GitHub of the project.

To add it to your system, all you have to do is run the following command in the terminal (Ctrl + Alt + T) to install it:

sudo apt install undistract-me

When the installation is finished, in the same terminal, run the following command to add "undistract-me" to your bash:

echo 'source /etc/profile.d/undistract-me.sh' >> ~/.bashrc

Alternatively, you can run this command to add it to your Bash:

echo "source /usr/share/undistract-me/long-running.bash\nnotify_when_long_running_commands_finish_install" >> .bashrc

Finally update changes running in the same terminal:

source ~/.bashrc

Configure Undistract-me

Change time for notification

By default, Undistract-me will consider any command that takes more than 10 seconds to complete as a long-running command. But this can be changed. This time interval can be changed by editing editing the file /usr/share/undistract-me/long-running.bash.

undistract-me setting time

sudo nano /usr/share/undistract-me/long-running.bash

Inside the file we will have to find the variable "LONG_RUNNING_COMMAND_TIMEOUT" and change the default (10 seconds) for another value of your choice. Then save and close the file. Don't forget to update the changes by executing the command:

source ~/.bashrc

Enable / Disable notifications for particular commands

In addition, we will be able to disable notifications for particular commands. To do so, we will have to search for the variable "LONG_RUNNING_IGNORE_LIST" and add the commands to be affected separated by spaces.

Enable / Disable Active Window Check

By default, the notification will only be displayed if the active window is not the window in which the command is executed. This means that we will only receive the notification if the command is running in the background window. If the command is executed in the active window, the notification will not be displayed. If we want this distinction to be made, we will be able to configure IGNORE_WINDOW_CHECK. We will select 1 to skip the window check.

Enable audio notification

The other cool feature of Undistract-me is that you can set the audio notification along with visual notification when a command completes. By default, it will only send a visual notification. You can change this behavior by setting the variable UDM_PLAY_SOUND en a nonzero integer On the line. However, our Ubuntu system must have the utilities pulseaudio-utils y sound-theme-freedesktop installed to enable this functionality.

Remember that you must execute the following command to update the changes made:

source ~/.bashrc

Testing Undistract-me

Time to check if this really works and let's see if the notification is displayed when long-running terminal commands complete. Now run any command that takes more than 10 seconds or the length of time that you have defined the Undistract-me configuration.

For this example, I simply ping one of the routers on my network a specified number of times. This command took about 25 seconds to complete. After completing the command, I received the following notification on the desktop.

pingundistract-me notification

Remember that the Undistract-me script only reports if the given command took more than 10 seconds to complete and the terminal it is running in is not the active window. If the command completes in less than 10 seconds, you will not be notified. Of course, you can change this time interval setting as I described in the Settings section.

I find this tool very useful for all of us who work at the terminal. And being so easy to use and install, I think it is something that should not be missing from any computer.


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.   Leonhard Suarez said

    This has it elementary os and it's great