Skip to content

Instantly share code, notes, and snippets.

@nickodell
Created May 16, 2025 22:08
Show Gist options
  • Select an option

  • Save nickodell/1834b190218c0fecb6733680f3407cb5 to your computer and use it in GitHub Desktop.

Select an option

Save nickodell/1834b190218c0fecb6733680f3407cb5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Sublime Text Wrapper Script
# Intended to launch Windows Sublime Text from WSL Sublime Merge
# Usage:
# Open sublime text
# sublime_text_translate_path
# Open specific file
# sublime_text_translate_path myfile
# Open specific file at specifc position
# sublime_text_translate_path myfile:40
set -euo pipefail
SUBL="/mnt/c/Program Files/Sublime Text/subl.exe"
if [ "$#" -ne 1 ]; then
# Execute unchanged
exec "$SUBL" "$@"
fi
# Have one argument
path="$1"
# Is this argument with : in it?
if [[ ! "$path" =~ ":" ]]; then
# Translate to WSL
path="$(wslpath -w "$path")"
exec "$SUBL" "$path"
fi
# Split path:row:col, and translate path, and leave rest of argument unchanged
first_path="$(cut -d: -f1 <<< "$path")"
rest_of_path="$(cut -d: -f2- <<< "$path")"
first_path="$(wslpath -w "$first_path")"
exec "$SUBL" "$first_path:$rest_of_path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment