Tooltip 14: Handy Bash/Zsh function to generate PlantUML diagrams

In this short clip, we’ll look at creating a simple Bash/Zsh function wrapping PlantUML so that we can use it from anywhere.


Download it where you can easily refer to it.

nmn$ ls -l $TOOLS_HOME/plantuml/plantuml.jar
-rw-r--r--@ 1 nmn  staff  7985304  9 Nov  2019 /Users/nmn/tools/plantuml/plantuml.jar

Next, we’ll create a function and put that in bash/zsh profile so that it can be loaded automatically on each session.

function plantuml() {
    cat $NAME | java -DPLANTUML_LIMIT_SIZE=8192 -jar $TOOLS_HOME/plantuml/plantuml.jar -pipe > $NAME.png
    open $NAME.png

Then you can call this function with the file name.

plantuml sample.png

Once you have it setup, this will convert the provided plantuml file to a PNG image and open it up using the default PNG viewer.

Here it is in action


👉 Tested on MacOS but should work on earlier versions and all flavours of Linux