Skip to content

Instantly share code, notes, and snippets.

@avdd
Last active January 22, 2023 11:41
Show Gist options
  • Save avdd/01fbeb37f7c9819aeeaad803d926aa86 to your computer and use it in GitHub Desktop.
Save avdd/01fbeb37f7c9819aeeaad803d926aa86 to your computer and use it in GitHub Desktop.
open file or url in windows from wsl
#!/bin/bash
arg="$*"
if [[ "$arg" =~ ^file:\/\/.*$ ]]
then
arg=${arg//file:\/\//}
fi
arg_path=$(readlink -f "$arg")
if [ -e "$arg_path" ]
then
arg=$(wslpath -aw "$arg_path")
elif ! [ "$(curl --head --silent "$arg" | head -n 1)" ]
then
echo "no such file: '$arg'"
exit 1
fi
powershell.exe Start "\"$arg\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment