Skip to content

Instantly share code, notes, and snippets.

@mulle-nat
Last active February 15, 2022 13:34
Show Gist options
  • Save mulle-nat/aaec794b0ab4d8ffd62a9bb94203c312 to your computer and use it in GitHub Desktop.
Save mulle-nat/aaec794b0ab4d8ffd62a9bb94203c312 to your computer and use it in GitHub Desktop.
Run dockerized mermaid more conveniently
#! /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