2 export COMPLETION_DIR_SSH=~/.ssh/hosts
3 export COMPLETION_DIR_TELNET=~/.telnet/hosts
4 export COMPLETION_DIR_RDP=~/.rdp/hosts
5 export COMPLETION_DIR_PING="$COMPLETION_DIR_SSH $COMPLETION_DIR_TELNET $COMPLETION_DIR_RDP"
7 function _generic_completion() {
8 COMPLETION_DIR=${1+"$@"}
10 cur=${COMP_WORDS[COMP_CWORD]}
12 HOSTS="$(find $COMPLETION_DIR -type f -perm -100 2>/dev/null | sed 's@.*/@@')"
14 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
18 # Process completion for killall.
20 cur=${COMP_WORDS[COMP_CWORD]}
22 PROCESSES="$(ps agx --no-heading | awk '{ print $5 }' | sed 's@.*/@@' | sort | uniq)"
24 COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
28 # Host completion for SSH known hosts.
29 function _known_hosts() {
30 cur=${COMP_WORDS[COMP_CWORD]}
32 HOSTS=$(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts)
34 COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
38 # Process completion for kill, strace etc.
40 cur=${COMP_WORDS[COMP_CWORD]}
42 PROCESSES="$(find /proc -name '[0-9]*' -maxdepth 1 2>/dev/null | sed 's@.*/@@')"
44 COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
48 # Complete ssh with hostnames from the Window Maker menu.
50 _generic_completion $COMPLETION_DIR_SSH
54 # Complete telnet with hostnames from the Window Maker menu.
56 _generic_completion $COMPLETION_DIR_TELNET
60 # Complete rdesktop with hostnames from the Window Maker menu.
62 _generic_completion $COMPLETION_DIR_RDP
66 # Ping hosts from any of the above lists.
68 _generic_completion $COMPLETION_DIR_PING
71 # Hacked up make rule.
74 cur=${COMP_WORDS[COMP_CWORD]}
76 RULES="all check clean dep depend install reinstall setup uninstall"
78 COMPREPLY=($(compgen -W "$RULES" -- "$cur"))
83 function _modprobe() {
85 cur=${COMP_WORDS[COMP_CWORD]}
88 MODULES="$(find /lib/modules/$ver -name \*.ko | sed -n 's@^.*/\([^/]*\).ko$@\1@p')"
90 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
94 # Look for loaded modules.
97 cur=${COMP_WORDS[COMP_CWORD]}
99 MODULES="$(lsmod | sed '1d;s/ .*$//')"
101 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
105 # Find tags with GNU GLOBAL.
108 cur=${COMP_WORDS[COMP_CWORD]}
110 COMPREPLY=($(global -c "$cur"))
114 complete -F _ssh rollout
116 complete -F _ssh sshterm
117 complete -F _ping telnet
118 complete -F _telnet telnetterm
119 complete -F _rdp rdesktop
120 complete -F _ping ping
121 complete -F _ping traceroute
122 complete -F _ping dnsip
123 complete -F _make make
124 complete -F _process killall
125 complete -F _pid kill
126 complete -F _pid strace
127 complete -F _known_hosts kill_known_host
128 complete -F _known_hosts knh
129 complete -F _modprobe modprobe
130 complete -F _rmmod rmmod
131 complete -F _global global