Skip to content

Instantly share code, notes, and snippets.

@loganlinn
Last active September 29, 2020 20:49
Show Gist options
  • Save loganlinn/9522f8fdefb85d8092ff169c60a5b7c5 to your computer and use it in GitHub Desktop.
Save loganlinn/9522f8fdefb85d8092ff169c60a5b7c5 to your computer and use it in GitHub Desktop.
bash script for opening URLs cross-platform (open, xdg-open, wslview)
#!/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