diff options
| author | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-25 04:32:15 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-25 04:32:31 +0530 |
| commit | 0afd73753d72b7ac2de83f80f457a85a5a33a29c (patch) | |
| tree | c09106db3779a59f3a9a7db9553da5ef3d928d46 /modules/desktop/rofi/default.nix | |
| parent | f36491c92269d3e1dd241e67c292af762ac498c3 (diff) | |
| download | home-manager-config-0afd73753d72b7ac2de83f80f457a85a5a33a29c.tar.gz home-manager-config-0afd73753d72b7ac2de83f80f457a85a5a33a29c.zip | |
feat(desktop/rofi): added rofi actions
Rofi actions allows users to run some of the most commonly run shell
commands (like shutdown, poweroff monitors, start usque/vpn tunnels),
from a rofi menu instead of having to memorize and type them out.
Diffstat (limited to 'modules/desktop/rofi/default.nix')
| -rw-r--r-- | modules/desktop/rofi/default.nix | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/modules/desktop/rofi/default.nix b/modules/desktop/rofi/default.nix index ed1cf05..0c0e6df 100644 --- a/modules/desktop/rofi/default.nix +++ b/modules/desktop/rofi/default.nix @@ -1,4 +1,4 @@ -# Application launcher and dmenu replacement +# Application launcher, dmenu replacement and action menu { config, lib, @@ -8,6 +8,30 @@ let cfg = config.desktop.rofi; base16Colors = import ../../colors/base16 { inherit config lib pkgs; }; + + actionOptionsString = lib.concatMapStringsSep "\\n" ( + action: action.name + lib.optionalString (action.icon != null) "\\0icon\\x1f${action.icon}" + ) cfg.action.actions; + + actionCasesString = lib.concatStringsSep "\n" ( + map (action: " \"${action.name}\") ${action.command} ;;") cfg.action.actions + ); + + actionScript = pkgs.writeShellApplication { + name = "rofi-action"; + runtimeInputs = [ + config.terminal.bash.package + cfg.package + ]; + text = + builtins.replaceStrings + [ + "@@OPTIONS@@" + ''"@@CASES@@") : ;;'' + ] + [ actionOptionsString actionCasesString ] + (builtins.readFile ./rofi-action.sh); + }; in { options.desktop.rofi = { @@ -17,6 +41,39 @@ in default = config.programs.rofi.finalPackage; description = "The rofi package to use."; }; + + action = { + actions = lib.mkOption { + type = lib.types.listOf ( + lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = "Name shown in the menu."; + }; + command = lib.mkOption { + type = lib.types.str; + description = "Shell command to run when the entry is selected."; + }; + icon = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = "Icon name shown next to the entry."; + }; + }; + } + ); + default = [ ]; + description = "Actions shown by the rofi-action menu."; + }; + + package = lib.mkOption { + type = lib.types.package; + readOnly = true; + default = actionScript; + description = "The rofi-action script package."; + }; + }; }; config = lib.mkIf config.desktop.enable { @@ -47,5 +104,7 @@ in sort = true; }; }; + + home.packages = lib.mkIf (cfg.action.actions != [ ]) [ cfg.action.package ]; }; } |
