Created
August 16, 2019 19:28
-
-
Save dhil/d7b8e1c36fd77a71c9cb373d0802d19c to your computer and use it in GitHub Desktop.
Open files in Windows from within the Windows Subsystem for Linux (WSL)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open files in Windows from within WSL. | |
function _windows_open() | |
{ | |
# Absolute, inside WSL, path to the file. | |
local file=$(readlink -e "$1") | |
if [[ ! (-f "$file" || -d "$file") ]]; then | |
echo "error: no such file '$1'" | |
return 1 | |
else | |
# Convert slashes into backslashes. | |
file=$(echo "$file" | sed 's/\//\\/g') | |
# Absolute, outside WSL, path to the target file. | |
local root="\\\\wsl\$\\Ubuntu" | |
local target="$root$file" | |
cmd.exe /C start "$target" | |
fi | |
} | |
alias open=_windows_open |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment