cleanup, script now runable anywhere

This commit is contained in:
Luke Smith 2018-07-25 13:45:05 -04:00
parent 5fc6f74598
commit 595ae287e1

View file

@ -1,32 +1,32 @@
#!/bin/bash #!/bin/bash
# This is a compilation handler, so to speak, which I have vim run. # This script will compile or run another finishing operation on a document. I
# have this script run via vim.
# #
# It compiles a document to pdf # tex files: Compiles to pdf, including bibliography if necessary
# # md files: Compiles to pdf via pandoc
# If you put the sequence `xelatex` somewhere in the first 5 lines of a .tex # rmd files: Compiles via R Markdown
# file, it will be compiled with `xelatex` rather than `pdflatex`. # config.h files: (For suckless utils) recompiles and installs program.
# # all others: run `sent` to show a presentation
# If it detects an `addbibresource` line, it will run `biber` and perform
# multiple compiles to get the references correct.
file=$(readlink -f "$1") file=$(readlink -f "$1")
ext="${file##*.}" dir=$(dirname "$file")
base="${file%.*}" base="${file%.*}"
textype() { \ textype() { \
command="pdflatex" command="pdflatex"
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex" ( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
$command "$base" && $command --output-directory="$dir" "$base" &&
grep -i addbibresource "$file" && grep -i addbibresource "$file" &&
biber "$base" && biber --input-directory "$dir" "$base" &&
$command "$base" && $command --output-directory="$dir" "$base" &&
$command "$base" $command --output-directory="$dir" "$base"
} }
case "$ext" in case "$file" in
rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;; *\.rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;;
tex) textype "$file" ;; *\.tex) textype "$file" ;;
md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;; *\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
*config.h) make && sudo make install ;;
*) sent "$file" 2>/dev/null & ;; *) sent "$file" 2>/dev/null & ;;
esac esac