1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
# -*- sh -*- bash programmable completion for Surfraw, v2.2
# This is for people who wish to use surfraw completion, without
# installing the bash-completion package which sets this explicitly.
shopt -s extglob
_surfraw()
{ COMPREPLY=()
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
local opts='-browser -elvi -escape-url-args -graphical \
-help -q -quote -text -version'
local elvi="$(cut -f1 @sysconfdir@/surfraw.bookmarks ~/.surfraw.bookmarks 2>&-
cd @ELVIDIR@ && echo * 2>&-
[ -d ~/.surfraw.d ] && cd ~/.surfraw.d && echo * 2>&-)"
if [[ $cur == -* ]]
then COMPREPLY=( $( compgen -W "$opts" -- $cur ) )
# I can't see a way to get the =yes/=no parts to work...
elif [[ $COMP_CWORD -eq 1 ]]
then COMPREPLY=( $( compgen -W "$elvi" -- $cur ) )
# "sr go<tab>" for google
elif [[ $prev == @(alioth|deb@(bugs|contents|packages|pts|sec)|freshmeat|fsfdir|sourceforge) ]]
then COMPREPLY=( $(apt-cache --generate pkgnames $cur) )
# "sr debbugs 4<tab>" to check 44bsd-rdist bugs...
elif [[ -x /usr/bin/look ]] # in bsdmainutils, "important"
then COMPREPLY=( $(/usr/bin/look ${cur:-''}) )
# "sr l<tab> vy<tab>" to find the German for "vying"
else COMPREPLY=( $( compgen -o default -- $cur) ) # copout
fi
return 0
}
# test first in case removed-but-unpurged
type -p surfraw >/dev/null 2>&1 && complete -F _surfraw surfraw sr
|