Created
August 23, 2025 02:25
-
-
Save Tremeschin/f35d1e47b2019cc43046d969c0dc5096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # fmt: off | |
| # Todo: Find a new name, write proper package | |
| from pathlib import Path | |
| DIVISOR = "# <!-- AUTOMATIC -->" | |
| HOME = Path().home() | |
| def main(): | |
| target = (HOME/".gitignore").read_text().split(DIVISOR)[0].splitlines() | |
| target = filter(lambda line: not line.startswith("#"), target) | |
| target = list(map(Path, filter(None, target))) | |
| ignore = list(map(str, sorted(target))) | |
| ignore.append(f"\n{DIVISOR}") | |
| ignore.append("*") | |
| for file in sorted(target): | |
| for path in reversed([file] + list(file.parents)[:-1]): | |
| ignore.append(f"!{path}") | |
| (HOME/".gitignore").write_text("\n".join(ignore)) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment