From 1f2049c0f100854b9baa02727928b0ce542390dd Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sun, 3 Nov 2024 19:00:37 -0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20refactor(fzf):=20Properly=20check?= =?UTF-8?q?=20that=20requirements=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- home/programs/fzf.nix | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/home/programs/fzf.nix b/home/programs/fzf.nix index c8294d3..6248c19 100644 --- a/home/programs/fzf.nix +++ b/home/programs/fzf.nix @@ -1,4 +1,12 @@ { lib, config, ... }: +let + has-ripgrep = config.programs.ripgrep.enable; + has-fd = config.programs.fd.enable; + has-eza = config.programs.eza.enable; + has-bat = config.programs.bat.enable; + has-tmux = config.programs.tmux.enable; + has-delta = config.programs.git.delta.enable; +in { programs.fzf = { enable = true; @@ -15,23 +23,20 @@ "--preview-window='border-sharp'" ]; - # TODO: Check that rg is installed. - defaultCommand = "rg --files --hidden --glob \"!.git\""; + defaultCommand = lib.mkIf has-ripgrep "rg --files --hidden --glob \"!.git\""; - # TODO: Check that fd is installed. - changeDirWidgetCommand = "fd --type d"; - changeDirWidgetOptions = lib.mkIf config.programs.eza.enable [ + changeDirWidgetCommand = lib.mkIf has-fd "fd --type d"; + changeDirWidgetOptions = lib.mkIf has-eza [ "--preview 'eza --all --color=always --sort=name --group-directories-first --level=3 {}'" ]; - # TODO: Check that fd is installed. - fileWidgetCommand = "fd --type f"; - fileWidgetOptions = lib.mkIf config.programs.bat.enable [ + fileWidgetCommand = lib.mkIf has-fd "fd --type f"; + fileWidgetOptions = lib.mkIf has-bat [ "--preview 'bat {}'" ]; - tmux.enableShellIntegration = lib.mkIf config.programs.tmux.enable true; + tmux.enableShellIntegration = lib.mkIf has-tmux true; }; - home.sessionVariables.fzf_diff_highlighter = "delta --paging=never --features=arctic-fox"; + home.sessionVariables.fzf_diff_highlighter = lib.mkIf has-delta "delta --paging=never --features=arctic-fox"; }