This repository was archived by the owner on Nov 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot-render
More file actions
executable file
·73 lines (58 loc) · 1.45 KB
/
dot-render
File metadata and controls
executable file
·73 lines (58 loc) · 1.45 KB
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
#!/usr/bin/env bash
#
# Render & view a DOT file.
#
fmt="png"
dot_renderer="dot"
_BASHPLATE_DIR="$HOME/.local/share/bashplate"
source "$_BASHPLATE_DIR/bashplate.sh"
_usage="\
Usage: $_FILENAME [options] FILE
Render a DOT file to a PNG & optionally view.
Options:
-f, --output <file> write to <file>
-o, --open open the rendered file
-v, --verbose be verbose
-h, --help display this help text and exit
If --open is specified without --output <file>, the image is rendered to a
temporary file.\
"
while getopts_long :vhof: opt \
verbose 0 \
help 0 \
open 0 \
output 1 \
"" "$@"
do
case "$opt" in
v|verbose) _VERBOSE=$(($_VERBOSE + 1)) ;;
h|help) _print_usage 0 ;;
:) _err "$OPTLERR"; _print_usage 1 ;;
o|open) _open_after=true ;;
f|output) outfile="$OPTLARG" ;;
esac
done
shift $((OPTLIND-1))
if [[ $# != 1 ]]; then
_err "expected exactly 1 argument" 2
fi
infile="$1"
if [[ ! -f "$infile" ]]; then
_err "not a file: $infile" 3
fi
if [[ ! "$outfile" ]]; then
if [[ $_open_after ]]; then
# no output file & opening: use temporary file
outfile="$(mktemp --suffix=".$fmt")"
else
# render next to file
outfile="${infile%.*}.$fmt"
fi
fi
$dot_renderer "$infile" -T "$fmt" -o "$outfile"
if [[ $? != 0 ]]; then
_err "dot failed (see above)" 4
fi
if [[ $_open_after ]]; then
$FILE_OPENER "$outfile"
fi