From 02500565fa852dba828e9de91f34559cc0e41b1c Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Sun, 25 Nov 2018 02:22:00 +0100 Subject: Mount scripts now use a dmenu numbered list --- dmenuMount.sh | 25 ++++++++++++++++++++----- dmenuUmount.sh | 13 ++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dmenuMount.sh b/dmenuMount.sh index ce0d93b..05615cc 100644 --- a/dmenuMount.sh +++ b/dmenuMount.sh @@ -18,16 +18,31 @@ pgrep -x dmenu && exit +# Select partition to mount mountable=$(lsblk -lp | grep "part $" | awk '{print $1, "(" $4 ")"}') -[[ "$mountable" = "" ]] && exit 1 +mountable="" +i=0 +while read -r line +do + i=$((i+1)) + mountable="$mountable$i. $( echo "$line" | awk '{print $1, "(" $4 ")"}' )"$'\n' +done <<< "$(lsblk -lp | grep "part $" )" lines=$(echo "$mountable" | wc -l) -chosen=$(echo "$mountable" | dmenu -i -l $lines -p "Mount which drive?" | awk '{print $1}') +chosen=$(echo "$mountable" | dmenu -i -l $lines -p "Mount which drive?" | awk '{print $2}') [[ "$chosen" = "" ]] && exit 1 -#sudo -u inigo mount "$chosen" && exit 0 mount "$chosen" && notify-send "$chosen mounted" && exit 0 + +# Select mount point dirs=$(find /media /home/inigo/mounts -type d -maxdepth 3 -empty 2>/dev/null) -lines=$(echo "$dirs" | wc -l) -mountpoint=$(echo "$dirs" | dmenu -i -l $lines -p "Type in mount point.") +directories="" +i=0 +while read -r line +do + i=$((i+1)) + directories="$directories$i. $line"$'\n' +done <<< "$(find /media /home/inigo/mounts -type d -maxdepth 3 -empty 2>/dev/null)" +lines=$(echo "$directories" | wc -l) +mountpoint=$(echo "$directories" | dmenu -i -l $lines -p "Type in mount point." | awk '{print $2}') [[ "$mountpoint" = "" ]] && exit 1 if [[ ! -d "$mountpoint" ]]; then bash /home/inigo/scripts/prompt.sh "$mountpoint does not exist. Create it?" "mkdir -p $mountpoint" diff --git a/dmenuUmount.sh b/dmenuUmount.sh index f50f4aa..ecc5160 100644 --- a/dmenuUmount.sh +++ b/dmenuUmount.sh @@ -1,5 +1,5 @@ #!/bin/bash -# _ _ +# _ # __| |_ __ ___ ___ _ __ _ _ # / _` | '_ ` _ \ / _ \ '_ \| | | | # | (_| | | | | | | __/ | | | |_| | @@ -14,10 +14,17 @@ # Shows mounted partitions; select one to unmount. exclusionregex="\(/boot\|/home\|/\)$" -drives=$(lsblk -lp | grep "part /" | grep -v "$exclusionregex" | awk '{print $1, "(" $4 ")", "on", $7}') +drives="" +i=0 +while read -r line +do + i=$((i+1)) + drives="$drives$i. $( echo "$line" | awk '{print $1, "(" $4 ")", "on", $7}' )"$'\n' +done <<< "$(lsblk -lp | grep "part /" | grep -v "$exclusionregex" )" + [[ "$drives" = "" ]] && exit lines=$(echo "$drives" | wc -l) -chosen=$(echo "$drives" | dmenu -i -l $lines -p "Unmount which drive?" | awk '{print $1}') +chosen=$(echo "$drives" | dmenu -i -l $lines -p "Unmount which drive?" | awk '{print $2}') [[ "$chosen" = "" ]] && exit umount $chosen && pgrep -x dunst && notify-send "$chosen unmounted." #umount $chosen && notify-send "$chosen unmounted." -- cgit v1.2.1