Woodland_Furniture
1025 строк · 24.5 Кб
1#!/bin/sh
2#---------------------------------------------
3# xdg-open
4#
5# Utility script to open a URL in the registered default application.
6#
7# Refer to the usage() function below for usage.
8#
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>
13#
14# LICENSE:
15#
16# Permission is hereby granted, free of charge, to any person obtaining a
17# copy of this software and associated documentation files (the "Software"),
18# to deal in the Software without restriction, including without limitation
19# the rights to use, copy, modify, merge, publish, distribute, sublicense,
20# and/or sell copies of the Software, and to permit persons to whom the
21# Software is furnished to do so, subject to the following conditions:
22#
23# The above copyright notice and this permission notice shall be included
24# in all copies or substantial portions of the Software.
25#
26# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32# OTHER DEALINGS IN THE SOFTWARE.
33#
34#---------------------------------------------
35
36manualpage()
37{
38cat << _MANUALPAGE
39Name
40
41xdg-open - opens a file or URL in the user's preferred
42application
43
44Synopsis
45
46xdg-open { file | URL }
47
48xdg-open { --help | --manual | --version }
49
50Description
51
52xdg-open opens a file or URL in the user's preferred
53application. If a URL is provided the URL will be opened in the
54user's preferred web browser. If a file is provided the file
55will be opened in the preferred application for files of that
56type. xdg-open supports file, ftp, http and https URLs.
57
58xdg-open is for use inside a desktop session only. It is not
59recommended to use xdg-open as root.
60
61Options
62
63--help
64Show command synopsis.
65
66--manual
67Show this manual page.
68
69--version
70Show the xdg-utils version information.
71
72Exit Codes
73
74An exit code of 0 indicates success while a non-zero exit code
75indicates failure. The following failure codes can be returned:
76
771
78Error in command line syntax.
79
802
81One of the files passed on the command line did not
82exist.
83
843
85A required tool could not be found.
86
874
88The action failed.
89
90See Also
91
92xdg-mime(1), xdg-settings(1), MIME applications associations
93specification
94
95Examples
96
97xdg-open 'http://www.freedesktop.org/'
98
99Opens the freedesktop.org website in the user's default
100browser.
101
102xdg-open /tmp/foobar.png
103
104Opens the PNG image file /tmp/foobar.png in the user's default
105image viewing application.
106_MANUALPAGE
107}
108
109usage()
110{
111cat << _USAGE
112xdg-open - opens a file or URL in the user's preferred
113application
114
115Synopsis
116
117xdg-open { file | URL }
118
119xdg-open { --help | --manual | --version }
120
121_USAGE
122}
123
124#@xdg-utils-common@
125
126#----------------------------------------------------------------------------
127# Common utility functions included in all XDG wrapper scripts
128#----------------------------------------------------------------------------
129
130DEBUG()
131{
132[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
133[ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
134shift
135echo "$@" >&2
136}
137
138# This handles backslashes but not quote marks.
139first_word()
140{
141read first rest
142echo "$first"
143}
144
145#-------------------------------------------------------------
146# map a binary to a .desktop file
147binary_to_desktop_file()
148{
149search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
150binary="`which "$1"`"
151binary="`readlink -f "$binary"`"
152base="`basename "$binary"`"
153IFS=:
154for dir in $search; do
155unset IFS
156[ "$dir" ] || continue
157[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
158for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
159[ -r "$file" ] || continue
160# Check to make sure it's worth the processing.
161grep -q "^Exec.*$base" "$file" || continue
162# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
163grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
164command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
165command="`which "$command"`"
166if [ x"`readlink -f "$command"`" = x"$binary" ]; then
167# Fix any double slashes that got added path composition
168echo "$file" | sed -e 's,//*,/,g'
169return
170fi
171done
172done
173}
174
175#-------------------------------------------------------------
176# map a .desktop file to a binary
177desktop_file_to_binary()
178{
179search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
180desktop="`basename "$1"`"
181IFS=:
182for dir in $search; do
183unset IFS
184[ "$dir" ] && [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
185# Check if desktop file contains -
186if [ "${desktop#*-}" != "$desktop" ]; then
187vendor=${desktop%-*}
188app=${desktop#*-}
189if [ -r $dir/applications/$vendor/$app ]; then
190file_path=$dir/applications/$vendor/$app
191elif [ -r $dir/applnk/$vendor/$app ]; then
192file_path=$dir/applnk/$vendor/$app
193fi
194fi
195if test -z "$file_path" ; then
196for indir in "$dir"/applications/ "$dir"/applications/*/ "$dir"/applnk/ "$dir"/applnk/*/; do
197file="$indir/$desktop"
198if [ -r "$file" ]; then
199file_path=$file
200break
201fi
202done
203fi
204if [ -r "$file_path" ]; then
205# Remove any arguments (%F, %f, %U, %u, etc.).
206command="`grep -E "^Exec(\[[^]=]*])?=" "$file_path" | cut -d= -f 2- | first_word`"
207command="`which "$command"`"
208readlink -f "$command"
209return
210fi
211done
212}
213
214#-------------------------------------------------------------
215# Exit script on successfully completing the desired operation
216
217exit_success()
218{
219if [ $# -gt 0 ]; then
220echo "$@"
221echo
222fi
223
224exit 0
225}
226
227
228#-----------------------------------------
229# Exit script on malformed arguments, not enough arguments
230# or missing required option.
231# prints usage information
232
233exit_failure_syntax()
234{
235if [ $# -gt 0 ]; then
236echo "xdg-open: $@" >&2
237echo "Try 'xdg-open --help' for more information." >&2
238else
239usage
240echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info."
241fi
242
243exit 1
244}
245
246#-------------------------------------------------------------
247# Exit script on missing file specified on command line
248
249exit_failure_file_missing()
250{
251if [ $# -gt 0 ]; then
252echo "xdg-open: $@" >&2
253fi
254
255exit 2
256}
257
258#-------------------------------------------------------------
259# Exit script on failure to locate necessary tool applications
260
261exit_failure_operation_impossible()
262{
263if [ $# -gt 0 ]; then
264echo "xdg-open: $@" >&2
265fi
266
267exit 3
268}
269
270#-------------------------------------------------------------
271# Exit script on failure returned by a tool application
272
273exit_failure_operation_failed()
274{
275if [ $# -gt 0 ]; then
276echo "xdg-open: $@" >&2
277fi
278
279exit 4
280}
281
282#------------------------------------------------------------
283# Exit script on insufficient permission to read a specified file
284
285exit_failure_file_permission_read()
286{
287if [ $# -gt 0 ]; then
288echo "xdg-open: $@" >&2
289fi
290
291exit 5
292}
293
294#------------------------------------------------------------
295# Exit script on insufficient permission to write a specified file
296
297exit_failure_file_permission_write()
298{
299if [ $# -gt 0 ]; then
300echo "xdg-open: $@" >&2
301fi
302
303exit 6
304}
305
306check_input_file()
307{
308if [ ! -e "$1" ]; then
309exit_failure_file_missing "file '$1' does not exist"
310fi
311if [ ! -r "$1" ]; then
312exit_failure_file_permission_read "no permission to read file '$1'"
313fi
314}
315
316check_vendor_prefix()
317{
318file_label="$2"
319[ -n "$file_label" ] || file_label="filename"
320file=`basename "$1"`
321case "$file" in
322[[:alpha:]]*-*)
323return
324;;
325esac
326
327echo "xdg-open: $file_label '$file' does not have a proper vendor prefix" >&2
328echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
329echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
330echo "Use --novendor to override or 'xdg-open --manual' for additional info." >&2
331exit 1
332}
333
334check_output_file()
335{
336# if the file exists, check if it is writeable
337# if it does not exists, check if we are allowed to write on the directory
338if [ -e "$1" ]; then
339if [ ! -w "$1" ]; then
340exit_failure_file_permission_write "no permission to write to file '$1'"
341fi
342else
343DIR=`dirname "$1"`
344if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
345exit_failure_file_permission_write "no permission to create file '$1'"
346fi
347fi
348}
349
350#----------------------------------------
351# Checks for shared commands, e.g. --help
352
353check_common_commands()
354{
355while [ $# -gt 0 ] ; do
356parm="$1"
357shift
358
359case "$parm" in
360--help)
361usage
362echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info."
363exit_success
364;;
365
366--manual)
367manualpage
368exit_success
369;;
370
371--version)
372echo "xdg-open 1.1.2"
373exit_success
374;;
375esac
376done
377}
378
379check_common_commands "$@"
380
381[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
382if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
383# Be silent
384xdg_redirect_output=" > /dev/null 2> /dev/null"
385else
386# All output to stderr
387xdg_redirect_output=" >&2"
388fi
389
390#--------------------------------------
391# Checks for known desktop environments
392# set variable DE to the desktop environments name, lowercase
393
394detectDE()
395{
396# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
397unset GREP_OPTIONS
398
399if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
400case "${XDG_CURRENT_DESKTOP}" in
401# only recently added to menu-spec, pre-spec X- still in use
402Cinnamon|X-Cinnamon)
403DE=cinnamon;
404;;
405ENLIGHTENMENT)
406DE=enlightenment;
407;;
408# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
409GNOME*)
410DE=gnome;
411;;
412KDE)
413DE=kde;
414;;
415LXDE)
416DE=lxde;
417;;
418LXQt)
419DE=lxqt;
420;;
421MATE)
422DE=mate;
423;;
424XFCE)
425DE=xfce
426;;
427X-Generic)
428DE=generic
429;;
430esac
431fi
432
433if [ x"$DE" = x"" ]; then
434# classic fallbacks
435if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
436elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
437elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
438elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
439elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
440elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
441elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
442elif [ x"$LXQT_SESSION_CONFIG" != x"" ]; then DE=lxqt;
443fi
444fi
445
446if [ x"$DE" = x"" ]; then
447# fallback to checking $DESKTOP_SESSION
448case "$DESKTOP_SESSION" in
449gnome)
450DE=gnome;
451;;
452LXDE|Lubuntu)
453DE=lxde;
454;;
455MATE)
456DE=mate;
457;;
458xfce|xfce4|'Xfce Session')
459DE=xfce;
460;;
461esac
462fi
463
464if [ x"$DE" = x"" ]; then
465# fallback to uname output for other platforms
466case "$(uname 2>/dev/null)" in
467CYGWIN*)
468DE=cygwin;
469;;
470Darwin)
471DE=darwin;
472;;
473esac
474fi
475
476if [ x"$DE" = x"gnome" ]; then
477# gnome-default-applications-properties is only available in GNOME 2.x
478# but not in GNOME 3.x
479which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
480fi
481
482if [ -f "$XDG_RUNTIME_DIR/flatpak-info" ]; then
483DE="flatpak"
484fi
485}
486
487#----------------------------------------------------------------------------
488# kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
489# It also always returns 1 in KDE 3.4 and earlier
490# Simply return 0 in such case
491
492kfmclient_fix_exit_code()
493{
494version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
495major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
496minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
497release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
498test "$major" -gt 3 && return $1
499test "$minor" -gt 5 && return $1
500test "$release" -gt 4 && return $1
501return 0
502}
503
504#----------------------------------------------------------------------------
505# Returns true if there is a graphical display attached.
506
507has_display()
508{
509if [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; then
510return 0
511else
512return 1
513fi
514}
515
516# This handles backslashes but not quote marks.
517last_word()
518{
519read first rest
520echo "$rest"
521}
522
523# Get the value of a key in a desktop file's Desktop Entry group.
524# Example: Use get_key foo.desktop Exec
525# to get the values of the Exec= key for the Desktop Entry group.
526get_key()
527{
528local file="${1}"
529local key="${2}"
530local desktop_entry=""
531
532IFS_="${IFS}"
533IFS=""
534while read line
535do
536case "$line" in
537"[Desktop Entry]")
538desktop_entry="y"
539;;
540# Reset match flag for other groups
541"["*)
542desktop_entry=""
543;;
544"${key}="*)
545# Only match Desktop Entry group
546if [ -n "${desktop_entry}" ]
547then
548echo "${line}" | cut -d= -f 2-
549fi
550esac
551done < "${file}"
552IFS="${IFS_}"
553}
554
555# Returns true if argument is a file:// URL or path
556is_file_url_or_path()
557{
558if echo "$1" | grep -q '^file://' \
559|| ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:'; then
560return 0
561else
562return 1
563fi
564}
565
566# If argument is a file URL, convert it to a (percent-decoded) path.
567# If not, leave it as it is.
568file_url_to_path()
569{
570local file="$1"
571if echo "$file" | grep -q '^file:///'; then
572file=${file#file://}
573file=${file%%#*}
574file=$(echo "$file" | sed -r 's/\?.*$//')
575local printf=printf
576if [ -x /usr/bin/printf ]; then
577printf=/usr/bin/printf
578fi
579file=$($printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")
580fi
581echo "$file"
582}
583
584open_cygwin()
585{
586cygstart "$1"
587
588if [ $? -eq 0 ]; then
589exit_success
590else
591exit_failure_operation_failed
592fi
593}
594
595open_darwin()
596{
597open "$1"
598
599if [ $? -eq 0 ]; then
600exit_success
601else
602exit_failure_operation_failed
603fi
604}
605
606open_kde()
607{
608if [ -n "${KDE_SESSION_VERSION}" ]; then
609case "${KDE_SESSION_VERSION}" in
6104)
611kde-open "$1"
612;;
6135)
614kde-open${KDE_SESSION_VERSION} "$1"
615;;
616esac
617else
618kfmclient exec "$1"
619kfmclient_fix_exit_code $?
620fi
621
622if [ $? -eq 0 ]; then
623exit_success
624else
625exit_failure_operation_failed
626fi
627}
628
629open_gnome3()
630{
631if gio help open 2>/dev/null 1>&2; then
632gio open "$1"
633elif gvfs-open --help 2>/dev/null 1>&2; then
634gvfs-open "$1"
635else
636open_generic "$1"
637fi
638
639if [ $? -eq 0 ]; then
640exit_success
641else
642exit_failure_operation_failed
643fi
644}
645
646open_gnome()
647{
648if gio help open 2>/dev/null 1>&2; then
649gio open "$1"
650elif gvfs-open --help 2>/dev/null 1>&2; then
651gvfs-open "$1"
652elif gnome-open --help 2>/dev/null 1>&2; then
653gnome-open "$1"
654else
655open_generic "$1"
656fi
657
658if [ $? -eq 0 ]; then
659exit_success
660else
661exit_failure_operation_failed
662fi
663}
664
665open_mate()
666{
667if gio help open 2>/dev/null 1>&2; then
668gio open "$1"
669elif gvfs-open --help 2>/dev/null 1>&2; then
670gvfs-open "$1"
671elif mate-open --help 2>/dev/null 1>&2; then
672mate-open "$1"
673else
674open_generic "$1"
675fi
676
677if [ $? -eq 0 ]; then
678exit_success
679else
680exit_failure_operation_failed
681fi
682}
683
684open_xfce()
685{
686if exo-open --help 2>/dev/null 1>&2; then
687exo-open "$1"
688elif gio help open 2>/dev/null 1>&2; then
689gio open "$1"
690elif gvfs-open --help 2>/dev/null 1>&2; then
691gvfs-open "$1"
692else
693open_generic "$1"
694fi
695
696if [ $? -eq 0 ]; then
697exit_success
698else
699exit_failure_operation_failed
700fi
701}
702
703open_enlightenment()
704{
705if enlightenment_open --help 2>/dev/null 1>&2; then
706enlightenment_open "$1"
707else
708open_generic "$1"
709fi
710
711if [ $? -eq 0 ]; then
712exit_success
713else
714exit_failure_operation_failed
715fi
716}
717
718open_flatpak()
719{
720gdbus call --session \
721--dest org.freedesktop.portal.Desktop \
722--object-path /org/freedesktop/portal/desktop \
723--method org.freedesktop.portal.OpenURI.OpenURI \
724"" "$1" {}
725
726if [ $? -eq 0 ]; then
727exit_success
728else
729exit_failure_operation_failed
730fi
731}
732
733#-----------------------------------------
734# Recursively search .desktop file
735
736search_desktop_file()
737{
738local default="$1"
739local dir="$2"
740local target="$3"
741
742local file=""
743# look for both vendor-app.desktop, vendor/app.desktop
744if [ -r "$dir/$default" ]; then
745file="$dir/$default"
746elif [ -r "$dir/`echo $default | sed -e 's|-|/|'`" ]; then
747file="$dir/`echo $default | sed -e 's|-|/|'`"
748fi
749
750if [ -r "$file" ] ; then
751command="$(get_key "${file}" "Exec" | first_word)"
752command_exec=`which $command 2>/dev/null`
753icon="$(get_key "${file}" "Icon")"
754# FIXME: Actually LC_MESSAGES should be used as described in
755# http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
756localised_name="$(get_key "${file}" "Name")"
757set -- $(get_key "${file}" "Exec" | last_word)
758# We need to replace any occurrence of "%f", "%F" and
759# the like by the target file. We examine each
760# argument and append the modified argument to the
761# end then shift.
762local args=$#
763local replaced=0
764while [ $args -gt 0 ]; do
765case $1 in
766%[c])
767replaced=1
768arg="${localised_name}"
769shift
770set -- "$@" "$arg"
771;;
772%[fFuU])
773replaced=1
774arg="$target"
775shift
776set -- "$@" "$arg"
777;;
778%[i])
779replaced=1
780shift
781set -- "$@" "--icon" "$icon"
782;;
783*)
784arg="$1"
785shift
786set -- "$@" "$arg"
787;;
788esac
789args=$(( $args - 1 ))
790done
791[ $replaced -eq 1 ] || set -- "$@" "$target"
792"$command_exec" "$@"
793
794if [ $? -eq 0 ]; then
795exit_success
796fi
797fi
798
799for d in $dir/*/; do
800[ -d "$d" ] && search_desktop_file "$default" "$d" "$target"
801done
802}
803
804
805open_generic_xdg_mime()
806{
807filetype="$2"
808default=`xdg-mime query default "$filetype"`
809if [ -n "$default" ] ; then
810xdg_user_dir="$XDG_DATA_HOME"
811[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
812
813xdg_system_dirs="$XDG_DATA_DIRS"
814[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
815
816DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
817for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
818search_desktop_file "$default" "$x/applications/" "$1"
819done
820fi
821}
822
823open_generic_xdg_file_mime()
824{
825filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
826open_generic_xdg_mime "$1" "$filetype"
827}
828
829open_generic_xdg_x_scheme_handler()
830{
831scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
832if [ -n $scheme ]; then
833filetype="x-scheme-handler/$scheme"
834open_generic_xdg_mime "$1" "$filetype"
835fi
836}
837
838open_envvar()
839{
840local oldifs="$IFS"
841local browser browser_with_arg
842
843IFS=":"
844for browser in $BROWSER; do
845IFS="$oldifs"
846
847if [ -z "$browser" ]; then
848continue
849fi
850
851if echo "$browser" | grep -q %s; then
852$(printf "$browser" "$1")
853else
854$browser "$1"
855fi
856
857if [ $? -eq 0 ]; then
858exit_success
859fi
860done
861}
862
863open_generic()
864{
865if is_file_url_or_path "$1"; then
866local file="$(file_url_to_path "$1")"
867
868check_input_file "$file"
869
870if has_display; then
871filetype=`xdg-mime query filetype "$file" | sed "s/;.*//"`
872open_generic_xdg_mime "$file" "$filetype"
873fi
874
875if which run-mailcap 2>/dev/null 1>&2; then
876run-mailcap --action=view "$file"
877if [ $? -eq 0 ]; then
878exit_success
879fi
880fi
881
882if has_display && mimeopen -v 2>/dev/null 1>&2; then
883mimeopen -L -n "$file"
884if [ $? -eq 0 ]; then
885exit_success
886fi
887fi
888fi
889
890if has_display; then
891open_generic_xdg_x_scheme_handler "$1"
892fi
893
894if [ -n "$BROWSER" ]; then
895open_envvar "$1"
896fi
897
898# if BROWSER variable is not set, check some well known browsers instead
899if [ x"$BROWSER" = x"" ]; then
900BROWSER=www-browser:links2:elinks:links:lynx:w3m
901if has_display; then
902BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium:chromium-browser:google-chrome:$BROWSER
903fi
904fi
905
906open_envvar "$1"
907
908exit_failure_operation_impossible "no method available for opening '$1'"
909}
910
911open_lxde()
912{
913# pcmanfm only knows how to handle file:// urls and filepaths, it seems.
914if is_file_url_or_path "$1"; then
915local file="$(file_url_to_path "$1")"
916
917# handle relative paths
918if ! echo "$file" | grep -q ^/; then
919file="$(pwd)/$file"
920fi
921
922pcmanfm "$file"
923else
924open_generic "$1"
925fi
926
927if [ $? -eq 0 ]; then
928exit_success
929else
930exit_failure_operation_failed
931fi
932}
933
934[ x"$1" != x"" ] || exit_failure_syntax
935
936url=
937while [ $# -gt 0 ] ; do
938parm="$1"
939shift
940
941case "$parm" in
942-*)
943exit_failure_syntax "unexpected option '$parm'"
944;;
945
946*)
947if [ -n "$url" ] ; then
948exit_failure_syntax "unexpected argument '$parm'"
949fi
950url="$parm"
951;;
952esac
953done
954
955if [ -z "${url}" ] ; then
956exit_failure_syntax "file or URL argument missing"
957fi
958
959detectDE
960
961if [ x"$DE" = x"" ]; then
962DE=generic
963fi
964
965DEBUG 2 "Selected DE $DE"
966
967# sanitize BROWSER (avoid caling ourselves in particular)
968case "${BROWSER}" in
969*:"xdg-open"|"xdg-open":*)
970BROWSER=$(echo $BROWSER | sed -e 's|:xdg-open||g' -e 's|xdg-open:||g')
971;;
972"xdg-open")
973BROWSER=
974;;
975esac
976
977case "$DE" in
978kde)
979open_kde "$url"
980;;
981
982gnome3|cinnamon)
983open_gnome3 "$url"
984;;
985
986gnome)
987open_gnome "$url"
988;;
989
990mate)
991open_mate "$url"
992;;
993
994xfce)
995open_xfce "$url"
996;;
997
998lxde|lxqt)
999open_lxde "$url"
1000;;
1001
1002enlightenment)
1003open_enlightenment "$url"
1004;;
1005
1006cygwin)
1007open_cygwin "$url"
1008;;
1009
1010darwin)
1011open_darwin "$url"
1012;;
1013
1014flatpak)
1015open_flatpak "$url"
1016;;
1017
1018generic)
1019open_generic "$url"
1020;;
1021
1022*)
1023exit_failure_operation_impossible "no method available for opening '$url'"
1024;;
1025esac
1026