xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 8a1c2c90c337733e475be9614736f19e07900700

Support MTP via simple-mtpfs in vifm-media
Thanks to FlyCat (a.k.a. yanwh0311) and Alexandre Viau.

Closes #623 on GitHub.
Author: xaizek
Author date (UTC): 2024-04-24 12:12
Committer name: xaizek
Committer date (UTC): 2024-04-25 16:28
Parent(s): 41a61b1c4b4ccb93847ada704513f44a0cd1ca82
Signing key: 99DC5E4DB05F6BE2
Tree: b6941661ae5c49c47c55092072a6122a27012257
File Lines added Lines deleted
ChangeLog 3 0
THANKS 1 0
data/vifm-media 99 2
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 THANKS changed (mode: 100644) (index 5db1ee7da..5fb5edb93)
... ... Fang (peromage)
99 99 Flaviu Tamas (flaviut) Flaviu Tamas (flaviut)
100 100 Florian Baumann (derflob) Florian Baumann (derflob)
101 101 flux242 flux242
102 FlyCat (yanwh0311)
102 103 fogine fogine
103 104 fohrums fohrums
104 105 gammaray gammaray
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 *) *)
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master