From f5270be4634c5c0d55c0afd4ad8e02d217236ea2 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sun, 20 Nov 2011 14:57:36 +0100 Subject: [PATCH] ENH: Append task text as shell comment when completing task number. This is useful for the paranoid before a destructive todo.txt operation. Appending the text as a shell comment doesn't affect the todo.txt command itself, but shows that the task number corresponds to the task you had in mind. --- todo_completion | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/todo_completion b/todo_completion index f620ce1..45f8245 100644 --- a/todo_completion +++ b/todo_completion @@ -29,8 +29,28 @@ _todo() *) case "$cur" in +*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);; @*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);; - *) return 0;; + *) 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] } + + # 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" + return 0 + else + return 0 + fi + ;; esac + ;; esac fi