OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 #--------------------------------------------- | 2 #--------------------------------------------- |
3 # xdg-desktop-menu | 3 # xdg-desktop-menu |
4 # | 4 # |
5 # Utility script to install menu items on a Linux desktop. | 5 # Utility script to install menu items on a Linux desktop. |
6 # Refer to the usage() function below for usage. | 6 # Refer to the usage() function below for usage. |
7 # | 7 # |
8 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> | 8 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> |
9 # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org> | 9 # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org> |
10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> | 10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 #---------------------------------------------------------------------------- | 411 #---------------------------------------------------------------------------- |
412 | 412 |
413 DEBUG() | 413 DEBUG() |
414 { | 414 { |
415 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; | 415 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; |
416 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; | 416 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; |
417 shift | 417 shift |
418 echo "$@" >&2 | 418 echo "$@" >&2 |
419 } | 419 } |
420 | 420 |
| 421 # This handles backslashes but not quote marks. |
| 422 first_word() |
| 423 { |
| 424 read first rest |
| 425 echo "$first" |
| 426 } |
| 427 |
| 428 #------------------------------------------------------------- |
| 429 # map a binary to a .desktop file |
| 430 binary_to_desktop_file() |
| 431 { |
| 432 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 433 binary="`which "$1"`" |
| 434 binary="`readlink -f "$binary"`" |
| 435 base="`basename "$binary"`" |
| 436 IFS=: |
| 437 for dir in $search; do |
| 438 unset IFS |
| 439 [ "$dir" ] || continue |
| 440 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue |
| 441 for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.deskto
p "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do |
| 442 [ -r "$file" ] || continue |
| 443 # Check to make sure it's worth the processing. |
| 444 grep -q "^Exec.*$base" "$file" || continue |
| 445 # Make sure it's a visible desktop file (e.g. not "preferred-web-bro
wser.desktop"). |
| 446 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue |
| 447 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | fir
st_word`" |
| 448 command="`which "$command"`" |
| 449 if [ x"`readlink -f "$command"`" = x"$binary" ]; then |
| 450 # Fix any double slashes that got added path composition |
| 451 echo "$file" | sed -e 's,//*,/,g' |
| 452 return |
| 453 fi |
| 454 done |
| 455 done |
| 456 } |
| 457 |
| 458 #------------------------------------------------------------- |
| 459 # map a .desktop file to a binary |
| 460 ## FIXME: handle vendor dir case |
| 461 desktop_file_to_binary() |
| 462 { |
| 463 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 464 desktop="`basename "$1"`" |
| 465 IFS=: |
| 466 for dir in $search; do |
| 467 unset IFS |
| 468 [ "$dir" -a -d "$dir/applications" ] || continue |
| 469 file="$dir/applications/$desktop" |
| 470 [ -r "$file" ] || continue |
| 471 # Remove any arguments (%F, %f, %U, %u, etc.). |
| 472 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_w
ord`" |
| 473 command="`which "$command"`" |
| 474 readlink -f "$command" |
| 475 return |
| 476 done |
| 477 } |
| 478 |
421 #------------------------------------------------------------- | 479 #------------------------------------------------------------- |
422 # Exit script on successfully completing the desired operation | 480 # Exit script on successfully completing the desired operation |
423 | 481 |
424 exit_success() | 482 exit_success() |
425 { | 483 { |
426 if [ $# -gt 0 ]; then | 484 if [ $# -gt 0 ]; then |
427 echo "$@" | 485 echo "$@" |
428 echo | 486 echo |
429 fi | 487 fi |
430 | 488 |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 | 1307 |
1250 ;; | 1308 ;; |
1251 esac | 1309 esac |
1252 done | 1310 done |
1253 | 1311 |
1254 if [ x"$update" = x"yes" ] ; then | 1312 if [ x"$update" = x"yes" ] ; then |
1255 update_desktop_database | 1313 update_desktop_database |
1256 fi | 1314 fi |
1257 | 1315 |
1258 exit_success | 1316 exit_success |
OLD | NEW |