diff --git a/todo_completion b/todo_completion index 644be6e..f26497b 100755 --- a/todo_completion +++ b/todo_completion @@ -48,23 +48,28 @@ _todo() completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listcon 2>/dev/null) ;; *) if [[ "$cur" =~ ^[0-9]+$ ]]; then - # Remove the (padded) task number; we prepend the - # 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. - # Remove any trailing whitespace; the Bash - # completion inserts a trailing space itself. - # Finally, limit the output to a single line just as - # a safety check of the ls action output. + declare -a sedTransformations=( + # Remove the (padded) task number; we prepend the + # user-provided $cur instead. + -e 's/^ *[0-9]\{1,\} //' + # Remove the timestamp prepended by the -t option, + # but keep any priority (as it's short and may + # provide useful context). + -e 's/^\((.) \)\{0,1\}[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' + # Remove the done date and (if there) the timestamp. + # Keep the "x" (as it's short and may provide useful + # context) + -e 's/^\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' + # Remove any trailing whitespace; the Bash + # completion inserts a trailing space itself. + -e 's/[[:space:]]*$//' + # Finally, limit the output to a single line just as + # a safety check of the ls action output. + -e '1q' + ) local todo=$( \ eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' 2>/dev/null | \ - sed -e 's/^ *[0-9]\{1,\} //' -e 's/^\((.) \)\{0,1\}[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 's/[[:space:]]*$//' \ - -e '1q' \ + sed "${sedTransformations[@]}" \ ) # Append task text as a shell comment. This # completion can be a safety check before a