Notifies you when long-running terminal commands complete

Related tags

undistract-me
Overview

undistract-me

Notifies you when long-running terminal commands complete.

What is this?

Does this ever happen to you?

You're doing some work, and as part of that you need to run a command on the terminal that takes a little while to finish. You run the command, watch it for maybe a second and then switch to doing something else – checking email or something.

You get so deeply involved in your email that twenty minutes fly by. When you switch back to your terminal the command has finished, but you've got no idea whether it was nineteen seconds ago or nineteen minutes ago.

This happens to me a lot. I'm just not disciplined enough to sit and watch commands, and I'm not prescient enough to add something to each invocation to tell me. What I want is something that alerts me whenever long running commands finish.

This is it.

Install this, and then you'll get a notification when any command finishes that took longer than ten seconds to finish.

Installation

From the Ubuntu repositories

$ sudo apt install undistract-me

From the branch

$ bzr checkout --lightweight lp:undistract-me
$ . undistract-me/long-running.bash
$ notify_when_long_running_commands_finish_install

Add to your Bash

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

Configuration

By default, a long-running command is any command that takes more than 10s to complete. If this default is not right for you, set LONG_RUNNING_COMMAND_TIMEOUT to a different number of seconds and export it. It is possible to disable notifications for certain commands by adding them space-separated to LONG_RUNNING_IGNORE_LIST variable.

By default, the notification will only show if the active window is not the window the command is running in. If this is not right for you, (eg. if you are an Emacs user), you can set IGNORE_WINDOW_CHECK to 1 to skip the window check.

In addition to a visual notification, you can make undistract-me notify you by playing an audible sound along with the notification popup by simply setting the variable UDM_PLAY_SOUND to a non-zero integer on the command line. This functionality requires that pulseaudio-utils and sound-theme-freedesktop (which provides the notification sound file) be installed on a Debian-based system.

Licensing

All of undistract-me, including this file, is made available with the Expat license. See LICENSE for details.

Getting help

There's no dedicated IRC channel, but feel free to ping jml on Freenode, probably in the #ubuntu-devel channel.

Alternatively, ask questions or file bugs on the undistract-me Launchpad project.

Credits

Glyph Lefkowitz wrote a neat hack to provide ZSH-like preexec support for bash.

A lot of help from Chris Jones of Terminator.

Mikey Neuling and Stephen Rothwell have made huge improvements to the performance and quality of the shell script. I'm amazed, humbled and grateful.

Issues
  • Getting started on Ubuntu 16.04

    Getting started on Ubuntu 16.04

    Dear @jml,

    Thank you so much for this excellent project!

    I installed undistract-me as follows:

    sudo apt install undistract-me.

    It installed the following version:

    ii  undistract-me                                        0.1.0+git20130402+3a9144bc1f-1                              all          Notifies user when long-running terminal commands complete via libnotify
    

    However, I am not receiving any notification on commands that take longer than 10 seconds.

    What else do I need to configure?

    Thankfully,

    -Robert

    opened by orschiro 9
  • Not working on Xubuntu Quantal

    Not working on Xubuntu Quantal

    The ENV VAR is there, tried opening a fresh terminal, doesn't work in terminal or konsole. I do have Gnome turned on, gedit works for instance. Sounds like a missing dependency?

    opened by johnfisher 6
  • horrible overhead

    horrible overhead

    without undistract-me:

    $ time for I in {0..512}; do printf "%s " {a..z}; done | md5sum 53bbf0d98205319cee2ba589e205c68b -

    real 0m0.022s user 0m0.021s sys 0m0.003s

    with undistract-me:

    $ . /usr/share/undistract-me/undistract-me.sh

    $ time for I in {0..512}; do printf "%s " {a..z}; done | md5sum 53bbf0d98205319cee2ba589e205c68b -

    real 0m16.099s user 0m2.452s sys 0m9.481s

    opened by karelzak 5
  • Add option to play notification sound.

    Add option to play notification sound.

    Default behavior is unchanged - does not play notification sound. To change this, set UDM_PLAY_SOUND in bashrc to non-zero value.

    opened by knuthingmuch 5
  • Use exit codes to customise notifications

    Use exit codes to customise notifications

    It'd be nice to be able to use the exit code coming from the program exiting to change the notifcations somehow. Maybe change the icon of the notify send, or up the urgency level from low.

    opened by mikey 4
  • Not working on ubuntu 12.04 box

    Not working on ubuntu 12.04 box

    Hello, I'd really like to be able to use this nice piece of software, but for some unknown reason is not working properly.

    I'm using undistract-me from daily ppa on a Ubuntu 12.04 64bit laptop with Unity.

    Any thoughts? Thanks

    This is the apt-cache policy for the undistract-me package

    undistract-me:
      Installed: 0.1.0-0~19~precise1
      Candidate:  0.1.0-0~19~precise1
      Version table:
     *** 0.1.0-0~19~precise1 0
            500 http://ppa.launchpad.net/undistract-me-packagers/daily/ubuntu/ precise/main amd64 Packages
            100 /var/lib/dpkg/status
    
    opened by endorama 3
  • Output a bell to cause an urgency hint if there is no notify-send available

    Output a bell to cause an urgency hint if there is no notify-send available

    This way users who don't use notify-send can still be undistracted and know when their long running commands are done because their window manager will likely notify them of urgency.

    opened by treytabner 3
  • Made notify icon a terminal

    Made notify icon a terminal

    The notify icon ought to be relevant instead of a cheap notification icon.

    opened by KennyStier 3
  • Move the time taken to the notification summary

    Move the time taken to the notification summary

    This change has a couple benefits:

    • Notify messages with a long body can get cut truncated by the user's notification GUI. Some GUIs (such as GNOME) don't offer any way to see the truncated message at so the information about how long the command took is completely lost.
    • The message body becomes just the command string which nullifies the need for quoting the command string string

    This change is Reviewable

    opened by nocnokneo 2
  • Message after uninstalling

    Message after uninstalling

    I've uninstalled undistract-me and now I get the following message when I open a terminal. Where is this coming from?

    bash: /usr/share/undistract-me/long-running.bash: No such file or directory
    bash: notify_when_long_running_commands_finish_install: command not found
    
    opened by iAbadia 2
  • Fix showing notifications in Wayland apps when running XWayland

    Fix showing notifications in Wayland apps when running XWayland

    XWayland will return 0x0 (the root window id) when a Wayland window is focused, so if you switch to another Wayland window, the notification will not be displayed. To workaround this, I just replaced nowindowid with 0x0 as a marker for no window being focused.

    NOTE: This change doesn't implement window checking for Wayland, so notifications from a focused Wayland window will be displayed.

    I also added an exit code check to only use the window id from xprop if it succeeds. This isn't essential to support Wayland + XWayland, but it should act as a safe guard if the X connection fails.

    opened by kira-bruneau 0
  • Syntax error when starting bash

    Syntax error when starting bash

    I've tried both the version in Ubuntu 20.04 (the same as on launchpad: 0.1.0+git20130402+3a9144bc1f-1) and building the deb package from the git repo.

    When I start a new shell, after adding the source /etc/profile.d/undistract-me.sh as the last line of my .bashrc, I get the following error messages:

    bash: PROMPT_COMMAND: line 0: syntax error near unexpected token `;'
    bash: PROMPT_COMMAND: line 0: `preexec_set_exit;history -a; history -n; ;preexec_invoke_cmd'
    

    It probably interferes with my original prompt command setting of history -a; history -n; history -a; history -n; pwd>&10;kill -STOP $$ .

    opened by atleta 0
  • Run paplay on background to avoid delay

    Run paplay on background to avoid delay

    When UDM_PLAY_SOUND is enabled the paplay command waits until the sound is played hanging the terminal. Let's run the paplay in the background to return immediately.

    Signed-off-by: Lukáš Doktor [email protected]

    opened by ldoktor 1
  • Fix incompatibilities with any other scripts that use `bash-preexec`

    Fix incompatibilities with any other scripts that use `bash-preexec`

    undistract-me is incompatible with any other script that relies on bash_preexec, for instance bash-timer.

    That is because undistract-me uses variables precmd and preexec to pass its callback functions to bash-preexec. If any other script does the same thing, then whichever is sourced last overwrites these variables and the callbacks of the other scripts are discarded.

    To solve this problem, newer versions of bash-preexec provide arrays precmd_functions and preexec_functions, where several scripts can append their callback functions without overwriting / discarding those of other scripts.

    This pull requests addresses the issue described above by :
    1/ updating preexec.bash to the latest version found in https://glyf.livejournal.com/63106.html, that is https://www.twistedmatrix.com/users/glyph/preexec.bash.txt
    2/ using the callback arrays instead of variables


    I applied and tested these modifications on my machine. They work. Could you consider merging them ? Let me know if you want any additional information / help for testing / etc.

    Cheers !

    opened by qbouvet 1
  • Incompatibility with any other script using `bash-preexec`

    Incompatibility with any other script using `bash-preexec`

    undistract-me is incompatible with any other script that relies on bash-preexec, for instance bash-timer.

    That is because undistract-me uses variables precmd and preexec to pass its callback functions to bash-preexec. If any other script does the same thing, then whichever is sourced last overwrites these variables and the callbacks of the other scripts are discarded.

    This is solved updating bash-preexec, I will send a PR shortly. Could you consider merging it in ? This is really useful for people using the script.

    Best

    opened by qbouvet 1
  • Only execute preexec_install if defined

    Only execute preexec_install if defined

    Some external preexec scripts loaded with LONG_RUNNING_PREEXEC_LOCATION do not use preexec_install, but instead install themselves automatically when sourced (eg. https://github.com/rcaloras/bash-preexec/). This commit avoids the error message "preexec_install not found" by skipping the invocation of preexec_install if it is not defined. command is defined by POSIX and should be available on all systems.

    Tested: bash 5.0.3 on Linux with bash-preexec 0.3.8.0 Debian package and LONG_RUNNING_PREEXEC_LOCATION=/usr/share/bash-preexec/bash_preexec.sh

    opened by kerneis 1
  • Don’t run preexec_install on ZSH

    Don’t run preexec_install on ZSH

    ZSH knows precmd and preexec, so preexec_install is unnecessary there

    It’s also broken there, since the bash options set inside don’t exist for ZSH

    opened by flying-sheep 0
  • Keep notifications while user is idle

    Keep notifications while user is idle

    Hi :)

    is it somehow possible to keep the notification while the user is not active?

    I sometime have really long running tasks (~ 30 min) and I don't always stay on screen while they are running. I might be on another desktop and then leave my PC. When I come back, I have to check "manually" if the task is done already because the notification disappears while I'm away.

    It would be nice if it was possible to keep the notification active until a key is pressed or the cursor is moved and only then start the timeout to hide the notification. That way I would instantly see, that the task has finished as soon as I return to my PC.

    opened by x3rAx 0
  • Broken for ZSH

    Broken for ZSH

    The following lines in preexec.bash terminate the execution of the script and the triggers will not be installed

        set -o functrace > /dev/null 2>&1
        shopt -s extdebug > /dev/null 2>&1
    

    Both commands trigger errors when run in zsh

    opened by Marenz 4
Owner
Jonathan Lange
Jonathan Lange
Notifies you when long-running terminal commands complete

undistract-me Notifies you when long-running terminal commands complete. What is this? Does this ever happen to you? You're doing some work, and as pa

Jonathan Lange 471 Jun 2, 2021
:mag: Google from the terminal

googler is a power tool to Google (web, news, videos and site search) from the command-line. It shows the title, URL and abstract for each result, whi

Piña Colada 5.2k Jun 6, 2021
Linux Kernel Manager and Activity Monitor 🐧💻

Linux Kernel Manager and Activity Monitor ?? ?? The kernel is the part of the operating system that facilitates interactions between hardware and soft

Orhun Parmaksız 1.2k Jun 1, 2021
:speech_balloon: Command-line translator using Google Translate, Bing Translator, Yandex.Translate, etc.

Translate Shell Translate Shell (formerly Google Translate CLI) is a command-line translator powered by Google Translate (default), Bing Translator, Y

Mort Yao 5k Jun 6, 2021
Terminal-based CPU stress and monitoring utility

The Stress Terminal UI: s-tui Stress-Terminal UI, s-tui, monitors CPU temperature, frequency, power and utilization in a graphical way from the termin

Alex Manuskin 2.6k Jun 3, 2021
cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

cloc Count Lines of Code cloc counts blank lines, comment lines, and physical lines of source code in many programming languages. Latest release: v1.9

null 11.7k Jun 7, 2021
Command-line program to download videos from YouTube.com and other video sites

youtube-dl - download videos from youtube.com or other video platforms INSTALLATION DESCRIPTION OPTIONS CONFIGURATION OUTPUT TEMPLATE FORMAT SELECTION

youtube-dl 95.9k Jun 5, 2021
:cherry_blossom: A command-line fuzzy finder

fzf is a general-purpose command-line fuzzy finder. It's an interactive Unix filter for command-line that can be used with any list; files, command hi

Junegunn Choi 37.1k Jun 6, 2021
:duck: DuckDuckGo from the terminal

ddgr ddgr is a cmdline utility to search DuckDuckGo (html version) from the terminal. While googler is extremely popular among cmdline users, in many

Piña Colada 2.1k Jun 5, 2021
A modern replacement for ‘ls’.

exa exa is a modern replacement for ls. README Sections: Options — Installation — Development exa is a modern replacement for the venerable file-listi

Benjamin Sago 13.5k Jun 6, 2021
Browse Reddit from your terminal

THIS PROJECT IS NO LONGER MAINTAINED RTV Development is Shutting Down List of Alternative Projects Reddit Terminal Viewer (RTV) A text-based interface

Michael Lazar 4.5k Jun 3, 2021
A smart and nice Twitter client on terminal written in Python.

A Note about Twitter API Change Heads-up! As Twitter discontinues supporting Stream API, RainbowStream's stream function has been stopped working for

orakaro.targaryen 3.3k May 31, 2021
A Ruby gem that beautifies the terminal's ls command, with color and font-awesome icons. :tada:

Color LS A Ruby script that colorizes the ls output with color and icons. Here are the screenshots of working example on an iTerm2 terminal (Mac OS),

Athitya Kumar 3.7k Jun 6, 2021
A fast CSV command line toolkit written in Rust.

xsv is a command line program for indexing, slicing, analyzing, splitting and joining CSV files. Commands should be simple, fast and composable: Simpl

Andrew Gallant 7.2k Jun 5, 2021