arri 0.0.5 → 0.0.6

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