dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

dmenu_mount (1323B)


      1 #!/bin/sh
      2 
      3 # get mountable partitions
      4 parts="$(
      5 	lsblk -sdn -o PATH,SIZE,TYPE,MOUNTPOINT \
      6 	| grep 'part[ ]*$'                      \
      7 	| awk '{print $1, "[" $2 "]"}'          \
      8 )"
      9 [ "$parts" = "" ] && exit 1
     10 
     11 # choose a partition to mount
     12 args=" -i -p partition:"
     13 part="$(
     14 	echo "$parts"                           \
     15 	| dmenu_vtc${args}                      \
     16 	| awk '{print $1}'                      \
     17 )"
     18 [ "$part" = "" ] && exit 1
     19 
     20 # try to mount using fstab, and exit on success
     21 sudo mount "$part" 2>/dev/null && exit 0
     22 
     23 # get available mount points
     24 dirs="$(
     25 	find                                    \
     26 		/mnt                                \
     27 		/media                              \
     28 		/mount                              \
     29 		~/mnt                               \
     30 		~/media                             \
     31 		~/mount                             \
     32 	-maxdepth 2                             \
     33 	-type d                                 \
     34 	-empty                                  \
     35 	2>/dev/null                             \
     36 )"
     37 
     38 # choose a mount point
     39 args=" -i -p directory:"
     40 mntpnt="$(
     41 	echo "$dirs"                            \
     42 	| dmenu_vtc${args}                      \
     43 )"
     44 [ "$mntpnt" = "" ] || [ ! -d "$mntpnt" ] && exit 1
     45 
     46 # finally mount the partition
     47 sudo mount $part $mntpnt && ztatus-notify "'$part' mounted at '$mntpnt'"