Mostrando la salida de `cabal-plan` visualmente

Cuando corremos cabal plan diff hay mucho ruido en la salida. Este script de python muestra la salida mucho más accesible: #!/usr/bin/env python3 """Summarize the `Package versions` section of `cabal-plan diff` output. Pipe `cabal-plan diff` (or similar) output to this script. It extracts the section between the `Package versions` and `Dependency graph` headers, then prints: pkg-name oldver -> newver # for packages that changed new pkg-name ver # for packages only on the + side deleted pkg-name ver # for packages only on the - side """ import re import sys LINE_RE = re.compile(r"^\s*([-+])(\S+?)-(\d[\w.]*)\s") def parse(stream): in_section = False removed: dict[str, str] = {} added: dict[str, str] = {} for line in stream: stripped = line.strip() if stripped.startswith("Package versions"): in_section = True continue if stripped.startswith("Dependency graph"): break if not in_section: continue m = LINE_RE.match(line) if not m: continue sign, name, version = m.group(1), m.group(2), m.group(3) (removed if sign == "-" else added)[name] = version return removed, added def main() -> int: removed, added = parse(sys.stdin) changed_names = sorted(set(removed) & set(added)) only_removed = sorted(set(removed) - set(added)) only_added = sorted(set(added) - set(removed)) name_w = max( (len(n) for n in changed_names + only_added + only_removed), default=0, ) old_w = max((len(removed[n]) for n in changed_names), default=0) for name in changed_names: print(f"{name:<{name_w}} {removed[name]:<{old_w}} -> {added[name]}") if only_added: print() for name in only_added: print(f"new {name:<{name_w}} {added[name]}") if only_removed: print() for name in only_removed: print(f"deleted {name:<{name_w}} {removed[name]}") return 0 if __name__ == "__main__": sys.exit(main()) Se usa pasando la entrada en una tubería: ...

19 May 2026 · 2 min · 417 words · Javier Sagredo

Un mejor cbor2pretty

Este pequeño script sirve para que cbor2pretty tambien muestre el contenido de una cadena de bytes envuelta en un tag 24: #!/bin/bash cbor2pretty.rb $1 | \ awk -v q="'" -v dq="\"" ' BEGIN { a = 0 } /tag\(24\)/ {a = 1} /"/ { if (a == 1) { print $0; spaces = match($0,/[^ ]|$/)-1; cmd = "perl -E " q "say " dq " " dq " x " spaces q; cmd | getline spacess; close(cmd); system("perl -e " q "print pack " dq "H*" dq ", " dq $1 dq q " \ | cbor2pretty.rb \ | sed " q "s/^/⭞" spacess "/g" q); a = 0 } else { print }; next } {print} ' Para configurarlo automaticamente en Git para mostrar diffs en archivos CBOR: ...

12 May 2026 · 1 min · 147 words · Javier Sagredo