X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=.profile.d%2Fcompletion.bashrc;h=782cb699d0c81087ab9dcde005134342598b3576;hb=fcd45e190b92e5f5f25df29df408b31038c94816;hp=cf77c1550425fe0730aa46ed51ce52de195bd631;hpb=9bc7cefe316314c162241101a15de05d96033256;p=profile.git diff --git a/.profile.d/completion.bashrc b/.profile.d/completion.bashrc index cf77c15..782cb69 100644 --- a/.profile.d/completion.bashrc +++ b/.profile.d/completion.bashrc @@ -1,9 +1,11 @@ -# $Id$ +# Old bash doesn't have completion support. +if ! builtin complete 2>&1 | grep 'not a shell builtin' >/dev/null; then + # Helper! -export COMPLETION_DIR_SSH=~/.ssh/hosts -export COMPLETION_DIR_TELNET=~/.telnet/hosts -export COMPLETION_DIR_RDP=~/.ssh/hosts -export COMPLETION_DIR_PING="$COMPLETION_DIR_SSH $COMPLETION_DIR_TELNET $COMPLETION_DIR_RDP" +COMPLETION_DIR_SSH=${PROFILE_HOME:-~}/.ssh/hosts +COMPLETION_DIR_TELNET=${PROFILE_HOME:-~}/.telnet/hosts +COMPLETION_DIR_RDP=${PROFILE_HOME:-~}/.rdp/hosts +COMPLETION_DIR_PING="$COMPLETION_DIR_SSH $COMPLETION_DIR_TELNET $COMPLETION_DIR_RDP" function _generic_completion() { COMPLETION_DIR=${1+"$@"} @@ -30,8 +32,28 @@ function _process() { function _known_hosts() { cur=${COMP_WORDS[COMP_CWORD]} - HOSTS=$(sed 's/[ ].*//;s/,/\ -/' ~/.ssh/known_hosts) + HOSTS=$(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts) + + COMPREPLY=($(compgen -W "$HOSTS" -- "$cur")) + return 0 +} + +# Host completion from dsh groups. +function _dshgroup() { + cur=${COMP_WORDS[COMP_CWORD]} + + HOSTS=$(grep -rh '^[A-Za-z0-9]' ~/.dsh/group) + + COMPREPLY=($(compgen -W "$HOSTS" -- "$cur")) + return 0 +} + +function _omnissh() { + cur=${COMP_WORDS[COMP_CWORD]} + + HOSTS="$(grep -rh '^[A-Za-z0-9]' ~/.dsh/group) +$(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts) +$(find $COMPLETION_DIR_SSH -type f -perm -100 2>/dev/null | sed 's@.*/@@')" COMPREPLY=($(compgen -W "$HOSTS" -- "$cur")) return 0 @@ -86,7 +108,7 @@ function _modprobe() { COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} - ver=$(uname -r) + ver=$KERNEL MODULES="$(find /lib/modules/$ver -name \*.ko | sed -n 's@^.*/\([^/]*\).ko$@\1@p')" COMPREPLY=($(compgen -W "$MODULES" -- "$cur")) @@ -104,9 +126,18 @@ function _rmmod() { return 0 } -complete -F _ssh rollout -complete -F _ssh ssh -complete -F _ssh sshterm +# Find tags with GNU GLOBAL. +function _global() { + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + + COMPREPLY=($(global -c "$cur")) + return 0 +} + +complete -F _omnissh rollout +complete -F _omnissh ssh +complete -F _omnissh sshterm complete -F _ping telnet complete -F _telnet telnetterm complete -F _rdp rdesktop @@ -119,5 +150,9 @@ complete -F _pid kill complete -F _pid strace complete -F _known_hosts kill_known_host complete -F _known_hosts knh +complete -F _omnissh knh complete -F _modprobe modprobe complete -F _rmmod rmmod +complete -F _global global + +fi