X-Git-Url: https://git.sthu.org/?p=shuber-gentoo-overlay.git;a=blobdiff_plain;f=dev-tex%2Flatexmk%2Ffiles%2Fcompletion.bash-2;fp=dev-tex%2Flatexmk%2Ffiles%2Fcompletion.bash-2;h=a24b7a819156bc61546572b7eef6eedfcc00722f;hp=0000000000000000000000000000000000000000;hb=ab807b56be9c705bd88131b3333daffa4c3a388e;hpb=66f3ed9037fbdf5c47078626ec03142f1930ccdc diff --git a/dev-tex/latexmk/files/completion.bash-2 b/dev-tex/latexmk/files/completion.bash-2 new file mode 100644 index 0000000..a24b7a8 --- /dev/null +++ b/dev-tex/latexmk/files/completion.bash-2 @@ -0,0 +1,45 @@ +#! /bin/bash + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# bash_completion for latexmk +# +# +# Author: Christoph Junghans +# ottxor@gentoo.org +# +# Revision history: +# 0.1 26-05-10 --- initial version +# 0.2 15-02-11 --- clean up +# +# HOWTO: +# source this file to enable it + +_latexmk() +{ + local cur output aopts opts prev + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + output=$( $1 -help 2> /dev/null) + #options with args ,pattern: ^ (-XXX) .*$ + aopts=" $( echo " $output" | sed -n 's/^[[:space:]]\+\(-[^[:space:]]\+\)[[:space:]]\+<[^>]\+>.*$/\1/p' | sort -u | tr '\n' ' ')" + #if previous option in in $aopts + if [[ -n "$prev" ]] && [[ -z "${aopts//* $prev *}" ]]; then + #argument of $prev ,pattern: ^ -XXX ().*$ + opts=$(echo "$output" | sed -n "s/^[[:space:]]\+$prev[[:space:]]\+\(<[^>]\+>\).*\$/\1/p") + COMPREPLY=( $( compgen -W '$opts' -- $cur ) ) + elif [[ "$cur" == -* ]]; then + #all options, pattern: ^ (-XXX).*$ + opts=$( echo "$output" | sed -n 's/^[[:space:]]\+\(-[^[:space:]]\+\).*$/\1/p'| sort -u ) + COMPREPLY=( $( compgen -W '$opts' -- $cur ) ) + else + #filenames *.tex and dirs, rest is done by '-o filenames' below + COMPREPLY=( $( eval compgen -f -X "!*.tex" -- ${cur} ) $( compgen -d -- $cur ) ) + fi +} + +complete -F _latexmk -o filenames latexmk