Skip to content

Instantly share code, notes, and snippets.

@mozillalives
Created January 22, 2012 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mozillalives/1655083 to your computer and use it in GitHub Desktop.
Save mozillalives/1655083 to your computer and use it in GitHub Desktop.
Improved notify for long running terminal tasks
#!/usr/bin/env python
# I tried the notify script at http://www.simplicidade.org/notes/archives/2007/08/tip_use_growlno.html but
# I always received errors with it. Not being a bash guy, I wrote mine in python.
# To use this, just save it as something like "n" in your bin/, mark it as executable and prepend it to
# whatever you plan on calling. For example.
# nj rm -rf blah
import sys
from subprocess import call
from tempfile import TemporaryFile
with TemporaryFile() as stdout:
with TemporaryFile() as stderr:
out = call(sys.argv[1:], stdout=stdout, stderr=stderr)
cmd = " ".join(sys.argv[1:])[:80]
if out == 0:
stdout.seek(0)
allout = stdout.read()
call(["notify-send", "'%s' finished" % cmd, allout[:120]])
else:
stderr.seek(0)
allout = stderr.read()
call(["notify-send", "'%s' FAILED!" % cmd, allout[:120]])
print allout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment