forked from kyleburton/bake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbake-completion.sh
More file actions
29 lines (24 loc) · 844 Bytes
/
bake-completion.sh
File metadata and controls
29 lines (24 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
_bake () {
local cword cur tasks words
_get_comp_words_by_ref -n : -c cur cword words
tasks="$(bake --tasks)"
if [[ "$cword" -eq "1" ]]; then
mapfile -t COMPREPLY < <(compgen -W "$tasks" -- "$cur")
else
mapfile -t COMPREPLY < <(compgen -W "$(bake -x "${words[1]}" "$cur")" -- "$cur")
fi
# NB: this is a workaround for bash's default of splitting words on colons
# when bake tasks also use colons as a namespace separator. What we need to
# do is fill COMPREPLY with the remaining parts of the task after the last
# colon.
# TODO: as is, this fails to drop incomplete tasks
if [[ $cur == *:* ]]; then
local pfx="${cur%%:*}:"
for ((ii = 0; ii < ${#COMPREPLY[@]}; ++ii)); do
local w="${COMPREPLY[$ii]}"
COMPREPLY[$ii]="${w#$pfx}"
done
fi
}
complete -F _bake bake