nix-config/packages/git-exclude.nix
Oliver Davies d4e5faf6c4 Add git-exclude
A Git commit that easily excludes files by adding them to
`.git/info/exclude`.
2025-07-12 17:39:44 +01:00

24 lines
591 B
Nix

{ pkgs }:
pkgs.writeShellApplication {
name = "git-exclude";
runtimeInputs = with pkgs; [ git ];
text = ''
# Based on https://github.com/jfly/snow/blob/fb727b39736666f54908f4dc7c83dd6284607c5a/machines/pattern/homies/bin/git-exclude.
root=$(git rev-parse --show-toplevel)
rel=$(realpath --relative-to "$root" .)
# For some reason, ignore rules like "./.envrc" don't seem to work, but
# "/.envrc" does. :shrug:
if [ "$rel" = "." ]; then
rel=""
fi
for item in "$@"; do
echo "''${rel}/$item" >> "$root/.git/info/exclude"
done
'';
}