-
Notifications
You must be signed in to change notification settings - Fork 0
/
__completer
50 lines (42 loc) · 1.21 KB
/
__completer
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# completer interface
# Local variables:
# mode: shell-script
# sh-basic-offset: 2
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=2 sw=2 et filetype=sh
COMPLETION_TOOL=bash-completer
__completer() {
# set -x
COMPREPLY=()
local argc=${COMP_CWORD}
local cur=${COMP_WORDS[$argc]}
local prev=${COMP_WORDS[$argc-1]}
local program=${COMP_WORDS[0]}
local values=
local optionCompleted=1
#echo -e "\nArgs=[$@]\nProgram: [$program]\nPrev - Cur = [$prev] - [$cur]"
# Get the completion for the option
if [[ $prev == -* ]]
then
values=$($COMPLETION_TOOL --program $program --complete $prev)
completionCode=$?
optionCompleted=0
fi
if [[ $optionCompleted = 1 ]] || [[ $completionCode > 2 ]]
then
# There is no completion for the option
case $cur in
-*) values=$($COMPLETION_TOOL --program $program --complete-options) ;;
*) values=$($COMPLETION_TOOL --program $program --complete-actions) ;;
esac
fi
COMPREPLY=( $( compgen -W "$values" -- $cur ) )
# set +x
return 0
}
# Scripts to complete
complete -F __completer $COMPLETION_TOOL # program:completer
PROGRAM_FILE="$HOME/.bash-completer/__registered-programs"
[ -e $PROGRAM_FILE ] && source $PROGRAM_FILE