633c86c9b774d60b6d83b35783d506f5be54dc7b
[profile.git] / .profile.d / completion.bashrc
1 # Helper!
2 export COMPLETION_DIR_SSH=~/.ssh/hosts
3 export COMPLETION_DIR_TELNET=~/.telnet/hosts
4 export COMPLETION_DIR_RDP=~/.ssh/hosts
5 export COMPLETION_DIR_PING="$COMPLETION_DIR_SSH $COMPLETION_DIR_TELNET $COMPLETION_DIR_RDP"
6
7 function _generic_completion() {
8   COMPLETION_DIR=${1+"$@"}
9   COMPREPLY=()
10   cur=${COMP_WORDS[COMP_CWORD]}
11
12   HOSTS="$(find $COMPLETION_DIR -type f -perm -100 | sed 's@.*/@@')"
13
14   COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
15   return 0
16 }
17
18 # Process completion for killall.
19 function _process() {
20   cur=${COMP_WORDS[COMP_CWORD]}
21
22   PROCESSES="$(ps agx --no-heading | awk '{ print $5 }' | sed 's@.*/@@' | sort | uniq)"
23
24   COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
25   return 0
26 }
27
28 # Process completion for kill, strace etc.
29 function _pid() {
30   cur=${COMP_WORDS[COMP_CWORD]}
31
32   PROCESSES="$(find /proc -name '[0-9]*' -maxdepth 1 | sed 's@.*/@@')"
33
34   COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur"))
35   return 0
36 }
37
38 # Complete ssh with hostnames from the Window Maker menu.
39 function _ssh() {
40   _generic_completion $COMPLETION_DIR_SSH
41   return 0
42 }
43
44 # Complete telnet with hostnames from the Window Maker menu.
45 function _telnet() {
46   _generic_completion $COMPLETION_DIR_TELNET
47   return 0
48 }
49
50 # Complete rdesktop with hostnames from the Window Maker menu.
51 function _rdp() {
52   _generic_completion $COMPLETION_DIR_RDP
53   return 0
54 }
55
56 # Ping hosts from any of the above lists.
57 function _ping() {
58   _generic_completion $COMPLETION_DIR_PING
59 }
60
61 # Hacked up make rule.
62 function _make() {
63   COMPREPLY=()
64   cur=${COMP_WORDS[COMP_CWORD]}
65
66   RULES="all check clean dep depend install reinstall setup uninstall"
67
68   COMPREPLY=($(compgen -W "$RULES" -- "$cur"))
69   return 0
70 }
71
72 complete -F _ssh rollout
73 complete -F _ssh ssh
74 complete -F _ssh sshterm
75 complete -F _ping telnet
76 complete -F _telnet telnetterm
77 complete -F _rdp rdesktop
78 complete -F _ping ping
79 complete -F _ping traceroute
80 complete -F _ping dnsip
81 complete -F _make make
82 complete -F _process killall
83 complete -F _pid kill
84 complete -F _pid strace