Last active
September 29, 2020 20:49
-
-
Save loganlinn/9522f8fdefb85d8092ff169c60a5b7c5 to your computer and use it in GitHub Desktop.
bash script for opening URLs cross-platform (open, xdg-open, wslview)
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 | |
main() { | |
local url=${1} | |
case "$OSTYPE" in | |
darwin*) | |
open "${url}" ;; | |
mysys*) | |
exe /c start "${url/&/^&}" ;; | |
*) | |
if (command -v xdg-open >/dev/null); then | |
xdg-open "${url}" | |
elif (command -v wslview >/dev/null); then | |
wslview "${url}" | |
else | |
echo >&2 "Unsupported platform." | |
return 1 | |
fi | |
;; | |
esac | |
} | |
main "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment