From 9808d1ff853a58c9734084a6762a37c73eee3fb8 Mon Sep 17 00:00:00 2001 From: Adrian Amaglio Date: Fri, 18 Feb 2022 16:05:36 +0100 Subject: [PATCH] text version working --- interractive_mount | 51 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/interractive_mount b/interractive_mount index b46f7fa..505a6c7 100755 --- a/interractive_mount +++ b/interractive_mount @@ -2,38 +2,31 @@ function usage () { echo "Usage:" - echo "$0 " + echo "$0 [mode]" echo "action is either mount or unmount" + echo "action is text or nothing" } # If no display found, full text interface. use dmenu and dunstify else. -if [ -z "$DISPLAY" ] ; then - interface=text +if [ "$2" = text ] || [ -z "$DISPLAY" ] ; then function notify () { - echo "$1\n$2" + echo -e "== $1 ==\n$2" } function ask () { - echo "Text interface not implemented. use X :(" >/dev/stderr - exit 1 - #TODO - i=0 - while read l ; do - echo "$i) $l" - ((i++)) - done - echo -n "Your choice: " - read choice - if [ "$choice" -le "$i" ] && [ "$choice" -ge 0 ] ; then - echo $i - fi + # $1 is the title + # $2 is the \n separated list of choices + # $3 is the number of choices + IFS=$'\n' read -r -d '' -a args <<< $(echo -e "$2") + dialog --no-items --menu "$1" 15 40 4 "${args[@]}" 2>&1 >/dev/tty + } else - interface=x function notify () { dunstify "$1" "$2" } function ask () { - dmenu + # See interface specification up + echo -en "$2" | dmenu -i -l "$3" -p "$1" } fi @@ -70,14 +63,22 @@ done <<< $(lsblk -prno NAME,SIZE,MOUNTPOINTS) # Prompt user for disk action if [ "$action" = "mount" ] ; then - read disk size <<< $(echo -en $umounted | dmenu -i -l "$umounted_nb" -p 'Mount: ') - if [ -b "$disk" ] ; then - notify "Mounting $disk" "$(udisksctl mount -b "$disk" 2>&1)" + if [ -z "$umounted" ] ; then + notify "Mounting" "Nothing to mount" + else + read disk size <<< $(ask 'Mount' "$umounted" "$umounted_nb") + if [ -b "$disk" ] ; then + notify "Mounting $disk" "$(udisksctl mount -b "$disk" 2>&1)" + fi fi elif [ "$action" = "umount" ] ; then - read disk size mountpoint <<< $(echo -en $mounted | dmenu -i -l "$mounted_nb" -p 'Unmount: ') - if [ -b "$disk" ] ; then - notify "Unmounting $disk" "$(udisksctl unmount -b "$disk" 2>&1)" + if [ -z "$mounted" ] ; then + notify "Unmounting" "Nothing to unmount" + else + read disk size mountpoint <<< $(ask 'Unmount' "$mounted" "$mounted_nb") + if [ -b "$disk" ] ; then + notify "Unmounting $disk" "$(udisksctl unmount -b "$disk" 2>&1)" + fi fi fi