Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fish Shell: Generate a clean changelog between two Git revisions
function changes -d "Generate a Markdown changelog from conventional commits" -a target
# Use fallback variables if no arguments were given.
if test (count $argv) -eq 0
set target master
end
# Include commit message, author name, and the short hash in parentheses.
set -l log_format "%s (_%aN_) (%h)"
# Compare against HEAD (the latest commit).
set -l source "HEAD"
# Filter to commits that pass the conventional commit format.
# See: https://www.conventionalcommits.org/
set -l commit_filter "^[a-z]+(\([a-z]+\))?:\s.+"
# Prefix each line with '- ' to render a Markdown list.
set -l prefix '{print "- " $0}'
# Write changelog header
echo -e "## `$target`\n\n"
echo -e "Write your release notes on this line.\n\n"
# Fill and sort the actual changelog
git log --oneline --pretty=format:$log_format $source...$target \
| grep -E "$commit_filter" \
| sort -k1 \
| awk "$prefix"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.