Commit Graph

135 Commits

Author SHA1 Message Date
Ed Blackman
12bbf8fe67 Fix spacing (tabs to spaces) 2009-03-14 01:17:46 -04:00
Ed Blackman
ab78607506 Use sed line counting to replace 'wc -l' 2009-03-14 01:15:52 -04:00
David A. Harding
6be78ca5fa Added Exclusion Syntax by Jacobo de Vera
-keyword or -"key phrase" should exclude those terms from the output.
2009-03-13 22:21:48 -04:00
Ed Blackman
9ab77253db Implement pre and post filters in _list 2009-03-13 18:17:16 -04:00
Ed Blackman
cf3c5312bf Export _list for call by extensions 2009-03-13 17:02:31 -04:00
Ed Blackman
37a7bb0e8a Use relative rather than absolute filename in status message 2009-03-13 16:40:55 -04:00
Ed Blackman
ed8e8e24d9 Consistent spacing for \ continuation in _list 2009-03-13 16:34:25 -04:00
David A. Harding
d6f00ca42f Minor formatting and comments changes 2009-03-13 12:14:08 -04:00
David A. Harding
a03a3bf66b Fixed Windows Regression, New _list Function
Commit f55f5e8b5f introduced a known regression on Windows that
prevented users from using configuration files starting with C:\.  The
following logic fixes this:
    +    ## If the file starts with a "/" use absolute path. Otherwise,
    +    ## try to find it in either $TODO_DIR or using a relative path
    +    if [ "${1:0:1}" == / ]
    +    then
    +        ## Absolute path
    +        src="$FILE"
    +    elif [ -f "$TODO_DIR/$FILE" ]
    +    then
    +        ## Path relative to todo.sh directory
    +        src="$TODO_DIR/$1"
    +    elif [ -f "$FILE" ]
    +    then
    +       ## Path relative to current working directory
    +       src="$FILE"
    +    else
    +        echo "TODO: File $FILE does not exist."
    +       exit 1
    +    fi

New _list function takes a filename and a list of search expressions.
We no longer use exec to call ourselves recursively.
2009-03-13 11:59:03 -04:00
David A. Harding
448cecb91d Simplify and Reused Code to Print ls Summary Line 2009-03-13 11:00:34 -04:00
David A. Harding
ee59233c36 Replaced Grep Loop, Fixed Sed Bug, Some Small Changes
Implemented several suggestions by Jacobo de Vera:

    > 1. [lines 539-551]: [...] replace the for loop with simply this:
    >    PADDING=${#LINES}

    > 2. [line 558]: As the script now supports a 6 digit number of tasks,
    > the first substitution should add 5 spaces instead of 2

    > 3. [lines 606-613]: The first search item is processed before the for
    >    loop, and the loop does the same for the rest. Wouldn't making this
    >    more general make the code more readable?

The changes for suggestion #3 let me add a new feature: when VERBOSE is
enabled, the summary line prints more info -- and it prints it on every
run:

    $ todo.sh ls "buy a"
    34 Buy a portable gas can @errands +safe
    --
    TODO: 1 of 49 tasks shown from /home/harding/var/git/todo/todo.txt

Also, generalizing and centralizing the code added a small but
measurable speed increase.

No new known regressions were introduced.
2009-03-12 22:23:59 -04:00
David A. Harding
f55f5e8b5f Make ls-Family Actions Use Listfile Backend
Essentially,

    ls)
	shift
	exec "$TODO_SH" listfile "$TODO_FILE" "$@"
	;;
    lsa)
	shift
	cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
	exec $TODO_SH listfile "$TMP_FILE" "$@"
	;;
    lsp)
	shift ## was "listpri"
	shift ## was priority
	exec $TODO_SH listfile "$TODO_FILE" "$pri" "$@"
	;;;

Also adds the following features:

    1. Numbers are padded with up to five zeros (but only the minimum
       necessary), letting you list up to 999,999 tasks with the same
       formatting.

    2. All ls-family commands hide context, priority, and project when
       the user sets those hide options.

    3. Quoted arguments are passed on to grep as whole arguments,
       enabling the following:

	$ todo.sh ls buy a | head -n2
	34 Buy a portable gas can
	22 Buy door

	$ todo.sh ls "buy a"
	34 Buy a portable gas can

    4. listfile can take an absolute path. Any filename starting with a
       "/" will be treated as an absolute path; any other filename will
       be treated as relative to $TODO_DIR. Since a leading "/" would be
       striped by the operating system anyway under the old code, this
       is fully backward compatible.

Contains the following regressions:

    1. The ls verbose line count messages are more generic.

    2. There is no verbose line count line for lspri.

    3. I don't think listfile's absolute path feature will work on
       Windows. If it doesn't, either this patch needs to be thrown
       away, listall needs to be rewritten, or (my preference) $TMP_FILE
       needs to set as relative to $TODO_DIR.
2009-03-12 11:52:28 -04:00
David A. Harding
d508ed9dee Modularized Listing Sed
Still more to do tomorrow.
2009-03-12 01:02:10 -04:00
Matt Brubeck
62f3313ff9 Merge branch 'master' of git://github.com/ginatrapani/todo.txt-cli 2009-03-11 16:22:27 -07:00
David A. Harding
6bc374c5f2 Revert "Set ls As the Default Action"
This reverts commit 87959a8aa8.
2009-03-11 17:54:25 -04:00
David A. Harding
87959a8aa8 Set ls As the Default Action
.
Suggested by mbrubeck
2009-03-11 17:42:15 -04:00
Matt Brubeck
6bc05000d9 Add TODOTXT_DEFAULT_ACTION variable.
I like to set this to "ls" so I can just run "todo.sh" (or "t") to list my
tasks.
2009-03-11 10:50:14 -07:00
David A. Harding
717f052f13 Only Reset Action When Necessary plus Comments 2009-03-09 16:19:30 -04:00
Philippe Teuwen
4ee8c332ed Remove redundant code 2009-03-09 20:43:42 +01:00
David A. Harding
88caf44e9e Override Overrides Using "command"
New action, "command", forces todo.sh to use builtins and ignore any
.todo.actions.d scripts.  For example, if there is an executable
.todo.actions.d/ls:

    ## Run .todo.actions.d/ls
    todo.sh ls

    ## Run builtin todo.sh ls
    todo.sh command ls

This mimicks bash's behaviour:

    ## Use the default echo
    harding@ziggy:~$ echo 'foo\nbar'
    foo\nbar

    ## Alias the echo command to "echo -e"
    harding@ziggy:~$ alias echo='echo -e'
    harding@ziggy:~$ echo 'foo\nbar'
    foo
    bar

    ## Force bash to call the default echo command
    harding@ziggy:~$ command echo 'foo\nbar'
    foo\nbar
2009-03-09 14:10:21 -04:00
Philippe Teuwen
db66767170 Add TODOTXT_UNDEF_CUSTOM_ACTIONS for recursive call of todo.sh from actions
And replace tabs by spaces.

To illustrate the interest of this new variable, here is an action
to replace the original add to allow a priority to be set when adding.
The action itself relies on the original add, therefore the need for
this new envvar.

action=$1
shift
[ "$action" = "usage" ] && {
  echo "    add pri PRIORITY \"THING I NEED TO DO +project @context\""
  echo "      add an item and prioritize it in one step"
  echo ""
  exit
}

. $TODOTXT_CFG_FILE
TODOTXT_UNDEF_CUSTOM_ACTIONS=1
PRIORITY=false
if [ x"$1" = x"pri" -o x"$1" = x"p" ] && [[ x"$2" =~ x[a-zA-Z] ]]; then
    PRIORITY=$2
    shift
    shift
fi
if $TODO_SH add "$@" && [ $PRIORITY != false ]; then
    # figure out the line of what we just added, and "do" it
    line=`wc -l "$TODO_FILE" | cut -d' ' -f1`
    $TODO_SH pri "$line" $PRIORITY
fi
2009-03-09 10:09:32 +01:00
David A. Harding
f8f8e83c40 Merge branch 'gina/master'
Conflicts:

	todo.sh
2009-03-08 22:29:27 -04:00
Philippe Teuwen
2648bb047c Keep it simple
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
2009-03-09 08:58:32 +08:00
Philippe Teuwen
bbff2d13bb Remove usage call and export TODOTXT_SH for action.d
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
2009-03-09 08:55:28 +08:00
David A. Harding
e4c7979888 Merge branch 'gina/master'
Conflicts:

	todo.sh
2009-03-08 20:50:27 -04:00
Ed Blackman
47c7ba75b3 Remove now-redundant export of CFG_FILE 2009-03-08 18:41:27 -04:00
Philippe Teuwen
2bd2e9f7bd Options & environment variables: add namespace & allow for preset
This patch does 2 things:
- Allowing environment variables corresponding to options (e.g. VERBOSE for -v)
to be predefined in the user environment instead of having to always use
the corresponding option.
- Adding namespace TODOTXT_ to those envvars to avoid clashes in user environment

todo.action.d scripts can call recursively todo.sh and this patch preserves
the options/envvars through the calls.
As a bonus, now the user can export in advance one of those variables in
his/her environment and it would have the same effect as using the todo.sh
corresponding option.

export TODOTXT_AUTO_ARCHIVE=0          is same as option -a
export TODOTXT_CFG_FILE=CONFIG_FILE    is same as option -d CONFIG_FILE
export TODOTXT_FORCE=1                 is same as option -f
export TODOTXT_PRESERVE_LINE_NUMBERS=0 is same as option -n
export TODOTXT_PLAIN=1                 is same as option -p
export TODOTXT_DATE_ON_ADD=1           is same as option -t
export TODOTXT_VERBOSE=1               is same as option -v

Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
2009-03-09 06:28:52 +08:00
David A. Harding
7b2c9f080a Merged In Gina's Latest 2009-03-08 12:08:04 -04:00
David A. Harding
98646a575a Exit If .todo.actions.d Script Is Run
.
Suggested by Philippe Teuwen, this patch undoes a lot of the unnecessary
formating changes in my previous patch.
2009-03-08 11:46:26 -04:00
David A. Harding
e6649e6293 Removed Extended Regexes from Hiding Code
.
Dave Hein noticed the extended regular expressions (regex) in the
original patch don't work by default on Mac OS X (FreeBSD sed).  Now
using his suggested regex format: [[:space:]]@[^[:space:]]\{1,\}
.
Also changed: I misapplied part of the patch originally.  That's now
fixed.  I expanded part of the regular expression in the list
sub-expression so that I could change part of the coloring code.
2009-03-08 11:25:12 -04:00
Ed Blackman
5683490c0e Export variables so that they can be easily used in actions
Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
2009-03-08 09:53:41 +08:00
David A. Harding
20e6892775 Run .todo.actions.d Before Builtins
.
Let users override default commands by creating a script in
~/.todo.actions.d/ with the same name as a default command.  Idea by Don
Harper and David A. Harding; patch by Harding.
.
The patch adds the following logic and increases the indent level for
the case statement:
.
+if [ -d "$HOME/.todo.actions.d" -a -x "$HOME/.todo.actions.d/$action" ]
+then
+    CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@"
+else
+    case $action in
2009-03-07 16:15:15 -05:00
David A. Harding
fd9b002ce1 Hiding Priority, Context, and Project
.
Adds three new switches that hide priorty, context, and project text in
list output.
.
Changes proposed by Dave Hein.  Original patch by Dave Hein.  Revised
patch by David A. Harding. Thread starts at
http://tech.groups.yahoo.com/group/todotxt/message/1848
2009-03-07 13:05:40 -05:00
Philippe Teuwen
586abe8282 Cleaning indentation and mix of tabs/spaces, nothing else I swear ;-)
Signed-off-by: ginatrapani <ginatrapani@gmail.com>
2009-03-07 06:00:08 +08:00
U-STARBUCK\gina
9c6efe2ed7 Version 2.1 first commit 2009-03-05 17:26:24 -08:00