text version working

This commit is contained in:
Adrian Amaglio 2022-02-18 16:05:36 +01:00
parent 345680076a
commit 9808d1ff85

View File

@ -2,38 +2,31 @@
function usage () {
echo "Usage:"
echo "$0 <action>"
echo "$0 <action> [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 [ -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 [ -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