a24b7a819156bc61546572b7eef6eedfcc00722f
[shuber-gentoo-overlay.git] / dev-tex / latexmk / files / completion.bash-2
1 #! /bin/bash
2
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)
6 # any later version.
7
8 # bash_completion for latexmk
9 #
10 #
11 # Author: Christoph Junghans
12 # ottxor@gentoo.org
13 #
14 # Revision history:
15 # 0.1 26-05-10 --- initial version
16 # 0.2 15-02-11 --- clean up
17 #
18 # HOWTO:
19 # source this file to enable it
20
21 _latexmk()
22 {
23 local cur output aopts opts prev
24 cur=${COMP_WORDS[COMP_CWORD]}
25 prev=${COMP_WORDS[COMP_CWORD-1]}
26
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 ) )
39 else
40 #filenames *.tex and dirs, rest is done by '-o filenames' below
41 COMPREPLY=( $( eval compgen -f -X "!*.tex" -- ${cur} ) $( compgen -d -- $cur ) )
42 fi
43 }
44
45 complete -F _latexmk -o filenames latexmk