OLD | NEW |
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 default_dir=`kde-config --path config 2> /dev/null | cut -d ':' -f 1` | 138 default_dir=`kde-config --path config 2> /dev/null | cut -d ':' -f 1` |
139 default_file="$default_dir/profilerc" | 139 default_file="$default_dir/profilerc" |
140 fi | 140 fi |
141 if [ -z "$default_dir" ]; then | 141 if [ -z "$default_dir" ]; then |
142 DEBUG 2 "make_default_kde: No kde runtime detected" | 142 DEBUG 2 "make_default_kde: No kde runtime detected" |
143 return | 143 return |
144 fi | 144 fi |
145 DEBUG 2 "make_default_kde $vendor $mimetype" | 145 DEBUG 2 "make_default_kde $vendor $mimetype" |
146 DEBUG 1 "Updating $default_file" | 146 DEBUG 1 "Updating $default_file" |
147 mkdir -p "$default_dir" | 147 mkdir -p "$default_dir" |
148 [ -f $default_file ] || touch $default_file | 148 [ -f "$default_file" ] || touch "$default_file" |
149 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then | 149 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
150 [ -f $default_file ] || touch $default_file | 150 [ -f "$default_file" ] || touch "$default_file" |
151 awk -v application="$vendor" -v mimetype="$mimetype" ' | 151 awk -v application="$vendor" -v mimetype="$mimetype" ' |
152 BEGIN { | 152 BEGIN { |
153 prefix=mimetype "=" | 153 prefix=mimetype "=" |
154 associations=0 | 154 associations=0 |
155 found=0 | 155 found=0 |
156 blanks=0 | 156 blanks=0 |
157 } | 157 } |
158 { | 158 { |
159 suppress=0 | 159 suppress=0 |
160 if (index($0, "[Added Associations]") == 1) { | 160 if (index($0, "[Added Associations]") == 1) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (!associations) { | 197 if (!associations) { |
198 print "[Added Associations]" | 198 print "[Added Associations]" |
199 } | 199 } |
200 print prefix application | 200 print prefix application |
201 } | 201 } |
202 while (blanks > 0) { | 202 while (blanks > 0) { |
203 print "" | 203 print "" |
204 blanks-- | 204 blanks-- |
205 } | 205 } |
206 } | 206 } |
207 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file | 207 ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_
file" |
208 eval 'kbuildsycoca4'$xdg_redirect_output | 208 eval 'kbuildsycoca4'$xdg_redirect_output |
209 else | 209 else |
210 awk -v application="$vendor" -v mimetype="$mimetype" ' | 210 awk -v application="$vendor" -v mimetype="$mimetype" ' |
211 BEGIN { | 211 BEGIN { |
212 header_start="[" mimetype " - " | 212 header_start="[" mimetype " - " |
213 suppress=0 | 213 suppress=0 |
214 } | 214 } |
215 { | 215 { |
216 if (index($0, header_start) == 1 ) | 216 if (index($0, header_start) == 1 ) |
217 suppress=1 | 217 suppress=1 |
218 else | 218 else |
219 if (/^\[/) { suppress=0 } | 219 if (/^\[/) { suppress=0 } |
220 | 220 |
221 if (!suppress) { | 221 if (!suppress) { |
222 print $0 | 222 print $0 |
223 } | 223 } |
224 } | 224 } |
225 END { | 225 END { |
226 print "" | 226 print "" |
227 print "[" mimetype " - 1]" | 227 print "[" mimetype " - 1]" |
228 print "Application=" application | 228 print "Application=" application |
229 print "AllowAsDefault=true" | 229 print "AllowAsDefault=true" |
230 print "GenericServiceType=Application" | 230 print "GenericServiceType=Application" |
231 print "Preference=1" | 231 print "Preference=1" |
232 print "ServiceType=" mimetype | 232 print "ServiceType=" mimetype |
233 } | 233 } |
234 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file | 234 ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_
file" |
235 fi | 235 fi |
236 } | 236 } |
237 | 237 |
238 make_default_generic() | 238 make_default_generic() |
239 { | 239 { |
240 # $1 is vendor-name.desktop | 240 # $1 is vendor-name.desktop |
241 # $2 is mime/type | 241 # $2 is mime/type |
242 # Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list | 242 # Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list |
243 xdg_user_dir="$XDG_DATA_HOME" | 243 xdg_user_dir="$XDG_DATA_HOME" |
244 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" | 244 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" |
245 default_file="$xdg_user_dir/applications/mimeapps.list" | 245 default_file="$xdg_user_dir/applications/mimeapps.list" |
246 DEBUG 2 "make_default_generic $1 $2" | 246 DEBUG 2 "make_default_generic $1 $2" |
247 DEBUG 1 "Updating $default_file" | 247 DEBUG 1 "Updating $default_file" |
| 248 [ -f "$default_file" ] || touch "$default_file" |
248 awk -v mimetype="$2" -v application="$1" ' | 249 awk -v mimetype="$2" -v application="$1" ' |
249 BEGIN { | 250 BEGIN { |
250 prefix=mimetype "=" | 251 prefix=mimetype "=" |
251 indefault=0 | 252 indefault=0 |
252 added=0 | 253 added=0 |
253 blanks=0 | 254 blanks=0 |
254 found=0 | 255 found=0 |
255 } | 256 } |
256 { | 257 { |
257 suppress=0 | 258 suppress=0 |
(...skipping 27 matching lines...) Expand all Loading... |
285 print "" | 286 print "" |
286 print "[Default Applications]" | 287 print "[Default Applications]" |
287 } | 288 } |
288 print prefix application | 289 print prefix application |
289 } | 290 } |
290 while (blanks > 0) { | 291 while (blanks > 0) { |
291 print "" | 292 print "" |
292 blanks-- | 293 blanks-- |
293 } | 294 } |
294 } | 295 } |
295 ' $default_file > ${default_file}.new && mv ${default_file}.new $default_file | 296 ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_
file" |
296 } | 297 } |
297 | 298 |
298 defapp_generic() | 299 defapp_generic() |
299 { | 300 { |
300 MIME="$1" | 301 MIME="$1" |
301 xdg_user_dir="$XDG_DATA_HOME" | 302 xdg_user_dir="$XDG_DATA_HOME" |
302 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" | 303 [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" |
303 xdg_user_dir="$xdg_user_dir/$xdg_dir_name" | 304 xdg_user_dir="$xdg_user_dir/$xdg_dir_name" |
304 xdg_system_dirs="$XDG_DATA_DIRS" | 305 xdg_system_dirs="$XDG_DATA_DIRS" |
305 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ | 306 [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 rm -f $kde_dir/$x.desktop | 862 rm -f $kde_dir/$x.desktop |
862 fi | 863 fi |
863 done | 864 done |
864 ;; | 865 ;; |
865 esac | 866 esac |
866 | 867 |
867 update_mime_database $xdg_base_dir | 868 update_mime_database $xdg_base_dir |
868 | 869 |
869 exit_success | 870 exit_success |
870 | 871 |
OLD | NEW |