aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2023-08-01 23:03:37 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2023-08-01 23:03:37 +0200
commit0e3e67166e9e76741161dd39fb7d1085493671d7 (patch)
tree03170bfa158b054a30e5cefe9ba143ba669c6780
parent381f1f80f0dcb2db7b7f007f61b8317ea6e8c6a4 (diff)
downloadscripts-0e3e67166e9e76741161dd39fb7d1085493671d7.tar.gz
scripts-0e3e67166e9e76741161dd39fb7d1085493671d7.zip
Fixed dmenuMount.sh at last.
-rwxr-xr-xdmenuMount.sh28
1 files changed, 17 insertions, 11 deletions
diff --git a/dmenuMount.sh b/dmenuMount.sh
index d91888a..45250bf 100755
--- a/dmenuMount.sh
+++ b/dmenuMount.sh
@@ -18,22 +18,28 @@
pgrep -x dmenu && exit
+# Exit if no unmounted partition
+if ! lsblk -lp | grep -q 'part $'; then
+ notify-send --category='moon' 'No unmounted partition available' "Partition table:\n$(lsblk -o 'name,mountpoints,size')"
+ exit 0
+fi
+
# Select partition to mount
mountable=""
i=0
while read -r line
do
i=$((i+1))
- name="$(echo "$line" | awk '{print $1}')"
- size="$(echo "$line" | awk '{print $4}')"
- label="$(lsblk -lpo "name,label" | grep "$name" | awk '{print $2}')"
- fstype="$(lsblk -lpo "name,fstype" | grep "$name" | awk '{print $2}')"
- mountable="$mountable$i. $name ($size) \"$label\" [$fstype]"$'\n'
+ name="$(printf '%s\n' "$line" | awk '{print $1}')"
+ size="$(printf '%s\n' "$line" | awk '{print $4}')"
+ label="$(lsblk -lpo 'name,label' | grep "$name" | cut -d' ' -f2-)"
+ fstype="$(lsblk -lpo 'name,fstype' | grep "$name" | cut -d' ' -f2-)"
+ mountable="${mountable}${i}. ${name} (${size}) \"${label}\" [${fstype}]\n"
#$( echo "$line" | awk '{print $, "(" $2 ")", "\"" $3 "\"", "[" $4 "]"}' )"$'\n'
-done <<< "$(lsblk -lp | grep "part $" )"
-[[ "$mountable" = "" ]] && exit 1
-lines=$(echo "$mountable" | wc -l)
-chosen=$(echo "$mountable" | dmenu -l "$lines" -p "Mount which drive?" | awk '{print $2}')
+done <<< "$(lsblk -lp | grep 'part $' )"
+
+lines=$(printf '%s\n' "$mountable" | wc -l)
+chosen=$(printf '%s\n' "$mountable" | dmenu -l "$lines" -p "Mount which drive?" | awk '{print $2}')
[ "$chosen" == "" ] && exit 1
sudo mount "$chosen" && pgrep -x dunst && notify-send "$chosen mounted." && exit 0
@@ -45,8 +51,8 @@ do
i=$((i+1))
directories="$directories$i. $line"$'\n'
done <<< "$(find /mnt "$HOME/mounts" -type d -maxdepth 3 -empty 2>/dev/null)"
-lines=$(echo "$directories" | wc -l)
-mountpoint=$(echo "$directories" | dmenu -l "$lines" -p "Type in mount point." | awk '{print $2}')
+lines=$(printf '%s\n' "$directories" | wc -l)
+mountpoint=$(printf '%s\n' "$directories" | dmenu -l "$lines" -p "Type in mount point." | awk '{print $2}')
[ "$mountpoint" == "" ] && exit 1
if [[ ! -d "$mountpoint" ]]; then
prompt.sh "$mountpoint does not exist. Create it?" "sudo mkdir -p $mountpoint"