Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kareefardi committed Nov 22, 2021
2 parents f41c710 + 15fd9c8 commit e2feff2
Show file tree
Hide file tree
Showing 26 changed files with 187 additions and 128 deletions.
11 changes: 7 additions & 4 deletions lib/cli.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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)'
Expand Down Expand Up @@ -171,9 +171,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]
Expand Down
5 changes: 2 additions & 3 deletions lib/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions lib/spectrum.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 6 additions & 7 deletions lib/termsupport.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# (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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions plugins/bgnotify/bgnotify.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ if ! (type bgnotify_formatted | grep -q 'function'); then ## allow custom functi
}
fi

currentAppId () {
if (( $+commands[osascript] )); then
osascript -e 'tell application (path to frontmost application as text) to id' 2>/dev/null
fi
}

currentWindowId () {
if hash osascript 2>/dev/null; then #osx
osascript -e 'tell application (path to frontmost application as text) to id of front window' 2&> /dev/null || echo "0"
Expand All @@ -32,11 +38,20 @@ currentWindowId () {

bgnotify () { ## args: (title, subtitle)
if hash terminal-notifier 2>/dev/null; then #osx
[[ "$TERM_PROGRAM" == 'iTerm.app' ]] && term_id='com.googlecode.iterm2';
[[ "$TERM_PROGRAM" == 'Apple_Terminal' ]] && term_id='com.apple.terminal';
local term_id="$bgnotify_appid"
if [[ -z "$term_id" ]]; then
case "$TERM_PROGRAM" in
iTerm.app) term_id='com.googlecode.iterm2' ;;
Apple_Terminal) term_id='com.apple.terminal' ;;
esac
fi

## now call terminal-notifier, (hopefully with $term_id!)
[ -z "$term_id" ] && terminal-notifier -message "$2" -title "$1" >/dev/null ||
terminal-notifier -message "$2" -title "$1" -activate "$term_id" -sender "$term_id" >/dev/null
if [[ -z "$term_id" ]]; then
terminal-notifier -message "$2" -title "$1" >/dev/null
else
terminal-notifier -message "$2" -title "$1" -activate "$term_id" -sender "$term_id" >/dev/null
fi
elif hash growlnotify 2>/dev/null; then #osx growl
growlnotify -m "$1" "$2"
elif hash notify-send 2>/dev/null; then #ubuntu gnome!
Expand All @@ -54,6 +69,7 @@ bgnotify () { ## args: (title, subtitle)
bgnotify_begin() {
bgnotify_timestamp=$EPOCHSECONDS
bgnotify_lastcmd="${1:-$2}"
bgnotify_appid="$(currentAppId)"
bgnotify_windowid=$(currentWindowId)
}

Expand All @@ -62,7 +78,7 @@ bgnotify_end() {
elapsed=$(( EPOCHSECONDS - bgnotify_timestamp ))
past_threshold=$(( elapsed >= bgnotify_threshold ))
if (( bgnotify_timestamp > 0 )) && (( past_threshold )); then
if [ $(currentWindowId) != "$bgnotify_windowid" ]; then
if [[ $(currentAppId) != "$bgnotify_appid" || $(currentWindowId) != "$bgnotify_windowid" ]]; then
print -n "\a"
bgnotify_formatted "$didexit" "$bgnotify_lastcmd" "$elapsed"
fi
Expand Down
13 changes: 5 additions & 8 deletions plugins/bundler/bundler.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bundle_install() {
else
local cores_num="$(nproc)"
fi
bundle install --jobs="$cores_num" "$@"
BUNDLE_JOBS="$cores_num" bundle install "$@"
}

## Gem wrapper
Expand Down Expand Up @@ -81,14 +81,12 @@ bundled_commands=(
)

# Remove $UNBUNDLED_COMMANDS from the bundled_commands list
for cmd in $UNBUNDLED_COMMANDS; do
bundled_commands=(${bundled_commands#$cmd});
done
bundled_commands=(${bundled_commands:|UNBUNDLED_COMMANDS})
unset UNBUNDLED_COMMANDS

# Add $BUNDLED_COMMANDS to the bundled_commands list
for cmd in $BUNDLED_COMMANDS; do
bundled_commands+=($cmd);
done
bundled_commands+=($BUNDLED_COMMANDS)
unset BUNDLED_COMMANDS

# Check if in the root or a subdirectory of a bundled project
_within-bundled-project() {
Expand Down Expand Up @@ -126,5 +124,4 @@ for cmd in $bundled_commands; do
compdef "_$cmd" "bundled_$cmd"="$cmd"
fi
done

unset cmd bundled_commands
2 changes: 1 addition & 1 deletion plugins/command-not-found/command-not-found.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ fi
# Termux: https://github.com/termux/command-not-found
if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then
command_not_found_handler() {
/data/data/com.termux/files/usr/libexec/termux/command-not-found -- "$1"
/data/data/com.termux/files/usr/libexec/termux/command-not-found "$1"
}
fi
8 changes: 4 additions & 4 deletions plugins/dirhistory/dirhistory.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export DIRHISTORY_SIZE=30
# Returns the element if the array was not empty,
# otherwise returns empty string.
function pop_past() {
eval "$1='$dirhistory_past[$#dirhistory_past]'"
print -v $1 "${dirhistory_past[$#dirhistory_past]}"
if [[ $#dirhistory_past -gt 0 ]]; then
dirhistory_past[$#dirhistory_past]=()
fi
}

function pop_future() {
eval "$1='$dirhistory_future[$#dirhistory_future]'"
print -v $1 "${dirhistory_future[$#dirhistory_future]}"
if [[ $#dirhistory_future -gt 0 ]]; then
dirhistory_future[$#dirhistory_future]=()
fi
Expand Down Expand Up @@ -182,7 +182,7 @@ bindkey "\e\e[A" dirhistory_zle_dirhistory_up # Putty
bindkey "\eO3A" dirhistory_zle_dirhistory_up # GNU screen
case "$TERM_PROGRAM" in
iTerm.app) bindkey "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2
Apple_Terminal) bindkey "^[OA" dirhistory_zle_dirhistory_up ;; # Terminal.app
Apple_Terminal) bindkey "^[[A" dirhistory_zle_dirhistory_up ;; # Terminal.app
esac
if (( ${+terminfo[kcuu1]} )); then
bindkey "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt
Expand All @@ -195,7 +195,7 @@ bindkey "\e\e[B" dirhistory_zle_dirhistory_down # Putty
bindkey "\eO3B" dirhistory_zle_dirhistory_down # GNU screen
case "$TERM_PROGRAM" in
iTerm.app) bindkey "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2
Apple_Terminal) bindkey "^[OB" dirhistory_zle_dirhistory_down ;; # Terminal.app
Apple_Terminal) bindkey "^[[B" dirhistory_zle_dirhistory_down ;; # Terminal.app
esac
if (( ${+terminfo[kcud1]} )); then
bindkey "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt
Expand Down
4 changes: 1 addition & 3 deletions plugins/docker-compose/docker-compose.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# support Compose v2 as docker CLI plugin
DOCKER_CONTEXT=default command docker compose &>/dev/null \
&& dccmd='docker compose' \
|| dccmd='docker-compose'
(( ${+commands[docker-compose]} )) && dccmd='docker-compose' || dccmd='docker compose'

alias dco="$dccmd"
alias dcb="$dccmd build"
Expand Down
18 changes: 11 additions & 7 deletions plugins/hitokoto/hitokoto.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
if ! (( $+commands[curl] )); then
echo "hitokoto plugin needs curl to work" >&2
return
echo "hitokoto plugin needs curl to work" >&2
return
fi

function hitokoto {
emulate -L zsh
Q=$(curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | jq -j '.hitokoto+"\t"+.from')
setopt localoptions nopromptsubst

TXT=$(echo "$Q" | awk -F '\t' '{print $1}')
WHO=$(echo "$Q" | awk -F '\t' '{print $2}')
# Get hitokoto data
local -a data
data=("${(ps:\n:)"$(command curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | command jq -j '.hitokoto+"\n"+.from')"}")

[[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
# Exit if could not fetch hitokoto
[[ -n "$data" ]] || return 0

local quote="${data[1]}" author="${data[2]}"
print -P "%F{3}${author}%f: “%F{5}${quote}%f”"
}
17 changes: 17 additions & 0 deletions plugins/kn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# kn - Knative CLI

This plugin provides autocompletion for [kn](https://knative.dev/docs/install/client/install-kn/) operations.

To use it, add `kn` to the plugins array of your zshrc file:

```zsh
plugins=(... kn)
```

## See Also

+ [kn/client](https://github.com/knative/client)

## Contributors

+ [btannous](https://github.com/btannous) - Plugin Author
8 changes: 8 additions & 0 deletions plugins/kn/kn.plugin.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Autocompletion for kn, the command line interface for knative
#
# Author: https://github.com/btannous

if [ $commands[kn] ]; then
source <(kn completion zsh)
compdef _kn kn
fi
6 changes: 0 additions & 6 deletions plugins/macos/macos.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Check if 'osx' is still in the plugins list and prompt to change to 'macos'
if [[ -n "${plugins[(r)osx]}" ]]; then
print ${(%):-"%F{yellow}The \`osx\` plugin is deprecated and has been renamed to \`macos\`."}
print ${(%):-"Please update your .zshrc to use the \`%Bmacos%b\` plugin instead.%f"}
fi

# Open the current directory in a Finder window
alias ofd='open_command $PWD'

Expand Down
1 change: 0 additions & 1 deletion plugins/macos/osx.plugin.zsh

This file was deleted.

1 change: 0 additions & 1 deletion plugins/osx

This file was deleted.

3 changes: 3 additions & 0 deletions plugins/osx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# osx plugin

**Deprecated: use the [`macos`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/macos) plugin instead.**
5 changes: 5 additions & 0 deletions plugins/osx/osx.plugin.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print ${(%):-'%F{yellow}The `osx` plugin is deprecated and has been renamed to `macos`.'}
print ${(%):-'Please update your .zshrc to use the `%Bmacos%b` plugin instead.%f'}

(( ${fpath[(Ie)$ZSH/plugins/macos]} )) || fpath=("$ZSH/plugins/macos" $fpath)
source "$ZSH/plugins/macos/macos.plugin.zsh"
23 changes: 16 additions & 7 deletions plugins/rand-quote/rand-quote.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
if ! (( $+commands[curl] )); then
echo "rand-quote plugin needs curl to work" >&2
return
echo "rand-quote plugin needs curl to work" >&2
return
fi

function quote {
emulate -L zsh
Q=$(curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" | iconv -c -f ISO-8859-1 -t UTF-8 | grep -m 1 "dt ")
setopt localoptions nopromptsubst

TXT=$(echo "$Q" | sed -e 's/<\/dt>.*//g' -e 's/.*html//g' -e 's/^[^a-zA-Z]*//' -e 's/<\/a..*$//g')
WHO=$(echo "$Q" | sed -e 's/.*\/quotes\///g' -e 's/<.*//g' -e 's/.*">//g')
# Get random quote data
local data
data="$(command curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" \
| iconv -c -f ISO-8859-1 -t UTF-8 \
| command grep -a -m 1 'dt class="quote"')"

[[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
# Exit if could not fetch random quote
[[ -n "$data" ]] || return 0

local quote author
quote=$(sed -e 's|</dt>.*||g' -e 's|.*html||g' -e 's|^[^a-zA-Z]*||' -e 's|</a..*$||g' <<< "$data")
author=$(sed -e 's|.*/quotes/||g' -e 's|<.*||g' -e 's|.*">||g' <<< "$data")

print -P "%F{3}${author}%f: “%F{5}${quote}%f”"
}

0 comments on commit e2feff2

Please sign in to comment.