OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 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 2006, Kevin Krammer <kevin.krammer@gmx.at> |
| 10 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> |
| 11 # |
| 12 # LICENSE: |
| 13 # |
| 14 #--------------------------------------------- |
| 15 |
| 16 manualpage() |
| 17 { |
| 18 cat << _MANUALPAGE |
| 19 _MANUALPAGE |
| 20 } |
| 21 |
| 22 usage() |
| 23 { |
| 24 cat << _USAGE |
| 25 _USAGE |
| 26 } |
| 27 |
| 28 #@xdg-utils-common@ |
| 29 |
| 30 open_kde() |
| 31 { |
| 32 kfmclient exec "$1" |
| 33 kfmclient_fix_exit_code $? |
| 34 |
| 35 if [ $? -eq 0 ]; then |
| 36 exit_success |
| 37 else |
| 38 exit_failure_operation_failed |
| 39 fi |
| 40 } |
| 41 |
| 42 open_gnome() |
| 43 { |
| 44 gnome-open "$1" |
| 45 |
| 46 if [ $? -eq 0 ]; then |
| 47 exit_success |
| 48 else |
| 49 exit_failure_operation_failed |
| 50 fi |
| 51 } |
| 52 |
| 53 open_xfce() |
| 54 { |
| 55 exo-open "$1" |
| 56 |
| 57 if [ $? -eq 0 ]; then |
| 58 exit_success |
| 59 else |
| 60 exit_failure_operation_failed |
| 61 fi |
| 62 } |
| 63 |
| 64 open_generic() |
| 65 { |
| 66 if mimeopen -v 2>/dev/null 1>&2; then |
| 67 mimeopen -n "$1" |
| 68 if [ $? -eq 0 ]; then |
| 69 exit_success |
| 70 fi |
| 71 fi |
| 72 |
| 73 if which run-mailcap 2>/dev/null 1>&2 && |
| 74 (echo "$1" | grep -q '^file://' || |
| 75 ! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:'); then |
| 76 |
| 77 local file=$(echo "$1" | sed 's%^file://%%') |
| 78 run-mailcap --action=view "$file" |
| 79 if [ $? -eq 0 ]; then |
| 80 exit_success |
| 81 fi |
| 82 fi |
| 83 |
| 84 IFS=":" |
| 85 for browser in $BROWSER; do |
| 86 if [ x"$browser" != x"" ]; then |
| 87 |
| 88 IFS=' ' |
| 89 browser_with_arg=${browser//'%s'/"$1"} |
| 90 |
| 91 if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1"; |
| 92 else $browser_with_arg; |
| 93 fi |
| 94 |
| 95 if [ $? -eq 0 ]; then exit_success; |
| 96 fi |
| 97 fi |
| 98 done |
| 99 |
| 100 exit_failure_operation_impossible "no method available for opening '$1'" |
| 101 } |
| 102 |
| 103 [ x"$1" != x"" ] || exit_failure_syntax |
| 104 |
| 105 url= |
| 106 while [ $# -gt 0 ] ; do |
| 107 parm="$1" |
| 108 shift |
| 109 |
| 110 case "$parm" in |
| 111 -*) |
| 112 exit_failure_syntax "unexpected option '$parm'" |
| 113 ;; |
| 114 |
| 115 *) |
| 116 if [ -n "$url" ] ; then |
| 117 exit_failure_syntax "unexpected argument '$parm'" |
| 118 fi |
| 119 url="$parm" |
| 120 ;; |
| 121 esac |
| 122 done |
| 123 |
| 124 if [ -z "${url}" ] ; then |
| 125 exit_failure_syntax "file or URL argument missing" |
| 126 fi |
| 127 |
| 128 detectDE |
| 129 |
| 130 if [ x"$DE" = x"" ]; then |
| 131 # if BROWSER variable is not set, check some well known browsers instead |
| 132 if [ x"$BROWSER" = x"" ]; then |
| 133 BROWSER=firefox:mozilla:netscape |
| 134 fi |
| 135 DE=generic |
| 136 fi |
| 137 |
| 138 case "$DE" in |
| 139 kde) |
| 140 open_kde "$url" |
| 141 ;; |
| 142 |
| 143 gnome) |
| 144 open_gnome "$url" |
| 145 ;; |
| 146 |
| 147 xfce) |
| 148 open_xfce "$url" |
| 149 ;; |
| 150 |
| 151 generic) |
| 152 open_generic "$url" |
| 153 ;; |
| 154 |
| 155 *) |
| 156 exit_failure_operation_impossible "no method available for opening '$url'" |
| 157 ;; |
| 158 esac |
OLD | NEW |