dotfiles

🎜 Clone'em, tweak'em, stick'em in your $HOME 🎝
git clone https://git.kevinlegouguec.net/dotfiles
Log | Files | Refs | README

usb-detach (565B)


      1 #!/bin/bash
      2 
      3 set -eu
      4 
      5 mounted_path=$(findmnt -l -o TARGET | grep /media/${USER})
      6 drive=$(findmnt -n -o SOURCE "${mounted_path}")
      7 
      8 # Any argument means "prompt for confirmation".
      9 if [ $# -ge 1 ]
     10 then
     11     read -p "Unmount ${drive} (${mounted_path})? " answer
     12 
     13     case ${answer} in
     14         [yY]*) ;;
     15         *) exit 0 ;;
     16     esac
     17 fi
     18 
     19 udisksctl unmount -b ${drive}
     20 udisksctl power-off -b ${drive}
     21 
     22 icon=/usr/share/icons/elementary-xfce/devices/48/drive-removable-media-usb.png
     23 
     24 notify-send -i ${icon} "You're all set." \
     25             "Don't forget to grab your drive."