dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles # fast
git clone https://src.adamsgaard.dk/dotfiles.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit 285103aff302ac309b372919b8dfd38479cab360
parent d9739f9c27c45ac9b840bdee983bed9b34a88f3d
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Sun, 14 Feb 2021 00:48:19 +0100

Merge branch 'master' of src.adamsgaard.dk:dotfiles

Diffstat:
M.local/bin/cdoc | 41++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/.local/bin/cdoc b/.local/bin/cdoc @@ -24,32 +24,35 @@ regeximatch() { printf '%s' "$1" | grep -iEq "$2" } -extract_tex_include() { - d="$(grep -v ".*%.*\\${2}" "$1" | - sed -nE "/.*\\${2}\\[*.*\\]*\\{([^}]*)\\}.*/{ s//\\1/;p; }")" - if [ "$2" = "bibliography" ] && [ -n "$d" ]; then - d="${d%.bib}.bib" - fi - if [ -n "$d" ]; then - printf '%s\n' "$d" +extract_tex_includes() { + if ! test -r "$1"; then + return fi + awk ' + function firstval(s) { + if(!match(s, /%.*\{/) && match(s, /\{.*\}/)) + return substr(s, RSTART+1, RLENGTH-2) + } + $0 ~ /\\input\{/ { print firstval($0) } + $0 ~ /\\include\{/ { print firstval($0) } + $0 ~ /\\includegraphics\[*.*\]*\{/ { print firstval($0) } + $0 ~ /\\addbibresource\{/ { print firstval($0) } + $0 ~ /\\bibliography\{/ && $0 !~ /%.*\{/ { + m = firstval($0) + if (m !~ /\.bib$/) + printf("%s.bib", m) + else + print m + } + ' "$1" } find_dependencies() { case "$1" in *.tex) printf '%s\n' "$1" - if grep -q -e '\input{' \ - -e '\include[graphics]' \ - -e '\addbibresource{' \ - -e '\bibliography{' \ - "$1"; then - extract_tex_include "$1" 'input' - extract_tex_include "$1" 'include' - extract_tex_include "$1" 'includegraphics' - extract_tex_include "$1" 'addbibresource' - extract_tex_include "$1" 'bibliography' - fi;; + extract_tex_includes "$1" + ;; *) die "cannot find dependencies in unknown file type $1";; esac