sway-config/rpkg.macros

38 lines
835 B
Bash

#!/bin/bash
# vim ft:sh
function git_tag {
git describe --tags --abbrev=0 2>/dev/null | head -n 1
}
function git_commit_count {
local tag=$1
if [ -n "$tag" ]; then
git rev-list "$tag"..HEAD --count 2>/dev/null || printf 0
else
git rev-list HEAD --count 2>/dev/null || printf 0
fi
}
function git_version {
tag="$(git_tag)"
tag_version="$(echo "$tag" | sed -E -n "s/^v?([^-]+)/\1/p")"
if [ -z "$tag_version" ]; then
tag_version=0
fi
commit_count="$(git_commit_count "$tag")"
if [ "$commit_count" -eq 0 ]; then
output "$tag_version"
else
shortcommit="$(git rev-parse --short HEAD)"
output "$tag_version^${commit_count}.git${shortcommit}"
fi
}
function git_release {
output "1"
}
function git_dir_release {
git_release "$@"
}