Created
January 22, 2012 02:05
-
-
Save mozillalives/1655083 to your computer and use it in GitHub Desktop.
Improved notify for long running terminal tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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