-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy paththings.bashcompletion.sh
More file actions
executable file
·27 lines (23 loc) · 895 Bytes
/
things.bashcompletion.sh
File metadata and controls
executable file
·27 lines (23 loc) · 895 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
#!/usr/bin/env bash
_things_complete() {
local cur_word option_list command_list
# COMP_WORDS is an array of words in the current command line.
# COMP_CWORD is the index of the current word (the one the cursor is
# in). So COMP_WORDS[COMP_CWORD] is the current word; we also record
# the previous word here, although this specific script doesn't
# use it yet.
cur_word="${COMP_WORDS[COMP_CWORD]}"
# Ask things.sh to generate a list of types it supports
option_list=$(things.sh show-options)
command_list=$(things.sh show-commands)
# Perform completion of commands and options.
if [[ ${cur_word} == -* ]]; then
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${option_list}" -- "${cur_word}"))
else
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${command_list}" -- "${cur_word}"))
fi
return 0
}
complete -F _things_complete things.sh