| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-mime | 3 # xdg-mime |
| 4 # | 4 # |
| 5 # Utility script to manipulate MIME related information | 5 # Utility script to manipulate MIME related information |
| 6 # on XDG compliant systems. | 6 # on XDG compliant systems. |
| 7 # | 7 # |
| 8 # Refer to the usage() function below for usage. | 8 # Refer to the usage() function below for usage. |
| 9 # | 9 # |
| 10 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> | 10 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 #-------------------------------------- | 423 #-------------------------------------- |
| 424 # Checks for known desktop environments | 424 # Checks for known desktop environments |
| 425 # set variable DE to the desktop environments name, lowercase | 425 # set variable DE to the desktop environments name, lowercase |
| 426 | 426 |
| 427 detectDE() | 427 detectDE() |
| 428 { | 428 { |
| 429 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; | 429 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
| 430 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; | 430 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
| 431 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; | 431 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; |
| 432 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; | 432 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; |
| 433 elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde; | 433 fi |
| 434 else DE="" | 434 |
| 435 if [ x"$DE" = x"" ]; then |
| 436 # fallback to checking $DESKTOP_SESSION |
| 437 case "$DESKTOP_SESSION" in |
| 438 LXDE) |
| 439 DE=lxde; |
| 440 ;; |
| 441 xfce|xfce4) |
| 442 DE=xfce; |
| 443 ;; |
| 444 esac |
| 445 fi |
| 446 |
| 447 if [ x"$DE" = x"" ]; then |
| 448 # fallback to uname output for other platforms |
| 449 case "$(uname 2>/dev/null)" in |
| 450 Darwin) |
| 451 DE=darwin; |
| 452 ;; |
| 453 esac |
| 454 fi |
| 455 |
| 456 if [ x"$DE" = x"gnome" ]; then |
| 457 # gnome-default-applications-properties is only available in GNOME 2.x |
| 458 # but not in GNOME 3.x |
| 459 which gnome-default-applications-properties 2> /dev/null || DE="gnome3" |
| 435 fi | 460 fi |
| 436 } | 461 } |
| 437 | 462 |
| 438 #---------------------------------------------------------------------------- | 463 #---------------------------------------------------------------------------- |
| 439 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 | 464 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
| 440 # It also always returns 1 in KDE 3.4 and earlier | 465 # It also always returns 1 in KDE 3.4 and earlier |
| 441 # Simply return 0 in such case | 466 # Simply return 0 in such case |
| 442 | 467 |
| 443 kfmclient_fix_exit_code() | 468 kfmclient_fix_exit_code() |
| 444 { | 469 { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 514 |
| 490 if [ $? -eq 0 ]; then | 515 if [ $? -eq 0 ]; then |
| 491 exit_success | 516 exit_success |
| 492 else | 517 else |
| 493 exit_failure_operation_failed | 518 exit_failure_operation_failed |
| 494 fi | 519 fi |
| 495 } | 520 } |
| 496 | 521 |
| 497 info_gnome() | 522 info_gnome() |
| 498 { | 523 { |
| 499 file=`readlink -f "$1"` # Normalize path | |
| 500 | |
| 501 if gvfs-info --help 2>/dev/null 1>&2; then | 524 if gvfs-info --help 2>/dev/null 1>&2; then |
| 502 DEBUG 1 "Running gvfs-info \"$file\"" | 525 DEBUG 1 "Running gvfs-info \"$1\"" |
| 503 gvfs-info "$file" 2> /dev/null | grep standard::content-type | cut -d' '
-f4 | 526 gvfs-info "$1" 2> /dev/null | grep standard::content-type | cut -d' ' -f
4 |
| 527 elif gnomevfs-info --help 2>/dev/null 1>&2; then |
| 528 DEBUG 1 "Running gnomevfs-info \"$1\"" |
| 529 gnomevfs-info --slow-mime "$1" 2> /dev/null | grep "^MIME" | cut -d ":" -
f 2 | sed s/"^ "// |
| 504 else | 530 else |
| 505 DEBUG 1 "Running gnomevfs-info \"$file\"" | 531 # according to https://bugs.freedesktop.org/show_bug.cgi?id=33094#c5 |
| 506 gnomevfs-info --slow-mime "$file" 2> /dev/null | grep "^MIME" | cut -d ":
" -f 2 | sed s/"^ "// | 532 # neither gvfs-info or gnomevfs-info are present in a default Ubuntu Natt
y |
| 533 # install, so fallback to info_generic |
| 534 info_generic "$1" |
| 507 fi | 535 fi |
| 508 | 536 |
| 509 if [ $? -eq 0 ]; then | 537 if [ $? -eq 0 ]; then |
| 510 exit_success | 538 exit_success |
| 511 else | 539 else |
| 512 exit_failure_operation_failed | 540 exit_failure_operation_failed |
| 513 fi | 541 fi |
| 514 } | 542 } |
| 515 | 543 |
| 516 info_generic() | 544 info_generic() |
| 517 { | 545 { |
| 518 DEBUG 1 "Running file -i \"$1\"" | 546 if mimetype --version >/dev/null 2>&1; then |
| 519 /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "// | 547 DEBUG 1 "Running mimetype -b \"$1\"" |
| 548 mimetype -b "$1" |
| 549 else |
| 550 DEBUG 1 "Running file -i \"$1\"" |
| 551 /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "// |
| 552 fi |
| 520 | 553 |
| 521 if [ $? -eq 0 ]; then | 554 if [ $? -eq 0 ]; then |
| 522 exit_success | 555 exit_success |
| 523 else | 556 else |
| 524 exit_failure_operation_failed | 557 exit_failure_operation_failed |
| 525 fi | 558 fi |
| 526 } | 559 } |
| 527 | 560 |
| 528 make_default_kde() | 561 make_default_kde() |
| 529 { | 562 { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 filename="$2" | 778 filename="$2" |
| 746 if [ -z "$filename" ] ; then | 779 if [ -z "$filename" ] ; then |
| 747 exit_failure_syntax "FILE argument missing" | 780 exit_failure_syntax "FILE argument missing" |
| 748 fi | 781 fi |
| 749 case $filename in | 782 case $filename in |
| 750 -*) | 783 -*) |
| 751 exit_failure_syntax "unexpected option '$filename'" | 784 exit_failure_syntax "unexpected option '$filename'" |
| 752 ;; | 785 ;; |
| 753 esac | 786 esac |
| 754 check_input_file "$filename" | 787 check_input_file "$filename" |
| 788 filename=`readlink -f -- "$filename"` |
| 755 ;; | 789 ;; |
| 756 | 790 |
| 757 default) | 791 default) |
| 758 action=defapp | 792 action=defapp |
| 759 mimetype="$2" | 793 mimetype="$2" |
| 760 if [ -z "$mimetype" ] ; then | 794 if [ -z "$mimetype" ] ; then |
| 761 exit_failure_syntax "mimetype argument missing" | 795 exit_failure_syntax "mimetype argument missing" |
| 762 fi | 796 fi |
| 763 case $mimetype in | 797 case $mimetype in |
| 764 -*) | 798 -*) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 if [ -x /usr/bin/file ]; then | 872 if [ -x /usr/bin/file ]; then |
| 839 DE=generic | 873 DE=generic |
| 840 fi | 874 fi |
| 841 fi | 875 fi |
| 842 | 876 |
| 843 case "$DE" in | 877 case "$DE" in |
| 844 kde) | 878 kde) |
| 845 info_kde "$filename" | 879 info_kde "$filename" |
| 846 ;; | 880 ;; |
| 847 | 881 |
| 848 gnome) | 882 gnome*) |
| 849 info_gnome "$filename" | 883 info_gnome "$filename" |
| 850 ;; | 884 ;; |
| 851 | 885 |
| 852 *) | 886 *) |
| 853 info_generic "$filename" | 887 info_generic "$filename" |
| 854 ;; | 888 ;; |
| 855 esac | 889 esac |
| 856 exit_failure_operation_impossible "no method available for quering MIME type
of '$filename'" | 890 exit_failure_operation_impossible "no method available for quering MIME type
of '$filename'" |
| 857 fi | 891 fi |
| 858 | 892 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 rm -f $kde_dir/$x.desktop | 1241 rm -f $kde_dir/$x.desktop |
| 1208 fi | 1242 fi |
| 1209 done | 1243 done |
| 1210 ;; | 1244 ;; |
| 1211 esac | 1245 esac |
| 1212 | 1246 |
| 1213 update_mime_database $xdg_base_dir | 1247 update_mime_database $xdg_base_dir |
| 1214 | 1248 |
| 1215 exit_success | 1249 exit_success |
| 1216 | 1250 |
| OLD | NEW |