Difference between revisions of "Bash completion"

From Apertium
Jump to navigation Jump to search
(Created page with 'I sent these in to the bash_completion people but it probably takes a while to get through. I haven't added for all the apertium-* programs. Put the files in /etc/bash_completion…')
 
(lttoolbox-java)
Line 5: Line 5:
 
# ex: ts=8 sw=8 noet filetype=sh
 
# ex: ts=8 sw=8 noet filetype=sh
 
#
 
#
  +
# lttoolbox and lttoolbox-java completion
# lttoolbox completion by Kevin Brubeck Unhammer <unhammer@gmail.com>
+
# by Kevin Brubeck Unhammer <unhammer@gmail.com>
 
# Licence: GNU GPL v2
 
# Licence: GNU GPL v2
   
Line 30: Line 31:
 
}
 
}
 
complete -F _ltproc $filenames lt-proc
 
complete -F _ltproc $filenames lt-proc
  +
complete -F _ltproc $filenames lt-proc-j
   
 
_ltcomp()
 
_ltcomp()
Line 58: Line 60:
 
}
 
}
 
complete -F _ltcomp $filenames lt-comp
 
complete -F _ltcomp $filenames lt-comp
  +
complete -F _ltcomp $filenames lt-comp-j
   
 
_ltexpand()
 
_ltexpand()
Line 80: Line 83:
 
}
 
}
 
complete -F _ltexpand $filenames lt-expand
 
complete -F _ltexpand $filenames lt-expand
  +
complete -F _ltexpand $filenames lt-expand-j
 
</pre>
 
</pre>
   

Revision as of 09:57, 8 December 2009

I sent these in to the bash_completion people but it probably takes a while to get through. I haven't added for all the apertium-* programs. Put the files in /etc/bash_completion.d/ or wherever (see http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_1 ). Probably it'd be simpler to use compleat instead.

# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
#
# lttoolbox and lttoolbox-java completion 
# by Kevin Brubeck Unhammer <unhammer@gmail.com>
# Licence: GNU GPL v2

_ltproc() 
{
	local cur

	COMPREPLY=()
	cur=`_get_cword`

	case "$cur" in
	    -*)
		COMPREPLY=( $( compgen -W '-a -c -g -n -d -p -s -t -z -w \
		-v -h --analysis --case-sensitive --generation --non-marked-gen \
		--debugged-gen --post-generation --sao --transliteration \
		--null-flush --dictionary-case --version --help' -- $cur ) )
		;;
	    *)
		_filedir bin
		;;
	esac
  
	return 0
}
complete -F _ltproc $filenames lt-proc
complete -F _ltproc $filenames lt-proc-j

_ltcomp() 
{
	local cur

	COMPREPLY=()
	cur=`_get_cword`

	case "$cur" in
	    *)
		if [ $COMP_CWORD -eq 1 ]; then
			COMPREPLY=( $( compgen -W 'lr rl' -- $cur ) )
		elif [ $COMP_CWORD -eq 2 ]; then
			_filedir '@(xml|dix)'
		elif [ $COMP_CWORD -eq 3 ]; then
		# of course, we _could_ only remove automorf.bin or
		# autogen.bin depending on lr and rl, or even find
		# nn-nb/nb-nn directions from that... but who calls
		# lt-comp manually anyway?
		    _filedir bin
		fi
		# no reason to offer more arguments than this, right? 
		;;
	esac
  
	return 0
}
complete -F _ltcomp $filenames lt-comp
complete -F _ltcomp $filenames lt-comp-j

_ltexpand() 
{
	local cur

	COMPREPLY=()
	cur=`_get_cword`

	case "$cur" in
	    *)
		if [ $COMP_CWORD -eq 1 ]; then
			_filedir '@(xml|dix)'
		elif [ $COMP_CWORD -eq 2 ]; then
		    _filedir bin
		fi
		# no reason to offer more arguments than this, right? 
		;;
	esac
  
	return 0
}
complete -F _ltexpand $filenames lt-expand
complete -F _ltexpand $filenames lt-expand-j
# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
#
# apertium completion by Kevin Brubeck Unhammer <unhammer@gmail.com>
# Licence: GNU GPL v2

_apertium() 
{
	local cur prev

	COMPREPLY=()
	cur=`_get_cword`
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case "$prev" in
	    -d)
		_filedir -d
		;;
	    -m)
		_filedir tmx
		;;
	    -f)
		COMPREPLY=( $( compgen -W 'txt html rtf odt docx wxml \
		xlsx pptx xpresstag wikimedia' -- $cur ) )
		;;
	    -o)
		COMPREPLY=( $( compgen -W "$(eval apertium -l)" -- $cur ) )
		;;
	    *)
		case "$cur" in
		    -*)
			COMPREPLY=( $( compgen -W '-d -f -a -u -m -o -l' -- $cur ) )
			;;
		    *)
		        local dirs=$(eval apertium -l)
		        local dirpat=$( echo $dirs | sed 's/ /|/g' )
			local langset=0
			# look through previous words and see if we've
			# set the language already
			for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ ))
			do
				if [[ "${COMP_WORDS[i]}" == @($dirpat) ]]; then
					# ignore -o-prefixed language code
					if [[ "${COMP_WORDS[i-1]}" != "-o" ]]; then
						langset=1
					fi
				fi
			done
			if [ $langset -eq 1 ]; then
				_filedir
			else
				COMPREPLY=( $( compgen -W "$dirs" -- $cur ) )
			fi
			;;
			# direction should only happen once!
		esac
	esac
  
	return 0
}
complete -F _apertium $filenames apertium