3 export COMPLETION_DIR_SSH=~/.ssh/hosts
4 export COMPLETION_DIR_TELNET=~/.telnet/hosts
5 export COMPLETION_DIR_RDP=~/.ssh/hosts
6 export COMPLETION_DIR_PING="$COMPLETION_DIR_SSH $COMPLETION_DIR_TELNET $COMPLETION_DIR_RDP"
8 function _generic_completion() {
9 COMPLETION_DIR=${1+"$@"}
11 cur=${COMP_WORDS[COMP_CWORD]}
13 HOSTS="$(find $COMPLETION_DIR -type f -perm -100 2>/dev/null | sed 's@.*/@@')"
15 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
19 # Process completion for killall.
21 cur=${COMP_WORDS[COMP_CWORD]}
23 PROCESSES="$(ps agx --no-heading | awk '{ print $5 }' | sed 's@.*/@@' | sort | uniq)"
25 COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
29 # Host completion for SSH known hosts.
30 function _known_hosts() {
31 cur=${COMP_WORDS[COMP_CWORD]}
33 HOSTS=$(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts)
35 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
39 # Process completion for kill, strace etc.
41 cur=${COMP_WORDS[COMP_CWORD]}
43 PROCESSES="$(find /proc -name '[0-9]*' -maxdepth 1 2>/dev/null | sed 's@.*/@@')"
45 COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
49 # Complete ssh with hostnames from the Window Maker menu.
51 _generic_completion $COMPLETION_DIR_SSH
55 # Complete telnet with hostnames from the Window Maker menu.
57 _generic_completion $COMPLETION_DIR_TELNET
61 # Complete rdesktop with hostnames from the Window Maker menu.
63 _generic_completion $COMPLETION_DIR_RDP
67 # Ping hosts from any of the above lists.
69 _generic_completion $COMPLETION_DIR_PING
72 # Hacked up make rule.
75 cur=${COMP_WORDS[COMP_CWORD]}
77 RULES="all check clean dep depend install reinstall setup uninstall"
79 COMPREPLY=($(compgen -W "$RULES" -- "$cur"))
84 function _modprobe() {
86 cur=${COMP_WORDS[COMP_CWORD]}
89 MODULES="$(find /lib/modules/$ver -name \*.ko | sed -n 's@^.*/\([^/]*\).ko$@\1@p')"
91 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
95 # Look for loaded modules.
98 cur=${COMP_WORDS[COMP_CWORD]}
100 MODULES="$(lsmod | sed '1d;s/ .*$//')"
102 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
106 # Find tags with GNU GLOBAL.
109 cur=${COMP_WORDS[COMP_CWORD]}
111 COMPREPLY=($(global -c "$cur"))
115 complete -F _ssh rollout
117 complete -F _ssh sshterm
118 complete -F _ping telnet
119 complete -F _telnet telnetterm
120 complete -F _rdp rdesktop
121 complete -F _ping ping
122 complete -F _ping traceroute
123 complete -F _ping dnsip
124 complete -F _make make
125 complete -F _process killall
126 complete -F _pid kill
127 complete -F _pid strace
128 complete -F _known_hosts kill_known_host
129 complete -F _known_hosts knh
130 complete -F _modprobe modprobe
131 complete -F _rmmod rmmod
132 complete -F _global global
134 unset COMPLETION_DIR_PING
135 unset COMPLETION_DIR_RDP
136 unset COMPLETION_DIR_SSH
137 unset COMPLETION_DIR_TELNET