2 # Copyleft 2010 Cengiz Gunay <cengique@users.sf.net>
10 shopt -q extglob && g=1
11 test $g -eq 0 && shopt -s extglob
14 cur=${COMP_WORDS[COMP_CWORD]}
16 local dbg_cmds=( "none info init key gui \
17 parser lyxrc kbmap latex mathed font tclass \
18 lyxvc lyxserver action lyxlex depend insets \
19 files workarea clipboard graphics changes \
20 external painting debug any undo scrolling \
21 macros rtl locale selection find" )
23 # The below code would get rid of the hardcoding, but could be fragile:
24 # local dbg_cmds=$( lyx -dbg | awk '{print $2}' | tail -n +2 )
25 # If it is ever used, please put a comment in the code for -dbg output
26 # about breaking auto completion if the format is changed.
28 #echo "cmds: '$dbg_cmds'"
30 if [[ $COMP_CWORD > 1 ]]; then
31 last=${COMP_WORDS[$(($COMP_CWORD - 1))]}
37 # check for export fmt. Short list presented
38 --export|-e|-E|--export-to)
39 COMPREPLY=( $(compgen -W 'latex pdflatex luatex xetex xhtml' -- $cur) );;
41 # check for import format. Short list presented
42 # (-i | --import) requireas a second input _filedir
43 # must point to *tex | *text | *xhtml depending on choice
44 COMPREPLY=( $(compgen -W 'latex text luatex xetex xhtml' -- $cur) );;
46 # check for multiple debug commands
47 if [[ $cur == *,* ]]; then #
48 COMPREPLY=( $( compgen -W '$dbg_cmds' \
49 -P ${cur%,*}, -- ${cur##*,} ) )
51 COMPREPLY=( $( compgen -W '$dbg_cmds' -- $cur ) )
54 COMPREPLY=( $( compgen -W 'all main none' -- $cur ) );;
56 latex|xetex|luatex|text|xhtml)
57 # we need to know if previous token was -i or -E
58 if [[ $COMP_CWORD > 2 ]]; then
59 prev=${COMP_WORDS[$(($COMP_CWORD - 2))]}
63 if (test $prev=="-i")|(test $prev=="-E"); then
70 _filedir '@(xhtml)' ;;
74 # we need to know if previous token was -E
75 if [[ $COMP_CWORD > 2 ]]; then
76 prev=${COMP_WORDS[$(($COMP_CWORD - 2))]}
80 if test $prev == "-E"; then
86 # LyX command line options
87 COMPREPLY=( $( compgen -W '-help -userdir -sysdir \
88 -geometry -dbg -x --execute -e --export \
89 -i --import -version -batch -E --export-to \
90 -f --force-overwrite -n --no-remote \
91 -r --remote ' -- $cur ) ) ;;
99 # turn it off if necessary
100 test $g -eq 0 && shopt -u extglob
102 } && complete -F _lyx $filenames lyx