fzf: group related module attributes

Group repeated attr prefixes so the fzf module and new tests are easier to scan without changing behavior.
This commit is contained in:
Austin Horstman
2026-07-02 15:28:15 -05:00
parent 0396024ea5
commit a4d410db95
6 changed files with 191 additions and 177 deletions
+80 -76
View File
@@ -387,87 +387,91 @@ in
}
];
home.packages = [ cfg.package ];
home.sessionVariables = lib.mapAttrs (_n: toString) fzfEnvVars;
home = {
packages = [ cfg.package ];
sessionVariables = lib.mapAttrs (_n: toString) fzfEnvVars;
};
# Load early so history managers can reclaim Ctrl-R.
programs.bash.initExtra =
let
vars = shellFzfEnvVars "bash";
in
mkIf cfg.enableBashIntegration (
mkOrder 200 (
''
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
''
+ lib.optionalString (vars != { }) "${config.lib.shell.exportAll vars}\n"
+ ''
eval "$(${getExe cfg.package} --bash)"
fi
''
)
);
# Still needs to be initialized after oh-my-zsh (order 800), otherwise
# omz will take precedence.
programs.zsh.initContent =
let
vars = shellFzfEnvVars "zsh";
in
mkIf cfg.enableZshIntegration (
mkOrder 910 (
''
if [[ $options[zle] = on ]]; then
''
+ lib.optionalString (vars != { }) "${config.lib.shell.exportAll vars}\n"
+ ''
source <(${getExe cfg.package} --zsh)
fi
''
)
);
programs.fish.interactiveShellInit =
let
vars = shellFzfEnvVars "fish";
exports = lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: value: "set -gx ${name} ${lib.escapeShellArg (toString value)}") vars
);
in
mkIf cfg.enableFishIntegration (
mkOrder 200 (
lib.optionalString (vars != { }) "${exports}\n"
+ ''
${getExe cfg.package} --fish | source
''
)
);
# Initialize after other completion integrations, such as carapace.
# fzf preserves the previous external completer and falls back to it
# when its own completer does not apply.
programs.nushell = lib.mkIf cfg.enableNushellIntegration {
environmentVariables = lib.mapAttrs (_n: toString) fzfEnvVars;
extraConfig =
programs = {
# Load early so history managers can reclaim Ctrl-R.
bash.initExtra =
let
vars = shellFzfEnvVars "nushell";
assignments = lib.concatStringsSep "\n" (
lib.mapAttrsToList (
name: value: "$env.${name} = ${lib.hm.nushell.toNushell { } (toString value)}"
) vars
vars = shellFzfEnvVars "bash";
in
mkIf cfg.enableBashIntegration (
mkOrder 200 (
''
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
''
+ lib.optionalString (vars != { }) "${config.lib.shell.exportAll vars}\n"
+ ''
eval "$(${getExe cfg.package} --bash)"
fi
''
)
);
# Still needs to be initialized after oh-my-zsh (order 800), otherwise
# omz will take precedence.
zsh.initContent =
let
vars = shellFzfEnvVars "zsh";
in
mkIf cfg.enableZshIntegration (
mkOrder 910 (
''
if [[ $options[zle] = on ]]; then
''
+ lib.optionalString (vars != { }) "${config.lib.shell.exportAll vars}\n"
+ ''
source <(${getExe cfg.package} --zsh)
fi
''
)
);
fish.interactiveShellInit =
let
vars = shellFzfEnvVars "fish";
exports = lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: value: "set -gx ${name} ${lib.escapeShellArg (toString value)}") vars
);
in
mkAfter (
lib.optionalString (vars != { }) "${assignments}\n"
+ ''
source ${
pkgs.runCommand "nushell-fzf-integration.nu" { } ''
${getExe cfg.package} --nushell > $out
''
}
''
mkIf cfg.enableFishIntegration (
mkOrder 200 (
lib.optionalString (vars != { }) "${exports}\n"
+ ''
${getExe cfg.package} --fish | source
''
)
);
# Initialize after other completion integrations, such as carapace.
# fzf preserves the previous external completer and falls back to it
# when its own completer does not apply.
nushell = lib.mkIf cfg.enableNushellIntegration {
environmentVariables = lib.mapAttrs (_n: toString) fzfEnvVars;
extraConfig =
let
vars = shellFzfEnvVars "nushell";
assignments = lib.concatStringsSep "\n" (
lib.mapAttrsToList (
name: value: "$env.${name} = ${lib.hm.nushell.toNushell { } (toString value)}"
) vars
);
in
mkAfter (
lib.optionalString (vars != { }) "${assignments}\n"
+ ''
source ${
pkgs.runCommand "nushell-fzf-integration.nu" { } ''
${getExe cfg.package} --nushell > $out
''
}
''
);
};
};
};
@@ -1,33 +1,35 @@
{ config, ... }:
{
programs.fzf = {
enable = true;
enableBashIntegration = true;
programs = {
fzf = {
enable = true;
enableBashIntegration = true;
historyWidget = {
command = "global-history";
bash.command = "";
historyWidget = {
command = "global-history";
bash.command = "";
};
fileWidget.bash.command = "$HOME/bin/files";
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
};
fileWidget.bash.command = "$HOME/bin/files";
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
bash.enable = true;
};
programs.bash.enable = true;
nmt.script = ''
assertFileRegex home-files/.bashrc \
'export FZF_CTRL_R_COMMAND='
@@ -1,31 +1,33 @@
{ config, ... }:
{
programs.fzf = {
enable = true;
enableFishIntegration = true;
programs = {
fzf = {
enable = true;
enableFishIntegration = true;
historyWidget = {
command = "global-history";
fish.command = "";
historyWidget = {
command = "global-history";
fish.command = "";
};
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
};
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
fish.enable = true;
};
programs.fish.enable = true;
nmt.script = ''
assertFileRegex home-files/.config/fish/config.fish \
'set -gx FZF_CTRL_R_COMMAND'
@@ -1,27 +1,29 @@
{ config, pkgs, ... }:
{
programs.fzf = {
enable = true;
enableNushellIntegration = true;
programs = {
fzf = {
enable = true;
enableNushellIntegration = true;
historyWidget.command = "";
historyWidget.command = "";
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
};
};
programs.nushell.enable = true;
nushell.enable = true;
};
nmt.script =
let
@@ -1,31 +1,33 @@
{ config, pkgs, ... }:
{
programs.fzf = {
enable = true;
enableNushellIntegration = true;
programs = {
fzf = {
enable = true;
enableNushellIntegration = true;
historyWidget = {
command = "global-history";
nushell.command = "";
historyWidget = {
command = "global-history";
nushell.command = "";
};
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
};
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
nushell.enable = true;
};
programs.nushell.enable = true;
nmt.script =
let
nushellConfigFile =
@@ -1,33 +1,35 @@
{ config, ... }:
{
programs.fzf = {
enable = true;
enableZshIntegration = true;
programs = {
fzf = {
enable = true;
enableZshIntegration = true;
historyWidget = {
command = "global-history";
zsh.command = "";
historyWidget = {
command = "global-history";
zsh.command = "";
};
fileWidget.zsh.command = "$HOME/bin/files";
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
};
fileWidget.zsh.command = "$HOME/bin/files";
package = config.lib.test.mkStubPackage {
name = "fzf";
version = "0.73.0";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/fzf <<'EOF'
#!/bin/sh
echo "Stub fzf"
EOF
chmod +x $out/bin/fzf
'';
};
zsh.enable = true;
};
programs.zsh.enable = true;
nmt.script = ''
assertFileRegex home-files/.zshrc \
'export FZF_CTRL_R_COMMAND='