#!/usr/bin/env bash
help_text="
NAME
drawio - Launch Draw.io application with specified file or URL
USAGE
drawio <path/url>
OPTIONS
-h, --help
Show help text.
DESCRIPTION
Launches the Windows drawio application with the specified file.
Automatically converts WSL paths to Windows paths when needed.
EXAMPLES
AUTHOR
mjnurse.github.io - 2025
"
help_line="Launch Draw.io application with specified file or URL"
web_desc_line="Launch Draw.io application with specified file or URL"
# Function to display help
show_help() {
echo "$help_text"
exit 0
}
# Function to display error and exit
error_exit() {
echo "Error: $1" >&2
echo "Try '${0##*/} --help' for more information." >&2
exit 1
}
# Check for help flag
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
show_help
fi
target="$1"
if [[ "$target" != "" ]]; then
# Convert to Windows path
if ! file_path=$(wslpath -w "$target" 2>/dev/null); then
error_exit "Failed to convert path '$target' to Windows format."
fi
# Verify the file exists (for local files)
if [[ ! -e "$target" ]]; then
error_exit "File '$target' does not exist."
fi
fi
# Launch Application
echo cmd.exe /c start "" "C:\Program Files\WindowsApps\draw.io.draw.ioDiagrams_28.2.7.0_x64__1zh33159kp73c\app\draw.io.exe $file_path"
if ! cmd.exe /c start "" "$file_path"; then
error_exit "Failed to launch drawio"
fi
exit 0