From ffc3600f4009ca39b6cb63b24127ca4f93792854 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:19:25 -0400 Subject: [PATCH] fd: add module --- modules/misc/news.nix | 7 +++++ modules/modules.nix | 1 + modules/programs/fd.nix | 59 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 modules/programs/fd.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 97b8da7bb..2c00c5ed3 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1476,6 +1476,13 @@ in { A new module is available: 'programs.bun'. ''; } + + { + time = "2024-04-18T22:30:49+00:00"; + message = '' + A new module is available: 'programs.fd'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index ff48b21a5..b182a33e9 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -86,6 +86,7 @@ let ./programs/emacs.nix ./programs/eww.nix ./programs/eza.nix + ./programs/fd.nix ./programs/feh.nix ./programs/firefox.nix ./programs/fish.nix diff --git a/modules/programs/fd.nix b/modules/programs/fd.nix new file mode 100644 index 000000000..bc5b709db --- /dev/null +++ b/modules/programs/fd.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: +with lib; { + meta.maintainers = [ maintainers.uncenter ]; + + options.programs.fd = { + enable = mkEnableOption + "fd, a simple, fast and user-friendly alternative to {command}`find`"; + + ignores = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ ".git/" "*.bak" ]; + description = "List of paths that should be globally ignored."; + }; + + hidden = mkOption { + type = types.bool; + default = false; + description = '' + Search hidden files and directories ({option}`--hidden` argument). + ''; + }; + + extraOptions = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "--no-ignore" "--absolute-path" ]; + description = '' + Extra command line options passed to fd. + ''; + }; + + package = mkPackageOption pkgs "fd" { }; + }; + + config = let + cfg = config.programs.fd; + + args = escapeShellArgs (optional cfg.hidden "--hidden" ++ cfg.extraOptions); + + optionsAlias = { fd = "fd ${args}"; }; + in mkIf cfg.enable { + home.packages = [ cfg.package ]; + + programs.bash.shellAliases = optionsAlias; + + programs.zsh.shellAliases = optionsAlias; + + programs.fish.shellAliases = optionsAlias; + + programs.ion.shellAliases = optionsAlias; + + programs.nushell.shellAliases = optionsAlias; + + xdg.configFile."fd/ignore" = mkIf (cfg.ignores != [ ]) { + text = concatStringsSep "\n" cfg.ignores + "\n"; + }; + }; +}