diff --git a/tools/changelog.sh b/tools/changelog.sh index b4b8d0c9e..966e91c25 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -181,6 +181,12 @@ function display-release { return fi + # Get length of longest scope for padding + local max_scope=0 + for hash in ${(k)scopes}; do + max_scope=$(( max_scope < ${#scopes[$hash]} ? ${#scopes[$hash]} : max_scope )) + done + ##* Formatting functions # Format the hash according to output format @@ -220,18 +226,13 @@ function display-release { #* Uses $scopes (A) and $hash from outer scope local scope="${1:-${scopes[$hash]}}" - # Get length of longest scope for padding - local max_scope=0 padding=0 - for hash in ${(k)scopes}; do - max_scope=$(( max_scope < ${#scopes[$hash]} ? ${#scopes[$hash]} : max_scope )) - done - # If no scopes, exit the function if [[ $max_scope -eq 0 ]]; then return fi # Get how much padding is required for this scope + local padding=0 padding=$(( max_scope < ${#scope} ? 0 : max_scope - ${#scope} )) padding="${(r:$padding:: :):-}" @@ -290,11 +291,15 @@ function display-release { md) fmt:header "BREAKING CHANGES ⚠" 3 ;; esac - local hash subject + local hash message + local wrap_width=$(( (COLUMNS < 100 ? COLUMNS : 100) - 3 )) for hash message in ${(kv)breaking}; do - echo " - $(fmt:hash) $(fmt:scope)$(fmt:subject "${message}")" - done | sort - echo + # Format the BREAKING CHANGE message by word-wrapping it at maximum 100 characters + # (use $COLUMNS if smaller than 100), and adding a 3-space left padding. + message="$(fmt -w $wrap_width <<< "$message" | sed 's/^/ /')" + # Display hash and scope first, and then the full message with newline separators + echo " - $(fmt:hash) $(fmt:scope)\n\n$(fmt:subject "$message")\n" + done } function display:type {