From 40a99619da804a78a0b166e5c6911108c059c3a8 Mon Sep 17 00:00:00 2001 From: Mario Rodas Date: Tue, 9 Apr 2024 01:57:29 -0500 Subject: [PATCH] =?UTF-8?q?fzf:=20add=20compatibility=20with=20fzf?= =?UTF-8?q?=E2=89=A50.48.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fzf 0.48.0 [1] changed the way it integrates with shells. [1] https://github.com/junegunn/fzf/releases/tag/0.48.0 --- modules/programs/fzf.nix | 51 +++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/modules/programs/fzf.nix b/modules/programs/fzf.nix index 062df186..31df95de 100644 --- a/modules/programs/fzf.nix +++ b/modules/programs/fzf.nix @@ -10,6 +10,35 @@ let concatStringsSep "," (mapAttrsToList (name: value: "${name}:${value}") colors); + hasShellIntegrationEmbedded = lib.versionAtLeast cfg.package.version "0.48.0"; + + bashIntegration = if hasShellIntegrationEmbedded then '' + if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then + eval "$(${getExe cfg.package} --bash)" + fi + '' else '' + if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then + . ${cfg.package}/share/fzf/completion.bash + . ${cfg.package}/share/fzf/key-bindings.bash + fi + ''; + + zshIntegration = if hasShellIntegrationEmbedded then '' + if [[ $options[zle] = on ]]; then + eval "$(${getExe cfg.package} --zsh)" + fi + '' else '' + if [[ $options[zle] = on ]]; then + . ${cfg.package}/share/fzf/completion.zsh + . ${cfg.package}/share/fzf/key-bindings.zsh + fi + ''; + + fishIntegration = if hasShellIntegrationEmbedded then '' + ${getExe cfg.package} --fish | source + '' else '' + source ${cfg.package}/share/fzf/key-bindings.fish && fzf_key_bindings + ''; in { imports = [ (mkRemovedOptionModule [ "programs" "fzf" "historyWidgetCommand" ] @@ -173,26 +202,16 @@ in { # Note, since fzf unconditionally binds C-r we use `mkOrder` to make the # initialization show up a bit earlier. This is to make initialization of # other history managers, like mcfly or atuin, take precedence. - programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 '' - if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then - . ${cfg.package}/share/fzf/completion.bash - . ${cfg.package}/share/fzf/key-bindings.bash - fi - ''); + programs.bash.initExtra = + mkIf cfg.enableBashIntegration (mkOrder 200 bashIntegration); # Note, since fzf unconditionally binds C-r we use `mkOrder` to make the # initialization show up a bit earlier. This is to make initialization of # other history managers, like mcfly or atuin, take precedence. - programs.zsh.initExtra = mkIf cfg.enableZshIntegration (mkOrder 200 '' - if [[ $options[zle] = on ]]; then - . ${cfg.package}/share/fzf/completion.zsh - . ${cfg.package}/share/fzf/key-bindings.zsh - fi - ''); + programs.zsh.initExtra = + mkIf cfg.enableZshIntegration (mkOrder 200 zshIntegration); - programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration - (mkOrder 200 '' - source ${cfg.package}/share/fzf/key-bindings.fish && fzf_key_bindings - ''); + programs.fish.interactiveShellInit = + mkIf cfg.enableFishIntegration (mkOrder 200 fishIntegration); }; }