3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
8 # bash_completion for latexmk
11 # Author: Christoph Junghans
15 # 0.1 26-05-10 --- initial version
16 # 0.2 15-02-11 --- clean up
19 # source this file to enable it
23 local cur output aopts opts prev
24 cur
=${COMP_WORDS[COMP_CWORD]}
25 prev
=${COMP_WORDS[COMP_CWORD-1]}
27 output
=$
( $1 -help 2> /dev
/null
)
28 #options with args ,pattern: ^ (-XXX) <YYYY>.*$
29 aopts
=" $( echo " $output" | sed -n 's/^[[:space:]]\+\(-[^[:space:]]\+\)[[:space:]]\+<[^>]\+>.*$/\1/p' | sort -u | tr '\n' ' ')"
30 #if previous option in in $aopts
31 if [[ -n "$prev" ]] && [[ -z "${aopts//* $prev *}" ]]; then
32 #argument of $prev ,pattern: ^ -XXX (<YYYY>).*$
33 opts
=$
(echo "$output" |
sed -n "s/^[[:space:]]\+$prev[[:space:]]\+\(<[^>]\+>\).*\$/\1/p")
34 COMPREPLY
=( $
( compgen
-W '$opts' -- $cur ) )
35 elif [[ "$cur" == -* ]]; then
36 #all options, pattern: ^ (-XXX).*$
37 opts
=$
( echo "$output" |
sed -n 's/^[[:space:]]\+\(-[^[:space:]]\+\).*$/\1/p'|
sort -u )
38 COMPREPLY
=( $
( compgen
-W '$opts' -- $cur ) )
40 #filenames *.tex and dirs, rest is done by '-o filenames' below
41 COMPREPLY
=( $
( eval compgen
-f -X "!*.tex" -- ${cur} ) $
( compgen
-d -- $cur ) )
45 complete
-F _latexmk
-o filenames latexmk