Skip to content

Instantly share code, notes, and snippets.

@gazpachoking
Last active May 26, 2018 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gazpachoking/49eeaa47eed0ae2b295522b7fe17061b to your computer and use it in GitHub Desktop.
Save gazpachoking/49eeaa47eed0ae2b295522b7fe17061b to your computer and use it in GitHub Desktop.
Allows easy use of Windows environment variables from within Windows subsystem for Linux (using fish shell.) Automatically translates variables that look like Windows paths to WSL paths.
function winenv --description "Echos windows environment variables from WSL."
for arg in $argv
set result (cmd.exe /c echo "%"$arg"%" | string trim)
if echo $result | grep -i "^[a-z]:\\\\" > /dev/null
for r in (echo $result|string split ";")
echo (wslpath $r)
end
else
echo $result
end
end
end
@gazpachoking
Copy link
Author

gazpachoking commented May 26, 2018

This function allows easier use of Windows environment variables from the fish shell in WSL. Examples:

> winenv USERNAME
MyWindowsUser

> winenv TEMP
/mnt/c/Users/MyWindowsUser/AppData/Local/Temp

> winenv LOCALAPPDATA
/mnt/c/Users/MyWindowsUser/AppData/Local

> winenv PATH
/mnt/c/ProgramData/Oracle/Java/javapath
/mnt/c/Windows/System32
/mnt/c/Windows
/mnt/c/Windows/System32/wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0
/mnt/c/Program Files/Git/cmd
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Windows/System32
/mnt/c/Windows
/mnt/c/Windows/System32/wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0
/mnt/c/Windows/System32/OpenSSH
/mnt/c/Users/MyWindowsUser/AppData/Local/Programs/Python/Python36-32/Scripts
/mnt/c/Users/MyWindowsUser/AppData/Local/Programs/Python/Python36-32
/mnt/c/Users/MyWindowsUser/AppData/Local/Microsoft/WindowsApps
/mnt/c/Users/MyWindowsUser/wsl-terminal

> winenv HOMEDRIVE HOMEPATH
C:
\Users\MyWindowsUser

> winenv HOMEDRIVE HOMEPATH | string join ""
C:\Users\MyWindowsUser

> wslpath (winenv HOMEDRIVE HOMEPATH | string join "")
/mnt/c/Users/MyWindowsUser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment