From 18d998b5de5a063e3502ee5aa2a75f5fbb6762de Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 11 Apr 2024 22:18:02 +0200 Subject: 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 … --- home/home-minimal.nix | 29 +++++++++++++++++++++++++++-- 1 file 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 -- + # 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 + ''; }; }; -- cgit v1.2.3