qmount.sh (1086B)
1 #!/bin/sh 2 3 mount_points="~/Downloads/USBDrive 4 ~/Downloads/BackupMount" 5 root_device="$(/usr/bin/lsblk -l -n --output NAME,MOUNTPOINTS | grep '/$' | sed 's/p[0-9] \///g; s/[0-9] \///g')" 6 7 mount () { 8 unmounted="$(/usr/bin/lsblk -l -n --output NAME,FSTYPE,SIZE,MOUNTPOINTS,TYPE | grep "part" | grep -v "/" | grep -v "$root_device" | tr -s " " | cut -d " " -f 1-3)" 9 10 chosen_partition="$(echo "$unmounted" | fzf | cut -d " " -f 1)" 11 [ "$chosen_partition" = "" ] && exit 12 chosen_mount_point="$(echo "$mount_points" | fzf | sed "s|~|$HOME|")" 13 [ "$chosen_mount_point" = "" ] && exit 14 15 sudo mount "/dev/${chosen_partition}" "$chosen_mount_point" && notify-send "Mounted Successfully" || notify-send "Mount Failed" 16 } 17 18 unmount () { 19 mounted="$(/usr/bin/lsblk -l -n --output NAME,MOUNTPOINTS | grep "/" | grep -v "$root_device" | tr -s " ")" 20 chosen_path="$(echo "$mounted" | fzf | cut -d " " -f 2-)" 21 [ "$chosen_path" = "" ] && exit 22 sudo umount "$chosen_path" && notify-send "Unmounted Successfully" || notify-send "Unmounting Failed" 23 } 24 25 case "$1" in 26 m*) 27 mount 28 ;; 29 u*) 30 unmount 31 ;; 32 esac