]> git.lyx.org Git - lyx.git/blob - lib/scripts/bash_completion
* bash_completion from Hernan Solari
[lyx.git] / lib / scripts / bash_completion
1 # lyx(1) completion 
2 # Copyleft 2010 Cengiz Gunay <cengique@users.sf.net>
3
4 _have lyx &&
5 _lyx()
6 {
7         local cur g last
8
9         # turn on extglob       
10         shopt -q extglob && g=1
11         test $g -eq 0 && shopt -s extglob
12
13         COMPREPLY=()
14         cur=${COMP_WORDS[COMP_CWORD]}
15
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" )
22
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.
27
28         #echo "cmds: '$dbg_cmds'"
29
30         if [[ $COMP_CWORD > 1 ]]; then
31                 last=${COMP_WORDS[$(($COMP_CWORD - 1))]}
32         else
33                 last=''
34         fi
35
36         case "$last" in
37                 # check for export fmt. Short list presented
38         --export|-e|-E|--export-to)
39                 COMPREPLY=( $(compgen -W 'latex pdflatex luatex xetex xhtml' -- $cur) );;
40         --import|-i)
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) );;
45         -dbg)
46                 # check for multiple debug commands
47                 if [[ $cur == *,* ]]; then #
48                         COMPREPLY=( $( compgen -W '$dbg_cmds' \
49                                                -P ${cur%,*}, -- ${cur##*,} ) )
50                 else
51                         COMPREPLY=( $( compgen -W '$dbg_cmds' -- $cur ) )
52                 fi;;
53         --force-overwrite|-f)
54                 COMPREPLY=( $( compgen -W 'all main none' -- $cur ) );;
55
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))]}
60                 else
61                         prev=''
62                 fi
63                 if (test $prev=="-i")|(test $prev=="-E"); then
64                         case $last in
65                                 text)
66                                         _filedir '@(txt)' ;;
67                                 latex|luatex|xetex)
68                                         _filedir '@(tex)' ;;
69                                 xhtml)
70                                         _filedir '@(xhtml)' ;;
71                         esac
72                 fi;;
73         pdflatex)
74                 # we need to know if previous token was -E
75                 if [[ $COMP_CWORD > 2 ]]; then
76                         prev=${COMP_WORDS[$(($COMP_CWORD - 2))]}
77                 else
78                         prev=''
79                 fi
80                 if test $prev == "-E"; then
81                                         _filedir '@(pdf)' 
82                 fi;;
83         *)
84           case "$cur" in
85           -*)
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 ) ) ;;
92           
93           *)
94                 # LyX files
95                 _filedir '@(lyx)' 
96           esac
97         esac
98
99         # turn it off if necessary
100         test $g -eq 0 && shopt -u extglob
101
102 } && complete -F _lyx $filenames lyx
103