X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=.profile.d%2Fcompletion.bashrc;h=cf77c1550425fe0730aa46ed51ce52de195bd631;hb=d4e50810bbf08371d1875a7c71dd98bb84f44c24;hp=633c86c9b774d60b6d83b35783d506f5be54dc7b;hpb=7ff1edff9e3b22a1fd1f7798a634538d7ed94c54;p=profile.git diff --git a/.profile.d/completion.bashrc b/.profile.d/completion.bashrc index 633c86c..cf77c15 100644 --- a/.profile.d/completion.bashrc +++ b/.profile.d/completion.bashrc @@ -1,3 +1,4 @@ +# $Id$ # Helper! export COMPLETION_DIR_SSH=~/.ssh/hosts export COMPLETION_DIR_TELNET=~/.telnet/hosts @@ -9,7 +10,7 @@ function _generic_completion() { 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 @@ -25,11 +26,22 @@ function _process() { return 0 } +# Host completion for SSH known hosts. +function _known_hosts() { + cur=${COMP_WORDS[COMP_CWORD]} + + HOSTS=$(sed 's/[ ].*//;s/,/\ +/' ~/.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 @@ -69,6 +81,29 @@ function _make() { return 0 } +# Look for modules. +function _modprobe() { + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + + ver=$(uname -r) + 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 +} + complete -F _ssh rollout complete -F _ssh ssh complete -F _ssh sshterm @@ -82,3 +117,7 @@ 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