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
This commit is contained in:
Julien Gautier
2026-05-11 10:49:46 +02:00
committed by Austin Horstman
parent c7e4087b4d
commit 5148001968
2 changed files with 67 additions and 23 deletions

View File

@@ -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";
};
}
);
};