1 # Old bash doesn't have completion support.
2 if ! builtin complete 2>&1 | grep 'not a shell builtin' >/dev/null; then
5 COMPLETION_DIR_SSH=${PROFILE_HOME:-~}/.ssh/hosts
6 COMPLETION_DIR_TELNET=${PROFILE_HOME:-~}/.telnet/hosts
7 COMPLETION_DIR_RDP=${PROFILE_HOME:-~}/.rdp/hosts
8 COMPLETION_DIR_PING="$COMPLETION_DIR_SSH $COMPLETION_DIR_TELNET $COMPLETION_DIR_RDP"
10 function _generic_completion() {
11 COMPLETION_DIR=${1+"$@"}
13 cur=${COMP_WORDS[COMP_CWORD]}
15 HOSTS="$(find $COMPLETION_DIR -type f -perm -100 2>/dev/null | sed 's@.*/@@')"
17 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
21 # Process completion for killall.
23 cur=${COMP_WORDS[COMP_CWORD]}
25 PROCESSES="$(ps agx --no-heading | awk '{ print $5 }' | sed 's@.*/@@' | sort | uniq)"
27 COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
31 # Host completion for SSH known hosts.
32 function _known_hosts() {
33 cur=${COMP_WORDS[COMP_CWORD]}
35 HOSTS=$(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts)
37 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
41 # Host completion from dsh groups.
42 function _dshgroup() {
43 cur=${COMP_WORDS[COMP_CWORD]}
45 HOSTS=$(grep -rh '^[A-Za-z0-9]' ~/.dsh/group)
47 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
52 cur=${COMP_WORDS[COMP_CWORD]}
54 HOSTS="$(grep -rh '^[A-Za-z0-9]' ~/.dsh/group)
55 $(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts)
56 $(find $COMPLETION_DIR_SSH -type f -perm -100 2>/dev/null | sed 's@.*/@@')"
58 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
62 # Process completion for kill, strace etc.
64 cur=${COMP_WORDS[COMP_CWORD]}
66 PROCESSES="$(find /proc -name '[0-9]*' -maxdepth 1 2>/dev/null | sed 's@.*/@@')"
68 COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
72 # Complete ssh with hostnames from the Window Maker menu.
74 _generic_completion $COMPLETION_DIR_SSH
78 # Complete telnet with hostnames from the Window Maker menu.
80 _generic_completion $COMPLETION_DIR_TELNET
84 # Complete rdesktop with hostnames from the Window Maker menu.
86 _generic_completion $COMPLETION_DIR_RDP
90 # Ping hosts from any of the above lists.
92 _generic_completion $COMPLETION_DIR_PING
95 # Hacked up make rule.
98 cur=${COMP_WORDS[COMP_CWORD]}
100 RULES="all check clean dep depend install reinstall setup uninstall"
102 COMPREPLY=($(compgen -W "$RULES" -- "$cur"))
107 function _modprobe() {
109 cur=${COMP_WORDS[COMP_CWORD]}
112 MODULES="$(find /lib/modules/$ver -name \*.ko | sed -n 's@^.*/\([^/]*\).ko$@\1@p')"
114 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
118 # Look for loaded modules.
121 cur=${COMP_WORDS[COMP_CWORD]}
123 MODULES="$(lsmod | sed '1d;s/ .*$//')"
125 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
129 # Find tags with GNU GLOBAL.
132 cur=${COMP_WORDS[COMP_CWORD]}
134 COMPREPLY=($(global -c "$cur"))
138 complete -F _omnissh rollout
139 complete -F _omnissh ssh
140 complete -F _omnissh sshterm
141 complete -F _ping telnet
142 complete -F _telnet telnetterm
143 complete -F _rdp rdesktop
144 complete -F _ping ping
145 complete -F _ping traceroute
146 complete -F _ping dnsip
147 complete -F _make make
148 complete -F _process killall
149 complete -F _pid kill
150 complete -F _pid strace
151 complete -F _known_hosts kill_known_host
152 complete -F _known_hosts knh
153 complete -F _omnissh knh
154 complete -F _modprobe modprobe
155 complete -F _rmmod rmmod
156 complete -F _global global