Krolyxon
Commit 1d81ae6

Branches

Refs →

dotfiles-x11.localbindmenuumount

44 lines · 1.4 KB · Bourne Again Shell (bash)

1#!/bin/sh
2
3# A dmenu prompt to unmount drives.
4# Provides you with mounted partitions, select one to unmount.
5# Drives mounted at /, /boot and /home will not be options to unmount.
6
7unmountusb() {
8 [ -z "$drives" ] && exit
9 chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1
10 chosen="$(echo "$chosen" | awk '{print $1}')"
11 [ -z "$chosen" ] && exit
12 sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted."
13 }
14
15unmountandroid() { \
16 chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1
17 [ -z "$chosen" ] && exit
18 sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted."
19 }
20
21asktype() { \
22 choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1
23 case "$choice" in
24 USB) unmountusb ;;
25 Android) unmountandroid ;;
26 esac
27 }
28
29drives=$(lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}')
30
31if ! grep simple-mtpfs /etc/mtab; then
32 [ -z "$drives" ] && echo "No drives to unmount." && exit
33 echo "Unmountable USB drive detected."
34 unmountusb
35else
36 if [ -z "$drives" ]
37 then
38 echo "Unmountable Android device detected."
39 unmountandroid
40 else
41 echo "Unmountable USB drive(s) and Android device(s) detected."
42 asktype
43 fi
44fi