Skip to content

Instantly share code, notes, and snippets.

@roryrjb
Last active January 22, 2023 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roryrjb/3686848f7a612c71e4c3f4fa6f60c39c to your computer and use it in GitHub Desktop.
Save roryrjb/3686848f7a612c71e4c3f4fa6f60c39c to your computer and use it in GitHub Desktop.
Sublime Text wrapper for use within WSL1
#!/usr/bin/env python3
import sys
import subprocess
import os
filename = os.path.abspath(sys.argv[1])
if filename.startswith('/mnt'):
# /mnt/c/a/b/c.txt -> c:\a\b\c.txt
parts = filename.split('/')
parts[2] += ':'
path = '\\'.join(parts[2:])
else:
# /a/b/c.txt -> \\wsl.localhost\Ubuntu\a\b\c.txt
path = '\\\\wsl.localhost\\Ubuntu\\' + filename.replace('/', '\\')
subprocess.run(['subl.exe', '-w', path])
@roryrjb
Copy link
Author

roryrjb commented Jan 22, 2023

  1. Create this file as subl (changing any hardcoded assumptions I have made) and make executable, then put it in your $PATH
  2. Ensure the original subl.exe is in your $PATH (e.g. PATH=/mnt/c/Program Files/Sublime Text:$PATH)
  3. make this subl your $EDITOR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment