# --------------------------------------------------------------------------- # custom tab completion .... # # cheatsheet... # COMP_LINE # COMP_POINT # COMP_WORDS # COMP_CWORD # $1 - command completed # $2 - word being completed # $3 - word before the one being completed # COMPREPLY - result # if bk is installed then build completion for bk commands if ( bk version > /dev/null 2>&1 ) ; then BKCMDS="`bk help topics |grep '^ bk' |cut -d ' ' -f 4 |xargs echo`" complete -A file -W "$BKCMDS" bk fi # create a function that allows for man page completion complete -o default -F _complete_man_pages man _complete_man_pages() { if test -z "$2" ; then return fi if test -z "$3" || test "$1" = "$3" ; then COMPREPLY=( $( apropos "$2" | cut -d ' ' -f 1 | grep "^$2" ) ) else COMPREPLY=( $( apropos "$3" "$2" | cut -d ' ' -f 1 | grep "^$2" ) ) fi } # create a function that handles tab completion on ssh complete -o default -F _complete_ssh_hosts ssh complete -o default -F _complete_ssh_hosts scp _complete_ssh_hosts() { if test -z "$2" ; then return fi KNOWN_HOSTS=".ssh/known_hosts" KNOWN_HOSTS2=".ssh/known_hosts2" if ! test -r "$KNOWN_HOSTS" -o -r "$KNOWN_HOSTS2" ; then return fi PREFIX="" SSHHOST=$( echo "$2" | cut -d '@' -f 2- ) if test "$SSHHOST" != "$2" ; then PREFIX=$( echo "$2" | cut -d '@' -f 1 )"@" fi COMPREPLY=( $( cat "$KNOWN_HOSTS" "$KNOWN_HOSTS2" | cut -d ' ' -f 1 \ | tr ',' '\n' | grep "^$SSHHOST" | sed -e "s/^/$PREFIX/;" ) ) } # create a function that handles tab completion on make complete -o default -F _complete_make_targets make _complete_make_targets() { if test -z "$2" ; then return fi DIR="." if (echo $COMP_LINE | grep 'make .*-C *[^ ]\+ ' > /dev/null) ; then DIR=$(echo $COMP_LINE | sed -e 's/^.*-C *//;' | cut -d ' ' -f 1) fi FILE="" if (echo $COMP_LINE | grep 'make .*-f *[^ ]\+ ' > /dev/null) ; then FILE=$(echo $COMP_LINE | sed -e 's/^.*-f *//;' | cut -d ' ' -f 1) fi FILE=$(for try in "$FILE" "GNUmakefile" "makefile" "Makefile" ; do if test -f "$DIR/$try" -a -r "$DIR/$try" ; then echo "$DIR/$try" fi done | head -n1) if ! test -f "$FILE" -a -r "$FILE" ; then return fi COMPREPLY=( $( cat "$FILE" | grep -i "^$2[a-z0-9_]*:" | cut -d : -f 1 ) ) } fi # end of interactive stuff # EOF