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

Side by Side Diff: scripts/xdg-settings

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-screensaver ('k') | scripts/xdg-settings.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-settings 3 # xdg-settings
4 # 4 #
5 # Utility script to get various settings from the desktop environment. 5 # Utility script to get various settings from the desktop environment.
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, Google Inc. 9 # Copyright 2009, Google Inc.
10 # 10 #
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 #---------------------------------------------------------------------------- 122 #----------------------------------------------------------------------------
123 123
124 DEBUG() 124 DEBUG()
125 { 125 {
126 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; 126 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
127 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; 127 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
128 shift 128 shift
129 echo "$@" >&2 129 echo "$@" >&2
130 } 130 }
131 131
132 # This handles backslashes but not quote marks.
133 first_word()
134 {
135 read first rest
136 echo "$first"
137 }
138
139 #-------------------------------------------------------------
140 # map a binary to a .desktop file
141 binary_to_desktop_file()
142 {
143 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha re:/usr/share}"
144 binary="`which "$1"`"
145 binary="`readlink -f "$binary"`"
146 base="`basename "$binary"`"
147 IFS=:
148 for dir in $search; do
149 unset IFS
150 [ "$dir" ] || continue
151 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue
152 for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.deskto p "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
153 [ -r "$file" ] || continue
154 # Check to make sure it's worth the processing.
155 grep -q "^Exec.*$base" "$file" || continue
156 # Make sure it's a visible desktop file (e.g. not "preferred-web-bro wser.desktop").
157 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
158 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | fir st_word`"
159 command="`which "$command"`"
160 if [ x"`readlink -f "$command"`" = x"$binary" ]; then
161 # Fix any double slashes that got added path composition
162 echo "$file" | sed -e 's,//*,/,g'
163 return
164 fi
165 done
166 done
167 }
168
169 #-------------------------------------------------------------
170 # map a .desktop file to a binary
171 ## FIXME: handle vendor dir case
172 desktop_file_to_binary()
173 {
174 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha re:/usr/share}"
175 desktop="`basename "$1"`"
176 IFS=:
177 for dir in $search; do
178 unset IFS
179 [ "$dir" -a -d "$dir/applications" ] || continue
180 file="$dir/applications/$desktop"
181 [ -r "$file" ] || continue
182 # Remove any arguments (%F, %f, %U, %u, etc.).
183 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_w ord`"
184 command="`which "$command"`"
185 readlink -f "$command"
186 return
187 done
188 }
189
132 #------------------------------------------------------------- 190 #-------------------------------------------------------------
133 # Exit script on successfully completing the desired operation 191 # Exit script on successfully completing the desired operation
134 192
135 exit_success() 193 exit_success()
136 { 194 {
137 if [ $# -gt 0 ]; then 195 if [ $# -gt 0 ]; then
138 echo "$@" 196 echo "$@"
139 echo 197 echo
140 fi 198 fi
141 199
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 ;; 438 ;;
381 *) 439 *)
382 exit_failure_syntax "invalid application name" 440 exit_failure_syntax "invalid application name"
383 ;; 441 ;;
384 esac 442 esac
385 } 443 }
386 444
387 # {{{ default browser 445 # {{{ default browser
388 # {{{ utility functions 446 # {{{ utility functions
389 447
390 # This handles backslashes but not quote marks.
391 first_word()
392 {
393 read first rest
394 echo "$first"
395 }
396
397 binary_to_desktop_file()
398 {
399 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha re:/usr/share}"
400 binary="`which "$1"`"
401 binary="`readlink -f "$binary"`"
402 base="`basename "$binary"`"
403 IFS=:
404 for dir in $search; do
405 unset IFS
406 [ "$dir" ] || continue
407 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue
408 for file in "$dir"/applications/*.desktop "$dir"/applnk/*.desktop; do
409 [ -r "$file" ] || continue
410 # Check to make sure it's worth the processing.
411 grep -q "^Exec.*$base" "$file" || continue
412 # Make sure it's a visible desktop file (e.g. not "preferred-web-bro wser.desktop").
413 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
414 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | fir st_word`"
415 command="`which "$command"`"
416 if [ x"`readlink -f "$command"`" = x"$binary" ]; then
417 # Fix any double slashes that got added path composition
418 echo "$file" | sed -e 's,//*,/,g'
419 return
420 fi
421 done
422 done
423 }
424
425 desktop_file_to_binary()
426 {
427 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha re:/usr/share}"
428 desktop="`basename "$1"`"
429 IFS=:
430 for dir in $search; do
431 unset IFS
432 [ "$dir" -a -d "$dir/applications" ] || continue
433 file="$dir/applications/$desktop"
434 [ -r "$file" ] || continue
435 # Remove any arguments (%F, %f, %U, %u, etc.).
436 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_w ord`"
437 command="`which "$command"`"
438 readlink -f "$command"
439 return
440 done
441 }
442
443 # In order to remove an application from the automatically-generated list of 448 # In order to remove an application from the automatically-generated list of
444 # applications for handling a given MIME type, the desktop environment may copy 449 # applications for handling a given MIME type, the desktop environment may copy
445 # the global .desktop file into the user's .local directory, and remove that 450 # the global .desktop file into the user's .local directory, and remove that
446 # MIME type from its list. In that case, we must restore the MIME type to the 451 # MIME type from its list. In that case, we must restore the MIME type to the
447 # application's list of MIME types before we can set it as the default for that 452 # application's list of MIME types before we can set it as the default for that
448 # MIME type. (We can't just delete the local version, since the user may have 453 # MIME type. (We can't just delete the local version, since the user may have
449 # made other changes to it as well. So, tweak the existing file.) 454 # made other changes to it as well. So, tweak the existing file.)
450 # This function is hard-coded for text/html but it could be adapted if needed. 455 # This function is hard-coded for text/html but it could be adapted if needed.
451 fix_local_desktop_file() 456 fix_local_desktop_file()
452 { 457 {
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 ;; 956 ;;
952 957
953 generic) 958 generic)
954 dispatch_generic "$@" 959 dispatch_generic "$@"
955 ;; 960 ;;
956 961
957 *) 962 *)
958 exit_failure_operation_impossible "unknown desktop environment" 963 exit_failure_operation_impossible "unknown desktop environment"
959 ;; 964 ;;
960 esac 965 esac
OLDNEW
« no previous file with comments | « scripts/xdg-screensaver ('k') | scripts/xdg-settings.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698