Skip to content

Instantly share code, notes, and snippets.

@0x6d64 0x6d64/cyclenext
Last active Dec 16, 2015

Embed
What would you like to do?
cyclenext is a shell script to monitor a specific taskwarrior (http://taskwarrior.org/) filter continuously.
#!/bin/sh
# Martin Demling, 2013
# 0x6d64@martin-demling.de
# cyclenext is a script to monitor a specific taskwarrior
# (http://taskwarrior.org/) view continuously
# the script was developed on an OSX 10.7.5 system, but should run on other
# UNIX platforms
# usage: cyclenext <filter>
TASKFILE="/Users/martindemling/taskdir/undo.data"
# trigger redraw if size of terminal window changes
trap 'redraw $*' WINCH
# returns age of file in seconds
filemodifiedseconds()
{
local OLD=`stat -f %m $1`;
local NOW=`date +%s`;
(( DIFF = (NOW - OLD) ));
echo $DIFF
}
# returns age of file in minutes
filemodifiedminutes()
{
local OLD=`stat -f %m $1`;
local NOW=`date +%s`;
(( DIFF = (NOW - OLD) ));
let DIFF=$DIFF/60;
echo $DIFF
}
# detects how many lines the terminal can currently display, limit the output
# accordingly. The number 15 was found by trial, you may have to increase/
# decrease based on how many of your tasks need more than one line (due to
# line wrapping)
linestodisplay()
{
lines=$(tput lines)
#columns=$(tput cols)
(( LINESTODISPLAY = ($lines - 15) ))
echo $LINESTODISPLAY
}
draw()
{
clear
local AGE=$(filemodifiedminutes $TASKFILE)
echo "last change: $AGE minutes ago"
task $* rc.gc=off limit:$(linestodisplay)
}
redraw()
{
sleep 1
draw $*
}
#---------
# main loop
if [ "$#" = "0" ]
then
echo "no task filter given!"
echo "usage: cyclenext <filter>"
else
DELAY=2
for ((;;)) do
draw $*
#sleep $DELAY
sleep 1;
# check file every $DELAY seconds, draw if change is detected,
# if 5 minutes (150*2secs) pass without change, draw regardless:
# this will be useful to reflect changes in the config files (which
# are not monitored otherwise
for (( c=1; c<=150; c++ ))
do
AGE=$(filemodifiedseconds $TASKFILE)
if [ $AGE -gt $DELAY ]
then
sleep $DELAY
else
sleep 1
break
fi
done
done
fi
@0x6d64

This comment has been minimized.

Copy link
Owner Author

0x6d64 commented Apr 25, 2013

Read my blogpost for a description, and feel free to comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.