X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Fbash_completion;h=af50b3655b310051e082fe63ddbd1f7d61302cf6;hb=11cb8997fcfe72a4d48a7ab0fc4cc6d81336d2eb;hp=35981ac3f6cae4e8f891b5fc465e549fbe01274d;hpb=f151e820ce60aea405d88f8885addeca7aae7764;p=lyx.git diff --git a/lib/scripts/bash_completion b/lib/scripts/bash_completion index 35981ac3f6..af50b3655b 100644 --- a/lib/scripts/bash_completion +++ b/lib/scripts/bash_completion @@ -1,22 +1,69 @@ # lyx(1) completion -# Modified inkscape template of allali@univ-mlv.fr -# by cengique@users.sf.net +# Copyleft 2010 Cengiz Gunay have lyx && _lyx() { - local cur + local cur g last + + # turn on extglob + shopt -q extglob && g=1 + test $g -eq 0 && shopt -s extglob COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} - if [[ "$cur" == -* ]]; then + local dbg_cmds=( "none info init key gui \ + parser lyxrc kbmap latex mathed font tclass \ + lyxvc lyxserver action lyxlex depend insets \ + files workarea insettext graphics changes \ + external painting debug any undo scrolling \ + macros rtl locale selection find" ) + + # The below code would get rid of the hardcoding, but could be fragile: + # local dbg_cmds=$( lyx -dbg | awk '{print $2}' | tail -n +2 ) + # If it is ever used, please put a comment in the code for -dbg output + # about breaking auto completion if the format is changed. + + #echo "cmds: '$dbg_cmds'" + + if [[ $COMP_CWORD > 1 ]]; then + last=${COMP_WORDS[$(($COMP_CWORD - 1))]} + else + last='' + fi + + case "$last" in + --export|-e) + _filedir '+(pdf[1234]|PDF[1234]|pdf|PDF|ps|PS|xhtml|XHTML)';; + -dbg) + # check for multiple debug commands + if [[ $cur == *,* ]]; then # + COMPREPLY=( $( compgen -W '$dbg_cmds' \ + -P ${cur%,*}, -- ${cur##*,} ) ) + else + COMPREPLY=( $( compgen -W '$dbg_cmds' -- $cur ) ) + fi;; + --force-overwrite|-f) + COMPREPLY=( $( compgen -W 'all main none' -- $cur ) );; + *) + case "$cur" in + -*) + # LyX command line options COMPREPLY=( $( compgen -W '-help -userdir -sysdir \ -geometry -dbg -x --execute -e --export \ - -i --import -version' -- $cur ) ) - else - _filedir '@(lyx)' - fi + -i --import -version -batch -E --export-to \ + -f --force-overwrite -n --no-remote \ + -r --remote ' -- $cur ) ) ;; + + *) + # LyX files + _filedir '@(lyx)' + esac + esac + + # turn it off if necessary + test $g -eq 0 && shopt -u extglob } [ "${have:-}" ] && complete -F _lyx $filenames lyx