X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.profile.d%2Fcompletion.bashrc;h=3c3ec3325cfcb82a15bbf49dd0a18cd8092d8032;hp=ad072bf51b7ae2d4975833bfeeceac7971e22c95;hb=0614eba6741fe0b5f1ef54ad7478fe003ca0e613;hpb=8c75606a52da5a4df6018134e0806e7041ca69e1 diff --git a/.profile.d/completion.bashrc b/.profile.d/completion.bashrc index ad072bf..3c3ec33 100644 --- a/.profile.d/completion.bashrc +++ b/.profile.d/completion.bashrc @@ -1,16 +1,18 @@ -# $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=~/.ssh/hosts +COMPLETION_DIR_TELNET=~/.telnet/hosts +COMPLETION_DIR_RDP=~/.rdp/hosts +COMPLETION_DIR_PING="$COMPLETION_DIR_SSH $COMPLETION_DIR_TELNET $COMPLETION_DIR_RDP" function _generic_completion() { COMPLETION_DIR=${1+"$@"} COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} - HOSTS="$(find $COMPLETION_DIR -type f -perm -100 | sed 's@.*/@@')" + HOSTS="$(find $COMPLETION_DIR -type f -perm -100 2>/dev/null | sed 's@.*/@@')" COMPREPLY=($(compgen -W "$HOSTS" -- "$cur")) return 0 @@ -26,11 +28,21 @@ function _process() { return 0 } +# Host completion for SSH known hosts. +function _known_hosts() { + cur=${COMP_WORDS[COMP_CWORD]} + + HOSTS=$(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts) + + COMPREPLY=($(compgen -W "$HOSTS" -- "$cur")) + return 0 +} + # Process completion for kill, strace etc. function _pid() { cur=${COMP_WORDS[COMP_CWORD]} - PROCESSES="$(find /proc -name '[0-9]*' -maxdepth 1 | sed 's@.*/@@')" + PROCESSES="$(find /proc -name '[0-9]*' -maxdepth 1 2>/dev/null | sed 's@.*/@@')" COMPREPLY=($(compgen -W "$PROCESSES" -- "$cur")) return 0 @@ -70,6 +82,38 @@ function _make() { return 0 } +# Look for modules. +function _modprobe() { + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + + ver=$KERNEL + MODULES="$(find /lib/modules/$ver -name \*.ko | sed -n 's@^.*/\([^/]*\).ko$@\1@p')" + + COMPREPLY=($(compgen -W "$MODULES" -- "$cur")) + return 0 +} + +# Look for loaded modules. +function _rmmod() { + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + + MODULES="$(lsmod | sed '1d;s/ .*$//')" + + COMPREPLY=($(compgen -W "$MODULES" -- "$cur")) + return 0 +} + +# Find tags with GNU GLOBAL. +function _global() { + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + + COMPREPLY=($(global -c "$cur")) + return 0 +} + complete -F _ssh rollout complete -F _ssh ssh complete -F _ssh sshterm @@ -83,3 +127,10 @@ complete -F _make make complete -F _process killall complete -F _pid kill complete -F _pid strace +complete -F _known_hosts kill_known_host +complete -F _known_hosts knh +complete -F _modprobe modprobe +complete -F _rmmod rmmod +complete -F _global global + +fi