Skip to content

Instantly share code, notes, and snippets.

@jbrzozoski
Last active January 6, 2022 14:56
Show Gist options
  • Save jbrzozoski/c8db1375a8a4aaf4cc8a9d94a4bc8f88 to your computer and use it in GitHub Desktop.
Save jbrzozoski/c8db1375a8a4aaf4cc8a9d94a4bc8f88 to your computer and use it in GitHub Desktop.
Script to list annotated tags on the CLI with git in a nicely formatted manner
#!/bin/bash
# Get all the annotated tag references
refs=$(git for-each-ref --format="%(if:equals=tag)%(objecttype)%(then)%(refname:short)%(end)" refs/tags)
# Review those to find the longest reference name
refs_as_list=(${refs})
let longest_ref=0
for i in "${refs_as_list[@]}"
do
if (( ${#i} > longest_ref ))
then
let longest_ref=${#i}
fi
done
# Now build the format string
fmt="%(color:yellow)%(align:${longest_ref})%(refname:short)%(end)%(color:reset) - %(color:red)%(*objectname:short)%(color:reset) - %(contents:subject) %(color:green)(%(taggerdate:relative)) %(color:bold blue)<%(taggername)>%(color:reset)"
# And finally spit out the nicely formatted and padded list
git tag --list --sort=-taggerdate --format="$fmt" $@ ${refs}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment