OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 #--------------------------------------------- | 2 #--------------------------------------------- |
3 # xdg-email | 3 # xdg-email |
4 # | 4 # |
5 # Utility script to open the users favorite email program, using the | 5 # Utility script to open the users favorite email program, using the |
6 # RFC 2368 mailto: URI spec | 6 # RFC 2368 mailto: URI spec |
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 #---------------------------------------------------------------------------- | 167 #---------------------------------------------------------------------------- |
168 | 168 |
169 DEBUG() | 169 DEBUG() |
170 { | 170 { |
171 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; | 171 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; |
172 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; | 172 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; |
173 shift | 173 shift |
174 echo "$@" >&2 | 174 echo "$@" >&2 |
175 } | 175 } |
176 | 176 |
| 177 # This handles backslashes but not quote marks. |
| 178 first_word() |
| 179 { |
| 180 read first rest |
| 181 echo "$first" |
| 182 } |
| 183 |
| 184 #------------------------------------------------------------- |
| 185 # map a binary to a .desktop file |
| 186 binary_to_desktop_file() |
| 187 { |
| 188 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 189 binary="`which "$1"`" |
| 190 binary="`readlink -f "$binary"`" |
| 191 base="`basename "$binary"`" |
| 192 IFS=: |
| 193 for dir in $search; do |
| 194 unset IFS |
| 195 [ "$dir" ] || continue |
| 196 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue |
| 197 for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.deskto
p "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do |
| 198 [ -r "$file" ] || continue |
| 199 # Check to make sure it's worth the processing. |
| 200 grep -q "^Exec.*$base" "$file" || continue |
| 201 # Make sure it's a visible desktop file (e.g. not "preferred-web-bro
wser.desktop"). |
| 202 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue |
| 203 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | fir
st_word`" |
| 204 command="`which "$command"`" |
| 205 if [ x"`readlink -f "$command"`" = x"$binary" ]; then |
| 206 # Fix any double slashes that got added path composition |
| 207 echo "$file" | sed -e 's,//*,/,g' |
| 208 return |
| 209 fi |
| 210 done |
| 211 done |
| 212 } |
| 213 |
| 214 #------------------------------------------------------------- |
| 215 # map a .desktop file to a binary |
| 216 ## FIXME: handle vendor dir case |
| 217 desktop_file_to_binary() |
| 218 { |
| 219 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 220 desktop="`basename "$1"`" |
| 221 IFS=: |
| 222 for dir in $search; do |
| 223 unset IFS |
| 224 [ "$dir" -a -d "$dir/applications" ] || continue |
| 225 file="$dir/applications/$desktop" |
| 226 [ -r "$file" ] || continue |
| 227 # Remove any arguments (%F, %f, %U, %u, etc.). |
| 228 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_w
ord`" |
| 229 command="`which "$command"`" |
| 230 readlink -f "$command" |
| 231 return |
| 232 done |
| 233 } |
| 234 |
177 #------------------------------------------------------------- | 235 #------------------------------------------------------------- |
178 # Exit script on successfully completing the desired operation | 236 # Exit script on successfully completing the desired operation |
179 | 237 |
180 exit_success() | 238 exit_success() |
181 { | 239 { |
182 if [ $# -gt 0 ]; then | 240 if [ $# -gt 0 ]; then |
183 echo "$@" | 241 echo "$@" |
184 echo | 242 echo |
185 fi | 243 fi |
186 | 244 |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 ;; | 837 ;; |
780 | 838 |
781 generic|lxde) | 839 generic|lxde) |
782 open_generic "${mailto}" | 840 open_generic "${mailto}" |
783 ;; | 841 ;; |
784 | 842 |
785 *) | 843 *) |
786 exit_failure_operation_impossible "no method available for opening '${mailto
}'" | 844 exit_failure_operation_impossible "no method available for opening '${mailto
}'" |
787 ;; | 845 ;; |
788 esac | 846 esac |
OLD | NEW |