Skip to content

Commit 3ea25d2

Browse files
committed
suggest function
1 parent 14bc0ac commit 3ea25d2

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ To customize the options for a given task, use a function named ${TASK}_bash_com
139139
$ soda my-task f[TAB]
140140
$ soda my-task foo
141141

142+
Alternatively, you can use the **suggest** function to map the bash completion function:
143+
144+
suggest suggestions my_task
145+
suggestions() {
146+
echo "foo"
147+
echo "bar"
148+
}
149+
142150
If a parameter is passed after the task declaration in command line, the suggestions will be only
143151
the parameters for the task namespace.
144152

scripts/soda/soda.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ bash_completion_task() {
6060
if [[ $(type -t "${TASK}${SODA_TASK_BASH_COMPLETION_SUFFIX}") ]]; then
6161
shift
6262
"${TASK}${SODA_TASK_BASH_COMPLETION_SUFFIX}" "$@"
63+
elif [[ -n "$(get_var SODA_SUGGESTION_${TASK})" ]]; then
64+
shift
65+
"$(get_var SODA_SUGGESTION_${TASK})" "$@"
6366
elif [[ $# == 0 ]]; then
6467
import_all_namespaces
6568
echo "$BASH_COMPLETION_TASKS"
@@ -72,3 +75,13 @@ bash_completion_task() {
7275
}
7376
fi
7477
}
78+
79+
# Maps a function to use for bash completion
80+
suggest() {
81+
local target=$1
82+
shift
83+
for arg in $@; do
84+
local task="${arg//-/_}"
85+
set_var SODA_SUGGESTION_${task} $target
86+
done
87+
}

0 commit comments

Comments
 (0)