summaryrefslogtreecommitdiff
path: root/.local/bin/usb-detach
blob: ec438ddce63fc65d52f0915c943c7fabdb833c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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."