From 13ae5ad530a98167dc87b0645d8a6bc80f059c9c Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Thu, 14 Mar 2024 00:10:13 +0100 Subject: [PATCH] Add caffeine --- README.md | 7 +++++++ home/scripts/caffeine.nix | 20 ++++++++++++++++++++ home/scripts/default.nix | 10 ++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 home/scripts/caffeine.nix diff --git a/README.md b/README.md index f9ca738..9638ba7 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ Themes and colors are managed by the `home/variable/theme` folder. - `sound-output` - `sound-change ` +## Caffeine + +Caffeine is a simple script that toggles the hypridle (disable suspend & screenlock). + +- `caffeine` # Toggle caffeine +- `caffeine-status` # Return active/inactive + # Installation ```sh diff --git a/home/scripts/caffeine.nix b/home/scripts/caffeine.nix new file mode 100644 index 0000000..a538af6 --- /dev/null +++ b/home/scripts/caffeine.nix @@ -0,0 +1,20 @@ +{ pkgs, config, ... }: +let + homedir = config.home.homeDirectory; + + caffeine-status = pkgs.writeShellScriptBin "caffeine-status" '' + [[ -f /tmp/caffeine ]] && echo "active" || echo "inactive" + ''; + + caffeine = pkgs.writeShellScriptBin "caffeine" '' + if [[ -f /tmp/caffeine ]]; then + rm /tmp/caffeine + ${pkgs.hypridle}/bin/hypridle & + ${pkgs.libnotify}/bin/notify-send "󰾪 Caffeine Deactivated" + else + touch /tmp/caffeine + pkill hypridle && ${pkgs.libnotify}/bin/notify-send "󰅶 Caffeine Activated" + fi + ''; + +in { home.packages = with pkgs; [ caffeine-status caffeine ]; } diff --git a/home/scripts/default.nix b/home/scripts/default.nix index d34fffe..2a6b33a 100644 --- a/home/scripts/default.nix +++ b/home/scripts/default.nix @@ -1,4 +1,10 @@ { - imports = - [ ./scripts.nix ./nerdfetch.nix ./nixy.nix ./sounds.nix ./brightness.nix ]; + imports = [ + ./scripts.nix + ./nerdfetch.nix + ./nixy.nix + ./sounds.nix + ./brightness.nix + ./caffeine.nix + ]; }