1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-12-18 18:31:59 +00:00

feat(cli): add omz version command

This commit is contained in:
Marc Cornellà 2021-11-30 10:13:23 +01:00
parent bf303965e6
commit f0f792fa6b
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -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"
)
}