aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/au
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/au')
-rwxr-xr-xpkgs/by-name/au/aumo/aumo.sh63
-rw-r--r--pkgs/by-name/au/aumo/package.nix33
2 files changed, 82 insertions, 14 deletions
diff --git a/pkgs/by-name/au/aumo/aumo.sh b/pkgs/by-name/au/aumo/aumo.sh
index 84d39deb..824d817a 100755
--- a/pkgs/by-name/au/aumo/aumo.sh
+++ b/pkgs/by-name/au/aumo/aumo.sh
@@ -1,28 +1,79 @@
#! /usr/bin/env dash
-# shellcheck source=/dev/null
-SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH
+# 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() {
+ 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="$(find /dev/disk/by-label -type l -printf "%P|" | rofi -sep "|" -dmenu -p "Select disk to mount")"
+ 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="$(find /dev/disk/by-label -type l -printf "%P|" | 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 20054bb5..c3c2f3ca 100644
--- a/pkgs/by-name/au/aumo/package.nix
+++ b/pkgs/by-name/au/aumo/package.nix
@@ -1,17 +1,34 @@
+# 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>.
{
- sysLib,
+ writeShellApplication,
+ # Dependencies
+ fd,
udisks,
- findutils,
rofi,
+ jq,
+ gnugrep,
+ util-linux,
+ gnused,
}:
-sysLib.writeShellScript {
+writeShellApplication {
name = "aumo";
- src = ./aumo.sh;
- generateCompletions = false;
- keepPath = false;
- dependencies = [
+ text = builtins.readFile ./aumo.sh;
+ inheritPath = false;
+ runtimeInputs = [
udisks
- findutils
+ fd
rofi
+ jq
+ gnugrep
+ util-linux # for findmnt
+ gnused
];
}