Last active
June 17, 2026 12:54
-
-
Save fellipec/b2258e66f9a343c7120ce2f1b446f282 to your computer and use it in GitHub Desktop.
Diff summary for Restic backups
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 | |
| import sys | |
| from collections import defaultdict | |
| import os | |
| # Cores ANSI | |
| GREEN = "\033[32m" | |
| RED = "\033[31m" | |
| YELLOW = "\033[33m" | |
| BOLD = "\033[1m" | |
| RESET = "\033[0m" | |
| changes = defaultdict(lambda: {"added": 0, "removed": 0, "modified": 0}) | |
| for line in sys.stdin: | |
| line = line.strip() | |
| if not line: | |
| continue | |
| status = line[0] | |
| path = line[1:].strip() | |
| directory = os.path.dirname(path) or "/" | |
| if status == "+": | |
| changes[directory]["added"] += 1 | |
| elif status == "-": | |
| changes[directory]["removed"] += 1 | |
| elif status.upper() == "M": | |
| changes[directory]["modified"] += 1 | |
| else: | |
| changes[directory]["modified"] += 1 | |
| for directory, stats in sorted(changes.items()): | |
| parts = [] | |
| if stats["added"] > 0: | |
| parts.append(f"{GREEN}+{stats['added']}{RESET}") | |
| if stats["removed"] > 0: | |
| parts.append(f"{RED}-{stats['removed']}{RESET}") | |
| if stats["modified"] > 0: | |
| parts.append(f"{YELLOW}M{stats['modified']}{RESET}") | |
| if not parts: | |
| continue | |
| total = stats["added"] + stats["removed"] + stats["modified"] | |
| # Se passou de 100 mudanças, deixa a linha inteira em negrito | |
| if total > 100: | |
| print(f"{BOLD}{directory}: " + " ".join(parts) + RESET) | |
| else: | |
| print(f"{directory}: " + " ".join(parts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment