]> Sergey Matveev's repositories - nnn.git/commitdiff
Miscellaneous improvements to nmount plugin (#1547)
author8B411 <113213448+8B411@users.noreply.github.com>
Wed, 21 Dec 2022 17:44:28 +0000 (19:44 +0200)
committerGitHub <noreply@github.com>
Wed, 21 Dec 2022 17:44:28 +0000 (23:14 +0530)
* 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

plugins/nmount

index e92fd5deb623a989ad16ae2d413da973e274eb63..c30efb4a0e5ab61f159fd4737150ebcf85524a6b 100755 (executable)
@@ -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