summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuebinm2024-04-11 22:18:02 +0200
committerstuebinm2024-04-11 22:18:02 +0200
commit18d998b5de5a063e3502ee5aa2a75f5fbb6762de (patch)
tree7601d728ca61b64cb7511c692b344c71db2c9352
parent4b19dcfc6883a794cf41376eb2489f2ba6f3e813 (diff)
home: markdown formatting for changelogs in git
I discovered `guix pull --news` recently and realised I barely ever keep up with nixpkgs's change logs, so here's a thing which might help to change that. It's actually a little more general than I thought it'd need to be — turns out that people do change old release notes items in nixpkgs (mostly to update links), so it can format deletions as well. (some vague inspiration was given by https://github.com/netj/markdown-diff) It's a little cursed, but then so is using `lowdown` at all I'd say …
-rw-r--r--home/home-minimal.nix29
1 files changed, 27 insertions, 2 deletions
diff --git a/home/home-minimal.nix b/home/home-minimal.nix
index fa969a6..42f358d 100644
--- a/home/home-minimal.nix
+++ b/home/home-minimal.nix
@@ -65,7 +65,7 @@
body = "";
};
md = ''
- lowdown -tterm --term-columns=(tput cols) $argv[1] | less
+ lowdown -tterm --term-columns=(tput cols) $argv | less -F
'';
mds.body = ''
if [ "$argv[1]" = "" ]
@@ -83,7 +83,32 @@
echo (git -C $git -C .. rev-parse --show-toplevel) (git --git-dir $git remote get-url origin)
end
end | fzf --preview 'git -C {1} show --no-show-signature --color=always' | cut -f1 -d" "
- '';
+ '';
+ # Usage as with `git diff`: show-changelog <old-commit> <new-commit> -- <path/to/changelog>
+ # useful in git post-merge (or similar) hooks. default is to show changes in nixpkgs.
+ show-changelog.body = ''
+ if test (count $argv) = 0
+ set -a argv "HEAD@{1}" -- nixos/doc/manual/release-notes
+ end
+ git diff \
+ -U0 \
+ --word-diff=plain \
+ # format markdown links as atomic changes
+ --word-diff-regex='\[[^]]*\]\([^\)]*\)|[^[:space:]]' \
+ $argv |
+ sed -E '
+ # delete diff noise
+ /^(\+\+\+|diff|@@|index).*$/d
+ # make header per file
+ s|^---.*/([^/]*)$|\n# \1\n|g
+ # do not mark whole-line adds
+ s|^\{\+(.*)\+\}$|\1|g
+ # format word changes
+ s|\{\+(.*)\+\}|**\1**|g
+ s|\[-(.*)-\]|~~\1~~|g
+ ' |
+ md --term-nolinks
+ '';
};
};