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:
@@ -46,15 +46,22 @@ test_todo_session 'todo 1 and 2 contexts' <<EOF
|
||||
EOF
|
||||
|
||||
# Define a second completion function that injects the different configuration
|
||||
# file. In real use, this would be installed via
|
||||
# file and uppercases all output. (This is a silly behavior change that still
|
||||
# requires a completion function override.)
|
||||
# In real use, this would be installed via
|
||||
# complete -F _todo2 todo2
|
||||
_uppercase_todo()
|
||||
{
|
||||
todo.sh "$@" | tr '[:lower:]' '[:upper:]'
|
||||
}
|
||||
_todo2()
|
||||
{
|
||||
local _todo_sh='todo.sh -d "$HOME/todo2.cfg"'
|
||||
local _todo_sh='_uppercase_todo -d "$HOME/todo2.cfg"'
|
||||
_todo "$@"
|
||||
}
|
||||
|
||||
test_todo_completion 'all todo1 contexts' 'todo1 list @' '@garden @outdoor @outside'
|
||||
test_todo_custom_completion _todo2 'all todo2 contexts' 'todo2 list @' '@home @oriental'
|
||||
test_todo_completion 'all todo2 contexts' 'todo2 list @' '@home @oriental'
|
||||
test_todo_custom_completion _todo2 'all uppercased todo2 contexts' 'doesNotMatter list @' '@HOME @ORIENTAL'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user