summaryrefslogtreecommitdiff
path: root/lib/cli.zsh
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2021-11-30 10:13:23 +0100
committerMarc Cornellà <hello@mcornella.com>2021-11-30 10:13:23 +0100
commitf0f792fa6b207bc72453ae55011b6b44f678fb78 (patch)
treed8e06669a06cf074c6334949eede28275edb89ec /lib/cli.zsh
parentbf303965e685489f2f1b764d5d22dc4766ca78c8 (diff)
downloadzsh-f0f792fa6b207bc72453ae55011b6b44f678fb78.tar.gz
zsh-f0f792fa6b207bc72453ae55011b6b44f678fb78.tar.bz2
zsh-f0f792fa6b207bc72453ae55011b6b44f678fb78.zip
feat(cli): add `omz version` command
Diffstat (limited to 'lib/cli.zsh')
-rw-r--r--lib/cli.zsh23
1 files changed, 23 insertions, 0 deletions
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 <command> 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"
+ )
+}