#! /usr/bin/env dash # nixos-config - My current NixOS configuration # # Copyright (C) 2025 Benedikt Peetz # SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of my nixos-config. # # You should have received a copy of the License along with this program. # If not, see . NAME="aumo" error() { printf "\033[1;91m==> ERROR:\033[0m \033[1;93m%s\033[0m\n" "$*" >&2 } die() { error "$1" exit "${2-1}" } usage() { echo "Usage: $NAME mount|unmount" } get_mounted_labels() { findmnt --output label --json | jq '.filesystems | map(.label) | sort | unique | map(select(. != null))' } get_unmounted_labels() { first=true find /dev/disk/by-label -printf "%P\n" | while read -r label; do if ! get_mounted_labels | jq 'join("\n")' --raw-output | grep "$label" --quiet; then if [ "$first" = "true" ]; then first=false else printf "|" fi printf "%s" "$label" fi done } unmounting() { disk_name="$(get_mounted_labels | jq 'join("|")' --join-output | rofi -sep "|" -dmenu -p "Select disk to unmount")" udisksctl unmount --block-device "/dev/disk/by-label/$disk_name" } mounting() { disk_name="$(get_unmounted_labels | rofi -sep "|" -dmenu -p "Select disk to mount")" udisksctl mount --block-device "/dev/disk/by-label/$disk_name" } case "${1-unset}" in "mount") mounting ;; "unmount" | "umount") unmounting ;; "unset") usage die "You need to provide one argument." ;; *) usage die "Unknown command: '$1'" ;; esac