Update fish functions to add a gotify-send function

This commit is contained in:
albert 2025-04-21 10:40:07 +02:00
parent 374538afa3
commit 409901769f
Signed by: albert
GPG key ID: 3895DD267CA11BA9
2 changed files with 52 additions and 1 deletions
home-manager/common/software/cli/fish
nixos

View file

@ -191,5 +191,50 @@
sudo snapper -c $volume list
end
'';
gotify-send = ''
if test (count $argv) -lt 1
echo "Usage: <command> | gotify-send <subject>" >&2
cat > /dev/null
return 1
end
set -l subject $argv[1]
set -l priority 3 # Default priority
set -l gotify_url "https://gotify.sysctl.io"
set -l token_file "/var/run/secrets/gotify_global_token"
# Read token from file
set -l gotify_token
if test -r "$token_file"
set gotify_token (cat "$token_file" | string trim)
else
echo "Error: Cannot read token file '$token_file'" >&2
cat > /dev/null
return 1
end
if test -z "$gotify_token"
echo "Error: Token file '$token_file' is empty or read failed." >&2
cat > /dev/null
return 1
end
set -l message_body (string collect)
set -l escaped_subject (string escape --style=json "$subject")
set -l escaped_message (string escape --style=json "$message_body")
set -l json_payload (printf '{"title": "%s", "message": "%s", "priority": %d}' \
"$escaped_subject" "$escaped_message" $priority)
# Assumes curl exists
echo $json_payload | curl -sS -X POST \
-H "Content-Type: application/json" \
-H "X-Gotify-Key: $gotify_token" \
--data @- \
"$gotify_url/message" > /dev/null 2>&1 &
return 0
'';
};
}

View file

@ -17,6 +17,12 @@
dev.enable = false;
nixos.enable = false;
};
# Used for the fish function "gotify-send"
sops.secrets."gotify_global_token" = {
sopsFile = ../secrets/secrets.yaml;
owner = "albert";
};
programs.fish.enable = true;
}