Skip to content

Instantly share code, notes, and snippets.

@joepie91

joepie91/.sh Secret

Created March 10, 2018 18:42
Show Gist options
  • Save joepie91/36d6ca313d910c72338b73ede4693436 to your computer and use it in GitHub Desktop.
Save joepie91/36d6ca313d910c72338b73ede4693436 to your computer and use it in GitHub Desktop.
open_generic()
{
if is_file_url_or_path "$1"; then
local file="$(file_url_to_path "$1")"
check_input_file "$file"
if has_display; then
filetype=`xdg-mime query filetype "$file" | sed "s/;.*//"`
open_generic_xdg_mime "$file" "$filetype"
fi
if type -P run-mailcap 2>/dev/null 1>&2; then
run-mailcap --action=view "$file"
if [ $? -eq 0 ]; then
exit_success
fi
fi
if has_display && mimeopen -v 2>/dev/null 1>&2; then
mimeopen -L -n "$file"
if [ $? -eq 0 ]; then
exit_success
fi
fi
fi
if has_display; then
open_generic_xdg_x_scheme_handler "$1"
fi
if [ -n "$BROWSER" ]; then
open_envvar "$1"
fi
# if BROWSER variable is not set, check some well known browsers instead
if [ x"$BROWSER" = x"" ]; then
BROWSER=www-browser:links2:elinks:links:lynx:w3m
if has_display; then
BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium:chromium-browser:google-chrome:$BROWSER
fi
fi
open_envvar "$1"
exit_failure_operation_impossible "no method available for opening '$1'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment