From 316c3f3b90d1ae6bba3e2e13e52aad37528940ea Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sat, 10 Oct 2026 19:03:32 +0200 Subject: [PATCH] Add phone script to mount Android phones over MTP as ~/Phone --- .local/bin/phone | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 .local/bin/phone diff --git a/.local/bin/phone b/.local/bin/phone new file mode 100755 index 0000000..49ccf28 --- /dev/null +++ b/.local/bin/phone @@ -0,0 +1,31 @@ +#!/bin/bash +# Mount/unmount Android phones over MTP via gvfs, exposed as ~/Phone +# Usage: phone [mount|umount] + +link="$HOME/Phone" + +case "${1:-mount}" in +mount) + gio mount -li | sed -n 's/^ *activation_root=\(mtp:.*\)/\1/p' | + while read -r uri; do gio mount "$uri"; done + + mounts=("$XDG_RUNTIME_DIR"/gvfs/mtp:host=*) + if [[ ! -e ${mounts[0]} ]]; then + echo "phone: no MTP device mounted" >&2 + exit 1 + fi + if [[ -e $link && ! -L $link ]]; then + echo "phone: $link exists and is not a symlink" >&2 + exit 1 + fi + ln -sfn "${mounts[0]}" "$link" + ;; +umount) + gio mount -s mtp + if [[ -L $link ]]; then rm "$link"; fi + ;; +*) + echo "usage: ${0##*/} [mount|umount]" >&2 + exit 1 + ;; +esac