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:
Ingo Karkat
2024-10-30 08:28:09 +01:00
parent a916aa97df
commit 9623f77af8
2 changed files with 19 additions and 20 deletions

View File

@@ -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