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

View File

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