2022-03-21 18:05:05 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-04-05 16:59:13 +02:00
|
|
|
# a simple dmenu usb managment script
|
|
|
|
|
2022-10-30 16:07:16 +01:00
|
|
|
. $HOME/.config/dmenu/config
|
2022-07-17 11:03:13 +02:00
|
|
|
|
2022-03-21 18:05:05 +01:00
|
|
|
driveCount(){
|
2022-04-22 12:48:51 +02:00
|
|
|
count="$(printf '%s\n' "$1" | wc -l)"
|
2022-03-21 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mount(){
|
|
|
|
mountable="$(lsblk -lp | awk '/^\/dev\/sd.*part $/ { print $1 " ("$4")" }')"
|
|
|
|
|
|
|
|
if [ "$mountable" = "" ]; then
|
2022-07-17 11:03:13 +02:00
|
|
|
quick-notify "$DMENU Usb Manager" "No drives to mount"
|
2022-03-21 18:05:05 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2022-07-17 11:03:13 +02:00
|
|
|
chosen="$(printf '%s' "$mountable" | $DMENU -p "Drive to mount?")"
|
2022-03-21 18:05:05 +01:00
|
|
|
|
|
|
|
if [ -n "$chosen" ];then
|
|
|
|
udisksctl mount -b "${chosen%% *}"
|
2022-04-22 12:48:51 +02:00
|
|
|
quick-notify "Dmenu Usb Manager" "Drive ${chosen%% *} mounted"
|
2022-03-21 18:05:05 +01:00
|
|
|
else
|
|
|
|
quick-notify "Dmenu Usb Manager" "No drives chosen to mount"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
unmount(){
|
|
|
|
mounted="$(lsblk -lp | awk '/run/ { print $1 " ("$4")" }')"
|
|
|
|
|
|
|
|
if [ "$mounted" = "" ]; then
|
|
|
|
quick-notify "Dmenu Usb Manager" "No drives to unmount"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2022-07-17 11:03:13 +02:00
|
|
|
chosen="$(printf "$mounted" | $DMENU -p "Drive to unmount?")"
|
2022-03-21 18:05:05 +01:00
|
|
|
|
|
|
|
if [ -n "$chosen" ];then
|
|
|
|
udisksctl unmount -b "${chosen%% *}"
|
2022-04-22 12:48:51 +02:00
|
|
|
quick-notify "Dmenu Usb Manager" "Drive ${chosen%% *} unmounted"
|
2022-03-21 18:05:05 +01:00
|
|
|
else
|
|
|
|
quick-notify "Dmenu Usb Manager" "No drives chosen to unmount"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-07-17 11:03:13 +02:00
|
|
|
case $(printf "mount\\nunmount" | $DMENU -p "Chose your usb action") in
|
2022-03-21 18:05:05 +01:00
|
|
|
"mount") mount ;;
|
|
|
|
"unmount") unmount ;;
|
|
|
|
esac
|