2
#---------------------------------------------
5
# Utility script to open a URL in the registered default application.
7
# Refer to the usage() function below for usage.
9
# Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
10
# Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
11
# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
12
# Copyright 2006, Jeremy White <jwhite@codeweavers.com>
16
#---------------------------------------------
32
# This handles backslashes but not quote marks.
52
exit_failure_operation_failed
58
if kde-open -v 2>/dev/null 1>&2; then
61
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
62
kfmclient openURL "$1"
65
kfmclient_fix_exit_code $?
72
exit_failure_operation_failed
78
if gvfs-open --help 2>/dev/null 1>&2; then
87
exit_failure_operation_failed
93
if gvfs-open --help 2>/dev/null 1>&2; then
102
exit_failure_operation_failed
110
if [ $? -eq 0 ]; then
113
exit_failure_operation_failed
117
open_generic_xdg_mime()
120
default=`xdg-mime query default "$filetype"`
121
if [ -n "$default" ] ; then
122
xdg_user_dir="$XDG_DATA_HOME"
123
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
125
xdg_system_dirs="$XDG_DATA_DIRS"
126
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
128
DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
129
for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
131
# look for both vendor-app.desktop, vendor/app.desktop
132
if [ -r "$x/applications/$default" ]; then
133
file="$x/applications/$default"
134
elif [ -r "$x/applications/`echo $default | sed -e 's|-|/|'`" ]; then
135
file="$x/applications/`echo $default | sed -e 's|-|/|'`"
138
if [ -r "$file" ] ; then
139
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
140
command_exec=`which $command 2>/dev/null`
141
arguments="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | last_word`"
142
arguments_exec="`echo $arguments | sed -e 's*%[fFuU]*"'"$1"'"*g'`"
143
if [ -x "$command_exec" ] ; then
144
if echo $arguments | grep -iq '%[fFuU]' ; then
145
eval $command_exec $arguments_exec
147
eval $command_exec $arguments_exec "$1"
150
if [ $? -eq 0 ]; then
159
open_generic_xdg_file_mime()
161
filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
162
open_generic_xdg_mime "$1" "$filetype"
165
open_generic_xdg_x_scheme_handler()
167
scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
168
if [ -n $scheme ]; then
169
filetype="x-scheme-handler/$scheme"
170
open_generic_xdg_mime "$1" "$filetype"
176
# Paths or file:// URLs
177
if (echo "$1" | grep -q '^file://' ||
178
! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:'); then
183
if echo "$file" | grep -q '^file:///'; then
186
if [ -x /usr/bin/printf ]; then
187
printf=/usr/bin/printf
189
file="$($printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")"
191
check_input_file "$file"
193
open_generic_xdg_file_mime "$file"
195
if [ -f /etc/debian_version ] &&
196
which run-mailcap 2>/dev/null 1>&2; then
197
run-mailcap --action=view "$file"
198
if [ $? -eq 0 ]; then
203
if mimeopen -v 2>/dev/null 1>&2; then
204
mimeopen -L -n "$file"
205
if [ $? -eq 0 ]; then
211
open_generic_xdg_x_scheme_handler "$1"
215
for browser in $BROWSER; do
217
if [ x"$browser" != x"" ]; then
219
browser_with_arg=`printf "$browser" "$1" 2>/dev/null`
220
if [ $? -ne 0 ]; then
221
browser_with_arg=$browser;
224
if [ x"$browser_with_arg" = x"$browser" ]; then
225
eval '$browser $1'$xdg_redirect_output;
226
else eval '$browser_with_arg'$xdg_redirect_output;
229
if [ $? -eq 0 ]; then
235
exit_failure_operation_impossible "no method available for opening '$1'"
240
# pcmanfm only knows how to handle file:// urls and filepaths, it seems.
241
if (echo "$1" | grep -q '^file://' ||
242
! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:')
244
local file="$(echo "$1" | sed 's%^file://%%')"
246
# handle relative paths
247
if ! echo "$file" | grep -q '^/'; then
257
if [ $? -eq 0 ]; then
260
exit_failure_operation_failed
264
[ x"$1" != x"" ] || exit_failure_syntax
267
while [ $# -gt 0 ] ; do
273
exit_failure_syntax "unexpected option '$parm'"
277
if [ -n "$url" ] ; then
278
exit_failure_syntax "unexpected argument '$parm'"
285
if [ -z "${url}" ] ; then
286
exit_failure_syntax "file or URL argument missing"
291
if [ x"$DE" = x"" ]; then
295
DEBUG 2 "Selected DE $DE"
297
# if BROWSER variable is not set, check some well known browsers instead
298
if [ x"$BROWSER" = x"" ]; then
299
BROWSER=links2:elinks:links:lynx:w3m
300
if [ -n "$DISPLAY" ]; then
301
BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
331
exit_failure_operation_impossible "no method available for opening '$url'"