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