-
Notifications
You must be signed in to change notification settings - Fork 0
/
completions
128 lines (109 loc) · 2.82 KB
/
completions
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#
# TODO: integrate this with the upstream code that provides
# these in places like /etc/completions.d/ and /etc/profile.d/
#
# TODO: use the 124 exit code mentioned in man page to
# implement a ~/.bash/completions.d/
#
shell_init_completions_host="
ssh
sshr
telnet
rsh
scp
ping
vncviewer
rdesktop
"
shell_init_completions_file="
scp
"
##############################################################################
#
# relies on ssh (only) as the source for host completions,
# (by extraction from known_hosts) and sets them up to be
# used for a number of commands
#
# TODO: does not handle '[ipaddr]:port' lines in known_hosts
# TODO: nor "markers" (ie lines beginning with '@')
#
shell_init_completions_host ()
{
local cmd
local infile=~/.ssh/known_hosts
local outfile=$HOSTFILE
# TODO this is broken, FIXME
return
if ! test -e $infile
then
# maybe anew host does not have any ssh known_hosts yet
true
return
elif test ! -e $outfile || test $infile -nt $outfile
then
echo "rebuilding completions"
# generates an /etc/hosts format file out of
# known_hosts in order to be useful to
# readline for hostname completion
#
awk '{
split($1, aliases, ",");
asort(aliases);
for (alias in aliases)
printf("%s ", aliases[alias]);
printf("\n");
}' < $infile >| $outfile
else
# use the cached completions
:
fi
set -- ${!FUNCNAME}
for cmd; do complete -A hostname $cmd; done
}
shell_init_completions_file ()
{
local cmd
set -- ${!FUNCNAME}
for cmd; do complete -A file $cmd; done
}
shell_init_completions_incus ()
{
((BASH_VERSINFO < 5)) && return
if [[ $(type -P incus) ]]
then
# from /usr/share/bash-completion/, incus completions expect
source init.d/completions.bash5
source <(incus completion bash) &>/dev/null \
&& complete -o default -F __start_incus incus sincus inc
fi
}
shell_init_completions_gcloud ()
{
((BASH_VERSINFO < 5)) && return # TODO not sure this is necessary?
[[ $(type -P gcloud) ]] || return
source /usr/share/google-cloud-sdk/completion.bash.inc &>/dev/null
}
##############################################################################
#
# these are retained after we exit, used by the completion
# routines themselves each time (ie we are complete -F)
#
# TODO what?
##############################################################################
# start completions fresh with a clean slate
#
complete -r
# run once and remove shell_init_foo() defined above
#
source ~/.bash/initfuncs
# sudo just prefixes any ordinary command
#
complete -c -A file sudo
complete -c -A file s # complete builtin is not alias-aware
# by default, we don't want to append the trailing spaces, and
# bring in both bash and readline defaults
# update: not yet, still have to think
# about it, leaving commented for now 20171230134138
#
#complete -D -o nospace -o bashdefault -o default
#