ENH: Reuse the todo.sh alias for completion
Having to define a completion function wrapper is cumbersome. I had seen the trick of simply using ${COMP_WORDS[0]} (i.e. the used todo.sh command itself) from Paul Mansfield (https://github.com/the1ts/todo.txt-plugins/blob/develop/bash_completion/todo.txt#L7), which neatly avoids this.
By keeping the _todo_sh variable, this is a one-line change and it still allows the old way of using the override in a wrapper function. (So users aren't forced to change their customizations when upgrading.)
Tests are adapted to verify that the alias is used, and still verify the wrapper function as well.
The documentation is simplified because there's normally no need for the completion wrapper function.
This commit is contained in:
@@ -18,7 +18,7 @@ _todo()
|
||||
mv prepend prep pri p replace report shorthelp"
|
||||
local -r MOVE_COMMAND_PATTERN='move|mv'
|
||||
|
||||
local _todo_sh=${_todo_sh:-todo.sh}
|
||||
local _todo_sh=${_todo_sh:-${COMP_WORDS[0]}}
|
||||
local completions
|
||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||
completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons 2>/dev/null) $OPTS"
|
||||
@@ -101,22 +101,14 @@ complete -F _todo todo.sh
|
||||
# ~/.bashrc (or wherever else you're defining your alias). If you simply
|
||||
# uncomment it here, you will need to redo this on every todo.txt update!
|
||||
|
||||
# If you have renamed the todo.sh executable, or if it is not accessible through
|
||||
# PATH, you need to add and use a wrapper completion function, like this:
|
||||
#_todoElsewhere()
|
||||
# The completion uses the alias itself, so any custom arguments (like a custom
|
||||
# configuration (-d "$HOME/todo2.cfg")) are used there as well.
|
||||
# If you don't want this, or need to further tweak the todo.sh command that's
|
||||
# used by the completion, you can add and use a wrapper completion function that
|
||||
# redefines _todo_sh before invoking _todo():
|
||||
#_todo_tweak()
|
||||
#{
|
||||
# local _todo_sh='/path/to/todo2.sh'
|
||||
# local _todo_sh='todo.sh -d "$HOME/todo-tweaked.cfg"'
|
||||
# _todo "$@"
|
||||
#}
|
||||
#complete -F _todoElsewhere /path/to/todo2.sh
|
||||
|
||||
# If you use aliases to use different configuration(s), you need to add and use
|
||||
# a wrapper completion function for each configuration if you want to complete
|
||||
# from the actual configured task locations:
|
||||
#alias todo2='todo.sh -d "$HOME/todo2.cfg"'
|
||||
#_todo2()
|
||||
#{
|
||||
# local _todo_sh='todo.sh -d "$HOME/todo2.cfg"'
|
||||
# _todo "$@"
|
||||
#}
|
||||
#complete -F _todo2 todo2
|
||||
#complete -F _todo_tweak todo.sh
|
||||
|
||||
Reference in New Issue
Block a user