File: surfraw-bash-completion

package info (click to toggle)
surfraw 2.1.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 780 kB
  • ctags: 139
  • sloc: sh: 7,085; perl: 355; makefile: 155
file content (27 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download
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
# -*- sh -*- bash programmable completion for Surfraw, v2.2
_surfraw() 
{       COMPREPLY=()
	local cur=${COMP_WORDS[COMP_CWORD]}
	local prev=${COMP_WORDS[COMP_CWORD-1]}
	local opts='-browser -elvi -escape-url-args -graphical \
		-help -p0rn -q -quote -quiet -text -version'
	local elvi="$(cut -f1 /etc/surfraw.bookmarks ~/.surfraw.bookmarks 2>&-
			cd /usr/lib/surfraw && 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 g<tab>" for google
	elif    [[ $prev == @(alioth|deb@(bug|content|package|pt)s|freshmeat|sourceforge) ]]
	then    COMPREPLY=( $(apt-cache --generate pkgnames $cur) )
		# "sr debbugs 4<tab>" to check 44bsd-rdist bugs...
	elif    test -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