I had long been used to doing open . on macOS to get finder window open on the current directory in the shell. I wanted something similar under WSL2, but this is the best I could come up with. It copies the current working directory to the clipboard such that you can press “ctrl-l crtl-v ret” in the File Explorer and get the same effect.

function wslpwd() {
  echo //wsl$/Ubuntu$PWD | sed 's:/:\\:g' | pbcopy
}

Assumptions

  • pbcopy is installed
  • WSL distro name is Ubuntu

It prepends the special //wsl$/Ubuntu string to the $PWD, then uses sed to transform the forward slashes to backslashes, then uses pbcopy to put the result on the system clipboard.