File ChangeLog changed (mode: 100644) (index 5afe8be40..df5855e9b) |
109 |
109 |
Make vifm-media not offer partitioned drives as they aren't mountable as a |
Make vifm-media not offer partitioned drives as they aren't mountable as a |
110 |
110 |
whole. |
whole. |
111 |
111 |
|
|
|
112 |
|
Extended vifm-media script to support MTP devices if simple-mtpfs tool is |
|
113 |
|
installed. Thanks to FlyCat (a.k.a. yanwh0311) and Alexandre Viau. |
|
114 |
|
|
112 |
115 |
Fixed line number column not including padding to the left of it. |
Fixed line number column not including padding to the left of it. |
113 |
116 |
|
|
114 |
117 |
Fixed local options not being loaded on Ctrl-W x. |
Fixed local options not being loaded on Ctrl-W x. |
File data/vifm-media changed (mode: 100755) (index c3b0a660e..81e503a5f) |
15 |
15 |
# - udisks2: second vesion of disk management D-Bus daemon |
# - udisks2: second vesion of disk management D-Bus daemon |
16 |
16 |
# requirements: `udisksctl` and either `python2` or `python3` with "dbus" |
# requirements: `udisksctl` and either `python2` or `python3` with "dbus" |
17 |
17 |
# module |
# module |
|
18 |
|
# |
|
19 |
|
# Support for additional protocols (used in addition to standard drives, but |
|
20 |
|
# support depends on installed dependencies): |
|
21 |
|
# - MTP: /dev/libmtp-* devices |
|
22 |
|
# requirements: requires `simple-mtpfs` command to obtain device's name or |
|
23 |
|
# mount/unmount it |
|
24 |
|
# limitations: can list and unmount only if this script was used for mounting |
|
25 |
|
# because source field of a FUSE mount is mounter's name rather |
|
26 |
|
# than the mounted device |
18 |
27 |
|
|
19 |
28 |
function usage_error() { |
function usage_error() { |
20 |
29 |
echo "Usage: vifm-media list | mount <device> | unmount <path>" |
echo "Usage: vifm-media list | mount <device> | unmount <path>" |
|
... |
... |
else |
173 |
182 |
exit 1 |
exit 1 |
174 |
183 |
fi |
fi |
175 |
184 |
|
|
|
185 |
|
function have_simple_mtpfs() { |
|
186 |
|
type simple-mtpfs > /dev/null 2>&1 |
|
187 |
|
} |
|
188 |
|
|
|
189 |
|
function make_mtp_mount_path() { |
|
190 |
|
local dev=$1 |
|
191 |
|
|
|
192 |
|
echo "/tmp/vifm-media$(echo -n "$dev" | tr -c 'a-zA-Z0-9-' _)" |
|
193 |
|
} |
|
194 |
|
|
|
195 |
|
function is_mtp_mount_path() { |
|
196 |
|
local path=$1 |
|
197 |
|
|
|
198 |
|
case "$path" in |
|
199 |
|
/tmp/vifm-media*) return 0 ;; |
|
200 |
|
*) return 1 ;; |
|
201 |
|
esac |
|
202 |
|
} |
|
203 |
|
|
|
204 |
|
function list_mtp() { |
|
205 |
|
for dev in /dev/libmtp-*; do |
|
206 |
|
echo device="$dev" |
|
207 |
|
|
|
208 |
|
if have_simple_mtpfs; then |
|
209 |
|
local label=$(simple-mtpfs --list-devices "$dev" | cut -f2- -d' ') |
|
210 |
|
echo "label=$label" |
|
211 |
|
fi |
|
212 |
|
|
|
213 |
|
echo -n /dev/libmtp-1-9 | tr -c 'a-zA-Z0-9-' _ |
|
214 |
|
|
|
215 |
|
local mount_path=$(make_mtp_mount_path "$dev") |
|
216 |
|
if findmnt "$mount_path"; then |
|
217 |
|
echo "mount-point=$mount_path" |
|
218 |
|
fi |
|
219 |
|
done |
|
220 |
|
} |
|
221 |
|
|
|
222 |
|
function is_mtp() { |
|
223 |
|
local dev=$1 |
|
224 |
|
|
|
225 |
|
case "$dev" in |
|
226 |
|
/dev/libmtp-*) return 0 ;; |
|
227 |
|
*) return 1 ;; |
|
228 |
|
esac |
|
229 |
|
} |
|
230 |
|
|
|
231 |
|
function mount_mtp() { |
|
232 |
|
local dev=$1 |
|
233 |
|
|
|
234 |
|
if ! have_simple_mtpfs; then |
|
235 |
|
echo "vifm-media: need simple-mtpfs command to mount over MTP" 1>&2 |
|
236 |
|
exit 1 |
|
237 |
|
fi |
|
238 |
|
|
|
239 |
|
local mount_path=$(make_mtp_mount_path "$dev") |
|
240 |
|
if [ -e "$mount_path" ]; then |
|
241 |
|
if ! rmdir "$mount_path"; then |
|
242 |
|
exit 1 |
|
243 |
|
fi |
|
244 |
|
fi |
|
245 |
|
|
|
246 |
|
if ! ( umask 077 && mkdir "$mount_path" ); then |
|
247 |
|
exit 1 |
|
248 |
|
fi |
|
249 |
|
|
|
250 |
|
if ! simple-mtpfs "$dev" "$mount_path"; then |
|
251 |
|
rmdir "$mount_path" |
|
252 |
|
exit 1 |
|
253 |
|
fi |
|
254 |
|
} |
|
255 |
|
|
|
256 |
|
function unmount_mtp() { |
|
257 |
|
local path=$1 |
|
258 |
|
|
|
259 |
|
umount "$path" && rmdir "$path" |
|
260 |
|
} |
|
261 |
|
|
176 |
262 |
case "$1" in |
case "$1" in |
177 |
263 |
list) |
list) |
178 |
264 |
if [ $# -ne 1 ]; then |
if [ $# -ne 1 ]; then |
179 |
265 |
usage_error |
usage_error |
180 |
266 |
fi |
fi |
181 |
267 |
list |
list |
|
268 |
|
list_mtp |
182 |
269 |
;; |
;; |
183 |
270 |
mount) |
mount) |
184 |
271 |
if [ $# -ne 2 ]; then |
if [ $# -ne 2 ]; then |
185 |
272 |
usage_error |
usage_error |
186 |
273 |
fi |
fi |
187 |
|
mount "$2" |
|
|
274 |
|
|
|
275 |
|
if is_mtp "$2"; then |
|
276 |
|
mount_mtp "$2" |
|
277 |
|
else |
|
278 |
|
mount "$2" |
|
279 |
|
fi |
188 |
280 |
;; |
;; |
189 |
281 |
unmount) |
unmount) |
190 |
282 |
if [ $# -ne 2 ]; then |
if [ $# -ne 2 ]; then |
191 |
283 |
usage_error |
usage_error |
192 |
284 |
fi |
fi |
193 |
|
unmount "$2" |
|
|
285 |
|
|
|
286 |
|
if is_mtp_mount_path "$2"; then |
|
287 |
|
unmount_mtp "$2" |
|
288 |
|
else |
|
289 |
|
unmount "$2" |
|
290 |
|
fi |
194 |
291 |
;; |
;; |
195 |
292 |
|
|
196 |
293 |
*) |
*) |