f0f792fa6b207bc72453ae55011b6b44f678fb78
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- Marc Cornellà <hello@mcornella.com>
- Date
Message
feat(cli): add `omz version` command
Diff
1diff --git a/lib/cli.zsh b/lib/cli.zsh
2index d90cc64699d91d629fc59713b050759350fcddcf..aed84e08f76f12cd6e39f51636feeaf13966f618 100644
3--- a/lib/cli.zsh
4+++ b/lib/cli.zsh
5@@ -29,6 +29,7 @@ function _omz {
6 'reload:Reload the current zsh session'
7 'theme:Manage themes'
8 'update:Update Oh My Zsh'
9+ 'version:Show the version'
10 )
11
12 if (( CURRENT == 2 )); then
13@@ -164,6 +165,7 @@ Available commands:
14 reload Reload the current zsh session
15 theme <command> Manage themes
16 update Update Oh My Zsh
17+ version Show the version
18
19 EOF
20 }
21@@ -777,3 +779,24 @@ function _omz::update {
22 [[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
23 fi
24 }
25+
26+function _omz::version {
27+ (
28+ cd "$ZSH"
29+
30+ # Get the version name:
31+ # 1) try tag-like version
32+ # 2) try name-rev
33+ # 3) try branch name
34+ local version
35+ version=$(command git describe --tags HEAD 2>/dev/null) \
36+ || version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \
37+ || version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null)
38+
39+ # Get short hash for the current HEAD
40+ local commit=$(command git rev-parse --short HEAD 2>/dev/null)
41+
42+ # Show version and commit hash
43+ printf "%s (%s)\n" "$version" "$commit"
44+ )
45+}