Last active
February 15, 2022 13:34
-
-
Save mulle-nat/aaec794b0ab4d8ffd62a9bb94203c312 to your computer and use it in GitHub Desktop.
Run dockerized mermaid more conveniently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# | |
# shellcheck disable=SC2006 | |
# | |
IFILE="$1" | |
case "${IFILE}" in | |
--help|help|-h|"") | |
cat <<EOF >&2 | |
Usage: | |
mermaid <in-file> [out-filename] [options] | |
The out-filename specifies the output format with its file extension. The | |
default is '.png'. '.pdf' and '.svg' are also available, but '.svg' is | |
apparently broken ATM. In-file can be located anywhere, but the output file | |
will be placed into the same directory as in-file. | |
See: https://github.com/mermaid-js/mermaid-cli for more info. | |
EOF | |
docker run -u "`id -u`" -it minlag/mermaid-cli -h 2>&1 \ | |
| egrep -v '^ -[io]' \ | |
| tail +3 >&2 | |
exit 1 | |
;; | |
esac | |
OFILENAME="$2" | |
IDIR="`dirname -- "${IFILE}" `" | |
case "${IDIR}" in | |
/*) | |
;; | |
.) | |
IDIR="${PWD}" | |
;; | |
*) | |
IDIR="${PWD}/${IDIR}" | |
;; | |
esac | |
IFILENAME="`basename -- "${IFILE}" `" | |
if [ -z "${OFILENAME}" ] | |
then | |
OFILENAME="${IFILENAME%.*}.png" | |
fi | |
docker run -u "`id -u`" \ | |
-it \ | |
-v "${IDIR}":/data \ | |
minlag/mermaid-cli \ | |
"$@" \ | |
-i "/data/${IFILENAME}" \ | |
-o "/data/${OFILENAME}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment