Skip to content

Instantly share code, notes, and snippets.

@v6ak
Last active January 4, 2020 10:45
Show Gist options
  • Save v6ak/5204011 to your computer and use it in GitHub Desktop.
Save v6ak/5204011 to your computer and use it in GitHub Desktop.
A handler for Task spooler
#!/bin/bash
# Copyright (C) 2012 Vít Šesták <v6ak.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
# This utility notifies about completed messages of Task spooler (see http://viric.name/soft/ts/).
# Just add the path to this utility to $TS_ONFINISH.
# This utility is not a part of Task spooler. It is a separate project with a different author.
#
# You may want to add following line to .bashrc:
# export TS_ONFINISH=/usr/bin/ts-finished
jobid="$1"
error="$2"
outfile="$3"
command="$4"
queueSize=$(ts | (read; cat) | grep -vE '^[0-9]+ +finished' | wc -l)
if [ "$error" = 0 ]; then
icon=terminal
else
icon=error
fi
notify-send \
-i "$icon" \
"[TS] finished
[$jobid] $command returned $error
$(tail -n3 "$outfile")
(see $outfile) $queueSize"
if [ "$queueSize" == 1 ]; then # this is the last command in the queue
notify-send \
--icon emblem-default \
-t $((60*60*1000)) \
"[TS] queue empty"
fi
@beikeland
Copy link

beikeland commented May 24, 2016

Found this when looking for an example, and added the following to clear out finished jobs after a given time.

tsp=/usr/bin/tsp
at="/usr/bin/at -M"
when="now + 7 days"
...
#check that jobid exist and then schedule for removal if finished
if  $tsp | grep  "^$jobid";  then
    echo "if $tsp | grep  \"^$jobid *finished\"; then $tsp -r $jobid;rm $outfile;fi" | $at $when
fi

edit: apparently i missed that when the TS_ONFINISH hook runs, the status is still running, moved the is finished check to the at job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment