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 # Process completion for kill, strace etc.
43 cur=${COMP_WORDS[COMP_CWORD]}
45 PROCESSES="$(find /proc -name '[0-9]*' -maxdepth 1 2>/dev/null | sed 's@.*/@@')"
47 COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
51 # Complete ssh with hostnames from the Window Maker menu.
53 _generic_completion $COMPLETION_DIR_SSH
57 # Complete telnet with hostnames from the Window Maker menu.
59 _generic_completion $COMPLETION_DIR_TELNET
63 # Complete rdesktop with hostnames from the Window Maker menu.
65 _generic_completion $COMPLETION_DIR_RDP
69 # Ping hosts from any of the above lists.
71 _generic_completion $COMPLETION_DIR_PING
74 # Hacked up make rule.
77 cur=${COMP_WORDS[COMP_CWORD]}
79 RULES="all check clean dep depend install reinstall setup uninstall"
81 COMPREPLY=($(compgen -W "$RULES" -- "$cur"))
86 function _modprobe() {
88 cur=${COMP_WORDS[COMP_CWORD]}
91 MODULES="$(find /lib/modules/$ver -name \*.ko | sed -n 's@^.*/\([^/]*\).ko$@\1@p')"
93 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
97 # Look for loaded modules.
100 cur=${COMP_WORDS[COMP_CWORD]}
102 MODULES="$(lsmod | sed '1d;s/ .*$//')"
104 COMPREPLY=($(compgen -W "$MODULES" -- "$cur"))
108 # Find tags with GNU GLOBAL.
111 cur=${COMP_WORDS[COMP_CWORD]}
113 COMPREPLY=($(global -c "$cur"))
117 complete -F _ssh rollout
119 complete -F _ssh sshterm
120 complete -F _ping telnet
121 complete -F _telnet telnetterm
122 complete -F _rdp rdesktop
123 complete -F _ping ping
124 complete -F _ping traceroute
125 complete -F _ping dnsip
126 complete -F _make make
127 complete -F _process killall
128 complete -F _pid kill
129 complete -F _pid strace
130 complete -F _known_hosts kill_known_host
131 complete -F _known_hosts knh
132 complete -F _modprobe modprobe
133 complete -F _rmmod rmmod
134 complete -F _global global