blob: bcfb3191d541a9a597747bc9770e9124eab7174e (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/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.
# Use make if Makefile exists.
# py files: runs via python command
# go files: compiles and runs with "go run"
# config.def.h files: (For suckless utils) recompiles and installs program.
# all others: run `sent` to show a presentation
file=$(readlink -f "$1")
ext="${file##*.}"
dir=${file%/*}
base="${file%.*}"
cd "$dir" || exit
Ifinstalled() {
command -v "$1" >/dev/null || { notify-send "📦 <b>$1</b> must be installed for this function." && exit 1; }
}
pandoccmd() {
Ifinstalled pdflatex && pandoc -V geometry:margin=4cm -f markdown-implicit_figures "$1" -o "${2}.pdf" ||
Ifinstalled groff && pandoc "${1}" -t ms --pdf-engine-opt=-p -o "${2}.pdf"
}
pandocorg() { pandoccmd "$file" "$base"; }
compilec() { [ -f "${dir}/Makefile" ] && make || cc "$file" -o "$base" && "$base"; }
case "${ext}" in
[0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf >"$base".pdf ;;
apl) apl -f "$file" ;;
c) compilec ;;
cob) cobc -x -o "$base" "$file" && "$base" ;;
config.h) make && sudo make install ;;
cpp) g++ "$file" -o "$base" && "$base" ;;
cs) mcs "$file" && mono "$base".exe ;;
docx | *\.doc)
Ifinstalled libreoffice && lowriter --convert-to pdf "$file" && exit
Ifinstalled pandoc && pandoccmd "$file" "$base" && exit
;;
dot | *\.gv) dot -Tsvg "$file" | convert svg:- "$base".eps ;;
h) compilec ;;
html) refreshbrowser ;;
fnl) fennel --compile "$file" >"$base".lua ;;
go) go run "$file" ;;
java) javac "$file" && echo "${base##*/}" | xargs java ;;
js) node "$file" ;;
m) octave "$file" ;;
md)
{ [ -x "$(command -v lowdown)" ] && [ -x "$(command -v groff)" ]; } &&
lowdown --parse-no-intraemph "${file}" -Tms | groff -mpdfmark -ms -kept -T pdf >"${base}.pdf" ||
{ [ -x "$(command -v groffdown)" ] && [ -x "$(command -v groff)" ]; } &&
groffdown -i "${file}" | groff -T pdf >"${base}.pdf" ||
pandoc -t ms --highlight-style="kate" -s -o "${base}.pdf" "${file}"
;;
me) groff -Gktes -b -w w -me -T ps "$file" | ps2pdf - >"$base".pdf ;;
mm) groff -Gktes -b -w w -mm -mpic -T ps "$file" | ps2pdf - >"$base".pdf ;;
mom) pdfroff -pktes -b -wall -mom -mpdfmark "$file" >"$base".pdf ;;
ms | *\.groff) preconv "$file" | groff -Tpdf -ktesp -G -ms >"$base".pdf ;;
org) Ifinstalled pandoc && pandocorg "$file" "$base" && exit ;;
present) groff -p -e -t -mm -mpresent "$file" | presentps -l | ps2pdf - >"$base".pdf ;;
ps) ps2pdf "$file" ;;
py) python "$file" ;;
[rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;;
r) R -f "$file" ;;
rink) rink -f "${file}" ;;
rkt) racket "$file" ;;
rs) cargo build ;;
sass) sassc -a "$file" "$base".css ;;
scad) openscad -o "$base".stl "$file" ;;
sent) setsid -f sent "$file" 2>/dev/null & ;;
tex) latexmk ;;
tcl) tclsh "$file" ;;
vim*) vint "$file" ;;
*) chmod +x "$file" && sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
esac
|