Add git-exclude

A Git commit that easily excludes files by adding them to
`.git/info/exclude`.
This commit is contained in:
Oliver Davies 2025-07-12 17:39:44 +01:00
parent a620888277
commit d4e5faf6c4
3 changed files with 26 additions and 0 deletions

24
packages/git-exclude.nix Normal file
View file

@ -0,0 +1,24 @@
{ 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
'';
}