feat: am one binary and clear output

This commit is contained in:
AngeD 2022-12-23 09:15:21 +01:00
parent dbd7223f08
commit e1cf0ba26f
2 changed files with 25 additions and 36 deletions

31
bin/am
View File

@ -3,16 +3,35 @@ set -e
# TODO
# - mount all partitions by selecting disk
# - hide already mounted partitions
# - usage
# - one device per line
# - support for /mnt
# - colors ?
readarray -t LSBLK <<< "$(lsblk -n --paths --list | grep part)"
function clear_output() {
local len="$1"
select dev in "${LSBLK[@]}"; do
name="$(cut -f1 -d' ' <<< "$dev")"
for _ in $(seq 0 "$len"); do
printf '\e[1A\e[K'
done
}
udisksctl mount -b "$name"
echo "$name" >> /tmp/automount
if ! [ -t 1 ]; then
exit 1
fi
while true; do
readarray -t LSBLK <<< "$(lsblk -n --paths --list | grep part)"
select dev in "${LSBLK[@]}"; do
name="$(cut -f1 -d' ' <<< "$dev")"
if mount | grep -q "$name"; then
umount "$name"
else
udisksctl mount -b "$name" > /dev/null
fi
clear_output "${#LSBLK[@]}"
break
done || exit
done

30
bin/dm
View File

@ -1,30 +0,0 @@
#!/bin/bash
set -e
function unmount() {
local name
for dev in "$@"; do
name="$(cut -f1 -d' ' <<< "$dev")"
umount "$name"
sed -i "\\|$name|d" /tmp/automount
done
}
readarray -t LSBLK <<< "$(lsblk --paths --list | grep -f /tmp/automount)"
while getopts a o; do
case "$o" in
a)
unmount "${LSBLK[@]}"
exit 0
;;
*)
;;
esac
done
select dev in "${LSBLK[@]}"; do
unmount "$dev"
done