mount-drive (764B) - raw


      1 #!/bin/sh
      2 
      3 get_drives() { lsblk -rpo "name,type,size,mountpoint" | sed '1d' | grep -v "/dev/sda" ; }
      4 format_drives() { awk '$2=="part"{printf "%s (%s%s)\n",$1,$3,($4=="")?"":", mounted"}' ; }
      5 select_drive() { dmenu -i -p "Select drive" ; }
      6 mount_point() { grep "^$drive " /proc/mounts | cut -d ' ' -f 2 ; }
      7 
      8 info="$(get_drives | format_drives | select_drive)"
      9 
     10 [ -z "$info" ] && exit
     11 
     12 drive="$(echo "$info" | awk '{print $1}')"
     13 mounted="$(echo "$info" | grep "mounted")"
     14 
     15 if [ -z "$mounted" ]; then
     16   udisksctl mount -b "$drive" \
     17     && notify-send "Drive mounted" "$(mount_point)" \
     18     || notify-send "Error while mounting drive"
     19 else
     20   udisksctl unmount -b "$drive" \
     21     && notify-send "Drive unmounted" \
     22     || notify-send "Error while unmounting drive"
     23 fi