This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/dmenuumount

33 lines
961 B
Plaintext
Raw Normal View History

2020-05-06 03:20:19 +02:00
#!/bin/sh
######################################################################
2020-05-23 15:47:21 +02:00
# @author : swytch (adapted form Luke Smith - lukesmith.xyz)
# @file : dmenuumount
# @license : MIT
2020-05-23 15:47:21 +02:00
# @created : Wednesday May 20, 2020 18:11:17 CEST
#
2020-05-23 15:47:21 +02:00
# @description : dmenu prompt to unmount drives
######################################################################
2020-05-06 03:20:19 +02:00
unmountusb() {
chosen=$(echo "$usbdrives" | dmenu -i -p "Unmount which drive?" | awk '{print $1}')
if [ -z "$chosen" ]; then
exit
else
if sudo -A umount "$chosen" ; then
notify-send "禍 USB unmounting" "$chosen unmounted."
else
notify-send -u "critical" -t 3000 "禍 USB ERROR" "Unmounting failed."
fi
fi
}
usbdrives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$2=="part"&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}')
if [ -z "$usbdrives" ]; then
notify-send -u "critical" -t 3000 "禍 USB ERROR" "No drive to unmount."
else
unmountusb
fi