qmount.sh (1521B)
1 #!/bin/sh 2 3 mount_points="~/Downloads/USBDrive 4 ~/Downloads/BackupMount" 5 6 root_device="$(/usr/bin/lsblk -l -n --output NAME,MOUNTPOINTS | grep '/$' | sed 's/p[0-9] \///g; s/[0-9] \///g')" 7 8 mount () { 9 # Filter out root disk 10 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)" 11 12 [ "$unmounted" = "" ] && echo "No drives to mount" && exit 13 14 chosen="$(echo "$unmounted" | fzf)" 15 chosen_partition="$(echo "$chosen" | cut -d " " -f 1)" 16 chosen_fstype="$(echo "$chosen" | cut -d " " -f 2)" 17 [ "$chosen_partition" = "" ] && exit 18 chosen_mount_point="$(echo "$mount_points" | fzf | sed "s|~|$HOME|")" 19 [ "$chosen_mount_point" = "" ] && exit 20 21 # Check if vfat or exfat, if so need special mount options to get permissions right 22 args="" 23 if [ "$chosen_fstype" = "vfat" ] || [ "$chosen_fstype" = "exfat" ]; then 24 args="-o rw,users,umask=000" 25 fi 26 27 sudo mount $args "/dev/${chosen_partition}" "$chosen_mount_point" && echo "Mounted Successfully" || echo "Mount Failed" 28 } 29 30 unmount () { 31 # Filter out root disk 32 mounted="$(/usr/bin/lsblk -l -n --output NAME,MOUNTPOINTS | grep "/" | grep -v "$root_device" | tr -s " ")" 33 [ "$mounted" = "" ] && echo "No drives to unmount" && exit 34 35 chosen_path="$(echo "$mounted" | fzf | cut -d " " -f 2-)" 36 [ "$chosen_path" = "" ] && exit 37 38 sudo umount "$chosen_path" && echo "Unmounted Successfully" || echo "Unmounting Failed" 39 } 40 41 case "$1" in 42 m*) 43 mount 44 ;; 45 u*) 46 unmount 47 ;; 48 esac