Skip to content

Instantly share code, notes, and snippets.

@dhil
Created August 16, 2019 19:28
Show Gist options
  • Save dhil/d7b8e1c36fd77a71c9cb373d0802d19c to your computer and use it in GitHub Desktop.
Save dhil/d7b8e1c36fd77a71c9cb373d0802d19c to your computer and use it in GitHub Desktop.
Open files in Windows from within the Windows Subsystem for Linux (WSL)
# 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