From 1196fdb95bd2549f9f26ac4f6c04357437f8f896 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 15 Feb 2025 16:01:36 -0600 Subject: [PATCH] menus: use shell script instead of wrapper Signed-off-by: Myned --- options/custom/desktops/hyprland/binds.nix | 1 + options/custom/desktops/niri/binds.nix | 12 ++--- options/custom/menus/default.nix | 2 +- options/custom/menus/rofi/default.nix | 26 ++++------ options/custom/menus/walker/default.nix | 6 +-- .../custom/programs/networkmanager-dmenu.nix | 48 ++++++++++--------- 6 files changed, 46 insertions(+), 49 deletions(-) diff --git a/options/custom/desktops/hyprland/binds.nix b/options/custom/desktops/hyprland/binds.nix index dcf8548..00e4279 100644 --- a/options/custom/desktops/hyprland/binds.nix +++ b/options/custom/desktops/hyprland/binds.nix @@ -265,6 +265,7 @@ in { (key "Super_L" "Super" "exec" config.custom.menus.default.show) (key "Super_L" "Super+Alt" "exec" config.custom.menus.vault.show) + (key "Super_L" "Super+Ctrl" "exec" config.custom.menus.calculator.show) (key "Super_L" "Super+Ctrl+Shift" "exec" config.custom.menus.network.show) (key "Super_L" "Super+Shift" "exec" config.custom.menus.search.show) ]; diff --git a/options/custom/desktops/niri/binds.nix b/options/custom/desktops/niri/binds.nix index 7f58144..ba314ef 100644 --- a/options/custom/desktops/niri/binds.nix +++ b/options/custom/desktops/niri/binds.nix @@ -136,7 +136,7 @@ in { (key "N" "Mod" (spawn networkmanager_dmenu)) (key "O" "Mod" (spawn [loupe "/tmp/wallpaper.png"])) (key "P" "Ctrl+Alt" (spawn [pkill "bitwarden"])) - (key "P" "Mod" (spawn [bash "-c" config.custom.menus.vault.show])) + (key "P" "Mod" (spawn config.custom.menus.vault.show)) (key "P" "Mod+Shift" (spawn bitwarden)) (key "Q" "Mod" close-window) (key "R" "Mod" focus-window-or-workspace-down) @@ -156,9 +156,9 @@ in { (key "T" "Mod" (spawn ghostty)) (key "Tab" "Mod" switch-focus-between-floating-and-tiling) (key "Up" "Mod" (spawn [swayosd-client "--brightness" "raise"])) - (key "V" "Mod" (spawn [bash "-c" config.custom.menus.clipboard.show])) + (key "V" "Mod" (spawn config.custom.menus.clipboard.show)) (key "V" "Mod+Ctrl" (spawn vm)) - (key "V" "Mod+Shift" (spawn [bash "-c" config.custom.menus.clipboard.clear])) + (key "V" "Mod+Shift" (spawn config.custom.menus.clipboard.clear)) (key "W" "Mod" focus-window-or-workspace-up) (key "W" "Mod+Shift" move-window-up-or-to-workspace-up) (key "WheelScrollDown" "Mod" focus-window-or-workspace-down) @@ -183,9 +183,9 @@ in { # TODO: Uncomment when fixed #// (key "Shift_L" "Mod" focus-workspace-previous) # TODO: Use "Super_L" when fixed - (key "Space" "Mod" (spawn [bash "-c" config.custom.menus.show])) - (key "Space" "Mod+Ctrl" (spawn [bash "-c" config.custom.menus.calculator.show])) - (key "Space" "Mod+Shift" (spawn [bash "-c" config.custom.menus.search.show])) + (key "Space" "Mod" (spawn config.custom.menus.default.show)) + (key "Space" "Mod+Ctrl" (spawn config.custom.menus.calculator.show)) + (key "Space" "Mod+Shift" (spawn config.custom.menus.search.show)) # Media keys # https://github.com/xkbcommon/libxkbcommon/blob/master/include/xkbcommon/xkbcommon-keysyms.h diff --git a/options/custom/menus/default.nix b/options/custom/menus/default.nix index 42a4828..86e0ef1 100644 --- a/options/custom/menus/default.nix +++ b/options/custom/menus/default.nix @@ -8,7 +8,7 @@ with lib; let in { options.custom.menus = { enable = mkOption {default = config.custom.full;}; - show = mkOption {default = "";}; + default.show = mkOption {default = "";}; calculator.show = mkOption {default = "";}; clipboard = { diff --git a/options/custom/menus/rofi/default.nix b/options/custom/menus/rofi/default.nix index fcfb611..2bdc94a 100644 --- a/options/custom/menus/rofi/default.nix +++ b/options/custom/menus/rofi/default.nix @@ -8,6 +8,7 @@ with lib; let cfg = config.custom.menus.rofi; hm = config.home-manager.users.${config.custom.username}; + bash = getExe pkgs.bash; cliphist = getExe hm.services.cliphist.package; echo = getExe' pkgs.coreutils "echo"; networkmanager_dmenu = getExe pkgs.networkmanager_dmenu; @@ -24,30 +25,21 @@ in { config = mkIf cfg.enable { custom = mkIf (config.custom.menu == "rofi") { - menus = let - quit = "${pkill} --exact rofi"; - in { - show = "${quit} || ${rofi} -show drun -show-icons"; - - calculator.show = concatStringsSep " " [ - "${quit} || ${rofi}" - "-show calc" - "-no-history" - "-calc-error-color '#dc322f'" - ''-calc-command "${echo} -n '{result}' | ${wl-copy}"'' - ]; + menus = mapAttrsRecursive (path: value: pkgs.writeShellScript (concatStringsSep "-" (["menus"] ++ path)) value) { + default.show = "${pkill} --exact rofi || ${rofi} -show drun -show-icons"; + calculator.show = ''${pkill} --exact rofi || ${rofi} -show calc -no-history -calc-error-color '#dc322f' -calc-command "${echo} -n '{result}' | ${wl-copy}"''; clipboard = { - show = "${quit} || ${rofi} -show clipboard -show-icons"; + show = "${pkill} --exact rofi || ${rofi} -show clipboard -show-icons"; clear = "${cliphist} wipe && ${notify-send} '> cliphist' 'Clipboard cleared' --urgency low"; clear-silent = "${cliphist} wipe"; }; - dmenu.show = "${quit} || ${rofi} -dmenu"; - emoji.show = "${quit} || ${rofimoji} --prompt 󰱰"; - network.show = "${quit} || ${networkmanager_dmenu}"; + dmenu.show = "${pkill} --exact rofi || ${rofi} -dmenu"; + emoji.show = "${pkill} --exact rofi || ${rofimoji} --prompt 󰱰"; + network.show = "${pkill} --exact rofi || ${networkmanager_dmenu}"; search.show = ""; - vault.show = "${quit} || ${rofi-rbw} --prompt 󰌾"; + vault.show = "${pkill} --exact rofi || ${rofi-rbw} --prompt 󰌾"; }; services = { diff --git a/options/custom/menus/walker/default.nix b/options/custom/menus/walker/default.nix index 71759de..9f5e056 100644 --- a/options/custom/menus/walker/default.nix +++ b/options/custom/menus/walker/default.nix @@ -19,9 +19,9 @@ in { }; config = mkIf cfg.enable { - custom = { - menus = mkIf (config.custom.menu == "walker") { - show = walker; + custom = mkIf (config.custom.menu == "walker") { + menus = mapAttrsRecursive (path: value: pkgs.writeShellScript (concatStringsSep "-" (["menus"] ++ path)) value) { + default.show = walker; clipboard = { show = "${walker} --modules clipboard"; diff --git a/options/custom/programs/networkmanager-dmenu.nix b/options/custom/programs/networkmanager-dmenu.nix index 62138d6..0312dca 100644 --- a/options/custom/programs/networkmanager-dmenu.nix +++ b/options/custom/programs/networkmanager-dmenu.nix @@ -10,33 +10,37 @@ with lib; let rofi = getExe hm.programs.rofi.package; in { - options.custom.programs.networkmanager-dmenu.enable = mkOption {default = false;}; + options.custom.programs.networkmanager-dmenu = { + enable = mkOption {default = false;}; + }; config = mkIf cfg.enable { # https://github.com/firecat53/networkmanager-dmenu environment.systemPackages = [pkgs.networkmanager_dmenu]; - home-manager.users.${config.custom.username} = { - # https://github.com/firecat53/networkmanager-dmenu/blob/main/config.ini.example - #!! Option not available, files written directly - xdg.configFile."networkmanager-dmenu/config.ini".text = let - menu = - if config.custom.menu == "rofi" - then "${rofi} -dmenu -p 󰛳" - else ""; - in '' - [dmenu] - compact = true - dmenu_command = ${menu} - list_saved = true - active_chars =  - highlight = true - wifi_icons = 󰤯󰤟󰤢󰤥󰤨 - format = {icon} {name} + home-manager.sharedModules = [ + { + # https://github.com/firecat53/networkmanager-dmenu/blob/main/config.ini.example + xdg.configFile = { + "networkmanager-dmenu/config.ini".text = let + menu = + if config.custom.menu == "rofi" + then "${rofi} -dmenu -p 󰛳" + else ""; + in '' + [dmenu] + compact = true + dmenu_command = ${menu} + active_chars =  + highlight = true + wifi_icons = 󰤯󰤟󰤢󰤥󰤨 + format = {icon} {name} - [dmenu_passphrase] - obscure = true - ''; - }; + [dmenu_passphrase] + obscure = true + ''; + }; + } + ]; }; }