mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-12 21:39:48 +01:00
feat(cli): add omz version
command
This commit is contained in:
parent
bf303965e6
commit
f0f792fa6b
1 changed files with 23 additions and 0 deletions
23
lib/cli.zsh
23
lib/cli.zsh
|
@ -29,6 +29,7 @@ function _omz {
|
||||||
'reload:Reload the current zsh session'
|
'reload:Reload the current zsh session'
|
||||||
'theme:Manage themes'
|
'theme:Manage themes'
|
||||||
'update:Update Oh My Zsh'
|
'update:Update Oh My Zsh'
|
||||||
|
'version:Show the version'
|
||||||
)
|
)
|
||||||
|
|
||||||
if (( CURRENT == 2 )); then
|
if (( CURRENT == 2 )); then
|
||||||
|
@ -164,6 +165,7 @@ Available commands:
|
||||||
reload Reload the current zsh session
|
reload Reload the current zsh session
|
||||||
theme <command> Manage themes
|
theme <command> Manage themes
|
||||||
update Update Oh My Zsh
|
update Update Oh My Zsh
|
||||||
|
version Show the version
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
@ -777,3 +779,24 @@ function _omz::update {
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||||
fi
|
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"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue