From f0f792fa6b207bc72453ae55011b6b44f678fb78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 30 Nov 2021 10:13:23 +0100 Subject: [PATCH] feat(cli): add `omz version` command --- lib/cli.zsh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/cli.zsh b/lib/cli.zsh index d90cc6469..aed84e08f 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -29,6 +29,7 @@ function _omz { 'reload:Reload the current zsh session' 'theme:Manage themes' 'update:Update Oh My Zsh' + 'version:Show the version' ) if (( CURRENT == 2 )); then @@ -164,6 +165,7 @@ Available commands: reload Reload the current zsh session theme Manage themes update Update Oh My Zsh + version Show the version EOF } @@ -777,3 +779,24 @@ function _omz::update { [[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh" fi } + +function _omz::version { + ( + cd "$ZSH" + + # Get the version name: + # 1) try tag-like version + # 2) try name-rev + # 3) try branch name + local version + version=$(command git describe --tags HEAD 2>/dev/null) \ + || version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \ + || version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) + + # Get short hash for the current HEAD + local commit=$(command git rev-parse --short HEAD 2>/dev/null) + + # Show version and commit hash + printf "%s (%s)\n" "$version" "$commit" + ) +}