From 248c56367f961c81d04fb94a7f6ee8c2cd9d8df1 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Mon, 9 Jan 2012 15:23:22 +0100 Subject: [PATCH] Remove task date(s) when completing prioritized and done tasks. Replace the primitive substitutions inside the completion function with a call to sed (instead of calling head), and supply more powerful substitutions there. --- todo_completion | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/todo_completion b/todo_completion index 7f3d391..1a62c5c 100644 --- a/todo_completion +++ b/todo_completion @@ -38,20 +38,25 @@ _todo() +*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);; @*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);; *) if [[ "$cur" =~ ^[0-9]+$ ]]; then - local item=$(TODOTXT_VERBOSE=0 todo.sh -@ -+ -p -x command ls "^ *${cur} " | head -n 1) - # Remove the (padded) task number; we prepend the - # user-provided $cur. - item=${item#* } - - # Remove the timestamp prepended by the -t option; - # there's no todo.txt option for that yet. - item=${item#[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] } - + # user-provided $cur instead. + # Remove the timestamp prepended by the -t option, + # and the done date (for done tasks); there's no + # todo.txt option for that yet. + # But keep priority and "x"; they're short and may + # provide useful context. + # Finally, limit the output to a single line just as + # a safety check of the ls action output. + local todo=$( \ + TODOTXT_VERBOSE=0 todo.sh -@ -+ -p -x command ls "^ *${cur} " | \ + sed -e 's/^ *[0-9]\+ //' -e 's/\((.) \)[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' \ + -e 's/\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \ + -e '1q' \ + ) # Append task text as a shell comment. This # completion can be a safety check before a # destructive todo.txt operation. - [ "$item" ] && COMPREPLY[0]="$cur # $item" + [ "$todo" ] && COMPREPLY[0]="$cur # $todo" return 0 else return 0