OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 #--------------------------------------------- | 2 #--------------------------------------------- |
3 # xdg-open | 3 # xdg-open |
4 # | 4 # |
5 # Utility script to open a URL in the registered default application. | 5 # Utility script to open a URL in the registered default application. |
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 #---------------------------------------------------------------------------- | 114 #---------------------------------------------------------------------------- |
115 | 115 |
116 DEBUG() | 116 DEBUG() |
117 { | 117 { |
118 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; | 118 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; |
119 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; | 119 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; |
120 shift | 120 shift |
121 echo "$@" >&2 | 121 echo "$@" >&2 |
122 } | 122 } |
123 | 123 |
| 124 # This handles backslashes but not quote marks. |
| 125 first_word() |
| 126 { |
| 127 read first rest |
| 128 echo "$first" |
| 129 } |
| 130 |
| 131 #------------------------------------------------------------- |
| 132 # map a binary to a .desktop file |
| 133 binary_to_desktop_file() |
| 134 { |
| 135 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 136 binary="`which "$1"`" |
| 137 binary="`readlink -f "$binary"`" |
| 138 base="`basename "$binary"`" |
| 139 IFS=: |
| 140 for dir in $search; do |
| 141 unset IFS |
| 142 [ "$dir" ] || continue |
| 143 [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue |
| 144 for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.deskto
p "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do |
| 145 [ -r "$file" ] || continue |
| 146 # Check to make sure it's worth the processing. |
| 147 grep -q "^Exec.*$base" "$file" || continue |
| 148 # Make sure it's a visible desktop file (e.g. not "preferred-web-bro
wser.desktop"). |
| 149 grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue |
| 150 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | fir
st_word`" |
| 151 command="`which "$command"`" |
| 152 if [ x"`readlink -f "$command"`" = x"$binary" ]; then |
| 153 # Fix any double slashes that got added path composition |
| 154 echo "$file" | sed -e 's,//*,/,g' |
| 155 return |
| 156 fi |
| 157 done |
| 158 done |
| 159 } |
| 160 |
| 161 #------------------------------------------------------------- |
| 162 # map a .desktop file to a binary |
| 163 ## FIXME: handle vendor dir case |
| 164 desktop_file_to_binary() |
| 165 { |
| 166 search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/sha
re:/usr/share}" |
| 167 desktop="`basename "$1"`" |
| 168 IFS=: |
| 169 for dir in $search; do |
| 170 unset IFS |
| 171 [ "$dir" -a -d "$dir/applications" ] || continue |
| 172 file="$dir/applications/$desktop" |
| 173 [ -r "$file" ] || continue |
| 174 # Remove any arguments (%F, %f, %U, %u, etc.). |
| 175 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_w
ord`" |
| 176 command="`which "$command"`" |
| 177 readlink -f "$command" |
| 178 return |
| 179 done |
| 180 } |
| 181 |
124 #------------------------------------------------------------- | 182 #------------------------------------------------------------- |
125 # Exit script on successfully completing the desired operation | 183 # Exit script on successfully completing the desired operation |
126 | 184 |
127 exit_success() | 185 exit_success() |
128 { | 186 { |
129 if [ $# -gt 0 ]; then | 187 if [ $# -gt 0 ]; then |
130 echo "$@" | 188 echo "$@" |
131 echo | 189 echo |
132 fi | 190 fi |
133 | 191 |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 ;; | 669 ;; |
612 | 670 |
613 generic) | 671 generic) |
614 open_generic "$url" | 672 open_generic "$url" |
615 ;; | 673 ;; |
616 | 674 |
617 *) | 675 *) |
618 exit_failure_operation_impossible "no method available for opening '$url'" | 676 exit_failure_operation_impossible "no method available for opening '$url'" |
619 ;; | 677 ;; |
620 esac | 678 esac |
OLD | NEW |