Something went wrong. Try again.
A shell script to convert a Windows filepath to Linux format. Great for working in WSL! (Now, I'm aware that *technically* it's the POSIX format but whatever the name has stuck)
Something went wrong. Try again.
562 B · 24 lines · Created 11mo ago
Python
123456789101112131415161718192021222324#!/usr/bin/env python3
import sysimport osimport re
args = sys.argv SCRIPT_NAME = os.path.basename(__file__)
if len(args) != 2: print("lp (linuxize path). made by cookie.") print(f"usage: {SCRIPT_NAME} WINDOWS_FILE_PATH") exit(1 if len(args)>2 else 0)
win_path = args[1]linux_path = win_path.replace("\\", "/")
# prepend with "/mnt/{drive_letter}" if is absolute pathm = re.match(r"[A-Z]:", linux_path)if m: drive_letter = m.group(0)[0].lower() linux_path = re.sub(r"[A-Z]:", f"/mnt/{drive_letter}", linux_path)
print(linux_path)