Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: scripts/xdg-mime

Issue 6928018: Linux: update xdg-utils to the latest git version and include a one-line fix in xdg-mime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/xdg-utils/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scripts/xdg-icon-resource ('k') | scripts/xdg-mime.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 #---------------------------------------------------------------------------- 237 #----------------------------------------------------------------------------
238 238
239 DEBUG() 239 DEBUG()
240 { 240 {
241 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; 241 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
242 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; 242 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
243 shift 243 shift
244 echo "$@" >&2 244 echo "$@" >&2
245 } 245 }
246 246
247 # This handles backslashes but not quote marks.
248 first_word()
249 {
250 read first rest
251 echo "$first"
252 }
253
254 #-------------------------------------------------------------
255 # map a binary to a .desktop file
256 binary_to_desktop_file()
257 {
258 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha re:/usr/share}"
259 binary="`which "$1"`"
260 binary="`readlink -f "$binary"`"
261 base="`basename "$binary"`"
262 IFS=:
263 for dir in $search; do
264 unset IFS
265 [ "$dir" ] || continue
266 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue
267 for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.deskto p "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
268 [ -r "$file" ] || continue
269 # Check to make sure it's worth the processing.
270 grep -q "^Exec.*$base" "$file" || continue
271 # Make sure it's a visible desktop file (e.g. not "preferred-web-bro wser.desktop").
272 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
273 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | fir st_word`"
274 command="`which "$command"`"
275 if [ x"`readlink -f "$command"`" = x"$binary" ]; then
276 # Fix any double slashes that got added path composition
277 echo "$file" | sed -e 's,//*,/,g'
278 return
279 fi
280 done
281 done
282 }
283
284 #-------------------------------------------------------------
285 # map a .desktop file to a binary
286 ## FIXME: handle vendor dir case
287 desktop_file_to_binary()
288 {
289 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha re:/usr/share}"
290 desktop="`basename "$1"`"
291 IFS=:
292 for dir in $search; do
293 unset IFS
294 [ "$dir" -a -d "$dir/applications" ] || continue
295 file="$dir/applications/$desktop"
296 [ -r "$file" ] || continue
297 # Remove any arguments (%F, %f, %U, %u, etc.).
298 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_w ord`"
299 command="`which "$command"`"
300 readlink -f "$command"
301 return
302 done
303 }
304
247 #------------------------------------------------------------- 305 #-------------------------------------------------------------
248 # Exit script on successfully completing the desired operation 306 # Exit script on successfully completing the desired operation
249 307
250 exit_success() 308 exit_success()
251 { 309 {
252 if [ $# -gt 0 ]; then 310 if [ $# -gt 0 ]; then
253 echo "$@" 311 echo "$@"
254 echo 312 echo
255 fi 313 fi
256 314
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 default_dir=`kde-config --path config 2> /dev/null | cut -d ':' -f 1` 650 default_dir=`kde-config --path config 2> /dev/null | cut -d ':' -f 1`
593 default_file="$default_dir/profilerc" 651 default_file="$default_dir/profilerc"
594 fi 652 fi
595 if [ -z "$default_dir" ]; then 653 if [ -z "$default_dir" ]; then
596 DEBUG 2 "make_default_kde: No kde runtime detected" 654 DEBUG 2 "make_default_kde: No kde runtime detected"
597 return 655 return
598 fi 656 fi
599 DEBUG 2 "make_default_kde $vendor $mimetype" 657 DEBUG 2 "make_default_kde $vendor $mimetype"
600 DEBUG 1 "Updating $default_file" 658 DEBUG 1 "Updating $default_file"
601 mkdir -p "$default_dir" 659 mkdir -p "$default_dir"
602 [ -f $default_file ] || touch $default_file 660 [ -f "$default_file" ] || touch "$default_file"
603 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then 661 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
604 [ -f $default_file ] || touch $default_file 662 [ -f "$default_file" ] || touch "$default_file"
605 awk -v application="$vendor" -v mimetype="$mimetype" ' 663 awk -v application="$vendor" -v mimetype="$mimetype" '
606 BEGIN { 664 BEGIN {
607 prefix=mimetype "=" 665 prefix=mimetype "="
608 associations=0 666 associations=0
609 found=0 667 found=0
610 blanks=0 668 blanks=0
611 } 669 }
612 { 670 {
613 suppress=0 671 suppress=0
614 if (index($0, "[Added Associations]") == 1) { 672 if (index($0, "[Added Associations]") == 1) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (!associations) { 709 if (!associations) {
652 print "[Added Associations]" 710 print "[Added Associations]"
653 } 711 }
654 print prefix application 712 print prefix application
655 } 713 }
656 while (blanks > 0) { 714 while (blanks > 0) {
657 print "" 715 print ""
658 blanks-- 716 blanks--
659 } 717 }
660 } 718 }
661 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file 719 ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_ file"
662 eval 'kbuildsycoca4'$xdg_redirect_output 720 eval 'kbuildsycoca4'$xdg_redirect_output
663 else 721 else
664 awk -v application="$vendor" -v mimetype="$mimetype" ' 722 awk -v application="$vendor" -v mimetype="$mimetype" '
665 BEGIN { 723 BEGIN {
666 header_start="[" mimetype " - " 724 header_start="[" mimetype " - "
667 suppress=0 725 suppress=0
668 } 726 }
669 { 727 {
670 if (index($0, header_start) == 1 ) 728 if (index($0, header_start) == 1 )
671 suppress=1 729 suppress=1
672 else 730 else
673 if (/^\[/) { suppress=0 } 731 if (/^\[/) { suppress=0 }
674 732
675 if (!suppress) { 733 if (!suppress) {
676 print $0 734 print $0
677 } 735 }
678 } 736 }
679 END { 737 END {
680 print "" 738 print ""
681 print "[" mimetype " - 1]" 739 print "[" mimetype " - 1]"
682 print "Application=" application 740 print "Application=" application
683 print "AllowAsDefault=true" 741 print "AllowAsDefault=true"
684 print "GenericServiceType=Application" 742 print "GenericServiceType=Application"
685 print "Preference=1" 743 print "Preference=1"
686 print "ServiceType=" mimetype 744 print "ServiceType=" mimetype
687 } 745 }
688 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file 746 ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_ file"
689 fi 747 fi
690 } 748 }
691 749
692 make_default_generic() 750 make_default_generic()
693 { 751 {
694 # $1 is vendor-name.desktop 752 # $1 is vendor-name.desktop
695 # $2 is mime/type 753 # $2 is mime/type
696 # Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list 754 # Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list
697 xdg_user_dir="$XDG_DATA_HOME" 755 xdg_user_dir="$XDG_DATA_HOME"
698 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" 756 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
699 default_file="$xdg_user_dir/applications/mimeapps.list" 757 default_file="$xdg_user_dir/applications/mimeapps.list"
700 DEBUG 2 "make_default_generic $1 $2" 758 DEBUG 2 "make_default_generic $1 $2"
701 DEBUG 1 "Updating $default_file" 759 DEBUG 1 "Updating $default_file"
760 [ -f "$default_file" ] || touch "$default_file"
702 awk -v mimetype="$2" -v application="$1" ' 761 awk -v mimetype="$2" -v application="$1" '
703 BEGIN { 762 BEGIN {
704 prefix=mimetype "=" 763 prefix=mimetype "="
705 indefault=0 764 indefault=0
706 added=0 765 added=0
707 blanks=0 766 blanks=0
708 found=0 767 found=0
709 } 768 }
710 { 769 {
711 suppress=0 770 suppress=0
(...skipping 27 matching lines...) Expand all
739 print "" 798 print ""
740 print "[Default Applications]" 799 print "[Default Applications]"
741 } 800 }
742 print prefix application 801 print prefix application
743 } 802 }
744 while (blanks > 0) { 803 while (blanks > 0) {
745 print "" 804 print ""
746 blanks-- 805 blanks--
747 } 806 }
748 } 807 }
749 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file 808 ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_ file"
750 } 809 }
751 810
752 defapp_generic() 811 defapp_generic()
753 { 812 {
754 MIME="$1" 813 MIME="$1"
755 xdg_user_dir="$XDG_DATA_HOME" 814 xdg_user_dir="$XDG_DATA_HOME"
756 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" 815 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
757 xdg_user_dir="$xdg_user_dir/$xdg_dir_name" 816 xdg_user_dir="$xdg_user_dir/$xdg_dir_name"
758 xdg_system_dirs="$XDG_DATA_DIRS" 817 xdg_system_dirs="$XDG_DATA_DIRS"
759 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ 818 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 rm -f $kde_dir/$x.desktop 1374 rm -f $kde_dir/$x.desktop
1316 fi 1375 fi
1317 done 1376 done
1318 ;; 1377 ;;
1319 esac 1378 esac
1320 1379
1321 update_mime_database $xdg_base_dir 1380 update_mime_database $xdg_base_dir
1322 1381
1323 exit_success 1382 exit_success
1324 1383
OLDNEW
« no previous file with comments | « scripts/xdg-icon-resource ('k') | scripts/xdg-mime.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698