Conditional formatting for partition labels

Conditionally formats dmenumount prompt with partition labels only if the label exists
This commit is contained in:
Lawrence Steele 2018-11-05 02:07:32 -05:00 committed by GitHub
parent 2f95b12a41
commit cb3c609ffa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,7 @@ getmount() { \
mountusb() { \ mountusb() { \
chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?" | awk '{print $2}')" chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?" | awk '{print $2}')"
sudo -A mount "$chosen" && exit 0 sudo -A mount "$chosen" && exit 0
getmount "/mnt /media /mount /home -maxdepth 5 -type d" getmount "/mnt /media /mount -maxdepth 3 -type d"
sudo -A mount "$chosen" "$mp" && pgrep -x dunst && notify-send "$chosen mounted to $mp." sudo -A mount "$chosen" "$mp" && pgrep -x dunst && notify-send "$chosen mounted to $mp."
} }
@ -37,8 +37,7 @@ asktype() { \
} }
anddrives=$(simple-mtpfs -l 2>/dev/null) anddrives=$(simple-mtpfs -l 2>/dev/null)
usbdrives="$(lsblk -rpo "name,type,size,mountpoint,label" | awk -F'[ ]' '$2=="part"&&$4==""{printf "[%s] %s (%s)\n",$5,$1,$3}')" usbdrives="$(lsblk -rpo "name,type,size,mountpoint,label" | awk -F'[ ]' '$2=="part" && $4=="" {str=($5=="") ? sprintf("%s (%s)\n",$1,$3) : sprintf("[%s] %s (%s)\n",$5,$1,$3); printf("%s",str)}')"
if [ -z "$usbdrives" ]; then if [ -z "$usbdrives" ]; then
[ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit
echo "Android device(s) detected." echo "Android device(s) detected."