diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2021-12-18 17:46:06 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2021-12-18 17:46:06 -0600 |
commit | 1bc186dabe12b3d01b2257e82f3a104c48b8b3c7 (patch) | |
tree | 54576312318c406b6ce2a35423198fcc92c8bf71 /lib | |
parent | 2a977876c6e85847652f097cc128e4ed5bec147a (diff) | |
parent | 904f8685f75ff5dd3f544f8c6f2cabb8e5952e9a (diff) | |
download | zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.gz zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.bz2 zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cli.zsh | 46 | ||||
-rw-r--r-- | lib/diagnostics.zsh | 2 | ||||
-rw-r--r-- | lib/directories.zsh | 2 | ||||
-rw-r--r-- | lib/functions.zsh | 9 | ||||
-rw-r--r-- | lib/git.zsh | 4 | ||||
-rw-r--r-- | lib/prompt_info_functions.zsh | 2 | ||||
-rw-r--r-- | lib/spectrum.zsh | 6 | ||||
-rw-r--r-- | lib/termsupport.zsh | 15 |
8 files changed, 57 insertions, 29 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" + ) +} diff --git a/lib/diagnostics.zsh b/lib/diagnostics.zsh index 650520797..eaeba7d23 100644 --- a/lib/diagnostics.zsh +++ b/lib/diagnostics.zsh @@ -335,7 +335,7 @@ function _omz_diag_dump_os_specific_version() { builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)" ;; cygwin) - command systeminfo | command head -4 | command tail -2 + command systeminfo | command head -n 4 | command tail -n 2 ;; esac diff --git a/lib/directories.zsh b/lib/directories.zsh index 6696854b0..c62f56468 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -26,7 +26,7 @@ function d () { if [[ -n $1 ]]; then dirs "$@" else - dirs -v | head -10 + dirs -v | head -n 10 fi } compdef _dirs d diff --git a/lib/functions.zsh b/lib/functions.zsh index 73b491a59..61f4dd49e 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -1,7 +1,7 @@ function zsh_stats() { fc -l 1 \ | awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \ - | grep -v "./" | sort -nr | head -20 | column -c3 -s " " -t | nl + | grep -v "./" | sort -nr | head -n 20 | column -c3 -s " " -t | nl } function uninstall_oh_my_zsh() { @@ -45,7 +45,7 @@ function takeurl() { data="$(mktemp)" curl -L "$1" > "$data" tar xf "$data" - thedir="$(tar tf "$data" | head -1)" + thedir="$(tar tf "$data" | head -n 1)" rm "$data" cd "$thedir" } @@ -237,12 +237,11 @@ function omz_urldecode { tmp=${tmp:gs/\\/\\\\/} # Handle %-escapes by turning them into `\xXX` printf escapes tmp=${tmp:gs/%/\\x/} - local decoded - eval "decoded=\$'$tmp'" + local decoded="$(printf -- "$tmp")" # Now we have a UTF-8 encoded string in the variable. We need to re-encode # it if caller is in a non-UTF-8 locale. - local safe_encodings + local -a safe_encodings safe_encodings=(UTF-8 utf8 US-ASCII) if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding) diff --git a/lib/git.zsh b/lib/git.zsh index 9a615e77b..62aac8f39 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -29,7 +29,7 @@ function git_prompt_info() { && upstream=" -> ${upstream}" fi - echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref}${upstream}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" } # Checks if working tree is dirty @@ -51,7 +51,7 @@ function parse_git_dirty() { FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}" ;; esac - STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -1) + STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1) fi if [[ -n $STATUS ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index 48f033da6..e5535848b 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -30,7 +30,7 @@ function rvm_prompt_info() { local rvm_prompt rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${=ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null) [[ -z "${rvm_prompt}" ]] && return 1 - echo "${ZSH_THEME_RUBY_PROMPT_PREFIX}${rvm_prompt}${ZSH_THEME_RUBY_PROMPT_SUFFIX}" + echo "${ZSH_THEME_RUBY_PROMPT_PREFIX}${rvm_prompt:gs/%/%%}${ZSH_THEME_RUBY_PROMPT_SUFFIX}" } ZSH_THEME_RVM_PROMPT_OPTIONS="i v g" diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index d5c22a8c5..97f5c360a 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -20,16 +20,18 @@ done # Show all 256 colors with color number function spectrum_ls() { + setopt localoptions nopromptsubst local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: ${FG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}" done } # Show all 256 colors where the background is set to specific color function spectrum_bls() { + setopt localoptions nopromptsubst local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: ${BG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}" done } diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index ef0d78895..4035d10a1 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -7,11 +7,10 @@ # (In screen, only short_tab_title is used) # Limited support for Apple Terminal (Terminal can't set window and tab separately) function title { - emulate -L zsh - setopt prompt_subst + setopt localoptions nopromptsubst # Don't set the title if inside emacs, unless using vterm - [[ -n "$INSIDE_EMACS" && "$INSIDE_EMACS" != vterm ]] && return + [[ -n "${INSIDE_EMACS:-}" && "$INSIDE_EMACS" != vterm ]] && return # if $2 is unset use $1 as default # if it is set and empty, leave it as is @@ -48,13 +47,13 @@ fi # Runs before showing the prompt function omz_termsupport_precmd { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE + [[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return + title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE" } # Runs before executing the command function omz_termsupport_preexec { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return + [[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return emulate -L zsh setopt extended_glob @@ -97,10 +96,10 @@ function omz_termsupport_preexec { fi # cmd name only, or if this is sudo or ssh, the next cmd - local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} + local CMD="${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}" local LINE="${2:gs/%/%%}" - title '$CMD' '%100>...>$LINE%<<' + title "$CMD" "%100>...>${LINE}%<<" } autoload -Uz add-zsh-hook |