#!/bin/bash set -e # TODO # mount all partitions by selecting disk # usage # support for /mnt # error handling (fs in use...) function clear_output() { local len="$1" for _ in $(seq 0 "$len"); do printf '\e[1A\e[K' done } if ! [ -t 1 ]; then exit 1 fi function umount_all() { local disks disks=($(mount | grep udisks2 | cut -f1 -d' ')) umount "${disks[@]}" echo "unmounted ${disks[@]}" } while getopts a o; do case "$o" in a) umount_all exit ;; *) ;; esac done while true; do #readarray -t LSBLK <<< "$(lsblk -n --paths | grep -v snap)" readarray -t LSBLK <<< "$(lsblk -n --paths --list | grep part)" COLUMNS=1 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