diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/desktop/niri/keybindings.nix | 6 | ||||
| -rw-r--r-- | modules/desktop/rofi/default.nix | 61 | ||||
| -rw-r--r-- | modules/desktop/rofi/rofi-action.sh | 13 |
3 files changed, 79 insertions, 1 deletions
diff --git a/modules/desktop/niri/keybindings.nix b/modules/desktop/niri/keybindings.nix index e8513f8..de2f144 100644 --- a/modules/desktop/niri/keybindings.nix +++ b/modules/desktop/niri/keybindings.nix @@ -110,6 +110,12 @@ in "drun" ]; }; + "Mod+Shift+E" = { + _props.hotkey-overlay-title = "Run an Action: rofi"; + spawn = [ + (lib.getExe config.desktop.rofi.action.package) + ]; + }; "Mod+Return" = lib.mkIf config.terminal.kitty.enable { _props.hotkey-overlay-title = "Open a Terminal: kitty"; spawn = [ (lib.getExe config.terminal.kitty.package) ]; 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 ]; }; } diff --git a/modules/desktop/rofi/rofi-action.sh b/modules/desktop/rofi/rofi-action.sh new file mode 100644 index 0000000..1e09b75 --- /dev/null +++ b/modules/desktop/rofi/rofi-action.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Fire-and-forget action menu driven by rofi's dmenu mode. +# The entries and the commands they run are generated at build time +# from `config.desktop.rofi.action.actions`. + +options="@@OPTIONS@@" + +chosen=$(echo -e "$options" | rofi -dmenu -i -p "Action:") + +case "$chosen" in +# replacing "@@CASES@@") : ;; instead of @@CASES@@ for linter/formatter +"@@CASES@@") : ;; +esac |
