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

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
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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 603 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') | scripts/xdg-mime.in » ('J')

Powered by Google App Engine
This is Rietveld 408576698