3 # Description: Toggle mount of MTP device (eg. Android device)
4 # 'l' to list mountable devices
5 # 'n' integer associated to device to mount
8 # Dependencies: gvfs-mtp
10 # Notes: The MTP device should be mounted at /run/user/$UID/gvfs.
11 # Put /run/user/$UID/gvfs to bookmark entries (NNN_BMS) for faster access.
12 # Make sure the device is unlocked when mounting.
14 # When doing copy-paste into MTP device, you will get an error like this:
15 # cp: preserving times for './gambar1.png': Operation not supported
16 # That just means the file is copied but timestamp won't be preserved.
17 # It's like doing `cp -p localfile.txt file-to-SMB.txt`.
19 # Shell: POSIX compliant
22 prompt="Device number ('l' to list): "
28 devs=$(gio mount -li | grep -e 'activation_root' | sed 's/\s*activation_root=//g')
30 printf "Devices list:\n"
32 printf "%s %s\\n" "$c" "$i"
44 if [ "$input" = "l" ]; then
46 elif [ "$input" = "q" ] || [ "$input" -eq 0 ]; then
48 elif [ "$input" -le "$(printf '%s\n' "${devs}" | grep -c '^')" ]; then
49 # dev=$(printf "%s\n" "$devs" | cut -d$'\n' -f${input})
53 if [ "$input" -eq $c ]; then
59 if (gio mount -l | grep '^Mount([1-9]).*'"$dev" ) 1>/dev/null; then
60 if gio mount -u "${dev}"; then
61 printf "%s unmounted\n" "$dev"
64 if gio mount "${dev}"; then
65 printf "%s mounted to /run/user/\$UID/gvfs\n" "$dev"
70 printf "Invalid input\n"