mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-22 12:09:36 +08:00
feat(cli): add omz version
command
This commit is contained in:
parent
bf303965e6
commit
f0f792fa6b
23
lib/cli.zsh
23
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"
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user