1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-02-17 05:35:06 +01:00

fish: support simple key bindings

support simple keybinds of the form "SEQUENCE" -> COMMAND,
as described in the fish docs: https://fishshell.com/docs/current/cmds/bind.html
This commit is contained in:
Arul Agrawal 2023-10-22 21:08:53 +02:00 committed by Arul Agrawal
parent 6e277d9566
commit 5b5cef33eb
No known key found for this signature in database
GPG key ID: D16A92BEDB48284C
3 changed files with 50 additions and 0 deletions

View file

@ -213,6 +213,9 @@ let
aliasesStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases);
bindsStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "bind ${k} ${escapeShellArg v}") cfg.shellBinds);
fishIndent = name: text:
pkgs.runCommand name {
nativeBuildInputs = [ cfg.package ];
@ -288,6 +291,20 @@ in {
'';
};
shellBinds = mkOption {
type = with types; attrsOf str;
default = { };
example = literalExpression ''
{
"\cg" = "git diff; commandline -f repaint";
}
'';
description = ''
An attribute set that maps a key bindings (the top level attribute names
in this option) to command strings or directly to build outputs.
'';
};
shellInit = mkOption {
type = types.lines;
default = "";
@ -474,6 +491,9 @@ in {
# Aliases
${aliasesStr}
# Binds
${bindsStr}
# Interactive shell initialisation
${cfg.interactiveShellInit}

View file

@ -0,0 +1,29 @@
{ config, ... }: {
config = {
programs.fish = {
enable = true;
shellBinds = {
"\\cd" = "exit";
"." = "rationalise-dot";
"\\cg" = "git diff; commandline -f repaint";
"\\cz" = "foo && bar";
};
};
nmt = {
description =
"if fish.shellBinds is set, check fish.config contains bindings";
script = ''
assertFileContains home-files/.config/fish/config.fish \
"bind \cd exit"
assertFileContains home-files/.config/fish/config.fish \
"bind . rationalise-dot"
assertFileContains home-files/.config/fish/config.fish \
"bind \cg 'git diff; commandline -f repaint'"
assertFileContains home-files/.config/fish/config.fish \
"bind \cz 'foo && bar'"
'';
};
};
}

View file

@ -4,4 +4,5 @@
fish-functions = ./functions.nix;
fish-no-functions = ./no-functions.nix;
fish-plugins = ./plugins.nix;
fish-bindings = ./bindings.nix;
}