Refactoring: Extract the many complex sed arguments into sedTransformations array and move the comments closer (#273)
There's too much distance between the comments that describe the various transformations that are done on the referenced task, and the corresponding sed expressions. By using a local Bash array, we can collect the arguments and have the comments close by. Co-authored-by: Ali Karbassi <ali@karbassi.com>
This commit is contained in:
@@ -48,23 +48,28 @@ _todo()
|
|||||||
completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listcon 2>/dev/null)
|
completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listcon 2>/dev/null)
|
||||||
;;
|
;;
|
||||||
*) if [[ "$cur" =~ ^[0-9]+$ ]]; then
|
*) if [[ "$cur" =~ ^[0-9]+$ ]]; then
|
||||||
# Remove the (padded) task number; we prepend the
|
declare -a sedTransformations=(
|
||||||
# user-provided $cur instead.
|
# Remove the (padded) task number; we prepend the
|
||||||
# Remove the timestamp prepended by the -t option,
|
# user-provided $cur instead.
|
||||||
# and the done date (for done tasks); there's no
|
-e 's/^ *[0-9]\{1,\} //'
|
||||||
# todo.txt option for that yet.
|
# Remove the timestamp prepended by the -t option,
|
||||||
# But keep priority and "x"; they're short and may
|
# but keep any priority (as it's short and may
|
||||||
# provide useful context.
|
# provide useful context).
|
||||||
# Remove any trailing whitespace; the Bash
|
-e 's/^\((.) \)\{0,1\}[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/'
|
||||||
# completion inserts a trailing space itself.
|
# Remove the done date and (if there) the timestamp.
|
||||||
# Finally, limit the output to a single line just as
|
# Keep the "x" (as it's short and may provide useful
|
||||||
# a safety check of the ls action output.
|
# 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=$( \
|
local todo=$( \
|
||||||
eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' 2>/dev/null | \
|
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/' \
|
sed "${sedTransformations[@]}" \
|
||||||
-e 's/^\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \
|
|
||||||
-e 's/[[:space:]]*$//' \
|
|
||||||
-e '1q' \
|
|
||||||
)
|
)
|
||||||
# Append task text as a shell comment. This
|
# Append task text as a shell comment. This
|
||||||
# completion can be a safety check before a
|
# completion can be a safety check before a
|
||||||
|
|||||||
Reference in New Issue
Block a user