forked from Gavinok/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor
executable file
·64 lines (57 loc) · 1.81 KB
/
executor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
# This script will compile or run another finishing operation on a document. I
# have this script run via vim.
#
# tex files: Compiles to pdf, including bibliography if necessary
# md files: Compiles to pdf via pandoc
# rmd files: Compiles via R Markdown
# c files: Compiles via whatever compiler is set to cc. Usually gcc.
# py files: runs via python command
# go files: compiles and runs with "go run"
# config.h files: (For suckless utils) recompiles and installs program.
# all others: run `sent` to show a presentation
file=$(readlink -f "$1")
dir=$(dirname "$file")
base="${file%.*}"
shebang=$(sed -n 1p "$file")
cd "$dir" || exit
textype() { \
command="pdflatex"
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
$command --output-directory="$dir" "$base" &&
grep -i addbibresource "$file" >/dev/null &&
biber --input-directory "$dir" "$base" &&
$command --output-directory="$dir" "$base" &&
$command --output-directory="$dir" "$base"
}
shebangtest() {
case "$shebang" in
\#\!*) "$file" ;;
*) sent "$file" 2>/dev/null & ;;
esac
}
compilec(){
if find $dir -name Makefile; then
make
if $dir -name a.out;then
./a.out;;
fi
exit
fi
cc "$file" -o "$base" && "$base"
}
# If there is a global $REFBIB variable/file for `refer`, use it.
[ -f "$REFBIB" ] && groffbib="-p $REFBIB"
case "$file" in
*\.ms) refer -PS -e $groffbib "$file" | groff -kejpt -ms -T pdf > "$base".pdf ;;
*\.groff) refer -PS -e $groffbib "$file" | groff -kejpt -ms -T pdf > "$base".pdf ;;
*\.rmd) echo "require(rmarkdown); render('$file')" | R --vanilla && mv "$base".pdf "$dir"/pdfs;;
*\.tex) textype "$file" ;;
*\.md) md2pdf "$file" ;;
*config.h) make && sudo make install ;;
*\.c) compilec ;;
*\.py) python "$file" ;;
*\.sh) chmod +x "$file"; shebangtest;;
*\.go) go run "$file" ;;
*) shebangtest ;;
esac