Add function to check for installed program

Notifies if program is missing.
This commit is contained in:
Marty Oehme 2019-12-04 16:57:15 +01:00
parent eb88925501
commit d4ae593f50
2 changed files with 14 additions and 3 deletions

View file

@ -15,8 +15,11 @@ base="${file%.*}"
cd "$dir" || exit
textype() {
if (sed 5q "$file" | grep -i -q 'xelatex') && ifinstalled xelatex; then
command="xelatex"
elif ifinstalled pdflatex; then
command="pdflatex"
(sed 5q "$file" | grep -i -q 'xelatex') && command="xelatex"
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" ;;

4
.local/bin/ifinstalled Executable file
View file

@ -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 ;}