| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info.
" | 272 echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info.
" |
| 273 exit_success | 273 exit_success |
| 274 ;; | 274 ;; |
| 275 | 275 |
| 276 --manual) | 276 --manual) |
| 277 manualpage | 277 manualpage |
| 278 exit_success | 278 exit_success |
| 279 ;; | 279 ;; |
| 280 | 280 |
| 281 --version) | 281 --version) |
| 282 echo "xdg-open 1.0.2" | 282 echo "xdg-open 1.1.0 rc1" |
| 283 exit_success | 283 exit_success |
| 284 ;; | 284 ;; |
| 285 esac | 285 esac |
| 286 done | 286 done |
| 287 } | 287 } |
| 288 | 288 |
| 289 check_common_commands "$@" | 289 check_common_commands "$@" |
| 290 | 290 |
| 291 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; | 291 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; |
| 292 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then | 292 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then |
| 293 # Be silent | 293 # Be silent |
| 294 xdg_redirect_output=" > /dev/null 2> /dev/null" | 294 xdg_redirect_output=" > /dev/null 2> /dev/null" |
| 295 else | 295 else |
| 296 # All output to stderr | 296 # All output to stderr |
| 297 xdg_redirect_output=" >&2" | 297 xdg_redirect_output=" >&2" |
| 298 fi | 298 fi |
| 299 | 299 |
| 300 #-------------------------------------- | 300 #-------------------------------------- |
| 301 # Checks for known desktop environments | 301 # Checks for known desktop environments |
| 302 # set variable DE to the desktop environments name, lowercase | 302 # set variable DE to the desktop environments name, lowercase |
| 303 | 303 |
| 304 detectDE() | 304 detectDE() |
| 305 { | 305 { |
| 306 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; | 306 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
| 307 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; | 307 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
| 308 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; | 308 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; |
| 309 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; | 309 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; |
| 310 elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde; |
| 311 else DE="" |
| 310 fi | 312 fi |
| 311 } | 313 } |
| 312 | 314 |
| 313 #---------------------------------------------------------------------------- | 315 #---------------------------------------------------------------------------- |
| 314 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 | 316 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
| 315 # It also always returns 1 in KDE 3.4 and earlier | 317 # It also always returns 1 in KDE 3.4 and earlier |
| 316 # Simply return 0 in such case | 318 # Simply return 0 in such case |
| 317 | 319 |
| 318 kfmclient_fix_exit_code() | 320 kfmclient_fix_exit_code() |
| 319 { | 321 { |
| 320 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` | 322 [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0; |
| 321 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` | 323 version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'` |
| 322 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` | 324 major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'` |
| 323 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` | 325 minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'` |
| 326 release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` |
| 324 test "$major" -gt 3 && return $1 | 327 test "$major" -gt 3 && return $1 |
| 325 test "$minor" -gt 5 && return $1 | 328 test "$minor" -gt 5 && return $1 |
| 326 test "$release" -gt 4 && return $1 | 329 test "$release" -gt 4 && return $1 |
| 327 return 0 | 330 return 0 |
| 328 } | 331 } |
| 329 | 332 |
| 330 # This handles backslashes but not quote marks. | 333 # This handles backslashes but not quote marks. |
| 331 first_word() | 334 first_word() |
| 332 { | 335 { |
| 333 read first rest | 336 read first rest |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` | 388 filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` |
| 386 default=`xdg-mime query default "$filetype"` | 389 default=`xdg-mime query default "$filetype"` |
| 387 if [ -n "$default" ] ; then | 390 if [ -n "$default" ] ; then |
| 388 xdg_user_dir="$XDG_DATA_HOME" | 391 xdg_user_dir="$XDG_DATA_HOME" |
| 389 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" | 392 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" |
| 390 | 393 |
| 391 xdg_system_dirs="$XDG_DATA_DIRS" | 394 xdg_system_dirs="$XDG_DATA_DIRS" |
| 392 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/shar
e/ | 395 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/shar
e/ |
| 393 | 396 |
| 394 for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do | 397 for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do |
| 395 file="$x/applications/$default" | 398 local file="$x/applications/$default" |
| 396 if [ -r "$file" ] ; then | 399 if [ -r "$file" ] ; then |
| 397 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`" | 400 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`" |
| 398 command_exec=`which $command 2>/dev/null` | 401 command_exec=`which $command 2>/dev/null` |
| 399 if [ -x "$command_exec" ] ; then | 402 if [ -x "$command_exec" ] ; then |
| 400 $command_exec "$1" | 403 $command_exec "$1" |
| 401 if [ $? -eq 0 ]; then | 404 if [ $? -eq 0 ]; then |
| 402 exit_success | 405 exit_success |
| 403 fi | 406 fi |
| 404 fi | 407 fi |
| 405 fi | 408 fi |
| 406 done | 409 done |
| 407 fi | 410 fi |
| 408 } | 411 } |
| 409 | 412 |
| 410 open_generic() | 413 open_generic() |
| 411 { | 414 { |
| 412 # Paths or file:// URLs | 415 # Paths or file:// URLs |
| 413 if (echo "$1" | grep -q '^file://' || | 416 if (echo "$1" | grep -q '^file://' || |
| 414 ! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:'); then | 417 ! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:'); then |
| 415 | 418 |
| 416 local file=$(echo "$1" | sed 's%^file://%%') | 419 local file="$1" |
| 417 | 420 |
| 418 # Decode URLs | 421 # Decode URLs |
| 419 # TODO | 422 if echo "$file" | grep -q '^file:///'; then |
| 420 | 423 file=${file#file://} |
| 424 file="$(printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x
\1@g')")" |
| 425 fi |
| 421 check_input_file "$file" | 426 check_input_file "$file" |
| 422 | 427 |
| 423 open_generic_xdg_mime "$file" | 428 open_generic_xdg_mime "$file" |
| 424 | 429 |
| 425 if [ -f /etc/debian_version ] && | 430 if [ -f /etc/debian_version ] && |
| 426 which run-mailcap 2>/dev/null 1>&2; then | 431 which run-mailcap 2>/dev/null 1>&2; then |
| 427 run-mailcap --action=view "$file" | 432 run-mailcap --action=view "$file" |
| 428 if [ $? -eq 0 ]; then | 433 if [ $? -eq 0 ]; then |
| 429 exit_success | 434 exit_success |
| 430 fi | 435 fi |
| (...skipping 23 matching lines...) Expand all Loading... |
| 454 | 459 |
| 455 if [ $? -eq 0 ]; then | 460 if [ $? -eq 0 ]; then |
| 456 exit_success; | 461 exit_success; |
| 457 fi | 462 fi |
| 458 fi | 463 fi |
| 459 done | 464 done |
| 460 | 465 |
| 461 exit_failure_operation_impossible "no method available for opening '$1'" | 466 exit_failure_operation_impossible "no method available for opening '$1'" |
| 462 } | 467 } |
| 463 | 468 |
| 469 open_lxde() |
| 470 { |
| 471 # pcmanfm only knows how to handle file:// urls and filepaths, it seems. |
| 472 if (echo "$1" | grep -q '^file://' || |
| 473 ! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:') |
| 474 then |
| 475 local file="$(echo "$1" | sed 's%^file://%%')" |
| 476 |
| 477 # handle relative paths |
| 478 if ! echo "$file" | grep -q '^/'; then |
| 479 file="$(pwd)/$file" |
| 480 fi |
| 481 |
| 482 pcmanfm "$file" |
| 483 |
| 484 else |
| 485 open_generic "$1" |
| 486 fi |
| 487 |
| 488 if [ $? -eq 0 ]; then |
| 489 exit_success |
| 490 else |
| 491 exit_failure_operation_failed |
| 492 fi |
| 493 } |
| 494 |
| 464 [ x"$1" != x"" ] || exit_failure_syntax | 495 [ x"$1" != x"" ] || exit_failure_syntax |
| 465 | 496 |
| 466 url= | 497 url= |
| 467 while [ $# -gt 0 ] ; do | 498 while [ $# -gt 0 ] ; do |
| 468 parm="$1" | 499 parm="$1" |
| 469 shift | 500 shift |
| 470 | 501 |
| 471 case "$parm" in | 502 case "$parm" in |
| 472 -*) | 503 -*) |
| 473 exit_failure_syntax "unexpected option '$parm'" | 504 exit_failure_syntax "unexpected option '$parm'" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 ;; | 537 ;; |
| 507 | 538 |
| 508 gnome) | 539 gnome) |
| 509 open_gnome "$url" | 540 open_gnome "$url" |
| 510 ;; | 541 ;; |
| 511 | 542 |
| 512 xfce) | 543 xfce) |
| 513 open_xfce "$url" | 544 open_xfce "$url" |
| 514 ;; | 545 ;; |
| 515 | 546 |
| 547 lxde) |
| 548 open_lxde "$url" |
| 549 ;; |
| 550 |
| 516 generic) | 551 generic) |
| 517 open_generic "$url" | 552 open_generic "$url" |
| 518 ;; | 553 ;; |
| 519 | 554 |
| 520 *) | 555 *) |
| 521 exit_failure_operation_impossible "no method available for opening '$url'" | 556 exit_failure_operation_impossible "no method available for opening '$url'" |
| 522 ;; | 557 ;; |
| 523 esac | 558 esac |
| OLD | NEW |