Skip to content

max-nothacker/cpath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

cpath

convert path

A 12-line bash function for WSL that auto-detects whether you handed it a Windows or a WSL path and converts it the other way. The result is printed and also copied to the Windows clipboard so you can paste it straight into File Explorer, an editor, or a chat.

It's a thin wrapper around Microsoft's built-in wslpath plus Windows' built-in clip.exe. No PHP, Python, Go, or Rust runtime — just bash and two tools that already ship with WSL and Windows.

Install

curl -fsSL https://raw.githubusercontent.com/max-nothacker/cpath/main/cpath.sh >> ~/.bashrc && source ~/.bashrc

Or copy the function out of cpath.sh into your own dotfiles.

Usage

$ cpath 'C:\path\to\folder'
/mnt/c/path/to/folder
# (and the same string is on the Windows clipboard)

$ cpath /home/user/repos
\\wsl.localhost\Ubuntu\home\user\repos
# (paste into File Explorer's address bar to open the WSL folder)

$ cpath /mnt/c/Users/Public
C:\Users\Public

How it works

  1. A regex checks whether the input starts with <letter>:[\/] or \\ → treats it as Windows and calls wslpath -u.
  2. Anything else is treated as a WSL path and converted with wslpath -w (backslash form — what File Explorer wants).
  3. The result is piped through clip.exe, which Windows exposes to WSL via interop.

That's the whole tool.

Prior art

cpath is a thin combination of two well-known pieces. Credit where it's due:

The niche cpath fills: auto-detect plus Windows clipboard plus zero non-Microsoft dependencies, in a function small enough to drop into ~/.bashrc.

License

MIT — see LICENSE.

About

convert path — tiny WSL bash function that auto-detects Windows↔WSL direction and copies the result to the Windows clipboard. Wraps wslpath + clip.exe.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages