Skip to content

Instantly share code, notes, and snippets.

@miloslavnosek
Last active June 20, 2021 16:22
Show Gist options
  • Save miloslavnosek/27c4860167341e87941cb0b3bf5c0ef1 to your computer and use it in GitHub Desktop.
Save miloslavnosek/27c4860167341e87941cb0b3bf5c0ef1 to your computer and use it in GitHub Desktop.
Replaces classic string with Windows path to WSL path
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