option to translate windows paths to linux paths in command line
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
Launching an app through wsl.exe with a file parameter from windows side is not straightforward because the windows path is not understood on the linux side. The wslpath tool exists to help with the translation, but using it requires to either: create a wrapper in linux to call wslpath on path params (error prone), or to wrap all paths in the commandline into wslpath 'c:\path\to\some\file' which works nicely but is quite cumbersome to type (and hard to understand what non-linux users since it uses backticks)
Describe the solution you'd like
Add an option to annotate (windows) paths in the wsl.exe commandline and auto translate them (essentially syntactic sugar for the wslpath solution):
IFF the first character of an argument is the ':' character, the string after ':' is treated as a windows path, translated to a linux path and then passed on (without the ':' character). Use '::' as the first two characters of an argument (or use ':') to transmit a single ':' to linux (escape sequence).
add an additional command line parameter "--no-path-translate" to turn off this feature (either for the whole command line, or for the rest of the command line) for script cases where proper escaping would be necessary but is hard to achieve.
Example:
wsl.exe vim /etc/hosts -> runs 'vim /etc/hosts'
wsl.exe vim :\MyFile.txt -> runs 'vim //mnt/x/MyFile.txt' (where x is the drive letter the command is run from since windows has multiple 'root' folders
wsl.exe vim relative\path\to\file.txt -> runs 'vim relative\path\to\file.txt'
wsl.exe vim :relative\path\to\file.txt -> runs 'vim relative/path/to/file.txt'
wsl.exe vim C:\MyFile.txt -> runs 'vim C:\MyFile.txt'
wsl.exe vim :C:\MyFile.txt -> runs 'vim //mnt/c/MyFile.txt'
wsl.exe vim ::C:\MyFile.txt -> runs 'vim :C:\MyFile.txt'
wsl.exe vim ":C:\Path With Space\file.txt -> runs 'vim "//mnt/c/Path With Space/File@file.txt"'
Describe alternatives you've considered
- I considered asking for automatic translation of paths without decoration, but I believe that too many things can go wrong, so I opted to use single character marker.
- I considered multiple escape characters, but chose ':' because now valid windows path may start with ':' (so doing something like "wsl.exe vim :%1" will never result in ambiguous results). It also isn't used as a shell special or escape character (like '.', '*' or ''), and it is rare that files start with ':' even in linux file systems, meaning that escape sequences are not needed often.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the wsl.exe command-line parsing entry point and reviewing how wslpath currently translates Windows paths. Trace how arguments are passed to Linux, then define handling for the ':' marker, '::' escape, and --no-path-translate option. Done means the examples work without changing ordinary arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100