diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index fc11e512414f..0c9bf056d5aa 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -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} diff --git a/tests/modules/programs/fish/bindings.nix b/tests/modules/programs/fish/bindings.nix new file mode 100644 index 000000000000..2d1a6c63f3cb --- /dev/null +++ b/tests/modules/programs/fish/bindings.nix @@ -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'" + ''; + }; + }; +} diff --git a/tests/modules/programs/fish/default.nix b/tests/modules/programs/fish/default.nix index f81ff971ea35..2594f2a9095d 100644 --- a/tests/modules/programs/fish/default.nix +++ b/tests/modules/programs/fish/default.nix @@ -4,4 +4,5 @@ fish-functions = ./functions.nix; fish-no-functions = ./no-functions.nix; fish-plugins = ./plugins.nix; + fish-bindings = ./bindings.nix; }