Krolyxon
Commit b17a3d9

Branches

Refs →

aurora.localbinunmounter

22 lines · 764 B · 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" | fuzzel -d -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
15drives=$(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}')
16
17if [ -z "$drives" ]; then
18 echo "No drives to unmount." && exit
19else
20 echo "Unmountable USB drive detected."
21 unmountusb
22fi