OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 #--------------------------------------------- | 2 #--------------------------------------------- |
3 # xdg-icon-resource | 3 # xdg-icon-resource |
4 # | 4 # |
5 # Utility script to install icons on a Linux desktop. | 5 # Utility script to install icons on a Linux desktop. |
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-2010, Fathi Boudra <fabo@freedesktop.org> | 9 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> |
10 # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org> | 10 # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org> |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 #---------------------------------------------------------------------------- | 207 #---------------------------------------------------------------------------- |
208 | 208 |
209 DEBUG() | 209 DEBUG() |
210 { | 210 { |
211 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; | 211 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; |
212 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; | 212 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; |
213 shift | 213 shift |
214 echo "$@" >&2 | 214 echo "$@" >&2 |
215 } | 215 } |
216 | 216 |
| 217 # This handles backslashes but not quote marks. |
| 218 first_word() |
| 219 { |
| 220 read first rest |
| 221 echo "$first" |
| 222 } |
| 223 |
| 224 #------------------------------------------------------------- |
| 225 # map a binary to a .desktop file |
| 226 binary_to_desktop_file() |
| 227 { |
| 228 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 229 binary="`which "$1"`" |
| 230 binary="`readlink -f "$binary"`" |
| 231 base="`basename "$binary"`" |
| 232 IFS=: |
| 233 for dir in $search; do |
| 234 unset IFS |
| 235 [ "$dir" ] || continue |
| 236 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue |
| 237 for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.deskto
p "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do |
| 238 [ -r "$file" ] || continue |
| 239 # Check to make sure it's worth the processing. |
| 240 grep -q "^Exec.*$base" "$file" || continue |
| 241 # Make sure it's a visible desktop file (e.g. not "preferred-web-bro
wser.desktop"). |
| 242 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue |
| 243 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | fir
st_word`" |
| 244 command="`which "$command"`" |
| 245 if [ x"`readlink -f "$command"`" = x"$binary" ]; then |
| 246 # Fix any double slashes that got added path composition |
| 247 echo "$file" | sed -e 's,//*,/,g' |
| 248 return |
| 249 fi |
| 250 done |
| 251 done |
| 252 } |
| 253 |
| 254 #------------------------------------------------------------- |
| 255 # map a .desktop file to a binary |
| 256 ## FIXME: handle vendor dir case |
| 257 desktop_file_to_binary() |
| 258 { |
| 259 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 260 desktop="`basename "$1"`" |
| 261 IFS=: |
| 262 for dir in $search; do |
| 263 unset IFS |
| 264 [ "$dir" -a -d "$dir/applications" ] || continue |
| 265 file="$dir/applications/$desktop" |
| 266 [ -r "$file" ] || continue |
| 267 # Remove any arguments (%F, %f, %U, %u, etc.). |
| 268 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_w
ord`" |
| 269 command="`which "$command"`" |
| 270 readlink -f "$command" |
| 271 return |
| 272 done |
| 273 } |
| 274 |
217 #------------------------------------------------------------- | 275 #------------------------------------------------------------- |
218 # Exit script on successfully completing the desired operation | 276 # Exit script on successfully completing the desired operation |
219 | 277 |
220 exit_success() | 278 exit_success() |
221 { | 279 { |
222 if [ $# -gt 0 ]; then | 280 if [ $# -gt 0 ]; then |
223 echo "$@" | 281 echo "$@" |
224 echo | 282 echo |
225 fi | 283 fi |
226 | 284 |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 if [ x"$update" = x"yes" ] ; then | 924 if [ x"$update" = x"yes" ] ; then |
867 update_icon_database "$xdg_base_dir" | 925 update_icon_database "$xdg_base_dir" |
868 if [ -n "$dot_icon_dir" ] ; then | 926 if [ -n "$dot_icon_dir" ] ; then |
869 if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then | 927 if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then |
870 update_icon_database $dot_base_dir | 928 update_icon_database $dot_base_dir |
871 fi | 929 fi |
872 fi | 930 fi |
873 fi | 931 fi |
874 | 932 |
875 exit_success | 933 exit_success |
OLD | NEW |