aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-14 11:38:40 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-14 11:38:40 +0200
commitc06421431d026eb0932291e3da15257b65d8163b (patch)
tree19667cd9c6fab8254f21018d2820179c65a9ca04 /pkgs
parentmodules/xdg/url-handler: Correctly put a newline between nvim and zathura (diff)
downloadnixos-config-c06421431d026eb0932291e3da15257b65d8163b.zip
pkgs/aumo: Migrate to writeShellApplication and don't show already mounted/unmouted disks
Diffstat (limited to 'pkgs')
-rwxr-xr-xpkgs/by-name/au/aumo/aumo.sh38
-rw-r--r--pkgs/by-name/au/aumo/package.nix12
2 files changed, 40 insertions, 10 deletions
diff --git a/pkgs/by-name/au/aumo/aumo.sh b/pkgs/by-name/au/aumo/aumo.sh
index 84d39deb..d86165b2 100755
--- a/pkgs/by-name/au/aumo/aumo.sh
+++ b/pkgs/by-name/au/aumo/aumo.sh
@@ -1,16 +1,46 @@
#! /usr/bin/env dash
-# shellcheck source=/dev/null
-SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH
+NAME="aumo"
+
+error() {
+ printf "\033[1;91m==> ERROR:\033[0m \033[1;93m%s\033[0m\n" "$*" >&2
+}
+
+die() {
+ error "$1"
+ if [ -n "$2" ]; then
+ exit "$2"
+ else
+ exit 1
+ fi
+}
+
+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="$(find /dev/disk/by-label -type l -printf "%P|" | rofi -sep "|" -dmenu -p "Select disk to mount")"
+ 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="$(find /dev/disk/by-label -type l -printf "%P|" | rofi -sep "|" -dmenu -p "Select disk to mount")"
+ disk_name="$(get_unmounted_labels | rofi -sep "|" -dmenu -p "Select disk to mount")"
udisksctl mount --block-device "/dev/disk/by-label/$disk_name"
}
diff --git a/pkgs/by-name/au/aumo/package.nix b/pkgs/by-name/au/aumo/package.nix
index 20054bb5..58618e63 100644
--- a/pkgs/by-name/au/aumo/package.nix
+++ b/pkgs/by-name/au/aumo/package.nix
@@ -1,15 +1,15 @@
{
- sysLib,
+ writeShellApplication,
+ # Dependencies
udisks,
findutils,
rofi,
}:
-sysLib.writeShellScript {
+writeShellApplication {
name = "aumo";
- src = ./aumo.sh;
- generateCompletions = false;
- keepPath = false;
- dependencies = [
+ text = builtins.readFile ./aumo.sh;
+ inheritPath = false;
+ runtimeInputs = [
udisks
findutils
rofi