Last active
June 20, 2021 16:22
-
-
Save miloslavnosek/27c4860167341e87941cb0b3bf5c0ef1 to your computer and use it in GitHub Desktop.
Replaces classic string with Windows path to WSL path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule WinToWslPathReplacer.PathHandler do | |
@moduledoc """ | |
Takes care of converting Windows to WSL path string | |
""" | |
def convert(path) do | |
path | |
|> String.replace("C:", "/mnt/c") | |
|> String.replace("D:", "/mnt/d") | |
|> String.replace("\\", "/") | |
|> String.replace("\n", "") | |
end | |
end | |
defmodule WinToWslPathReplacer.ConsoleInquirer do | |
@moduledoc """ | |
Takes care of console input and output | |
""" | |
def get_path() do | |
IO.gets("Please enter Windows path to convert <: ") | |
|> WinToWslPathReplacer.PathHandler.convert() | |
|> WinToWslPathReplacer.ConsoleInquirer.return_path() | |
end | |
def return_path(path) do | |
IO.puts("WSL path (also auto-copied to clipboard) >:") | |
IO.puts("\"#{path}\"") | |
:os.cmd(:"echo -n \"#{path}\" | clip.exe") | |
end | |
end | |
WinToWslPathReplacer.ConsoleInquirer.get_path() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment