Skip to content

Instantly share code, notes, and snippets.

@Milly
Created October 16, 2019 08:21
Show Gist options
  • Save Milly/4817ea447f7aaaa0e7ac9ec7078685fd to your computer and use it in GitHub Desktop.
Save Milly/4817ea447f7aaaa0e7ac9ec7078685fd to your computer and use it in GitHub Desktop.
Open a file or directory by the default application from command in the wsl, Like xdg-open.
#!/bin/bash -eu
target=${1:-.}
cmd=
if [[ -d $target ]]; then
# open directory
cmd=explorer.exe
fi
if [[ -e $target ]]; then
# target exists
target=$(wslpath -a -w "$target")
elif [[ $target == *://* ]]; then
# open uri
:
else
echo "File not found: $target" >&2
exit 2
fi
# avoid UNC path error in cmd.exe
[[ -d /mnt/c ]] && cd /mnt/c
cmd.exe /c start $cmd "$target"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment