summaryrefslogtreecommitdiff
path: root/lib/cli.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cli.zsh')
-rw-r--r--lib/cli.zsh46
1 files changed, 37 insertions, 9 deletions
diff --git a/lib/cli.zsh b/lib/cli.zsh
index 0b6bbc6cb..4917bc354 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
@@ -36,7 +37,7 @@ function _omz {
elif (( CURRENT == 3 )); then
case "$words[2]" in
changelog) local -a refs
- refs=("${(@f)$(command git -C "$ZSH" for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
+ refs=("${(@f)$(cd "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
_describe 'command' refs ;;
plugin) subcmds=(
'disable:Disable plugin(s)'
@@ -67,10 +68,12 @@ function _omz {
_describe 'plugin' valid_plugins ;;
plugin::info)
- local -aU plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
+ local -aU plugins
+ plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
_describe 'plugin' plugins ;;
theme::(set|use))
- local -aU themes=("$ZSH"/themes/*.zsh-theme(.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
+ local -aU themes
+ themes=("$ZSH"/themes/*.zsh-theme(.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
_describe 'theme' themes ;;
esac
elif (( CURRENT > 4 )); then
@@ -164,6 +167,7 @@ Available commands:
reload Reload the current zsh session
theme <command> Manage themes
update Update Oh My Zsh
+ version Show the version
EOF
}
@@ -171,9 +175,12 @@ EOF
function _omz::changelog {
local version=${1:-HEAD} format=${3:-"--text"}
- if ! command git -C "$ZSH" show-ref --verify refs/heads/$version &>/dev/null && \
- ! command git -C "$ZSH" show-ref --verify refs/tags/$version &>/dev/null && \
- ! command git -C "$ZSH" rev-parse --verify "${version}^{commit}" &>/dev/null; then
+ if (
+ cd "$ZSH"
+ ! command git show-ref --verify refs/heads/$version && \
+ ! command git show-ref --verify refs/tags/$version && \
+ ! command git rev-parse --verify "${version}^{commit}"
+ ) &>/dev/null; then
cat >&2 <<EOF
Usage: omz changelog [version]
@@ -446,9 +453,9 @@ function _omz::plugin::load {
fi
# Check if it has completion to reload compinit
- if [[ -f "$base/_$plugin" ]]; then
- has_completion=1
- fi
+ local -a comp_files
+ comp_files=($base/_*(N))
+ has_completion=$(( $#comp_files > 0 ))
# Load the plugin
if [[ -f "$base/$plugin.plugin.zsh" ]]; then
@@ -774,3 +781,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"
+ )
+}