From 2e8efdf87e5d0198620a8ae144b07626d83b9122 Mon Sep 17 00:00:00 2001 From: Tammy Cravit Date: Thu, 16 Oct 2008 18:53:30 -0700 Subject: [PATCH] Added initial version of todo action extensions v1 --- bin/todo.sh | 28 ++++++++++++++- dot-todo-actions.d/projects | 41 +++++++++++++++++++++ dot-todo-actions.d/todotxt_helpers.pl | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletions(-) create mode 100755 dot-todo-actions.d/projects create mode 100755 dot-todo-actions.d/todotxt_helpers.pl diff --git a/bin/todo.sh b/bin/todo.sh index 9510502..d9f3a17 100755 --- a/bin/todo.sh +++ b/bin/todo.sh @@ -87,7 +87,22 @@ help() report Adds the number of open todo's and closed done's to report.txt. +EndHelp + if [ -d "$HOME/.todo.actions.d" ] + then + echo "" + for action in $HOME/.todo.actions.d/* + do + if [ -x $action ] + then + $action usage + fi + done + echo "" + fi + + sed -e 's/^ //' <) + { + chomp $_; +# if ($_ =~ m/\s+P:(\S+)\s+/) + if ($_ =~ m/\s+\+(\S+)\s+/) + { + $PROJECTS{$1} = 1; + } + } + close FILE; + + foreach $proj (sort keys %PROJECTS) + { + if ($PROJECTS{$proj} == 1) + { + print $proj, "\n"; + } + } +} + +todotxt_run_custom_action(\@ARGV, \&usage, \&run_action); + +exit 0; diff --git a/dot-todo-actions.d/todotxt_helpers.pl b/dot-todo-actions.d/todotxt_helpers.pl new file mode 100755 index 0000000..53b4abc --- /dev/null +++ b/dot-todo-actions.d/todotxt_helpers.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl + +sub todotxt_usage +{ + my ($cmdname, $description, @extra) = @_; + print " $cmdname\n"; + print " $description\n"; + foreach $line (@extra) + { + print " $line\n"; + } +} + +sub todotxt_run_custom_action +{ + my ($argsref, $usagefunc, $actionfunc) = @_; + my @args = @$argsref; + if ($args[0] =~ m/usage/i) + { + &$usagefunc(); + } + else + { + &$actionfunc(@args); + } +} + +sub todotxt_get_cfg_option +{ + my ($option) = @_; + my $optval = undef; + my $TODO_DIR = $ENV{'HOME'}; + my $HOMEDIR = $ENV{'HOME'}; + + open (CFG, $ENV{'HOME'} . "/.todo") || die; + while () + { + chomp; + if (m/^$option\s*=\s*"?(\S+)"?/) + { + $optval = $1; + } + if (m/^TODO_DIR\s*=\s*"?(\S+)"?/) + { + $TODO_DIR = $1; + } + } + close CFG; + unless (defined $optval) + { + return undef; + } + + $optval =~ s/\$TODO_DIR/$TODO_DIR/; + $optval =~ s/\$HOME/$HOMEDIR/; + $optval =~ s/\"//g; + return $optval; +} + +sub todotxt_get_file_path +{ + return todotxt_get_cfg_option("TODO_FILE"); +} + +1; -- 1.6.0.2