#! /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" } is_label_mounted() { label="$1" findmnt --output label --json | jq --arg label "$label" '.filesystems | map(.label) | sort | unique | map(select(. != null)) | index($label) != null' } get_mounted_labels() { findmnt --output label --json | jq '.filesystems | map(.label) | sort | unique | map(select(. != null))' } get_unmounted_labels() { first=true fd . /dev/disk/by-label --format "{/.}" | while read -r label; do if ! [ "$(is_label_mounted "$label")" = true ]; then if [ "$first" = "true" ]; then first=false else printf "\0" fi printf "%s" "$label" fi done } unmounting() { disk_name="$(get_mounted_labels | jq 'join("\u0000")' --join-output | rofi -sep "\0" -dmenu -p "Select disk to unmount" | sed 's/ /\\x20/')" udisksctl unmount --block-device "/dev/disk/by-label/$disk_name" } mounting() { disk_name="$(get_unmounted_labels | rofi -sep "\0" -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