From fbf8c1d3cf60bf620b1535a0af523ff23ae3a200 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sat, 7 Dec 2024 03:38:14 +0200 Subject: new ak flag -v: prints version of ak and exits --- bin/ak | 4 ++++ lib/_ak_script | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bin/ak b/bin/ak index 8dbd0bd..6d7dbd9 100755 --- a/bin/ak +++ b/bin/ak @@ -52,6 +52,10 @@ then _ak_usage exit 1 ;; + -v|--version) + _ak_version + exit 1 + ;; esac fi diff --git a/lib/_ak_script b/lib/_ak_script index 81da347..2338d1d 100755 --- a/lib/_ak_script +++ b/lib/_ak_script @@ -58,7 +58,27 @@ _ak_title_description(){ _ak_usage(){ _ak_title_description - _ak_help + _ak_help 2>&1 +} + +_ak_print_version(){ + git_repo="$(ls -l $AK_LIBDIR/_ak_script | cut -d '>' -f 2 | sed 's/^ //' | rev | cut -d '/' -f 3- | rev)" + patch_version="$(git --git-dir="${git_repo}/.git" -P log --reverse --oneline --decorate | tail -n 1 | cut -d ' ' -f 1)" + gtags="$(git --git-dir="${git_repo}/.git" -P tag | tail -n 1)" + if [ -f "$AK_WORKDIR/version" ] + then + cat $AK_WORKDIR/version + elif [ -n "${gtags}" ] + then + echo "${gtags}" + else + echo "v0.0.0-${patch_version}" + fi +} + +_ak_version(){ + printf '%s - ' "$PROGRAM" + _ak_print_version 2>&1 } _ak_not_implemented(){ -- cgit v1.2.3