| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-open | 3 # xdg-open |
| 4 # | 4 # |
| 5 # Utility script to open a URL in the registered default application. | 5 # Utility script to open a URL in the registered default application. |
| 6 # | 6 # |
| 7 # Refer to the usage() function below for usage. | 7 # Refer to the usage() function below for usage. |
| 8 # | 8 # |
| 9 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> | 9 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> |
| 10 # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org> | 10 # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 #@xdg-utils-common@ | 30 #@xdg-utils-common@ |
| 31 | 31 |
| 32 # This handles backslashes but not quote marks. | 32 # This handles backslashes but not quote marks. |
| 33 first_word() | 33 first_word() |
| 34 { | 34 { |
| 35 read first rest | 35 read first rest |
| 36 echo "$first" | 36 echo "$first" |
| 37 } | 37 } |
| 38 | 38 |
| 39 last_word() |
| 40 { |
| 41 read first rest |
| 42 echo "$rest" |
| 43 } |
| 44 |
| 39 open_kde() | 45 open_kde() |
| 40 { | 46 { |
| 41 if kde-open -v 2>/dev/null 1>&2; then | 47 if kde-open -v 2>/dev/null 1>&2; then |
| 42 kde-open "$1" | 48 kde-open "$1" |
| 43 else | 49 else |
| 44 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then | 50 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
| 45 kfmclient openURL "$1" | 51 kfmclient openURL "$1" |
| 46 else | 52 else |
| 47 kfmclient exec "$1" | 53 kfmclient exec "$1" |
| 48 kfmclient_fix_exit_code $? | 54 kfmclient_fix_exit_code $? |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` | 93 filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` |
| 88 default=`xdg-mime query default "$filetype"` | 94 default=`xdg-mime query default "$filetype"` |
| 89 if [ -n "$default" ] ; then | 95 if [ -n "$default" ] ; then |
| 90 xdg_user_dir="$XDG_DATA_HOME" | 96 xdg_user_dir="$XDG_DATA_HOME" |
| 91 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" | 97 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" |
| 92 | 98 |
| 93 xdg_system_dirs="$XDG_DATA_DIRS" | 99 xdg_system_dirs="$XDG_DATA_DIRS" |
| 94 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/shar
e/ | 100 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/shar
e/ |
| 95 | 101 |
| 96 for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do | 102 for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do |
| 97 file="$x/applications/$default" | 103 local file |
| 104 # look for both vendor-app.desktop, vendor/app.desktop |
| 105 if [ -r "$x/applications/$default" ]; then |
| 106 file="$x/applications/$default" |
| 107 elif [ -r "$x/applications/`echo $default | sed -e 's|-|/|'`" ]; the
n |
| 108 file="$x/applications/`echo $default | sed -e 's|-|/|'`" |
| 109 fi |
| 110 |
| 98 if [ -r "$file" ] ; then | 111 if [ -r "$file" ] ; then |
| 99 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`" | 112 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`" |
| 100 command_exec=`which $command 2>/dev/null` | 113 command_exec=`which $command 2>/dev/null` |
| 114 arguments="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2-
| last_word`" |
| 115 arguments_exec="`echo $arguments | sed -e 's*%[fFuU]*"'"$1"'"*g'
`" |
| 101 if [ -x "$command_exec" ] ; then | 116 if [ -x "$command_exec" ] ; then |
| 102 $command_exec "$1" | 117 if echo $arguments | grep -iq '%[fFuU]' ; then |
| 118 eval $command_exec $arguments_exec |
| 119 else |
| 120 eval $command_exec $arguments_exec "$1" |
| 121 fi |
| 122 |
| 103 if [ $? -eq 0 ]; then | 123 if [ $? -eq 0 ]; then |
| 104 exit_success | 124 exit_success |
| 105 fi | 125 fi |
| 106 fi | 126 fi |
| 107 fi | 127 fi |
| 108 done | 128 done |
| 109 fi | 129 fi |
| 110 } | 130 } |
| 111 | 131 |
| 112 open_generic() | 132 open_generic() |
| 113 { | 133 { |
| 114 # Paths or file:// URLs | 134 # Paths or file:// URLs |
| 115 if (echo "$1" | grep -q '^file://' || | 135 if (echo "$1" | grep -q '^file://' || |
| 116 ! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:'); then | 136 ! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:'); then |
| 117 | 137 |
| 118 local file=$(echo "$1" | sed 's%^file://%%') | 138 local file="$1" |
| 119 | 139 |
| 120 # Decode URLs | 140 # Decode URLs |
| 121 # TODO | 141 if echo "$file" | grep -q '^file:///'; then |
| 122 | 142 file=${file#file://} |
| 143 file="$(printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x
\1@g')")" |
| 144 fi |
| 123 check_input_file "$file" | 145 check_input_file "$file" |
| 124 | 146 |
| 125 open_generic_xdg_mime "$file" | 147 open_generic_xdg_mime "$file" |
| 126 | 148 |
| 127 if [ -f /etc/debian_version ] && | 149 if [ -f /etc/debian_version ] && |
| 128 which run-mailcap 2>/dev/null 1>&2; then | 150 which run-mailcap 2>/dev/null 1>&2; then |
| 129 run-mailcap --action=view "$file" | 151 run-mailcap --action=view "$file" |
| 130 if [ $? -eq 0 ]; then | 152 if [ $? -eq 0 ]; then |
| 131 exit_success | 153 exit_success |
| 132 fi | 154 fi |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if [ -n "$DISPLAY" ]; then | 248 if [ -n "$DISPLAY" ]; then |
| 227 BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrom
e:$BROWSER | 249 BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrom
e:$BROWSER |
| 228 fi | 250 fi |
| 229 fi | 251 fi |
| 230 | 252 |
| 231 case "$DE" in | 253 case "$DE" in |
| 232 kde) | 254 kde) |
| 233 open_kde "$url" | 255 open_kde "$url" |
| 234 ;; | 256 ;; |
| 235 | 257 |
| 236 gnome) | 258 gnome*) |
| 237 open_gnome "$url" | 259 open_gnome "$url" |
| 238 ;; | 260 ;; |
| 239 | 261 |
| 240 xfce) | 262 xfce) |
| 241 open_xfce "$url" | 263 open_xfce "$url" |
| 242 ;; | 264 ;; |
| 243 | 265 |
| 244 lxde) | 266 lxde) |
| 245 open_lxde "$url" | 267 open_lxde "$url" |
| 246 ;; | 268 ;; |
| 247 | 269 |
| 248 generic) | 270 generic) |
| 249 open_generic "$url" | 271 open_generic "$url" |
| 250 ;; | 272 ;; |
| 251 | 273 |
| 252 *) | 274 *) |
| 253 exit_failure_operation_impossible "no method available for opening '$url'" | 275 exit_failure_operation_impossible "no method available for opening '$url'" |
| 254 ;; | 276 ;; |
| 255 esac | 277 esac |
| OLD | NEW |