From 90f7dc88457dbbef8eabb9a38abff43ddbe1ade2 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sun, 20 Jul 2025 14:23:44 +0200 Subject: [PATCH] Modules/Hyprland: Improve keybinding help by truncating /nix/store and /home/christoph paths --- home/modules/hyprland/default.nix | 34 +++++++++++++++++++------------ home/modules/rofi/default.nix | 14 ++++++------- lib/rofi.nix | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/home/modules/hyprland/default.nix b/home/modules/hyprland/default.nix index e1d7f541..3c51251e 100644 --- a/home/modules/hyprland/default.nix +++ b/home/modules/hyprland/default.nix @@ -5,6 +5,7 @@ mylib, pkgs, nixosConfig, + username, ... }: let inherit (config.modules) hyprland color; @@ -168,27 +169,34 @@ in { file = { ".config/hypr/keybindings.info".text = let - fixupNoMod = key: ''${builtins.replaceStrings - ["<-"] - ["<"] - key}''; + fixupHomeDir = key: + builtins.replaceStrings ["/home/${username}"] ["~"] key; - mkBindHelpKey = key: ''${builtins.replaceStrings - ["$mainMod" " " ","] - ["${hyprland.keybindings.main-mod}" "-" ""] - key}''; + fixupNixStore = key: let + # The pattern has to match the entire string, otherwise it won't work + matches = builtins.match ".*/nix/store/(.*)/.*" key; + in + if (matches == null) + then key + else builtins.replaceStrings matches ["..."] key; - mkBindHelpAction = action: ''${builtins.replaceStrings - [","] - [""] - action}''; + fixupNoMod = key: + builtins.replaceStrings ["<-"] ["<"] key; + + mkBindHelpKey = key: + builtins.replaceStrings ["$mainMod" " " ","] ["${hyprland.keybindings.main-mod}" "-" ""] key; + + mkBindHelpAction = action: + builtins.replaceStrings [","] [""] action; mkBindHelp = key: action: "<${mkBindHelpKey key}>: ${mkBindHelpAction action}"; mkBindsHelp = key: actions: actions |> builtins.map (mkBindHelp key) - |> builtins.map fixupNoMod; + |> builtins.map fixupNoMod + |> builtins.map fixupNixStore + |> builtins.map fixupHomeDir; in (hyprland.keybindings.bindings // always-bind) |> builtins.mapAttrs mkBindsHelp diff --git a/home/modules/rofi/default.nix b/home/modules/rofi/default.nix index 9bd3c9bf..0240d661 100644 --- a/home/modules/rofi/default.nix +++ b/home/modules/rofi/default.nix @@ -134,17 +134,17 @@ in { modules.hyprland.keybindings = let vpn-menu = - pkgs.writeScript + pkgs.writeScriptBin "rofi-menu-vpn" (builtins.readFile ./menus/vpn.fish); keybinds-menu = - pkgs.writeScript + pkgs.writeScriptBin "rofi-menu-keybinds" (builtins.readFile ./menus/keybinds.fish); lectures-menu = - pkgs.writeScript + pkgs.writeScriptBin "rofi-menu-lectures" (builtins.readFile ./menus/lectures.fish); @@ -182,13 +182,13 @@ in { in { bindings = lib.mergeAttrsList [ { - "$mainMod, escape" = ["exec, \"${power-menu}\""]; - "$mainMod, m" = ["exec, \"${keybinds-menu}\""]; - "$mainMod, w" = ["exec, \"${wallpaper-menu}\""]; + "$mainMod, escape" = ["exec, \"${power-menu}/bin/rofi-menu-power\""]; + "$mainMod, m" = ["exec, \"${keybinds-menu}/bin/rofi-menu-keybinds\""]; + "$mainMod, w" = ["exec, \"${wallpaper-menu}/bin/rofi-menu-wall\""]; # "$mainMod, o" = ["exec, \"${lectures-menu}\""]; } (lib.optionalAttrs (!nixosConfig.modules.network.useNetworkManager) { - "$mainMod, U" = ["exec, \"${vpn-menu}\""]; + "$mainMod, U" = ["exec, \"${vpn-menu}/rofi-menu-vpn\""]; }) ]; }; diff --git a/lib/rofi.nix b/lib/rofi.nix index 854c822a..033a8cf6 100644 --- a/lib/rofi.nix +++ b/lib/rofi.nix @@ -22,7 +22,7 @@ |> builtins.concatStringsSep "\n"; in prompt: attrs: - pkgs.writeScript "rofi-menu-${prompt}" '' + pkgs.writeScriptBin "rofi-menu-${prompt}" '' #! ${pkgs.fish}/bin/fish # OPTIONS contains all possible values Rofi will display