Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fish: support simple key bindings #4599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions modules/programs/fish.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -474,6 +491,9 @@ in {
# Aliases
${aliasesStr}

# Binds
${bindsStr}

# Interactive shell initialisation
${cfg.interactiveShellInit}

Expand Down
29 changes: 29 additions & 0 deletions tests/modules/programs/fish/bindings.nix
Original file line number Diff line number Diff line change
@@ -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'"
'';
};
};
}
1 change: 1 addition & 0 deletions tests/modules/programs/fish/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
fish-functions = ./functions.nix;
fish-no-functions = ./no-functions.nix;
fish-plugins = ./plugins.nix;
fish-bindings = ./bindings.nix;
}
Loading