From bf6873cfd7239562fbade86027e55a3a588c2028 Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Mon, 9 Mar 2026 18:05:21 +0100 Subject: [PATCH 1/4] Add: Bash script for in-place converting all found .drawio files to svg's --- scripts/export-drawio.sh | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 scripts/export-drawio.sh diff --git a/scripts/export-drawio.sh b/scripts/export-drawio.sh new file mode 100755 index 0000000..d00d8b8 --- /dev/null +++ b/scripts/export-drawio.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Check for draw.io installation +DRAWIO_PATH="" +check_drawio_installed() { + if command -v drawio &>/dev/null; then + DRAWIO_PATH=$(command -v drawio) + return 0 # drawio via PATH + elif [[ -x "/Applications/draw.io.app/Contents/MacOS/draw.io" ]]; then + DRAWIO_PATH="/Applications/draw.io.app/Contents/MacOS/draw.io" + return 0 # For macOS check at default path + else + return 1 # not found + fi +} + +if ! check_drawio_installed; then + echo "Error: 'drawio' was not found. Make sure, that the draw.io cli is installed." + echo "https://www.diagrams.net/" + exit 1 +else + echo "Draw.io installation found at: $DRAWIO_PATH" +fi + +needs_export() { + local drawio_file="$1" + local svg_file="$2" + + # If no file found, export + if [[ ! -f "$svg_file" ]]; then + return 0 + fi + + # Compare source (draw.io document) and exported file on mtime + if [[ "$drawio_file" -nt "$svg_file" ]]; then + return 0 + else + return 1 + fi +} + +export_file() { + local drawio_file="$1" + local svg_file="${drawio_file%.drawio}.svg" + + if needs_export "$drawio_file" "$svg_file"; then + echo "↻ Exportiere: $drawio_file" + echo "$svg_file" + echo "$drawio_file" + + "$DRAWIO_PATH" --export --format svg --transparent --output "$svg_file" "$drawio_file" + else + echo "✓ Up-to-date: $drawio_file" + fi +} + +main() { + # Source - https://stackoverflow.com/a/9612232 + # Posted by Kevin, modified by community. See post 'Timeline' for change history + # Retrieved 2026-03-09, License - CC BY-SA 4.0 + find . -name '*.drawio' -print0 | + while IFS= read -r -d '' line; do + export_file "$line" + done + + echo "✓ Exported all $file_count files" +} + +# Start script at entry point +main -- 2.52.0 From 8579f15868761ca2160f2a81badcc58c5ef5763d Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Mon, 9 Mar 2026 18:06:19 +0100 Subject: [PATCH 2/4] Add: 'Export drawio to SVG'-task, executable via vscode --- .vscode/tasks.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..101c28b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,11 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Export drawio to SVG", + "type": "shell", + "command": "./scripts/export-drawio.sh", + "problemMatcher": [] + } + ] +} \ No newline at end of file -- 2.52.0 From 76c182313e116ba1756cc494eafecb34e8d8d54f Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Mon, 9 Mar 2026 18:07:49 +0100 Subject: [PATCH 3/4] Fix: Remove leftover variable in echo --- scripts/export-drawio.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/export-drawio.sh b/scripts/export-drawio.sh index d00d8b8..764dfe2 100755 --- a/scripts/export-drawio.sh +++ b/scripts/export-drawio.sh @@ -63,7 +63,7 @@ main() { export_file "$line" done - echo "✓ Exported all $file_count files" + echo "✓ Exported all files" } # Start script at entry point -- 2.52.0 From dc784050bf6451f875e9b1ed9f034f42b139d5a6 Mon Sep 17 00:00:00 2001 From: Lars Simon Winzer Date: Mon, 9 Mar 2026 18:11:18 +0100 Subject: [PATCH 4/4] Style: Add comments and overall cleanup --- scripts/export-drawio.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/export-drawio.sh b/scripts/export-drawio.sh index 764dfe2..f075d01 100755 --- a/scripts/export-drawio.sh +++ b/scripts/export-drawio.sh @@ -5,12 +5,12 @@ DRAWIO_PATH="" check_drawio_installed() { if command -v drawio &>/dev/null; then DRAWIO_PATH=$(command -v drawio) - return 0 # drawio via PATH + return 0 # drawio via PATH elif [[ -x "/Applications/draw.io.app/Contents/MacOS/draw.io" ]]; then DRAWIO_PATH="/Applications/draw.io.app/Contents/MacOS/draw.io" - return 0 # For macOS check at default path + return 0 # For macOS check at default path else - return 1 # not found + return 1 # not found fi } @@ -22,6 +22,7 @@ else echo "Draw.io installation found at: $DRAWIO_PATH" fi +# Compare source (draw.io document) and exported file svg on mtime needs_export() { local drawio_file="$1" local svg_file="$2" @@ -31,7 +32,6 @@ needs_export() { return 0 fi - # Compare source (draw.io document) and exported file on mtime if [[ "$drawio_file" -nt "$svg_file" ]]; then return 0 else @@ -39,12 +39,13 @@ needs_export() { fi } +# If (re-)export is necessary export with drawio cli export_file() { local drawio_file="$1" local svg_file="${drawio_file%.drawio}.svg" if needs_export "$drawio_file" "$svg_file"; then - echo "↻ Exportiere: $drawio_file" + echo "↻ Exporting: $drawio_file" echo "$svg_file" echo "$drawio_file" @@ -54,6 +55,7 @@ export_file() { fi } +# Iterate over all .drawio files main() { # Source - https://stackoverflow.com/a/9612232 # Posted by Kevin, modified by community. See post 'Timeline' for change history -- 2.52.0