Skip to content

Instantly share code, notes, and snippets.

@Karlheinzniebuhr
Last active March 31, 2022 05:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Karlheinzniebuhr/0e996d986ae99f7feb13f7af5b9eb3af to your computer and use it in GitHub Desktop.
Save Karlheinzniebuhr/0e996d986ae99f7feb13f7af5b9eb3af to your computer and use it in GitHub Desktop.
Convert Windows Path to Windows Subsystem for Linux Path with AutoHotKey
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^+F1:: ; Ctrl+Shift+F1 (/)
;Empty the Clipboard.
Clipboard =
;Copy the select text to the Clipboard.
SendInput, ^c
;Wait for the Clipboard to fill.
ClipWait
;Perform the RegEx find and replace operation,
;where the needle is what we want to replace.
haystack := Clipboard
needle := "\\"
replacement := "/"
result1 := RegExReplace(haystack, needle, replacement)
needle := "C:/"
replacement := "/mnt/c/"
result2 := RegExReplace(result1, needle, replacement)
;Empty the Clipboard
Clipboard =
;Copy the result to the Clipboard.
Clipboard := result2
;##works until here##
;Wait for the Clipboard to fill.
ClipWait
;-- Optional: --
;Send (paste) the contents of the new Clipboard.
SendInput, %Clipboard%
;Done!
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment