Clean up awk sections in the mount scripts

This commit is contained in:
Stefen Ramirez 2019-01-21 13:34:57 -06:00
parent 76d0de001d
commit ab889e8d5e
2 changed files with 10 additions and 8 deletions

View File

@ -16,11 +16,11 @@ getmount() { \
}
mountusb() { \
keys=$(echo -e $usbdrives | awk '/name/{ if ($6 != "null") printf "%s (%s)\\n", $6, $4; else printf "%s (%s)\\n", $2, $4; }')
map=$(echo -e $usbdrives | awk '/name/{ if ($6 != "null") printf "[\"%s\"]=%s\n", $6, $2; else printf "[\"%s\"]=%s\n", $2, $2; }')
keys=$(echo -e "$usbdrives" | awk '{ printf "%s (%s)\\n", $2 != "null" ? $2 : $1, $3; }')
hmap=$(echo -e "$usbdrives" | awk '{ printf "[\"%s\"]=%s\n", $2 != "null" ? $2 : $1, $1; }')
device="$(echo -e "$keys" | sort -r | dmenu -i -p "Mount which drive?" | awk '{print $1}')"
eval declare -A devices=($map)
eval declare -A devices=($hmap)
chosen=${devices["$device"]}
sudo -A mount "$chosen" && notify-send -i "$PIX/usb.svg" "$chosen mounted." && exit 0
@ -48,7 +48,9 @@ asktype() { \
}
anddrives=$(simple-mtpfs -l 2>/dev/null)
usbdrives=$(lsblk -Jplf -o name,size,label,type,mountpoint | tr -d " \"{}" | sed 's/:\|,/ /g' | awk /name/'{ if ($NF == "null" && $8 == "part") printf "%s\\n", $0; }')
usbdrives=$(lsblk -Jplf -o name,label,size,type,mountpoint | tr -d " \"{}" | sed 's/:\|,/ /g' | awk '/name/ && $NF=="null" && $8=="part"{print $2, $4, $6; }')
echo "$usbdrives"
if [ -z "$usbdrives" ]; then
[ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit

View File

@ -6,11 +6,11 @@
unmountusb() {
[ -z "$drives" ] && exit
keys=$(echo -e $drives | awk '/name/{ if ($6 != "null") printf "%s (%s)\\n", $6, $4; else printf "%s (%s)\\n", $2, $4; }')
map=$(echo -e $drives | awk '/name/{ if ($6 != "null") printf "[\"%s\"]=%s\n", $6, $2; else printf "[\"%s\"]=%s\n", $2, $2; }')
keys=$(echo -e "$drives" | awk '{ printf "%s (%s)\n", $2 != "null" ? $2 : $1, $3; }')
hmap=$(echo -e "$drives" | awk '{ printf "[\"%s\"]=%s\n", $2 != "null" ? $2 : $1, $1; }')
chosen="$(echo -e "$keys" | sort -r | dmenu -i -p "Unmount which drive?" | awk '{print $1}')"
eval declare -A devices=($map)
eval declare -A devices=($hmap)
mp=${devices["$chosen"]}
[ -z "$chosen" ] && exit
@ -30,7 +30,7 @@ asktype() { \
esac
}
drives=$(lsblk -Jplf -o name,size,label,type,mountpoint | tr -d " \"{}" | sed 's/:\|,/ /g' | awk /name/'{ if ($NF != "null" && $NF !~/\/boot|\/home$|SWAP/&&length($NF)>1 && $8 == "part") printf "%s\\n", $0; }')
drives=$(lsblk -Jplf -o name,label,size,type,mountpoint | tr -d " \"{}" | sed 's/:\|,/ /g' | awk '/name/ && $NF != "null" && $NF !~/\/boot|\/home$|SWAP/&&length($NF)>1 && $8=="part" {print $2, $4, $6;}')
if ! grep simple-mtpfs /etc/mtab; then
[ -z "$drives" ] && echo "No drives to unmount." && exit