blob: 0994d396dccaf8f8a6fe712d0524103f13006b0c (
plain)
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
51
52
53
54
|
# hostinfo completion
_get_first_hostinfo_arg()
{
local i
arg=
for (( i=1; i < COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" != -* ]]; then
arg=${COMP_WORDS[i]}
break
fi
[[ "${COMP_WORDS[i]}" == "--path" || "${COMP_WORDS[i]}" == "-p" ]] && i=$((i+1))
done
}
_get_hostinfo_path()
{
local i
path=
for (( i=1; i < COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" == "--path" || "${COMP_WORDS[i]}" == "-p" ]]; then
path="--path ${COMP_WORDS[i+1]}"
break
fi
done
}
_hostinfo() {
local cur prev
COMPREPLY=()
_get_comp_words_by_ref cur prev
if [[ "$prev" == "-p" || "$prev" == "--path" ]]; then
COMPREPLY=( $( compgen -d -o dirnames -S "/" $cur ) )
compopt -o nospace
else
_get_first_hostinfo_arg
_get_hostinfo_path
if [[ -z "$arg" ]]; then
_completion="$(hostinfo $path --hosts --short 2>/dev/null)"
else
_completion="$(hostinfo $path --keys $arg 2>/dev/null)"
fi
COMPREPLY=( $( compgen -W "-o --oneline -f --file -k --keys -h -? --help
-p --path $_completion" -- $cur ) )
fi
}
complete -F _hostinfo hostinfo
|