#!/bin/sh #--------------------------------------------- # xdg-open # # Utility script to open a URL in the registered default application. # # Refer to the usage() function below for usage. # # Copyright 2006, Kevin Krammer # Copyright 2006, Jeremy White # # LICENSE: # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # #--------------------------------------------- usage() { cat << _USAGE xdg-open -- opens a file or URL in the user's preferred application Synopsis xdg-open [--help] [[file] | [URL]] _USAGE exit 1 } open_kde() { kfmclient exec "$1" exit $? } open_gnome() { gnome-open "$1" exit $? } open_generic() { # should rather iterate over all entries in BROWSER browser=`echo "$BROWSER" | cut -d ':' -f 1` if [ "$browser" == "" ]; then exit 2; fi browser_with_arg=`echo "$browser" | sed s#%s#"$1"#` if [ "$browser_with_arg" == "$browser" ]; then "$browser" "$1"; else $browser_with_arg; fi exit 0 } [ "$1" != "" ] || usage [ "$1" != "--help" ] || usage #@xdg-utils-common@ #---------------------------------------------------------------------------- # Common utility functions included in all XDG wrapper scripts #---------------------------------------------------------------------------- detectDE() { if [ "$KDE_FULL_SESSION" == "true" ]; then DE=kde; elif [ "$GNOME_DESKTOP_SESSION_ID" != "" ]; then DE=gnome; fi } detectDE #---------------------------------------------------------------------------- case "$DE" in kde) open_kde "$1" ;; gnome) open_gnome "$1" ;; generic) open_generic "$1" ;; *) echo Sorry, no method available for opening "$1" exit 2 ;; esac