From 5148001968d1189a3715759998b6dcce5ba3ac5f Mon Sep 17 00:00:00 2001 From: Julien Gautier Date: Mon, 11 May 2026 10:49:46 +0200 Subject: [PATCH] nix-search-tv: add keybindings and actions Use the same keybindings as nix-search-tv's author used here: https://github.com/3timeslazy/nix-search-tv/blob/main/nixpkgs.sh#L26 Also, handle case where the package is null --- modules/programs/nix-search-tv.nix | 29 +++++++-- .../programs/nix-search-tv/television.nix | 61 +++++++++++++------ 2 files changed, 67 insertions(+), 23 deletions(-) diff --git a/modules/programs/nix-search-tv.nix b/modules/programs/nix-search-tv.nix index 43d55302d..1e3e4edd3 100644 --- a/modules/programs/nix-search-tv.nix +++ b/modules/programs/nix-search-tv.nix @@ -70,7 +70,9 @@ in programs.television.channels.nix-search-tv = lib.mkIf cfg.enableTelevisionIntegration ( let - path = lib.getExe cfg.package; + nix-search-tv-path = if cfg.package != null then lib.getExe cfg.package else "nix-search-tv"; + keybinding_modifier = if pkgs.stdenv.isDarwin then "alt" else "ctrl"; + opener = if pkgs.stdenv.isDarwin then "open" else "xdg-open"; in { metadata = { @@ -78,17 +80,36 @@ in description = "Search nix options and packages"; }; - source.command = "${path} print"; - preview.command = ''${path} preview "{}"''; + source.command = "${nix-search-tv-path} print"; + preview.command = ''${nix-search-tv-path} preview "{}"''; + + keybindings = { + "${keybinding_modifier}-r" = "actions:run"; + "${keybinding_modifier}-i" = "actions:shell"; + "${keybinding_modifier}-s" = "actions:source"; + "${keybinding_modifier}-o" = "actions:homepage"; + }; actions.run = { + description = "Run the package"; command = ''nix run {replace:s/\/ /#/g}''; - mode = "fork"; + mode = "execute"; }; actions.shell = { + description = "Enter new nix shell with this package"; command = ''nix shell {replace:s/\/ /#/g}''; mode = "execute"; }; + actions.source = { + description = "Open link to source code"; + command = "${nix-search-tv-path} source '{}' | xargs ${opener}"; + mode = "execute"; + }; + actions.homepage = { + description = "Open link to homepage"; + command = "${nix-search-tv-path} homepage '{}' | xargs ${opener}"; + mode = "execute"; + }; } ); }; diff --git a/tests/modules/programs/nix-search-tv/television.nix b/tests/modules/programs/nix-search-tv/television.nix index 8f8db6dae..b0e97d9b3 100644 --- a/tests/modules/programs/nix-search-tv/television.nix +++ b/tests/modules/programs/nix-search-tv/television.nix @@ -4,27 +4,50 @@ programs.nix-search-tv.enable = true; - nmt.script = '' - assertFileExists home-files/.config/television/cable/nix-search-tv.toml - assertFileContent home-files/.config/television/cable/nix-search-tv.toml \ - ${pkgs.writeText "settings-expected" '' - [actions.run] - command = "nix run {replace:s/\\/ /#/g}" - mode = "fork" + nmt.script = + let + keybinding_modifier = if pkgs.stdenv.isDarwin then "alt" else "ctrl"; + opener = if pkgs.stdenv.isDarwin then "open" else "xdg-open"; + in + '' + assertFileExists home-files/.config/television/cable/nix-search-tv.toml + assertFileContent home-files/.config/television/cable/nix-search-tv.toml \ + ${pkgs.writeText "settings-expected" '' + [actions.homepage] + command = "${lib.getExe pkgs.nix-search-tv} homepage '{}' | xargs ${opener}" + description = "Open link to homepage" + mode = "execute" - [actions.shell] - command = "nix shell {replace:s/\\/ /#/g}" - mode = "execute" + [actions.run] + command = "nix run {replace:s/\\/ /#/g}" + description = "Run the package" + mode = "execute" - [metadata] - description = "Search nix options and packages" - name = "nix-search-tv" + [actions.shell] + command = "nix shell {replace:s/\\/ /#/g}" + description = "Enter new nix shell with this package" + mode = "execute" - [preview] - command = "${lib.getExe pkgs.nix-search-tv} preview \"{}\"" + [actions.source] + command = "${lib.getExe pkgs.nix-search-tv} source '{}' | xargs ${opener}" + description = "Open link to source code" + mode = "execute" - [source] - command = "${lib.getExe pkgs.nix-search-tv} print" - ''} - ''; + [keybindings] + ${keybinding_modifier}-i = "actions:shell" + ${keybinding_modifier}-o = "actions:homepage" + ${keybinding_modifier}-r = "actions:run" + ${keybinding_modifier}-s = "actions:source" + + [metadata] + description = "Search nix options and packages" + name = "nix-search-tv" + + [preview] + command = "${lib.getExe pkgs.nix-search-tv} preview \"{}\"" + + [source] + command = "${lib.getExe pkgs.nix-search-tv} print" + ''} + ''; }