nnn

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a51437ff1626fb70a70625642e5afec7e3a491f0
parent e236bd0b3a97e4ac3b4e85da08edbdad9046e3f1
Author: 8B411 <113213448+8B411@users.noreply.github.com>
Date:   Wed, 21 Dec 2022 19:44:28 +0200

Miscellaneous improvements to nmount plugin (#1547)

* plugins/nmount: keep `while` & `do` on one line for consistency

* plugins/nmount: sync only that device, which user wants to unmount

* plugins/nmount: replace all instances of `$dev` with `/dev/$dev`

* plugins/nmount: add `--no-user-interaction` option to `udisksctl`

Otherwise the user will be asked for authentication each time he wants
to unmount, say, HDD, since `udisksctl` will try to power it off.

* plugins/nmount: try to mount only existing block devices

* plugins/nmount: do not invoke `lsblk` immediately after mounting

Sometimes `lsblk` fails to provide mountpoint in such a short time frame.

* plugins/nmount: simplify pipe

* plugins/nmount: keep `echo` arguments in a single pair of quotes

* plugins/nmount: report mountpoint only if mounting was successful
Diffstat:
Mplugins/nmount | 23++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/plugins/nmount b/plugins/nmount @@ -26,26 +26,27 @@ printf "\nEnsure you aren't still in the mounted device.\n" printf "%s" "$prompt" read -r dev -while [ -n "$dev" ] -do +while [ -n "$dev" ]; do if [ "$dev" = "l" ]; then lsblk elif [ "$dev" = "q" ]; then exit else if grep -qs "$dev " /proc/mounts; then - sync - if pumount "$dev" - then - echo "$dev" unmounted. - if udisksctl power-off -b /dev/"$dev" - then - echo "$dev" ejected. + sync "$(lsblk -n "/dev/$dev" -o MOUNTPOINT | sed "/^$/d")" + if pumount "/dev/$dev"; then + echo "/dev/$dev unmounted." + if udisksctl power-off -b "/dev/$dev" --no-user-interaction; then + echo "/dev/$dev ejected." fi fi + elif [ -b "/dev/$dev" ]; then + if pmount "/dev/$dev"; then + sleep 1 + echo "/dev/$dev mounted to $(lsblk -n "/dev/$dev" -o MOUNTPOINT | sed "/^$/d")." + fi else - pmount "$dev" - echo "$dev" mounted to "$(lsblk -n /dev/"$dev" | rev | cut -d' ' -f1 | rev)". + echo "/dev/$dev does not exist or is not a block device." fi fi