diff options
Diffstat (limited to '')
| -rwxr-xr-x | pkgs/by-name/au/aumo/aumo.sh | 45 | ||||
| -rw-r--r-- | pkgs/by-name/au/aumo/package.nix | 21 |
2 files changed, 52 insertions, 14 deletions
diff --git a/pkgs/by-name/au/aumo/aumo.sh b/pkgs/by-name/au/aumo/aumo.sh index d86165b2..824d817a 100755 --- a/pkgs/by-name/au/aumo/aumo.sh +++ b/pkgs/by-name/au/aumo/aumo.sh @@ -1,5 +1,15 @@ #! /usr/bin/env dash +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# 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 <https://www.gnu.org/licenses/gpl-3.0.txt>. + NAME="aumo" error() { @@ -8,11 +18,17 @@ error() { die() { error "$1" - if [ -n "$2" ]; then - exit "$2" - else - exit 1 - fi + 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() { @@ -21,12 +37,12 @@ get_mounted_labels() { 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 + 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 "|" + printf "\0" fi printf "%s" "$label" fi @@ -34,25 +50,30 @@ get_unmounted_labels() { } unmounting() { - disk_name="$(get_mounted_labels | jq 'join("|")' --join-output | rofi -sep "|" -dmenu -p "Select disk to unmount")" + 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 "|" -dmenu -p "Select disk to mount")" + 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" in +case "${1-unset}" in "mount") mounting ;; "unmount" | "umount") unmounting ;; +"unset") + usage + die "You need to provide one argument." + ;; *) - die "Usage: $NAME mount|unmount" + usage + die "Unknown command: '$1'" ;; esac diff --git a/pkgs/by-name/au/aumo/package.nix b/pkgs/by-name/au/aumo/package.nix index 58618e63..c3c2f3ca 100644 --- a/pkgs/by-name/au/aumo/package.nix +++ b/pkgs/by-name/au/aumo/package.nix @@ -1,9 +1,22 @@ +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# 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 <https://www.gnu.org/licenses/gpl-3.0.txt>. { writeShellApplication, # Dependencies + fd, udisks, - findutils, rofi, + jq, + gnugrep, + util-linux, + gnused, }: writeShellApplication { name = "aumo"; @@ -11,7 +24,11 @@ writeShellApplication { inheritPath = false; runtimeInputs = [ udisks - findutils + fd rofi + jq + gnugrep + util-linux # for findmnt + gnused ]; } |
