Skip to content

Instantly share code, notes, and snippets.

@theodric
Last active December 23, 2024 19:21
Show Gist options
  • Save theodric/685af2d1eb4d551640eeb776b5eac3e9 to your computer and use it in GitHub Desktop.
Save theodric/685af2d1eb4d551640eeb776b5eac3e9 to your computer and use it in GitHub Desktop.
macOS 'open' for bash on linux
open() {
if [[ -z "$1" ]]; then
echo "usage: open <file>" >&2
return 1
fi
if [[ ! -e "$1" ]]; then
echo "file not found: $1" >&2
return 1
fi
command -v xdg-open >/dev/null 2>&1 || {
echo "xdg-open not found; install it or figure out an alternative" >&2
return 1
}
xdg-open "$1" &>/dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment