[Surfraw-devel] Re: Bug#240629: surfraw: bash-completion

Justin B Rye jbr@edlug.org.uk
Tue, 30 Mar 2004 16:47:20 +0100


--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Moritz Muehlenhoff wrote:         
> Justin B Rye wrote:         
>> I hasten to add that it's a distinctly simplistic bash-completer
>> compared to most of the existing Debian-packaged ones; but It Works
>> For Me.  A properly written version might also cover the sub-options
>> such as --lucky, which would require hard-coding the elvi-list.
>
> It would also be very useful to have tab-completion for the debbugs,
> debpackages and debcontents elvis.

I suppose I wouldn't have to hard-code the whole list to do that...
okay, here's a slightly silly Mark 2 version.  I've added the other
software-related sites to the packagename-completion set on the
grounds that it's better than the fallback of using dictionary
words.

If you want easier completion on the common options, why not give
them each a unique initial letter?
	-b(rowser),
	-c(ensored, ie non-p0rn),
	-e(scaped),
	-g(raphical),
	-h(elp),
	-l(ist, ie elvi),
	-n(oisy, ie non-silent),
	-p(0rn),
	-q(uoted),
	-r(aw, ie non-escaped)
	-s(ilent, ie quiet),
	-t(ext),
	-v(ersion)
-- 
JBR
Ankh kak! (Ancient Egyptian blessing)

--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=surfraw

# -*- sh -*- bash programmable completion for Surfraw
_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=no -quiet=yes -text -version'
	local elvi="$(cut -f1 /etc/surfraw.bookmarks ~/.surfraw.bookmarks 2>&-
			ls /usr/lib/surfraw 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)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
}
complete -F _surfraw surfraw sr

--2fHTh5uZTiUOsy+g--