Difference between revisions of "Bash completion"

From Apertium
Jump to navigation Jump to search
(lttoolbox-java)
(Replaced content with 'If you want "intelligent" bash completion on TAB for apertium, lttoolbox, vislcg3, hfst, see https://github.com/unhammer/apertium-completion')
Line 1: Line 1:
  +
If you want "intelligent" bash completion on TAB for apertium, lttoolbox, vislcg3, hfst, see https://github.com/unhammer/apertium-completion
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 [http://limpet.net/mbrubeck/2009/10/30/compleat.html compleat] instead.
 
 
<pre>
 
# -*- 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
 
</pre>
 
 
<pre>
 
# -*- 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
 
</pre>
 

Revision as of 12:54, 11 July 2013

If you want "intelligent" bash completion on TAB for apertium, lttoolbox, vislcg3, hfst, see https://github.com/unhammer/apertium-completion