summaryrefslogtreecommitdiff
path: root/.local/bin/usb-detach
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/usb-detach')
-rwxr-xr-x.local/bin/usb-detach25
1 files changed, 25 insertions, 0 deletions
diff --git a/.local/bin/usb-detach b/.local/bin/usb-detach
new file mode 100755
index 0000000..ec438dd
--- /dev/null
+++ b/.local/bin/usb-detach
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+set -eu
+
+mounted_path=$(findmnt -l -o TARGET | grep /media/${USER})
+drive=$(findmnt -n -o SOURCE "${mounted_path}")
+
+# Any argument means "prompt for confirmation".
+if [ $# -ge 1 ]
+then
+ read -p "Unmount ${drive} (${mounted_path})? " answer
+
+ case ${answer} in
+ [yY]*) ;;
+ *) exit 0 ;;
+ esac
+fi
+
+udisksctl unmount -b ${drive}
+udisksctl power-off -b ${drive}
+
+icon=/usr/share/icons/elementary-xfce/devices/48/drive-removable-media-usb.png
+
+notify-send -i ${icon} "You're all set." \
+ "Don't forget to grab your drive."