From d4ae593f50d2fcb2614db40d050b29c8c0037b83 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 4 Dec 2019 16:57:15 +0100 Subject: [PATCH] Add function to check for installed program Notifies if program is missing. --- .local/bin/compile | 13 ++++++++++--- .local/bin/ifinstalled | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100755 .local/bin/ifinstalled diff --git a/.local/bin/compile b/.local/bin/compile index 9196d46..375adea 100755 --- a/.local/bin/compile +++ b/.local/bin/compile @@ -15,8 +15,11 @@ base="${file%.*}" cd "$dir" || exit textype() { - command="pdflatex" - (sed 5q "$file" | grep -i -q 'xelatex') && command="xelatex" + if (sed 5q "$file" | grep -i -q 'xelatex') && ifinstalled xelatex; then + command="xelatex" + elif ifinstalled pdflatex; then + command="pdflatex" + fi $command --output-directory="$dir" "$base" && grep -i addbibresource "$file" >/dev/null && biber --input-directory "$dir" "$base" && @@ -24,11 +27,15 @@ textype() { $command --output-directory="$dir" "$base" } +sendtoRmd() { + ifinstalled R && echo "require(rmarkdown); render('$1')" | R -q --vanilla +} + case "$file" in *\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf >"$base".pdf ;; *\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf >"$base".pdf ;; *\.[0-9]) refer -PS -e "$file" | groff -mandoc -T pdf >"$base".pdf ;; -*\.[Rr]md | *\.md | *\.mkd | *\.markdown) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;; +*\.[Rr]md | *\.md | *\.mkd | *\.markdown) sendtoRmd "$file" ;; *\.tex) textype "$file" ;; *config.h) sudo make install ;; *\.c) cc "$file" -o "$base" && "$base" ;; diff --git a/.local/bin/ifinstalled b/.local/bin/ifinstalled new file mode 100755 index 0000000..26c3b51 --- /dev/null +++ b/.local/bin/ifinstalled @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +# If $1 command is not available, error code and notify. + +command -v "$1" >/dev/null || { notify-send "📦 $1" "must be installed for this function." && exit 1 ;}