Skip to content

Instantly share code, notes, and snippets.

@tsibley
Last active June 23, 2022 18:13
Show Gist options
  • Select an option

  • Save tsibley/3db7f8df1ec61d407354b0e6c36ba170 to your computer and use it in GitHub Desktop.

Select an option

Save tsibley/3db7f8df1ec61d407354b0e6c36ba170 to your computer and use it in GitHub Desktop.
changes
#!/bin/bash
# Extract changelog for a specified version (or __NEXT__ if no version
# specified).
set -euo pipefail
cd "$(dirname "$0")/.."
version="${1:-__NEXT__}"
export version
perl -ne 'print if /^# \Q$ENV{version}\E( |$)/ ... (/^# / and exit)' CHANGES.md | tail -n +2
#!/bin/bash
# Extract changelog for a specified version (or __NEXT__ if no version
# specified).
set -euo pipefail
cd "$(dirname "$0")/.."
main() {
local version="${1:-__NEXT__}"
# Open changelog on stdin
exec < CHANGES.md
declare line
while read line; do
# Find the heading for this version
if [[ "$line" == "# $version" || "$line" == "# $version "* ]]; then
# Print subsequent lines until we reach the next version heading
while read line; do
if [[ "$line" == "# "* ]]; then
return 0
fi
echo "$line"
done
fi
done
return 1
}
read() {
# Disable word splitting (IFS) and backslash escape processing (-r)
IFS=$'\0' builtin read -r "$@"
}
main "$@"
#!/usr/bin/env python3
"""
Extract changelog for a specified version (or __NEXT__ if no version
specified).
"""
from pathlib import Path
from sys import argv, exit, stdout
CHANGELOG = Path(__file__).parent / "../CHANGES.md"
def main(version = "__NEXT__"):
with CHANGELOG.open(encoding = "utf-8") as file:
for line in file:
# Find the heading for this version
if line.startswith(f"# {version}") or line.startswith(f"# {version} "):
# Print subsequent lines until we reach the next version heading
for line in file:
if line.startswith("# "):
break
stdout.write(line)
return 0
return 1
if __name__ == "__main__":
exit(main(*argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment