Created
October 16, 2019 08:21
-
-
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.
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
#!/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