Skip to content

Instantly share code, notes, and snippets.

@zmughal
Created September 10, 2011 03:01
Show Gist options
  • Save zmughal/1207871 to your computer and use it in GitHub Desktop.
Save zmughal/1207871 to your computer and use it in GitHub Desktop.
conky + todo.pl
#!/bin/sh
BOLD_FONT="Lucida Sans:size=6:bold"
NORM_FONT="Lucida Sans:size=6:normal"
if [ "$1" = "format-color" ]; then
sed 's,\[3\([0-9]\)\(;1\)\?m,${color\1},g' \
| sed 's,\[2m,${font '"$BOLD_FONT"'},g' \
| sed 's,\[0m,${color}${font '"$NORM_FONT"'},g' \
| sed 's/^\(\*\) \([A-Z0-9]\+\)/${color8}\1${color} ${font '"$BOLD_FONT"'}${color4}\2${color}${font '"$NORM_FONT"'}/g'
exit
elif [ "$1" = "format" ]; then
sed 's,^#,* ,' \
| sed 's/#/\\#/g' \
| sed 's,\$,$$,g' \
| perl -MText::Autoformat -e'autoformat {all=>1, left=>0, right=>72}' \
| $0 "format-color"
exit
elif [ "$1" = "sort" ]; then
perl -e '
my @contexts = qw/@school @home @computer/;
my @grouping;
while(<>) {
$line = $_;
@w = grep { $line =~ /$contexts[$_]/} 0..$#contexts;
push @{$grouping[ $w[0] // @contexts ]}, $line;
}
@{$grouping[$_]} and
print "- ", "-" x 20,
$contexts[$_] // "",
"-" x 20, "-\n",
@{$grouping[$_]} for(0..$#grouping);
'
exit
elif [ "$1" = "output" ]; then
date +"Now: %a, %d %b %Y %R"
echo '${color0}$hr'
echo '${color8}Personal ${color}'
export TERM="xterm"
script -qc 'todo.pl --group "personal" list' /dev/null | $0 "sort" | $0 "format"
echo '${color0}$hr'
echo '${color8}CougarCS ${color}'
script -qc 'todo.pl --group "CougarCS" list' /dev/null | $0 "sort" | $0 "format"
exit
fi
TEMP_OUT="$HOME/.conky/conky_todo.tmp"
CACHE_OUT="$HOME/.conky/conky_todo.cache"
$0 output > "$TEMP_OUT"
if grep -q '[A-Z0-9]\{5\}' "$TEMP_OUT"; then
# assume that if there is a task ID, the script was sucessful
mv "$TEMP_OUT" "$CACHE_OUT"
else
rm -f "$TEMP_OUT"
fi
cat "$CACHE_OUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment