]> git.lyx.org Git - lyx.git/blob - lib/scripts/bash_completion
Update of the bash completion script
[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 insettext 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         --export|-e)
38                 _filedir '+(pdf[1234]|PDF[1234]|pdf|PDF|ps|PS|xhtml|XHTML)';;
39         -dbg)
40                 # check for multiple debug commands
41                 if [[ $cur == *,* ]]; then #
42                         COMPREPLY=( $( compgen -W '$dbg_cmds' \
43                                                -P ${cur%,*}, -- ${cur##*,} ) )
44                 else
45                         COMPREPLY=( $( compgen -W '$dbg_cmds' -- $cur ) )
46                 fi;;
47         --force-overwrite|-f)
48                 COMPREPLY=( $( compgen -W 'all main none' -- $cur ) );;
49         *)
50           case "$cur" in
51           -*)
52                 # LyX command line options
53                 COMPREPLY=( $( compgen -W '-help -userdir -sysdir \
54                                 -geometry -dbg -x --execute -e --export \
55                                 -i --import -version -batch -E --export-to \
56                                 -f --force-overwrite -n --no-remote \
57                                 -r --remote ' -- $cur ) ) ;;
58           
59           *)
60                 # LyX files
61                 _filedir '@(lyx)' 
62           esac
63         esac
64
65         # turn it off if necessary
66         test $g -eq 0 && shopt -u extglob
67
68 }
69 [ "${have:-}" ] && complete -F _lyx $filenames lyx