Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acc11bc5f4 | ||
|
|
d03d367f82 | ||
|
|
eccb32c94c |
@@ -19,7 +19,7 @@ dependencies:
|
|||||||
plugins/history-substring-search:
|
plugins/history-substring-search:
|
||||||
repo: zsh-users/zsh-history-substring-search
|
repo: zsh-users/zsh-history-substring-search
|
||||||
branch: master
|
branch: master
|
||||||
version: a0bdb0d47dbaba31dba2db7af8c48a5d9c74049a
|
version: 14c8d2e0ffaee98f2df9850b19944f32546fdea5
|
||||||
precopy: |
|
precopy: |
|
||||||
set -e
|
set -e
|
||||||
rm -f zsh-history-substring-search.plugin.zsh
|
rm -f zsh-history-substring-search.plugin.zsh
|
||||||
@@ -30,7 +30,7 @@ dependencies:
|
|||||||
plugins/kube-ps1:
|
plugins/kube-ps1:
|
||||||
repo: jonmosco/kube-ps1
|
repo: jonmosco/kube-ps1
|
||||||
branch: master
|
branch: master
|
||||||
version: b4cd09ec8d4dc007173e28da40aeebf8eff8c87f
|
version: 04af46f7fe888ad287abcab6699b9bb10234bc3d
|
||||||
precopy: |
|
precopy: |
|
||||||
set -e
|
set -e
|
||||||
find . ! -name kube-ps1.sh ! -name LICENSE ! -name README.md -delete
|
find . ! -name kube-ps1.sh ! -name LICENSE ! -name README.md -delete
|
||||||
@@ -55,46 +55,3 @@ dependencies:
|
|||||||
set -e
|
set -e
|
||||||
test -e _zshz && mv -f _zshz _z
|
test -e _zshz && mv -f _zshz _z
|
||||||
test -e zsh-z.plugin.zsh && mv -f zsh-z.plugin.zsh z.plugin.zsh
|
test -e zsh-z.plugin.zsh && mv -f zsh-z.plugin.zsh z.plugin.zsh
|
||||||
plugins/zsh-autosuggestions:
|
|
||||||
repo: zsh-users/zsh-autosuggestions
|
|
||||||
branch: master
|
|
||||||
version: 85919cd1ffa7d2d5412f6d3fe437ebdbeeec4fc5
|
|
||||||
precopy: |
|
|
||||||
set -e
|
|
||||||
test -e README.md && mv -f README.md MANUAL.md
|
|
||||||
sed -i 's|\[INSTALL.md\](INSTALL.md)|[the Oh My Zsh plugin README](README.md)|' MANUAL.md
|
|
||||||
rm -f zsh-autosuggestions.plugin.zsh
|
|
||||||
mv -f zsh-autosuggestions.zsh zsh-autosuggestions.plugin.zsh
|
|
||||||
find . -depth -mindepth 1 \
|
|
||||||
! -path './LICENSE' \
|
|
||||||
! -path './MANUAL.md' \
|
|
||||||
! -path './src' \
|
|
||||||
! -path './src/*' \
|
|
||||||
! -path './zsh-autosuggestions.plugin.zsh' \
|
|
||||||
-delete
|
|
||||||
plugins/zsh-syntax-highlighting:
|
|
||||||
repo: zsh-users/zsh-syntax-highlighting
|
|
||||||
branch: master
|
|
||||||
version: 2fc57d63067c18b1100ecdbf684fa5baf49459d1
|
|
||||||
precopy: |
|
|
||||||
set -e
|
|
||||||
version=$(<.version)
|
|
||||||
test -e README.md && mv -f README.md MANUAL.md
|
|
||||||
sed -i 's|\[INSTALL.md\](INSTALL.md)|[the Oh My Zsh plugin README](README.md)|' MANUAL.md
|
|
||||||
rm -f zsh-syntax-highlighting.plugin.zsh
|
|
||||||
mv -f zsh-syntax-highlighting.zsh zsh-syntax-highlighting.plugin.zsh
|
|
||||||
mv -f COPYING.md LICENSE
|
|
||||||
sed -i "s|typeset -g ZSH_HIGHLIGHT_VERSION=.*|typeset -g ZSH_HIGHLIGHT_VERSION=$version|" zsh-syntax-highlighting.plugin.zsh
|
|
||||||
sed -i 's|typeset -g ZSH_HIGHLIGHT_REVISION=.*|typeset -g ZSH_HIGHLIGHT_REVISION=HEAD|' zsh-syntax-highlighting.plugin.zsh
|
|
||||||
find highlighters -type d -name test-data -prune -exec rm -rf {} +
|
|
||||||
find . -depth -mindepth 1 \
|
|
||||||
! -path './LICENSE' \
|
|
||||||
! -path './MANUAL.md' \
|
|
||||||
! -path './docs' \
|
|
||||||
! -path './docs/*' \
|
|
||||||
! -path './highlighters' \
|
|
||||||
! -path './highlighters/*' \
|
|
||||||
! -path './images' \
|
|
||||||
! -path './images/*' \
|
|
||||||
! -path './zsh-syntax-highlighting.plugin.zsh' \
|
|
||||||
-delete
|
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ charset-normalizer==3.5.1
|
|||||||
idna==3.19
|
idna==3.19
|
||||||
PyYAML==6.0.3
|
PyYAML==6.0.3
|
||||||
requests==2.34.2
|
requests==2.34.2
|
||||||
semver==3.1.0
|
semver==3.0.4
|
||||||
urllib3==2.8.0
|
urllib3==2.7.0
|
||||||
|
|||||||
@@ -60,6 +60,6 @@ jobs:
|
|||||||
retention-days: 5
|
retention-days: 5
|
||||||
|
|
||||||
- name: "Upload to code-scanning"
|
- name: "Upload to code-scanning"
|
||||||
uses: github/codeql-action/upload-sarif@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0
|
uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
|
|||||||
@@ -474,22 +474,6 @@ zstyle ':omz:update' frequency 7
|
|||||||
zstyle ':omz:update' frequency 0
|
zstyle ':omz:update' frequency 0
|
||||||
```
|
```
|
||||||
|
|
||||||
By default, updates always pull the latest changes. If you'd rather let others kick the tires first
|
|
||||||
before an update reaches your machine, you can set a cooldown (in days). You'll still get everything —
|
|
||||||
just a little later:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# Only apply updates that are at least 10 days old
|
|
||||||
zstyle ':omz:update' cooldown 10
|
|
||||||
```
|
|
||||||
|
|
||||||
`omz update` honors this setting. If you call `upgrade.sh` directly, pass the same
|
|
||||||
value with `-c`, because that script does not read your `.zshrc`:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ZSH/tools/upgrade.sh -c 10
|
|
||||||
```
|
|
||||||
|
|
||||||
### Updates Verbosity
|
### Updates Verbosity
|
||||||
|
|
||||||
You can also limit the update verbosity with the following settings:
|
You can also limit the update verbosity with the following settings:
|
||||||
|
|||||||
@@ -738,9 +738,6 @@ function _omz::reload {
|
|||||||
|
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
# Old zsh versions don't have ZSH_ARGZERO
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||||
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
|
||||||
# anything that is not absolute via $PATH at exec time (see #13919)
|
|
||||||
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
|
||||||
# Check whether to run a login shell
|
# Check whether to run a login shell
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||||
}
|
}
|
||||||
@@ -906,11 +903,8 @@ function _omz::update {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run update script
|
# Run update script
|
||||||
local verbose_mode cooldown_days
|
|
||||||
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
||||||
zstyle -s ':omz:update' cooldown cooldown_days || cooldown_days=0
|
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $?
|
||||||
[[ $cooldown_days == <-> ]] || cooldown_days=0
|
|
||||||
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode -c $cooldown_days || return $?
|
|
||||||
|
|
||||||
# Update last updated file
|
# Update last updated file
|
||||||
zmodload zsh/datetime
|
zmodload zsh/datetime
|
||||||
@@ -922,9 +916,6 @@ function _omz::update {
|
|||||||
if [[ "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
if [[ "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
# Old zsh versions don't have ZSH_ARGZERO
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||||
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
|
||||||
# anything that is not absolute via $PATH at exec time (see #13919)
|
|
||||||
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
|
||||||
# Check whether to run a login shell
|
# Check whether to run a login shell
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -12,16 +12,10 @@ function __git_prompt_git() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _omz_git_prompt_info() {
|
function _omz_git_prompt_info() {
|
||||||
# Get the git dir and the current branch name in one call. Outside a repo
|
# If we are on a folder not tracked by git, get out.
|
||||||
# there is no output. On a detached HEAD the branch is "HEAD". On an unborn
|
# Otherwise, check for hide-info at global and local repository level
|
||||||
# branch git exits non-zero after printing the git dir.
|
if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
|
||||||
local -a info
|
|| [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
||||||
info=("${(@f)$(__git_prompt_git rev-parse --git-dir --abbrev-ref HEAD 2> /dev/null)}")
|
|
||||||
local unborn=$(( $? != 0 ))
|
|
||||||
[[ -n "$info[1]" ]] || return 0
|
|
||||||
|
|
||||||
# Check for hide-info at global and local repository level
|
|
||||||
if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -29,15 +23,11 @@ function _omz_git_prompt_info() {
|
|||||||
# - the current branch name
|
# - the current branch name
|
||||||
# - the tag name if we are on a tag
|
# - the tag name if we are on a tag
|
||||||
# - the short SHA of the current commit
|
# - the short SHA of the current commit
|
||||||
# a git dir path may contain newlines, so the branch is the last line
|
local ref
|
||||||
local ref="$info[-1]"
|
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \
|
||||||
if (( unborn )); then
|
|| ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \
|
||||||
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) || return 0
|
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \
|
||||||
elif [[ "$ref" == HEAD ]]; then
|
|| return 0
|
||||||
ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \
|
|
||||||
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \
|
|
||||||
|| return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info
|
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info
|
||||||
local upstream
|
local upstream
|
||||||
@@ -254,8 +244,7 @@ function parse_git_dirty() {
|
|||||||
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# only non-emptiness matters, so keep one line instead of the whole list
|
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
|
||||||
__git_prompt_git status ${FLAGS} 2> /dev/null | read -r STATUS
|
|
||||||
fi
|
fi
|
||||||
if [[ -n $STATUS ]]; then
|
if [[ -n $STATUS ]]; then
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ function title {
|
|||||||
print -Pn "\e]1;${1:q}\a" # set tab name
|
print -Pn "\e]1;${1:q}\a" # set tab name
|
||||||
;;
|
;;
|
||||||
screen*|tmux*)
|
screen*|tmux*)
|
||||||
print -Pn "\e]2;${2:q}\e\\" # set tmux pane title
|
print -Pn "\ek${1:q}\e\\" # set screen hardstatus
|
||||||
print -Pn "\ek${1:q}\e\\" # set screen hardstatus/tmux window name if `allow-rename` is on
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
|
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
|
||||||
|
|||||||
@@ -13,92 +13,69 @@ ZSH_THEME_RUBY_PROMPT_PREFIX="("
|
|||||||
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
|
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
|
||||||
|
|
||||||
|
|
||||||
# The command probes below fork a process each, and their result doesn't change
|
|
||||||
# from one shell to the next, so they're cached for a day (like lib/grep.zsh).
|
|
||||||
typeset -A __omz_probes
|
|
||||||
__omz_probe_cache="$ZSH_CACHE_DIR/appearance-probes"
|
|
||||||
__omz_probe_cached=("$__omz_probe_cache"(Nm-1))
|
|
||||||
[[ -z "$__omz_probe_cached" ]] || source "$__omz_probe_cache"
|
|
||||||
|
|
||||||
function __omz_test_cmd_args {
|
|
||||||
# Usage: __omz_test_cmd_args cmd args...
|
|
||||||
# Runs `cmd args... /dev/null` and remembers whether it succeeded, so a
|
|
||||||
# command needing two operands passes the first one itself:
|
|
||||||
# e.g. __omz_test_cmd_args gls --color -> gls --color /dev/null
|
|
||||||
# __omz_test_cmd_args diff --color /dev/null -> diff --color /dev/null /dev/null
|
|
||||||
local key="$*"
|
|
||||||
if (( ! ${+__omz_probes[$key]} )); then
|
|
||||||
command "$@" /dev/null &>/dev/null
|
|
||||||
__omz_probes[$key]=$?
|
|
||||||
if [[ -w "$ZSH_CACHE_DIR" ]]; then
|
|
||||||
print -r -- "__omz_probes=(" "${(@qqkv)__omz_probes}" ")" >| "$__omz_probe_cache"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
return $__omz_probes[$key]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Use diff --color if available
|
# Use diff --color if available
|
||||||
if __omz_test_cmd_args diff --color /dev/null; then
|
if command diff --color /dev/null{,} &>/dev/null; then
|
||||||
function diff {
|
function diff {
|
||||||
command diff --color "$@"
|
command diff --color "$@"
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set up ls coloring. Done in a function so the early return below still
|
# Don't set ls coloring if disabled
|
||||||
# reaches the cleanup at the end of this file.
|
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
|
||||||
() {
|
|
||||||
# Don't set ls coloring if disabled
|
|
||||||
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
|
|
||||||
|
|
||||||
# Default coloring for BSD-based ls
|
# Default coloring for BSD-based ls
|
||||||
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||||||
|
|
||||||
# Default coloring for GNU-based ls
|
# Default coloring for GNU-based ls
|
||||||
if [[ -z "$LS_COLORS" ]]; then
|
if [[ -z "$LS_COLORS" ]]; then
|
||||||
# Define LS_COLORS via dircolors if available. Otherwise, set a default
|
# Define LS_COLORS via dircolors if available. Otherwise, set a default
|
||||||
# equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
|
# equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
|
||||||
if (( $+commands[dircolors] )); then
|
if (( $+commands[dircolors] )); then
|
||||||
[[ -f "$HOME/.dircolors" ]] \
|
[[ -f "$HOME/.dircolors" ]] \
|
||||||
&& source <(dircolors -b "$HOME/.dircolors") \
|
&& source <(dircolors -b "$HOME/.dircolors") \
|
||||||
|| source <(dircolors -b)
|
|| source <(dircolors -b)
|
||||||
else
|
else
|
||||||
export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
|
export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Find the option for using colors in ls, depending on the version
|
function test-ls-args {
|
||||||
case "$OSTYPE" in
|
# Usage: test-ls-args cmd args...
|
||||||
netbsd*)
|
# e.g. test-ls-args gls --color
|
||||||
# On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
|
command "$@" /dev/null &>/dev/null
|
||||||
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
|
|
||||||
__omz_test_cmd_args gls --color && alias ls='gls --color=tty'
|
|
||||||
;;
|
|
||||||
openbsd*)
|
|
||||||
# On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
|
|
||||||
# with color and multibyte support) are available from ports.
|
|
||||||
# `colorls` will be installed on purpose and can't be pulled in by installing
|
|
||||||
# coreutils (which might be installed for ), so prefer it to `gls`.
|
|
||||||
__omz_test_cmd_args gls --color && alias ls='gls --color=tty'
|
|
||||||
__omz_test_cmd_args colorls -G && alias ls='colorls -G'
|
|
||||||
;;
|
|
||||||
(darwin|freebsd)*)
|
|
||||||
# This alias works by default just using $LSCOLORS
|
|
||||||
__omz_test_cmd_args ls -G && alias ls='ls -G'
|
|
||||||
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
|
|
||||||
# as the default coloring scheme is not very pretty
|
|
||||||
zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
|
|
||||||
&& __omz_test_cmd_args gls --color \
|
|
||||||
&& alias ls='gls --color=tty'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
if __omz_test_cmd_args ls --color; then
|
|
||||||
alias ls='ls --color=tty'
|
|
||||||
elif __omz_test_cmd_args ls -G; then
|
|
||||||
alias ls='ls -G'
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unfunction __omz_test_cmd_args
|
# Find the option for using colors in ls, depending on the version
|
||||||
unset __omz_probes __omz_probe_cache __omz_probe_cached
|
case "$OSTYPE" in
|
||||||
|
netbsd*)
|
||||||
|
# On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
|
||||||
|
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
|
||||||
|
test-ls-args gls --color && alias ls='gls --color=tty'
|
||||||
|
;;
|
||||||
|
openbsd*)
|
||||||
|
# On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
|
||||||
|
# with color and multibyte support) are available from ports.
|
||||||
|
# `colorls` will be installed on purpose and can't be pulled in by installing
|
||||||
|
# coreutils (which might be installed for ), so prefer it to `gls`.
|
||||||
|
test-ls-args gls --color && alias ls='gls --color=tty'
|
||||||
|
test-ls-args colorls -G && alias ls='colorls -G'
|
||||||
|
;;
|
||||||
|
(darwin|freebsd)*)
|
||||||
|
# This alias works by default just using $LSCOLORS
|
||||||
|
test-ls-args ls -G && alias ls='ls -G'
|
||||||
|
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
|
||||||
|
# as the default coloring scheme is not very pretty
|
||||||
|
zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
|
||||||
|
&& test-ls-args gls --color \
|
||||||
|
&& alias ls='gls --color=tty'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if test-ls-args ls --color; then
|
||||||
|
alias ls='ls --color=tty'
|
||||||
|
elif test-ls-args ls -G; then
|
||||||
|
alias ls='ls -G'
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
unfunction test-ls-args
|
||||||
|
|||||||
@@ -100,28 +100,7 @@ done
|
|||||||
# Figure out the SHORT hostname
|
# Figure out the SHORT hostname
|
||||||
if [[ "$OSTYPE" = darwin* ]]; then
|
if [[ "$OSTYPE" = darwin* ]]; then
|
||||||
# macOS's $HOST changes with dhcp, etc. Use LocalHostName if possible.
|
# macOS's $HOST changes with dhcp, etc. Use LocalHostName if possible.
|
||||||
# scutil costs a fork on every start, so remember its answer for a day
|
SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) || SHORT_HOST="${HOST/.*/}"
|
||||||
# (like lib/grep.zsh) and re-check sooner if $HOST changes.
|
|
||||||
__omz_host_cache="$ZSH_CACHE_DIR/localhostname"
|
|
||||||
__omz_host_cached=("$__omz_host_cache"(Nm-1))
|
|
||||||
__omz_host_key=
|
|
||||||
SHORT_HOST=
|
|
||||||
if [[ -n "$__omz_host_cached" ]]; then
|
|
||||||
if ! { read -r __omz_host_key && read -r SHORT_HOST } < "$__omz_host_cache"; then
|
|
||||||
__omz_host_key=
|
|
||||||
SHORT_HOST=
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ "$__omz_host_key" != "$HOST" || -z "$SHORT_HOST" ]]; then
|
|
||||||
# only cache what scutil actually answered, so a transient failure
|
|
||||||
# doesn't pin the fallback name for a day
|
|
||||||
if SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) && [[ -n "$SHORT_HOST" ]]; then
|
|
||||||
[[ ! -w "$ZSH_CACHE_DIR" ]] || print -rl -- "$HOST" "$SHORT_HOST" >| "$__omz_host_cache"
|
|
||||||
else
|
|
||||||
SHORT_HOST="${HOST/.*/}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
unset __omz_host_cache __omz_host_cached __omz_host_key
|
|
||||||
else
|
else
|
||||||
SHORT_HOST="${HOST/.*/}"
|
SHORT_HOST="${HOST/.*/}"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
# AppSignal CLI plugin
|
|
||||||
|
|
||||||
This plugin adds aliases, guard rails and completion for the
|
|
||||||
[AppSignal CLI](https://docs.appsignal.com/cli).
|
|
||||||
|
|
||||||
To use it, add `appsignal-cli` to the plugins array in your zshrc file:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(... appsignal-cli)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
[AppSignal CLI](https://docs.appsignal.com/cli) 2.1 or newer, installed and on
|
|
||||||
your `PATH`. The plugin does nothing if it is not:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
brew install appsignal/appsignal-cli/appsignal-cli
|
|
||||||
# or
|
|
||||||
curl -sSL https://github.com/appsignal/appsignal-cli/releases/latest/download/install.sh | sudo sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Most commands need `appsignal-cli auth login` first.
|
|
||||||
|
|
||||||
## Aliases
|
|
||||||
|
|
||||||
| Alias | Command | Description |
|
|
||||||
| :------ | :----------------------------- | :--------------------------------- |
|
|
||||||
| `asig` | `appsignal-cli` | The AppSignal CLI itself |
|
|
||||||
| `aslog` | `appsignal-cli logs tail` | Stream log lines as they arrive |
|
|
||||||
| `asinc` | `appsignal-cli incidents list` | List incidents for an application |
|
|
||||||
|
|
||||||
`aslog` and `asinc` complete like the commands they stand in for, so
|
|
||||||
`aslog --<TAB>` offers the flags of `appsignal-cli logs tail`.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
| Function | Description |
|
|
||||||
| :-------------- | :----------------------------------------------------------------- |
|
|
||||||
| `appsignal-cli` | Wraps the CLI to confirm before irreversible commands. See Settings |
|
|
||||||
|
|
||||||
## Completion
|
|
||||||
|
|
||||||
Every command completes with a description of what it does, at every level, and
|
|
||||||
so do their flags and allowed values: incident states and severities, sort
|
|
||||||
orders, log severities, trigger fields and comparison operators, output formats
|
|
||||||
and skill targets. `samples` and `sample` complete like `traces`, as they do in
|
|
||||||
the CLI itself.
|
|
||||||
|
|
||||||
`--org` completes offline from the `org` key of your project's
|
|
||||||
`.appsignal.toml` and of the global config.
|
|
||||||
|
|
||||||
The AppSignal CLI ships no completion generator of its own, so `_appsignal-cli`
|
|
||||||
is written from its command definitions and kept in this repository. It targets
|
|
||||||
AppSignal CLI 2.1.x.
|
|
||||||
|
|
||||||
## Settings
|
|
||||||
|
|
||||||
Set these with `zstyle` in your zshrc, before Oh My Zsh is sourced.
|
|
||||||
|
|
||||||
### Confirming destructive commands
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:appsignal-cli' confirm-destructive no
|
|
||||||
```
|
|
||||||
|
|
||||||
By default the plugin asks for confirmation before four operations that the CLI
|
|
||||||
itself performs without a prompt:
|
|
||||||
|
|
||||||
- `appsignal-cli logs metrics delete`
|
|
||||||
- `appsignal-cli logs triggers delete`
|
|
||||||
- `appsignal-cli triggers archive`, which also closes the trigger's alerts and
|
|
||||||
incidents
|
|
||||||
- `appsignal-cli incidents update --state CLOSED` when it names more than one
|
|
||||||
incident, since that flag accepts a comma-separated list
|
|
||||||
|
|
||||||
Nothing else is intercepted, and the prompt is skipped when stdin is not a
|
|
||||||
terminal, so scripts, pipelines and CI are unaffected. Set the style to `no` to
|
|
||||||
turn the prompt off entirely, or run `command appsignal-cli` for a single
|
|
||||||
invocation.
|
|
||||||
|
|
||||||
### Completing applications
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:appsignal-cli' dynamic-app-completion yes
|
|
||||||
```
|
|
||||||
|
|
||||||
Off by default. When enabled, `--app`, `--app-id` and `--environment` are
|
|
||||||
completed from `appsignal-cli apps list --output json`, showing each
|
|
||||||
application's name and environment next to its ID instead of making you copy
|
|
||||||
IDs by hand. It is opt-in because it runs the CLI and makes a network call when
|
|
||||||
you press <kbd>Tab</kbd>, and because it needs you to be authenticated. Results
|
|
||||||
are cached for five minutes.
|
|
||||||
|
|
||||||
### Disabling the aliases
|
|
||||||
|
|
||||||
This works for every Oh My Zsh plugin:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:appsignal-cli' aliases no
|
|
||||||
```
|
|
||||||
|
|
||||||
## Caveats
|
|
||||||
|
|
||||||
- `appsignal-cli` and the AppSignal Ruby gem's `appsignal` command are different
|
|
||||||
tools. The gem's command installs and diagnoses the agent inside your app;
|
|
||||||
this one queries your data. The plugin deliberately leaves `appsignal` alone,
|
|
||||||
so it keeps working in projects that use the gem.
|
|
||||||
- `appsignal-cli` is a shell function here. Run `command appsignal-cli` to reach
|
|
||||||
the binary directly.
|
|
||||||
- Most commands need exactly one of `--app-id` or `--app`. `--environment` only
|
|
||||||
narrows `--app`; it does nothing next to `--app-id`.
|
|
||||||
- `appsignal-cli project init` writes `.appsignal.toml`, and `auth login` then
|
|
||||||
stores OAuth tokens in it. Do not commit that file.
|
|
||||||
- `incidents delete-note`, `auth logout` and the `--clear-*` flags of
|
|
||||||
`logs metrics update` and `logs triggers update` are destructive too, but are
|
|
||||||
not prompted for: each affects a single note, login or field.
|
|
||||||
- `triggers create` and `triggers update` have their own `--format`, for the
|
|
||||||
format of the metric value. Everywhere else `--format` is a synonym for
|
|
||||||
`--output`.
|
|
||||||
- The CLI sends usage telemetry by default. `APPSIGNAL_CLI_TELEMETRY=0` turns it
|
|
||||||
off, and `APPSIGNAL_CLI_DEBUG=1` shows internal errors.
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
# AppSignal CLI: completion, aliases and guard rails.
|
|
||||||
# https://docs.appsignal.com/cli
|
|
||||||
|
|
||||||
if (( ! $+commands[appsignal-cli] )); then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Does this invocation need confirming? Sets REPLY to the reason.
|
|
||||||
#
|
|
||||||
# The command path is collected from the leading bare words. Only the global
|
|
||||||
# flags may precede a subcommand, so the first other flag ends the path: that
|
|
||||||
# way an option value such as `--app "My App"` is never mistaken for one.
|
|
||||||
function _appsignal_cli_is_destructive() {
|
|
||||||
zstyle -T ':omz:plugins:appsignal-cli' confirm-destructive || return 1
|
|
||||||
|
|
||||||
# Nobody to answer: CI and pipelines are unaffected.
|
|
||||||
[[ -t 0 ]] || return 1
|
|
||||||
|
|
||||||
local -a args=("$@") path numbers
|
|
||||||
local arg state=""
|
|
||||||
integer i=1 n=$# path_done=0
|
|
||||||
|
|
||||||
while (( i <= n )); do
|
|
||||||
arg="$args[i]"
|
|
||||||
case "$arg" in
|
|
||||||
--) break ;;
|
|
||||||
--state=*) state="${arg#--state=}"; path_done=1 ;;
|
|
||||||
--state) state="$args[i+1]"; (( i++ )); path_done=1 ;;
|
|
||||||
--number=*) numbers+=(${(s:,:)${arg#--number=}}); path_done=1 ;;
|
|
||||||
# --number takes one or more values, comma-separated or repeated.
|
|
||||||
--number)
|
|
||||||
path_done=1
|
|
||||||
while (( i < n )) && [[ "$args[i+1]" != -* ]]; do
|
|
||||||
(( i++ ))
|
|
||||||
numbers+=(${(s:,:)args[i]})
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
# The output flag is global, so it can appear before the subcommand.
|
|
||||||
-o|--output|--format) (( i++ )) ;;
|
|
||||||
-o*|--output=*|--format=*) ;;
|
|
||||||
-*) path_done=1 ;;
|
|
||||||
*) (( path_done )) || path+=("$arg") ;;
|
|
||||||
esac
|
|
||||||
(( i++ ))
|
|
||||||
done
|
|
||||||
|
|
||||||
case "${(j: :)path[1,3]}" in
|
|
||||||
"logs metrics delete")
|
|
||||||
REPLY="deleting a log-derived metric cannot be undone."
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
"logs triggers delete")
|
|
||||||
REPLY="deleting a log-based trigger cannot be undone."
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
"triggers archive")
|
|
||||||
REPLY="archiving a trigger also closes its alerts and incidents."
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
"incidents update")
|
|
||||||
if [[ "${(U)state}" == CLOSED ]] && (( $#numbers > 1 )); then
|
|
||||||
REPLY="this closes $#numbers incidents at once."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Adds a confirmation prompt before irreversible operations. Everything else
|
|
||||||
# passes straight through, so `logs tail` keeps streaming and pipes stay clean.
|
|
||||||
function appsignal-cli() {
|
|
||||||
local REPLY
|
|
||||||
if _appsignal_cli_is_destructive "$@"; then
|
|
||||||
print -u2 -- "appsignal-cli: $REPLY"
|
|
||||||
if ! read -q "?Continue? [y/N] "; then
|
|
||||||
print -u2 -- ""
|
|
||||||
return 130
|
|
||||||
fi
|
|
||||||
print -u2 -- ""
|
|
||||||
fi
|
|
||||||
|
|
||||||
command appsignal-cli "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Complete the aliases like the commands they stand in for.
|
|
||||||
if (( $+functions[compdef] )); then
|
|
||||||
_aslog() {
|
|
||||||
words=(appsignal-cli logs tail ${words[2,-1]})
|
|
||||||
(( CURRENT += 2 ))
|
|
||||||
_appsignal-cli
|
|
||||||
}
|
|
||||||
|
|
||||||
_asinc() {
|
|
||||||
words=(appsignal-cli incidents list ${words[2,-1]})
|
|
||||||
(( CURRENT += 2 ))
|
|
||||||
_appsignal-cli
|
|
||||||
}
|
|
||||||
|
|
||||||
compdef _appsignal-cli asig
|
|
||||||
compdef _aslog aslog
|
|
||||||
compdef _asinc asinc
|
|
||||||
fi
|
|
||||||
|
|
||||||
alias asig='appsignal-cli'
|
|
||||||
alias aslog='appsignal-cli logs tail'
|
|
||||||
alias asinc='appsignal-cli incidents list'
|
|
||||||
@@ -15,9 +15,6 @@ This plugin does not add any aliases.
|
|||||||
This plugin caches the completion script and is automatically updated when the
|
This plugin caches the completion script and is automatically updated when the
|
||||||
plugin is loaded, which is usually when you start up a new terminal emulator.
|
plugin is loaded, which is usually when you start up a new terminal emulator.
|
||||||
|
|
||||||
The cache is stored at:
|
The completion script is stored at `$ZSH_CACHE_DIR/completions/_gh`. If an
|
||||||
|
update fails, the plugin keeps the last successfully generated completion
|
||||||
- `$ZSH/plugins/gh/_gh` completions script
|
script.
|
||||||
|
|
||||||
- `$ZSH_CACHE_DIR/gh_version` version of GitHub CLI, used to invalidate
|
|
||||||
the cache.
|
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ fi
|
|||||||
|
|
||||||
zmodload -F zsh/files b:zf_mv
|
zmodload -F zsh/files b:zf_mv
|
||||||
() {
|
() {
|
||||||
local TMPPREFIX="$ZSH_CACHE_DIR/completions/_gh"
|
local completion_file="$ZSH_CACHE_DIR/completions/_gh"
|
||||||
zf_mv -f -- =( gh completion --shell zsh ) "$TMPPREFIX"
|
local completion_tmp="${completion_file}.$$.${RANDOM}"
|
||||||
|
|
||||||
|
if gh completion --shell zsh >| "$completion_tmp" && [[ -s "$completion_tmp" ]]; then
|
||||||
|
zf_mv -f -- "$completion_tmp" "$completion_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
command rm -f -- "$completion_tmp"
|
||||||
} &|
|
} &|
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ plugins=(... git)
|
|||||||
| `glods` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short` |
|
| `glods` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short` |
|
||||||
| `glol` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` |
|
| `glol` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` |
|
||||||
| `glola` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all` |
|
| `glola` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all` |
|
||||||
| `glolm` | `git log $(git_main_branch) --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` |
|
|
||||||
| `glols` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat` |
|
| `glols` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat` |
|
||||||
| `glo` | `git log --oneline --decorate` |
|
| `glo` | `git log --oneline --decorate` |
|
||||||
| `glog` | `git log --oneline --decorate --graph` |
|
| `glog` | `git log --oneline --decorate --graph` |
|
||||||
@@ -255,7 +254,6 @@ receive further support.
|
|||||||
| `git_current_user_name` | Returns the `user.name` config value (Lives in `lib/git.zsh`) |
|
| `git_current_user_name` | Returns the `user.name` config value (Lives in `lib/git.zsh`) |
|
||||||
| `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise |
|
| `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise |
|
||||||
| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise |
|
| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise |
|
||||||
| `gbcopy` | Copies current branch name to clipboard |
|
|
||||||
| `grename <old> <new>` | Renames branch `<old>` to `<new>`, including on the origin remote |
|
| `grename <old> <new>` | Renames branch `<old>` to `<new>`, including on the origin remote |
|
||||||
| `gbda` | Deletes all merged branches |
|
| `gbda` | Deletes all merged branches |
|
||||||
| `gbds` | Deletes all squash-merged branches (**Note: performance degrades with number of branches**) |
|
| `gbds` | Deletes all squash-merged branches (**Note: performance degrades with number of branches**) |
|
||||||
|
|||||||
@@ -49,16 +49,6 @@ function git_main_branch() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function gbcopy() {
|
|
||||||
command git rev-parse --git-dir &>/dev/null || return
|
|
||||||
|
|
||||||
local branch
|
|
||||||
branch="$(git_current_branch)" || return
|
|
||||||
[[ -n "$branch" ]] || return 1
|
|
||||||
|
|
||||||
print -rn -- "$branch" | clipcopy
|
|
||||||
}
|
|
||||||
|
|
||||||
function grename() {
|
function grename() {
|
||||||
if [[ -z "$1" || -z "$2" ]]; then
|
if [[ -z "$1" || -z "$2" ]]; then
|
||||||
echo "Usage: $0 old_branch new_branch"
|
echo "Usage: $0 old_branch new_branch"
|
||||||
@@ -249,7 +239,6 @@ alias glod='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgre
|
|||||||
alias glola='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all'
|
alias glola='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all'
|
||||||
alias glols='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat'
|
alias glols='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat'
|
||||||
alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
|
alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
|
||||||
alias glolm='git log $(git_main_branch) --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
|
|
||||||
alias glo='git log --oneline --decorate'
|
alias glo='git log --oneline --decorate'
|
||||||
alias glog='git log --oneline --decorate --graph'
|
alias glog='git log --oneline --decorate --graph'
|
||||||
alias gloga='git log --oneline --decorate --graph --all'
|
alias gloga='git log --oneline --decorate --graph --all'
|
||||||
|
|||||||
@@ -1,45 +1,43 @@
|
|||||||
# github plugin
|
# github plugin
|
||||||
|
|
||||||
This plugin supports working with GitHub from the command line. It provides a few things:
|
> [!WARNING]
|
||||||
|
> This plugin is deprecated and will be removed in a future release. It supports
|
||||||
|
> the legacy [`hub`](https://github.com/mislav/hub) CLI, not the current GitHub
|
||||||
|
> CLI. For `gh` completion, use the [`gh` plugin](../gh) instead.
|
||||||
|
|
||||||
* Sets up the `hub` wrapper and completions for the `git` command if you have [`hub`](https://github.com/github/hub) installed.
|
The plugin provides compatibility for existing `hub` users by:
|
||||||
* Completion for the [`github` Ruby gem](https://github.com/defunkt/github-gem).
|
|
||||||
* Convenience functions for working with repos and URLs.
|
|
||||||
|
|
||||||
### Functions
|
- aliasing `git` to `hub` when `hub` is installed;
|
||||||
|
- adding completion for `hub`; and
|
||||||
|
- defining convenience functions for creating repositories.
|
||||||
|
|
||||||
* `empty_gh` - Creates a new empty repo (with a `README.md`) and pushes it to GitHub
|
## Migrating to GitHub CLI
|
||||||
* `new_gh` - Initializes an existing directory as a repo and pushes it to GitHub
|
|
||||||
* `exist_gh` - Takes an existing repo and pushes it to GitHub
|
|
||||||
|
|
||||||
|
Install [GitHub CLI](https://cli.github.com/), replace `github` with `gh` in
|
||||||
## Installation
|
your plugin list, and restart your shell:
|
||||||
|
|
||||||
[Hub](https://github.com/github/hub) needs to be installed if you want to use it. On OS X with Homebrew, this can be done with `brew install hub`. The `hub` completion definition needs to be added to your `$FPATH` before initializing OMZ.
|
|
||||||
|
|
||||||
The [`github` Ruby gem](https://github.com/defunkt/github-gem) needs to be installed if you want to use it.
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
|
|
||||||
These settings affect `github`'s behavior.
|
|
||||||
|
|
||||||
#### Environment variables
|
|
||||||
|
|
||||||
* `$GITHUB_USER`
|
|
||||||
* `$GITHUB_PASSWORD`
|
|
||||||
|
|
||||||
#### Git configuration options
|
|
||||||
|
|
||||||
* `github.user` - GitHub username for repo operations
|
|
||||||
|
|
||||||
See `man hub` for more details.
|
|
||||||
|
|
||||||
### Homebrew installation note
|
|
||||||
|
|
||||||
If you have installed `hub` using Homebrew, its completions may not be on your `$FPATH` if you are using the system `zsh`. Homebrew installs `zsh` completion definitions to `/usr/local/share/zsh/site-functions`, which will be on `$FPATH` for the Homebrew-installed `zsh`, but not for the system `zsh`. If you want it to work with the system `zsh`, add this to your `~/.zshrc` before it sources `oh-my-zsh.sh`.
|
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
if (( ! ${fpath[(I)/usr/local/share/zsh/site-functions]} )); then
|
plugins=(... gh)
|
||||||
FPATH=/usr/local/share/zsh/site-functions:$FPATH
|
|
||||||
fi
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `gh` plugin supplies completion for the installed GitHub CLI. It does not
|
||||||
|
alias `git`, because `gh` is not a Git wrapper.
|
||||||
|
|
||||||
|
The closest replacement for creating a GitHub repository from an existing
|
||||||
|
local repository is:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
gh repo create --source=. --push
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deprecated functions
|
||||||
|
|
||||||
|
- `empty_gh` - creates a new repository with a `README.md` and pushes it to GitHub
|
||||||
|
- `new_gh` - initializes an existing directory and pushes it to GitHub
|
||||||
|
- `exist_gh` - pushes an existing Git repository to GitHub
|
||||||
|
|
||||||
|
These functions remain available during the deprecation period and require
|
||||||
|
`hub`. They will be removed with the plugin.
|
||||||
|
|
||||||
|
If you continue using `hub`, see its documentation for authentication and
|
||||||
|
configuration details.
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
print -Pru2 -- '%F{yellow}[oh-my-zsh] The %Bgithub%b plugin is deprecated and will be removed in a future release.'
|
||||||
|
print -Pru2 -- 'It supports the legacy %Bhub%b CLI. Use the %Bgh%b plugin for GitHub CLI completion.%f'
|
||||||
|
|
||||||
# Set up hub wrapper for git, if it is available; https://github.com/github/hub
|
# Set up hub wrapper for git, if it is available; https://github.com/github/hub
|
||||||
if (( $+commands[hub] )); then
|
if (( $+commands[hub] )); then
|
||||||
alias git=hub
|
alias git=hub
|
||||||
@@ -26,7 +29,7 @@ empty_gh() { # [NAME_OF_REPO]
|
|||||||
# This function will add all non-hidden files to git.
|
# This function will add all non-hidden files to git.
|
||||||
new_gh() { # [DIRECTORY]
|
new_gh() { # [DIRECTORY]
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
local repo="$1"
|
local repo="${1:-.}"
|
||||||
cd "$repo" \
|
cd "$repo" \
|
||||||
|| return
|
|| return
|
||||||
|
|
||||||
@@ -42,7 +45,7 @@ new_gh() { # [DIRECTORY]
|
|||||||
|| return
|
|| return
|
||||||
hub create \
|
hub create \
|
||||||
|| return
|
|| return
|
||||||
git push -u origin master \
|
git push -u origin HEAD \
|
||||||
|| return
|
|| return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,18 +55,19 @@ new_gh() { # [DIRECTORY]
|
|||||||
# to your GitHub.
|
# to your GitHub.
|
||||||
exist_gh() { # [DIRECTORY]
|
exist_gh() { # [DIRECTORY]
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
local repo=$1
|
local repo="${1:-.}"
|
||||||
cd "$repo"
|
cd "$repo" \
|
||||||
|
|| return
|
||||||
|
|
||||||
hub create \
|
hub create \
|
||||||
|| return
|
|| return
|
||||||
git push -u origin master
|
git push -u origin HEAD
|
||||||
}
|
}
|
||||||
|
|
||||||
# git.io "GitHub URL"
|
# git.io "GitHub URL"
|
||||||
#
|
#
|
||||||
# Shorten GitHub url, example:
|
# Shorten GitHub url, example:
|
||||||
# https://github.com/nvogel/dotzsh > https://git.io/8nU25w
|
# https://github.com/nvogel/dotzsh > https://git.io/8nU25w
|
||||||
# source: https://github.com/nvogel/dotzsh
|
# source: https://github.com/nvogel/dotzsh
|
||||||
# documentation: https://github.com/blog/985-git-io-github-url-shortener
|
# documentation: https://github.com/blog/985-git-io-github-url-shortener
|
||||||
#
|
#
|
||||||
@@ -74,4 +78,3 @@ git.io() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# End Functions #############################################################
|
# End Functions #############################################################
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ _go() {
|
|||||||
'tool[run specified go tool]'
|
'tool[run specified go tool]'
|
||||||
'version[print Go version]'
|
'version[print Go version]'
|
||||||
'vet[run go tool vet on packages]'
|
'vet[run go tool vet on packages]'
|
||||||
'work[workspace maintenance]'
|
|
||||||
)
|
)
|
||||||
if (( CURRENT == 2 )); then
|
if (( CURRENT == 2 )); then
|
||||||
# explain go commands
|
# explain go commands
|
||||||
@@ -89,38 +88,19 @@ _go() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
build_flags=(
|
build_flags=(
|
||||||
'-C[change to dir before running the command]:directory:_path_files -/'
|
'-a[force reinstallation of packages that are already up to date]'
|
||||||
'-a[force rebuilding of packages that are already up-to-date]'
|
|
||||||
'-n[print the commands but do not run them]'
|
'-n[print the commands but do not run them]'
|
||||||
'-p[number of parallel builds]:number'
|
'-p[number of parallel builds]:number'
|
||||||
'-race[enable data race detection]'
|
'-race[enable data race detection]'
|
||||||
'-msan[enable interoperation with memory sanitizer]'
|
|
||||||
'-asan[enable interoperation with address sanitizer]'
|
|
||||||
'-cover[enable code coverage instrumentation]'
|
|
||||||
'-covermode[set the mode for coverage analysis]:mode:(set count atomic)'
|
|
||||||
'-coverpkg[apply coverage analysis to matching packages]:pattern'
|
|
||||||
'-v[print the names of packages as they are compiled]'
|
|
||||||
'-work[print temporary directory name and keep it]'
|
|
||||||
'-x[print the commands]'
|
'-x[print the commands]'
|
||||||
'-asmflags[arguments to pass on each go tool asm invocation]:flags'
|
'-work[print temporary directory name and keep it]'
|
||||||
'-buildmode[build mode to use]:mode:(archive c-archive c-shared default shared exe pie plugin)'
|
'-ccflags[flags for 5c/6c/8c]:flags'
|
||||||
'-buildvcs[stamp binaries with version control information]:mode:(true false auto)'
|
'-gcflags[flags for 5g/6g/8g]:flags'
|
||||||
'-compiler[name of compiler to use]:name:(gccgo gc)'
|
'-ldflags[flags for 5l/6l/8l]:flags'
|
||||||
'-gccgoflags[arguments to pass on each gccgo compiler/linker invocation]:flags'
|
'-gccgoflags[flags for gccgo]:flags'
|
||||||
'-gcflags[arguments to pass on each go tool compile invocation]:flags'
|
'-compiler[name of compiler to use]:name'
|
||||||
'-installsuffix[suffix to use in the package installation directory]:suffix'
|
'-installsuffix[suffix to add to package directory]:suffix'
|
||||||
'-json[emit build output in JSON suitable for automated processing]'
|
|
||||||
'-ldflags[arguments to pass on each go tool link invocation]:flags'
|
|
||||||
'-linkshared[build code that will be linked against shared libraries]'
|
|
||||||
'-mod[module download mode to use]:mode:(readonly vendor mod)'
|
|
||||||
'-modcacherw[leave newly-created directories in the module cache read-write]'
|
|
||||||
'-modfile[read and write an alternate go.mod file]:file:_files -g "*.mod"'
|
|
||||||
'-overlay[read a JSON config file that provides an overlay for build operations]:file:_files -g "*.json"'
|
|
||||||
'-pgo[specify the file path of a profile for profile-guided optimization]:file:_files'
|
|
||||||
'-pkgdir[install and load all packages from dir]:directory:_path_files -/'
|
|
||||||
'-tags[list of build tags to consider satisfied]:tags'
|
'-tags[list of build tags to consider satisfied]:tags'
|
||||||
'-trimpath[remove all file system paths from the resulting executable]'
|
|
||||||
'-toolexec[program to use to invoke toolchain programs]:command'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
case ${words[2]} in
|
case ${words[2]} in
|
||||||
@@ -145,20 +125,17 @@ _go() {
|
|||||||
;;
|
;;
|
||||||
install)
|
install)
|
||||||
_arguments -s -w : ${build_flags[@]} \
|
_arguments -s -w : ${build_flags[@]} \
|
||||||
|
"-v[show package names]" \
|
||||||
'*:importpaths:__go_packages'
|
'*:importpaths:__go_packages'
|
||||||
;;
|
;;
|
||||||
get)
|
get)
|
||||||
_arguments -s -w : \
|
_arguments -s -w : \
|
||||||
${build_flags[@]} \
|
${build_flags[@]}
|
||||||
"-t[consider modules needed to build tests of packages]" \
|
|
||||||
"-u[update modules providing dependencies to newer minor or patch releases]" \
|
|
||||||
"-u=[update modules providing dependencies to patch releases]:mode:(patch)" \
|
|
||||||
"-tool[add a matching tool line to go.mod for each listed package]" \
|
|
||||||
"*:importpaths:__go_packages"
|
|
||||||
;;
|
;;
|
||||||
build)
|
build)
|
||||||
_arguments -s -w : \
|
_arguments -s -w : \
|
||||||
${build_flags[@]} \
|
${build_flags[@]} \
|
||||||
|
"-v[show package names]" \
|
||||||
"-o[output file]:file:_files" \
|
"-o[output file]:file:_files" \
|
||||||
"*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
|
"*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
|
||||||
;;
|
;;
|
||||||
@@ -261,60 +238,6 @@ _go() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
work)
|
|
||||||
local -a work_commands
|
|
||||||
work_commands+=(
|
|
||||||
'edit[edit go.work from tools or scripts]'
|
|
||||||
'init[initialize workspace file]'
|
|
||||||
'sync[sync workspace build list to modules]'
|
|
||||||
'use[add modules to workspace file]'
|
|
||||||
'vendor[make vendored copy of dependencies]'
|
|
||||||
)
|
|
||||||
|
|
||||||
if (( CURRENT == 3 )); then
|
|
||||||
_values 'go work commands' ${work_commands[@]} "help[display help]"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
case ${words[3]} in
|
|
||||||
help)
|
|
||||||
_values 'go work commands' ${work_commands[@]}
|
|
||||||
;;
|
|
||||||
edit)
|
|
||||||
_arguments -s -w : \
|
|
||||||
"-fmt[reformat the go.work file]" \
|
|
||||||
"-godebug[=key=value add a godebug key=value line]:key=value" \
|
|
||||||
"-dropgodebug[=key drop an existing godebug line]:key" \
|
|
||||||
"-use[=path add a use directive]:directory:_path_files -/" \
|
|
||||||
"-dropuse[=path drop a use directive]:directory:_path_files -/" \
|
|
||||||
"-replace[=old{@v}=new{@v} add a replacement of the given module path and version pair]:name" \
|
|
||||||
"-dropreplace[=old{@v} drop a replacement of the given module path and version pair]:name" \
|
|
||||||
"-go[={version} set the expected Go language version]:number" \
|
|
||||||
"-toolchain[=name set the Go toolchain to use]:name" \
|
|
||||||
"-print[print the final go.work in its text format]" \
|
|
||||||
"-json[print the final go.work file in JSON format]" \
|
|
||||||
"1:go.work file:_files -g 'go.work'"
|
|
||||||
;;
|
|
||||||
init)
|
|
||||||
_arguments -s -w : \
|
|
||||||
"*:module directories:_path_files -/"
|
|
||||||
;;
|
|
||||||
sync)
|
|
||||||
;;
|
|
||||||
use)
|
|
||||||
_arguments -s -w : \
|
|
||||||
"-r[search recursively for modules in the argument directories]" \
|
|
||||||
"*:module directories:_path_files -/"
|
|
||||||
;;
|
|
||||||
vendor)
|
|
||||||
_arguments -s -w : \
|
|
||||||
"-e[attempt to proceed despite errors encountered while loading packages]" \
|
|
||||||
"-v[print the names of vendored modules and packages]" \
|
|
||||||
"-o[create the vendor directory at the given path]:output directory:_path_files -/" \
|
|
||||||
"*:flags"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
help)
|
help)
|
||||||
_values "${commands[@]}" \
|
_values "${commands[@]}" \
|
||||||
'environment[show Go environment variables available]' \
|
'environment[show Go environment variables available]' \
|
||||||
@@ -324,13 +247,6 @@ _go() {
|
|||||||
'testflag[description of testing flags]' \
|
'testflag[description of testing flags]' \
|
||||||
'testfunc[description of testing functions]'
|
'testfunc[description of testing functions]'
|
||||||
;;
|
;;
|
||||||
version)
|
|
||||||
_arguments -s -w : \
|
|
||||||
"-m[print module version information]" \
|
|
||||||
"-v[report unrecognized files]" \
|
|
||||||
"-json[print module version information in JSON format]" \
|
|
||||||
"*:file:_files"
|
|
||||||
;;
|
|
||||||
run)
|
run)
|
||||||
_arguments -s -w : \
|
_arguments -s -w : \
|
||||||
${build_flags[@]} \
|
${build_flags[@]} \
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ Requirements
|
|||||||
Install
|
Install
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
Using the [Homebrew]( https://brew.sh ) package manager:
|
Using the [Homebrew](https://brew.sh) package manager:
|
||||||
|
|
||||||
brew install zsh-history-substring-search
|
brew install zsh-history-substring-search
|
||||||
echo 'source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
|
echo 'source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
|
||||||
@@ -51,7 +51,7 @@ Using [zplug](https://github.com/zplug/zplug):
|
|||||||
|
|
||||||
1. Add this repo to `~/.zshrc`:
|
1. Add this repo to `~/.zshrc`:
|
||||||
|
|
||||||
zplug "zsh-users/zsh-history-substring-search", as:plugin
|
zplug "zsh-users/zsh-history-substring-search", as: plugin
|
||||||
|
|
||||||
Using [antigen](https://github.com/zsh-users/antigen):
|
Using [antigen](https://github.com/zsh-users/antigen):
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ Using [Zinit](https://github.com/zdharma-continuum/zinit):
|
|||||||
|
|
||||||
1. Use the `Oh-my-zsh` Zinit snippet in `~/.zshrc`:
|
1. Use the `Oh-my-zsh` Zinit snippet in `~/.zshrc`:
|
||||||
|
|
||||||
zinit snippet OMZ::plugins/git/git.plugin.zsh
|
zinit snippet OMZ::plugins/git/git.plugin.zsh`
|
||||||
|
|
||||||
2. Load the plugin in `~/.zshrc`:
|
2. Load the plugin in `~/.zshrc`:
|
||||||
|
|
||||||
|
|||||||
@@ -295,8 +295,8 @@ _history-substring-search-begin() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Escape and join query parts with wildcard character '*' as seperator
|
# Escape and join query parts with wildcard character '*' as separator
|
||||||
# `(j:CHAR:)` join array to string with CHAR as seperator
|
# `(j:CHAR:)` join array to string with CHAR as separator
|
||||||
#
|
#
|
||||||
local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
|
local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Kubernetes prompt info for bash, fish, and zsh
|
# Kubernetes prompt helper for bash/zsh
|
||||||
# Displays current context and namespace
|
# Displays current context and namespace
|
||||||
|
|
||||||
# Copyright 2026 Jon Mosco
|
# Copyright 2026 Jon Mosco
|
||||||
@@ -121,7 +121,7 @@ _kube_ps1_color_fg() {
|
|||||||
if [[ "${_KUBE_PS1_TPUT_AVAILABLE}" == "true" ]]; then
|
if [[ "${_KUBE_PS1_TPUT_AVAILABLE}" == "true" ]]; then
|
||||||
_KUBE_PS1_FG_CODE="$(tput setaf "${_KUBE_PS1_FG_CODE}")"
|
_KUBE_PS1_FG_CODE="$(tput setaf "${_KUBE_PS1_FG_CODE}")"
|
||||||
elif [[ $_KUBE_PS1_FG_CODE -ge 0 ]] && [[ $_KUBE_PS1_FG_CODE -le 255 ]]; then
|
elif [[ $_KUBE_PS1_FG_CODE -ge 0 ]] && [[ $_KUBE_PS1_FG_CODE -le 255 ]]; then
|
||||||
_KUBE_PS1_FG_CODE=$'\033'"[38;5;${_KUBE_PS1_FG_CODE}m"
|
_KUBE_PS1_FG_CODE="\033[38;5;${_KUBE_PS1_FG_CODE}m"
|
||||||
else
|
else
|
||||||
_KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}"
|
_KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}"
|
||||||
fi
|
fi
|
||||||
@@ -154,7 +154,7 @@ _kube_ps1_color_bg() {
|
|||||||
if [[ "${_KUBE_PS1_TPUT_AVAILABLE}" == "true" ]]; then
|
if [[ "${_KUBE_PS1_TPUT_AVAILABLE}" == "true" ]]; then
|
||||||
_KUBE_PS1_BG_CODE="$(tput setab "${_KUBE_PS1_BG_CODE}")"
|
_KUBE_PS1_BG_CODE="$(tput setab "${_KUBE_PS1_BG_CODE}")"
|
||||||
elif [[ $_KUBE_PS1_BG_CODE -ge 0 ]] && [[ $_KUBE_PS1_BG_CODE -le 255 ]]; then
|
elif [[ $_KUBE_PS1_BG_CODE -ge 0 ]] && [[ $_KUBE_PS1_BG_CODE -le 255 ]]; then
|
||||||
_KUBE_PS1_BG_CODE=$'\033'"[48;5;${_KUBE_PS1_BG_CODE}m"
|
_KUBE_PS1_BG_CODE="\033[48;5;${_KUBE_PS1_BG_CODE}m"
|
||||||
else
|
else
|
||||||
_KUBE_PS1_BG_CODE="${_KUBE_PS1_DEFAULT_BG}"
|
_KUBE_PS1_BG_CODE="${_KUBE_PS1_DEFAULT_BG}"
|
||||||
fi
|
fi
|
||||||
@@ -412,8 +412,6 @@ kube_ps1() {
|
|||||||
|
|
||||||
local KUBE_PS1
|
local KUBE_PS1
|
||||||
local KUBE_PS1_RESET_COLOR="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_FG}${_KUBE_PS1_CLOSE_ESC}"
|
local KUBE_PS1_RESET_COLOR="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_FG}${_KUBE_PS1_CLOSE_ESC}"
|
||||||
local ctx_color="${KUBE_PS1_CTX_COLOR-red}"
|
|
||||||
local ns_color="${KUBE_PS1_NS_COLOR-cyan}"
|
|
||||||
|
|
||||||
# Background Color
|
# Background Color
|
||||||
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="$(_kube_ps1_color_bg "${KUBE_PS1_BG_COLOR}")"
|
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="$(_kube_ps1_color_bg "${KUBE_PS1_BG_COLOR}")"
|
||||||
@@ -434,29 +432,22 @@ kube_ps1() {
|
|||||||
|
|
||||||
# Context
|
# Context
|
||||||
if [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then
|
if [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then
|
||||||
|
local ctx_color="${KUBE_PS1_CTX_COLOR:-red}"
|
||||||
|
|
||||||
# Allow custom function to override color based on context
|
# Allow custom function to override color based on context
|
||||||
if [[ -n "${KUBE_PS1_CTX_COLOR_FUNCTION}" ]]; then
|
if [[ -n "${KUBE_PS1_CTX_COLOR_FUNCTION}" ]]; then
|
||||||
ctx_color="$("${KUBE_PS1_CTX_COLOR_FUNCTION}" "${KUBE_PS1_CONTEXT}")"
|
ctx_color="$("${KUBE_PS1_CTX_COLOR_FUNCTION}" "${KUBE_PS1_CONTEXT}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${ctx_color}" ]]; then
|
KUBE_PS1+="$(_kube_ps1_color_fg "${ctx_color}")${KUBE_PS1_CONTEXT}${KUBE_PS1_RESET_COLOR}"
|
||||||
KUBE_PS1+="$(_kube_ps1_color_fg "${ctx_color}")${KUBE_PS1_CONTEXT}${KUBE_PS1_RESET_COLOR}"
|
|
||||||
else
|
|
||||||
KUBE_PS1+="${KUBE_PS1_CONTEXT}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Namespace
|
# Namespace
|
||||||
if [[ "${KUBE_PS1_NS_ENABLE}" == true ]]; then
|
if [[ "${KUBE_PS1_NS_ENABLE}" == true ]]; then
|
||||||
if [[ -n "${KUBE_PS1_DIVIDER}" && "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then
|
if [[ -n "${KUBE_PS1_DIVIDER}" ]] && [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then
|
||||||
KUBE_PS1+="${KUBE_PS1_DIVIDER}"
|
KUBE_PS1+="${KUBE_PS1_DIVIDER}"
|
||||||
fi
|
fi
|
||||||
|
KUBE_PS1+="$(_kube_ps1_color_fg "${KUBE_PS1_NS_COLOR:-cyan}")${KUBE_PS1_NAMESPACE}${KUBE_PS1_RESET_COLOR}"
|
||||||
if [[ -n "${ns_color}" ]]; then
|
|
||||||
KUBE_PS1+="$(_kube_ps1_color_fg "${ns_color}")${KUBE_PS1_NAMESPACE}${KUBE_PS1_RESET_COLOR}"
|
|
||||||
else
|
|
||||||
KUBE_PS1+="${KUBE_PS1_NAMESPACE}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Suffix
|
# Suffix
|
||||||
@@ -469,5 +460,5 @@ kube_ps1() {
|
|||||||
# Close Background color if defined
|
# Close Background color if defined
|
||||||
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_BG}${_KUBE_PS1_CLOSE_ESC}"
|
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_BG}${_KUBE_PS1_CLOSE_ESC}"
|
||||||
|
|
||||||
printf '%s' "${KUBE_PS1}"
|
echo "${KUBE_PS1}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,13 +157,13 @@ case $state in
|
|||||||
'*::file:_files'
|
'*::file:_files'
|
||||||
;;
|
;;
|
||||||
(test)
|
(test)
|
||||||
_path_files -X "All tests" -g "test/**/*_test.exs" -g "apps/*/test/**/*_test.exs"
|
_files
|
||||||
;;
|
;;
|
||||||
(test.watch)
|
(test.watch)
|
||||||
_files
|
_files
|
||||||
;;
|
;;
|
||||||
(run)
|
(run)
|
||||||
_files -g "*.(exs|ex)"
|
_files
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -23,16 +23,6 @@ plugins=(... podman)
|
|||||||
| pirm | `podman image rm` | Remove one or more images |
|
| pirm | `podman image rm` | Remove one or more images |
|
||||||
| pit | `podman image tag` | Add a name and tag to a particular image |
|
| pit | `podman image tag` | Add a name and tag to a particular image |
|
||||||
| plo | `podman container logs` | Fetch the logs of a podman container |
|
| plo | `podman container logs` | Fetch the logs of a podman container |
|
||||||
| pmif | `podman machine info` | Display machine host info |
|
|
||||||
| pmit | `podman machine init` | Initialize a virtual machine |
|
|
||||||
| pmis | `podman machine inspect` | Inspect an existing machine |
|
|
||||||
| pml | `podman machine list` | List machines |
|
|
||||||
| pmo | `podman machine os` | Manage a Podman virtual machine's OS |
|
|
||||||
| pmrm | `podman machine rm` | Remove an existing machine |
|
|
||||||
| pms | `podman machine set` | Set a virtual machine setting |
|
|
||||||
| pmss | `podman machine ssh` | SSH into an existing machine |
|
|
||||||
| pmst | `podman machine start` | Start an existing machine |
|
|
||||||
| pmsp | `podman machine stop` | Stop an existing machine |
|
|
||||||
| pnc | `podman network create` | Create a new network |
|
| pnc | `podman network create` | Create a new network |
|
||||||
| pncn | `podman network connect` | Connect a container to a network |
|
| pncn | `podman network connect` | Connect a container to a network |
|
||||||
| pndcn | `podman network disconnect` | Disconnect a container from a network |
|
| pndcn | `podman network disconnect` | Disconnect a container from a network |
|
||||||
|
|||||||
@@ -26,16 +26,6 @@ alias pils='podman image ls'
|
|||||||
alias pipu='podman image push'
|
alias pipu='podman image push'
|
||||||
alias pirm='podman image rm'
|
alias pirm='podman image rm'
|
||||||
alias pit='podman image tag'
|
alias pit='podman image tag'
|
||||||
alias pmif='podman machine info'
|
|
||||||
alias pmit='podman machine init'
|
|
||||||
alias pmis='podman machine inspect'
|
|
||||||
alias pml='podman machine list'
|
|
||||||
alias pmo='podman machine os'
|
|
||||||
alias pmrm='podman machine rm'
|
|
||||||
alias pms='podman machine set'
|
|
||||||
alias pmss='podman machine ssh'
|
|
||||||
alias pmst='podman machine start'
|
|
||||||
alias pmsp='podman machine stop'
|
|
||||||
alias plo='podman container logs'
|
alias plo='podman container logs'
|
||||||
alias pnc='podman network create'
|
alias pnc='podman network create'
|
||||||
alias pncn='podman network connect'
|
alias pncn='podman network connect'
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ if [[ "$TERM" == screen* ]]; then
|
|||||||
# tell GNU screen what the tab window title ($1) and the hardstatus($2) should be
|
# tell GNU screen what the tab window title ($1) and the hardstatus($2) should be
|
||||||
function screen_set()
|
function screen_set()
|
||||||
{
|
{
|
||||||
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return 0
|
|
||||||
|
|
||||||
# set the tab window title (%t) for screen
|
# set the tab window title (%t) for screen
|
||||||
print -nR $'\033k'$1$'\033'\\\
|
print -nR $'\033k'$1$'\033'\\\
|
||||||
|
|
||||||
|
|||||||
@@ -1,112 +0,0 @@
|
|||||||
# Shopify CLI plugin
|
|
||||||
|
|
||||||
This plugin adds aliases, helper functions and completion for the
|
|
||||||
[Shopify CLI](https://shopify.dev/docs/api/shopify-cli).
|
|
||||||
|
|
||||||
To use it, add `shopify` to the plugins array in your zshrc file:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(... shopify)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
[Shopify CLI](https://shopify.dev/docs/api/shopify-cli) 4.0 or newer, installed
|
|
||||||
and on your `PATH`. The plugin does nothing if it is not:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
npm install -g @shopify/cli
|
|
||||||
# or
|
|
||||||
brew tap shopify/shopify && brew install shopify-cli
|
|
||||||
```
|
|
||||||
|
|
||||||
## Aliases
|
|
||||||
|
|
||||||
| Alias | Command | Description |
|
|
||||||
| :----- | :-------- | :--------------------- |
|
|
||||||
| `shop` | `shopify` | The Shopify CLI itself |
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
| Function | Description |
|
|
||||||
| :------------- | :--------------------------------------------------------------------------------- |
|
|
||||||
| `shopd` | Runs `theme dev`, `app dev` or `hydrogen dev`, whichever fits the current project |
|
|
||||||
| `shopi` | Shows what the current project is connected to |
|
|
||||||
| `shopify_here` | Prints the kind of Shopify project you are in and the commands worth running in it |
|
|
||||||
| `shopify` | Wraps the CLI to confirm before irreversible commands. See Settings |
|
|
||||||
|
|
||||||
`shopd` and `shopi` work out which topic applies by looking at the project you
|
|
||||||
are standing in, so you do not have to remember whether this directory is a
|
|
||||||
theme, an app or a Hydrogen storefront. They complete like the command they
|
|
||||||
stand in for, so in a theme `shopd --<TAB>` offers the flags of
|
|
||||||
`shopify theme dev`.
|
|
||||||
|
|
||||||
## Completion
|
|
||||||
|
|
||||||
Every command completes with a description of what it does, at every level, and
|
|
||||||
so do their flags, short forms and allowed values. `--environment` completes
|
|
||||||
from the `[environments.*]` sections of your local `shopify.theme.toml` or
|
|
||||||
`shopify.app.toml`.
|
|
||||||
|
|
||||||
The Shopify CLI ships no completion generator of its own, so `_shopify` is
|
|
||||||
generated from `shopify commands --json` and kept in this repository. It targets
|
|
||||||
Shopify CLI 4.x.
|
|
||||||
|
|
||||||
## Settings
|
|
||||||
|
|
||||||
Set these with `zstyle` in your zshrc, before Oh My Zsh is sourced.
|
|
||||||
|
|
||||||
### Confirming destructive commands
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:shopify' confirm-destructive no
|
|
||||||
```
|
|
||||||
|
|
||||||
By default the plugin asks for confirmation before three irreversible
|
|
||||||
operations:
|
|
||||||
|
|
||||||
- `shopify theme push` with `--live`/`-l` or `--publish`/`-p`, which overwrites
|
|
||||||
or publishes the live storefront
|
|
||||||
- `shopify theme delete`, which the CLI's own help describes as impossible to
|
|
||||||
undo
|
|
||||||
- `shopify app deploy --allow-deletes`, which can permanently remove extensions
|
|
||||||
|
|
||||||
Nothing else is intercepted, and the prompt is skipped when the command already
|
|
||||||
carries `--force`/`-f` or when stdin is not a terminal, so scripts, pipelines
|
|
||||||
and CI are unaffected. Set the style to `no` to turn the prompt off entirely.
|
|
||||||
|
|
||||||
### Completing theme IDs
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:shopify' dynamic-theme-completion yes
|
|
||||||
```
|
|
||||||
|
|
||||||
Off by default. When enabled, `--theme` is completed from
|
|
||||||
`shopify theme list --json`, showing each theme's name and role next to its ID
|
|
||||||
instead of making you copy IDs by hand. It is opt-in because it runs the CLI and
|
|
||||||
makes a network call when you press <kbd>Tab</kbd>, and because it needs you to
|
|
||||||
be authenticated. Results are cached for five minutes.
|
|
||||||
|
|
||||||
### Disabling the aliases
|
|
||||||
|
|
||||||
This works for every Oh My Zsh plugin:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:shopify' aliases no
|
|
||||||
```
|
|
||||||
|
|
||||||
## Caveats
|
|
||||||
|
|
||||||
- `shopify` is a shell function here. Run `command shopify` to reach the binary
|
|
||||||
directly.
|
|
||||||
- When a project has its own copy of the CLI in `node_modules/.bin/shopify`,
|
|
||||||
that one is used in preference to the global install. App and Hydrogen
|
|
||||||
projects normally pin the CLI in `package.json`, and running a different
|
|
||||||
global version against them is a common source of confusing errors.
|
|
||||||
- `--password` and `--store-password` are unrelated, and you often need both.
|
|
||||||
`--password` is the CLI's own authentication token, from the Theme Access app
|
|
||||||
or the Admin API. `--store-password` is the password for a
|
|
||||||
password-protected storefront.
|
|
||||||
- `shopify theme push` deletes remote files that are missing locally, and
|
|
||||||
`shopify theme pull` deletes local files that are missing remotely, unless you
|
|
||||||
pass `--nodelete`/`-n`. The plugin does not prompt for these.
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
# Shopify CLI: completion, aliases and guard rails.
|
|
||||||
# https://shopify.dev/docs/api/shopify-cli
|
|
||||||
|
|
||||||
if (( ! $+commands[shopify] )); then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Prefer a project-local CLI: app and Hydrogen projects pin their own version.
|
|
||||||
# The walk stops at $HOME so a stray ~/node_modules cannot hijack every project.
|
|
||||||
# $commands avoids resolving back to the wrapper function below.
|
|
||||||
function _shopify_bin() {
|
|
||||||
local dir="$PWD"
|
|
||||||
while [[ -n "$dir" && "$dir" != "/" && "$dir" != "$HOME" ]]; do
|
|
||||||
if [[ -x "$dir/node_modules/.bin/shopify" ]]; then
|
|
||||||
print -r -- "$dir/node_modules/.bin/shopify"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
dir="${dir:h}"
|
|
||||||
done
|
|
||||||
print -r -- "$commands[shopify]"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Print the project type in $PWD: hydrogen, app or theme.
|
|
||||||
# Hydrogen is tested first because those projects usually carry a
|
|
||||||
# shopify.app.toml too. shopify.theme.toml is not a theme marker: it only
|
|
||||||
# exists once environments are configured.
|
|
||||||
function _shopify_project_type() {
|
|
||||||
local dir="$PWD"
|
|
||||||
local -a app_config
|
|
||||||
|
|
||||||
while [[ -n "$dir" && "$dir" != "/" && "$dir" != "$HOME" ]]; do
|
|
||||||
if [[ -x "$dir/node_modules/.bin/h2" ]] ||
|
|
||||||
[[ -r "$dir/package.json" && "$(<"$dir/package.json")" == *'"@shopify/hydrogen"'* ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
app_config=("$dir"/shopify.app*.toml(N))
|
|
||||||
if (( $#app_config )); then
|
|
||||||
print -r -- app
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -f "$dir/config/settings_schema.json" && -f "$dir/layout/theme.liquid" ]]; then
|
|
||||||
print -r -- theme
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
dir="${dir:h}"
|
|
||||||
done
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Does this invocation need confirming? Sets REPLY to the reason.
|
|
||||||
function _shopify_is_destructive() {
|
|
||||||
zstyle -T ':omz:plugins:shopify' confirm-destructive || return 1
|
|
||||||
|
|
||||||
# Nobody to answer: CI and pipelines are unaffected.
|
|
||||||
[[ -t 0 ]] || return 1
|
|
||||||
|
|
||||||
local topic="$1" subcommand="$2" arg
|
|
||||||
local -a long
|
|
||||||
local short=""
|
|
||||||
|
|
||||||
# Short flags can be bundled, so collect them as characters: -al counts as l.
|
|
||||||
for arg in "${@[3,-1]}"; do
|
|
||||||
[[ "$arg" == "--" ]] && break
|
|
||||||
case "$arg" in
|
|
||||||
--*) long+=("${arg%%=*}") ;;
|
|
||||||
-?*) short+="${${arg%%=*}#-}" ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# An explicit force flag states the intent already.
|
|
||||||
if (( long[(I)--force] )) || [[ "$short" == *f* ]]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$topic $subcommand" in
|
|
||||||
"theme push")
|
|
||||||
if (( long[(I)--live] || long[(I)--publish] )) || [[ "$short" == *[lp]* ]]; then
|
|
||||||
REPLY="this overwrites or publishes the live theme on the storefront."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
"theme delete")
|
|
||||||
REPLY="deleting a theme cannot be undone."
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
"app deploy")
|
|
||||||
if (( long[(I)--allow-deletes] )); then
|
|
||||||
REPLY="this can permanently remove app extensions."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Adds a confirmation prompt before irreversible operations. Everything else
|
|
||||||
# passes straight through, so `theme dev` stays interactive and pipes stay clean.
|
|
||||||
function shopify() {
|
|
||||||
local REPLY
|
|
||||||
if _shopify_is_destructive "$@"; then
|
|
||||||
print -u2 -- "shopify: $REPLY"
|
|
||||||
if ! read -q "?Continue? [y/N] "; then
|
|
||||||
print -u2 -- ""
|
|
||||||
return 130
|
|
||||||
fi
|
|
||||||
print -u2 -- ""
|
|
||||||
fi
|
|
||||||
|
|
||||||
"$(_shopify_bin)" "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Print the commands worth running in the current directory.
|
|
||||||
function shopify_here() {
|
|
||||||
local project_type
|
|
||||||
project_type="$(_shopify_project_type)"
|
|
||||||
|
|
||||||
case "$project_type" in
|
|
||||||
theme)
|
|
||||||
print -- "Shopify theme project."
|
|
||||||
print -- " shopify theme dev Preview locally with live reload"
|
|
||||||
print -- " shopify theme check Lint the theme"
|
|
||||||
print -- " shopify theme list List the themes on the store"
|
|
||||||
print -- " shopify theme pull Download a remote theme into this folder"
|
|
||||||
print -- " shopify theme push Upload this folder to a remote theme"
|
|
||||||
;;
|
|
||||||
app)
|
|
||||||
print -- "Shopify app project."
|
|
||||||
print -- " shopify app dev Run the app against a development store"
|
|
||||||
print -- " shopify app info Show how the app is configured"
|
|
||||||
print -- " shopify app deploy Deploy the app and its extensions"
|
|
||||||
print -- " shopify app logs Stream app logs"
|
|
||||||
;;
|
|
||||||
hydrogen)
|
|
||||||
print -- "Hydrogen storefront."
|
|
||||||
print -- " shopify hydrogen dev Run the storefront locally"
|
|
||||||
print -- " shopify hydrogen build Build for production"
|
|
||||||
print -- " shopify hydrogen deploy Deploy to Oxygen"
|
|
||||||
print -- " shopify hydrogen link Link this project to a storefront"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print -- "No Shopify project found here."
|
|
||||||
print -- " shopify theme init Start a new theme"
|
|
||||||
print -- " shopify app init Start a new app"
|
|
||||||
print -- " shopify hydrogen init Start a new Hydrogen storefront"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run the dev server for whichever kind of project this is.
|
|
||||||
function shopd() {
|
|
||||||
local project_type
|
|
||||||
if ! project_type="$(_shopify_project_type)"; then
|
|
||||||
print -u2 -- "shopd: not inside a Shopify theme, app or Hydrogen project."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
shopify "$project_type" dev "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show what the current project is connected to.
|
|
||||||
function shopi() {
|
|
||||||
local project_type
|
|
||||||
if ! project_type="$(_shopify_project_type)"; then
|
|
||||||
print -u2 -- "shopi: not inside a Shopify theme, app or Hydrogen project."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
case "$project_type" in
|
|
||||||
hydrogen) shopify hydrogen list "$@" ;;
|
|
||||||
*) shopify "$project_type" info "$@" ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Complete the helpers like the commands they stand in for.
|
|
||||||
if (( $+functions[compdef] )); then
|
|
||||||
_shopd() {
|
|
||||||
local project_type
|
|
||||||
project_type="$(_shopify_project_type)" || return 1
|
|
||||||
words=(shopify "$project_type" dev ${words[2,-1]})
|
|
||||||
(( CURRENT += 2 ))
|
|
||||||
_shopify
|
|
||||||
}
|
|
||||||
|
|
||||||
_shopi() {
|
|
||||||
local project_type
|
|
||||||
project_type="$(_shopify_project_type)" || return 1
|
|
||||||
if [[ "$project_type" == hydrogen ]]; then
|
|
||||||
words=(shopify hydrogen list ${words[2,-1]})
|
|
||||||
else
|
|
||||||
words=(shopify "$project_type" info ${words[2,-1]})
|
|
||||||
fi
|
|
||||||
(( CURRENT += 2 ))
|
|
||||||
_shopify
|
|
||||||
}
|
|
||||||
|
|
||||||
compdef _shopd shopd
|
|
||||||
compdef _shopi shopi
|
|
||||||
fi
|
|
||||||
|
|
||||||
alias shop='shopify'
|
|
||||||
@@ -19,7 +19,6 @@ plugins=(... systemadmin)
|
|||||||
| mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output |
|
| mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output |
|
||||||
| psmem | `ps -e -orss=,args= \| sort -b -k1 -nr` | Display the processes using the most memory |
|
| psmem | `ps -e -orss=,args= \| sort -b -k1 -nr` | Display the processes using the most memory |
|
||||||
| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -n 10` | Display the top 10 processes using the most memory |
|
| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -n 10` | Display the top 10 processes using the most memory |
|
||||||
| pszombie| `ps -eo user,pid,ppid,state,comm \| awk '$4=="Z"'` | List zombie processes with ownership and parent process details |
|
|
||||||
| pscpu | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr` | Display the top processes using the most CPU |
|
| pscpu | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr` | Display the top processes using the most CPU |
|
||||||
| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -n 10` | Display the top 10 processes using the most CPU |
|
| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -n 10` | Display the top 10 processes using the most CPU |
|
||||||
| hist10 | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10` | Display the top 10 most used commands in the history |
|
| hist10 | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10` | Display the top 10 most used commands in the history |
|
||||||
@@ -49,4 +48,5 @@ plugins=(... systemadmin)
|
|||||||
| d0 | Delete 0 byte files recursively in the current directory or another if specified |
|
| d0 | Delete 0 byte files recursively in the current directory or another if specified |
|
||||||
| geteip | Gather information regarding an external IP address using [icanhazip.com](https://icanhazip.com) |
|
| geteip | Gather information regarding an external IP address using [icanhazip.com](https://icanhazip.com) |
|
||||||
| getip | Determine the local IP Address with `ip addr` or `ifconfig` |
|
| getip | Determine the local IP Address with `ip addr` or `ifconfig` |
|
||||||
|
| clrz | Clear zombie processes |
|
||||||
| conssec | Show number of concurrent connections per second based on nginx/access.log file or another log file if specified |
|
| conssec | Show number of concurrent connections per second based on nginx/access.log file or another log file if specified |
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ alias mkdir='mkdir -pv'
|
|||||||
# get top process eating memory
|
# get top process eating memory
|
||||||
alias psmem='ps -e -orss=,args= | sort -b -k1 -nr'
|
alias psmem='ps -e -orss=,args= | sort -b -k1 -nr'
|
||||||
alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -n 10'
|
alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -n 10'
|
||||||
# list all zombie processes with ownership and parent process details
|
|
||||||
alias pszombie="ps -eo user,pid,ppid,state,comm | awk '\$4==\"Z\"'"
|
|
||||||
# get top process eating cpu if not work try execute : export LC_ALL='C'
|
# get top process eating cpu if not work try execute : export LC_ALL='C'
|
||||||
alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr'
|
alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr'
|
||||||
alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr | head -n 10'
|
alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr | head -n 10'
|
||||||
@@ -179,6 +177,11 @@ function getip() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Clear zombie processes
|
||||||
|
function clrz() {
|
||||||
|
ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9
|
||||||
|
}
|
||||||
|
|
||||||
# Second concurrent
|
# Second concurrent
|
||||||
function conssec() {
|
function conssec() {
|
||||||
awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)" | sort -k 2 -nr | head -n10
|
awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)" | sort -k 2 -nr | head -n10
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# term_tab plugin
|
# term_tab plugin
|
||||||
|
|
||||||
This plugin works on Linux, macOS and Solaris.
|
This plugin only works for Solaris and linux.
|
||||||
|
|
||||||
term_tab - `cwd` for all open zsh sessions
|
term_tab - `cwd` for all open zsh sessions
|
||||||
|
|
||||||
|
|||||||
@@ -178,11 +178,6 @@ alias tmux=_zsh_tmux_plugin_run
|
|||||||
function _tmux_directory_session() {
|
function _tmux_directory_session() {
|
||||||
# current directory without leading path
|
# current directory without leading path
|
||||||
local dir=${PWD##*/}
|
local dir=${PWD##*/}
|
||||||
# tmux target syntax treats '.' and ':' as separators, a leading '$', '@' or '%'
|
|
||||||
# as an id and a leading '=' as an exact-match prefix, so a session named after
|
|
||||||
# such a directory can't be found on reattach
|
|
||||||
dir=${dir//[.:]/_}
|
|
||||||
dir=${dir/#[\$@%=]/_}
|
|
||||||
# md5 hash for the full working directory path
|
# md5 hash for the full working directory path
|
||||||
local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1)
|
local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1)
|
||||||
# human friendly unique session name for this directory
|
# human friendly unique session name for this directory
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
Copyright (c) 2013 Thiago de Arruda
|
|
||||||
Copyright (c) 2016-2021 Eric Freese
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
|
||||||
obtaining a copy of this software and associated documentation
|
|
||||||
files (the "Software"), to deal in the Software without
|
|
||||||
restriction, including without limitation the rights to use,
|
|
||||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the
|
|
||||||
Software is furnished to do so, subject to the following
|
|
||||||
conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
||||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
||||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||||
OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
# zsh-autosuggestions
|
|
||||||
|
|
||||||
_[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
|
|
||||||
|
|
||||||
It suggests commands as you type based on history and completions.
|
|
||||||
|
|
||||||
Requirements: Zsh v4.3.11 or later
|
|
||||||
|
|
||||||
[](https://gitter.im/zsh-users/zsh-autosuggestions)
|
|
||||||
|
|
||||||
<a href="https://asciinema.org/a/37390" target="_blank"><img src="https://asciinema.org/a/37390.png" width="400" /></a>
|
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
See [the Oh My Zsh plugin README](README.md).
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
As you type commands, you will see a completion offered after the cursor in a muted gray color. This color can be changed by setting the `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` variable. See [configuration](#configuration).
|
|
||||||
|
|
||||||
If you press the <kbd>→</kbd> key (`forward-char` widget) or <kbd>End</kbd> (`end-of-line` widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.
|
|
||||||
|
|
||||||
If you invoke the `forward-word` widget, it will partially accept the suggestion up to the point that the cursor moves to.
|
|
||||||
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
You may want to override the default global config variables. Default values of these variables can be found [here](src/config.zsh).
|
|
||||||
|
|
||||||
**Note:** If you are using Oh My Zsh, you can put this configuration in a file in the `$ZSH_CUSTOM` directory. See their comments on [overriding internals](https://github.com/robbyrussell/oh-my-zsh/wiki/Customization#overriding-internals).
|
|
||||||
|
|
||||||
|
|
||||||
### Suggestion Highlight Style
|
|
||||||
|
|
||||||
Set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to configure the style that the suggestion is shown with. The default is `fg=8`, which will set the foreground color to color 8 from the [256-color palette](https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg). If your terminal only supports 8 colors, you will need to use a number between 0 and 7.
|
|
||||||
|
|
||||||
Background color can also be set, and the suggestion can be styled bold, underlined, or standout. For example, this would show suggestions with bold, underlined, pink text on a cyan background:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"
|
|
||||||
```
|
|
||||||
|
|
||||||
For more info, read the Character Highlighting section of the zsh manual: `man zshzle` or [online](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting).
|
|
||||||
|
|
||||||
**Note:** Some iTerm2 users have reported [not being able to see the suggestions](https://github.com/zsh-users/zsh-autosuggestions/issues/416#issuecomment-486516333). If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black are **different**.
|
|
||||||
|
|
||||||
|
|
||||||
### Suggestion Strategy
|
|
||||||
|
|
||||||
`ZSH_AUTOSUGGEST_STRATEGY` is an array that specifies how suggestions should be generated. The strategies in the array are tried successively until a suggestion is found. There are currently three built-in strategies to choose from:
|
|
||||||
|
|
||||||
- `history`: Chooses the most recent match from history.
|
|
||||||
- `completion`: Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` module, which is included with zsh since 4.0.1)
|
|
||||||
- `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches the most recently executed command ([more info](src/strategies/match_prev_cmd.zsh)). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`.
|
|
||||||
|
|
||||||
For example, setting `ZSH_AUTOSUGGEST_STRATEGY=(history completion)` will first try to find a suggestion from your history, but, if it can't find a match, will find a suggestion from the completion engine.
|
|
||||||
|
|
||||||
|
|
||||||
### Widget Mapping
|
|
||||||
|
|
||||||
This plugin works by triggering custom behavior when certain [zle widgets](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets) are invoked. You can add and remove widgets from these arrays to change the behavior of this plugin:
|
|
||||||
|
|
||||||
- `ZSH_AUTOSUGGEST_CLEAR_WIDGETS`: Widgets in this array will clear the suggestion when invoked.
|
|
||||||
- `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked.
|
|
||||||
- `ZSH_AUTOSUGGEST_EXECUTE_WIDGETS`: Widgets in this array will execute the suggestion when invoked.
|
|
||||||
- `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked.
|
|
||||||
- `ZSH_AUTOSUGGEST_IGNORE_WIDGETS`: Widgets in this array will not trigger any custom behavior.
|
|
||||||
|
|
||||||
Widgets that modify the buffer and are not found in any of these arrays will fetch a new suggestion after they are invoked.
|
|
||||||
|
|
||||||
**Note:** A widget shouldn't belong to more than one of the above arrays.
|
|
||||||
|
|
||||||
|
|
||||||
### Disabling suggestion for large buffers
|
|
||||||
|
|
||||||
Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20.
|
|
||||||
This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.
|
|
||||||
|
|
||||||
### Asynchronous Mode
|
|
||||||
|
|
||||||
Suggestions are fetched asynchronously by default in zsh versions 5.0.8 and greater. To disable asynchronous suggestions and fetch them synchronously instead, `unset ZSH_AUTOSUGGEST_USE_ASYNC` after sourcing the plugin.
|
|
||||||
|
|
||||||
Alternatively, if you are using a version of zsh older than 5.0.8 and want to enable asynchronous mode, set the `ZSH_AUTOSUGGEST_USE_ASYNC` variable after sourcing the plugin (it can be set to anything). Note that there is [a bug](https://github.com/zsh-users/zsh-autosuggestions/issues/364#issuecomment-481423232) in versions of zsh older than 5.0.8 where <kbd>ctrl</kbd> + <kbd>c</kbd> will fail to reset the prompt immediately after fetching a suggestion asynchronously.
|
|
||||||
|
|
||||||
### Disabling automatic widget re-binding
|
|
||||||
|
|
||||||
Set `ZSH_AUTOSUGGEST_MANUAL_REBIND` (it can be set to anything) to disable automatic widget re-binding on each precmd. This can be a big boost to performance, but you'll need to handle re-binding yourself if any of the widget lists change or if you or another plugin wrap any of the autosuggest widgets. To re-bind widgets, run `_zsh_autosuggest_bind_widgets`.
|
|
||||||
|
|
||||||
### Ignoring history suggestions that match a pattern
|
|
||||||
|
|
||||||
Set `ZSH_AUTOSUGGEST_HISTORY_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering suggestions for history entries that match the pattern. For example, set it to `"cd *"` to never suggest any `cd` commands from history. Or set to `"?(#c50,)"` to never suggest anything 50 characters or longer.
|
|
||||||
|
|
||||||
**Note:** This only affects the `history` and `match_prev_cmd` suggestion strategies.
|
|
||||||
|
|
||||||
### Skipping completion suggestions for certain cases
|
|
||||||
|
|
||||||
Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to `"git *"` to disable completion suggestions for git subcommands.
|
|
||||||
|
|
||||||
**Note:** This only affects the `completion` suggestion strategy.
|
|
||||||
|
|
||||||
|
|
||||||
### Key Bindings
|
|
||||||
|
|
||||||
This plugin provides a few widgets that you can use with `bindkey`:
|
|
||||||
|
|
||||||
1. `autosuggest-accept`: Accepts the current suggestion.
|
|
||||||
2. `autosuggest-execute`: Accepts and executes the current suggestion.
|
|
||||||
3. `autosuggest-clear`: Clears the current suggestion.
|
|
||||||
4. `autosuggest-fetch`: Fetches a suggestion (works even when suggestions are disabled).
|
|
||||||
5. `autosuggest-disable`: Disables suggestions.
|
|
||||||
6. `autosuggest-enable`: Re-enables suggestions.
|
|
||||||
7. `autosuggest-toggle`: Toggles between enabled/disabled suggestions.
|
|
||||||
|
|
||||||
For example, this would bind <kbd>ctrl</kbd> + <kbd>space</kbd> to accept the current suggestion.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
bindkey '^ ' autosuggest-accept
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
If you have a problem, please search through [the list of issues on GitHub](https://github.com/zsh-users/zsh-autosuggestions/issues?q=) to see if someone else has already reported it.
|
|
||||||
|
|
||||||
### Reporting an Issue
|
|
||||||
|
|
||||||
Before reporting an issue, please try temporarily disabling sections of your configuration and other plugins that may be conflicting with this plugin to isolate the problem.
|
|
||||||
|
|
||||||
When reporting an issue, please include:
|
|
||||||
|
|
||||||
- The smallest, simplest `.zshrc` configuration that will reproduce the problem. See [this comment](https://github.com/zsh-users/zsh-autosuggestions/issues/102#issuecomment-180944764) for a good example of what this means.
|
|
||||||
- The version of zsh you're using (`zsh --version`)
|
|
||||||
- Which operating system you're running
|
|
||||||
|
|
||||||
|
|
||||||
## Uninstallation
|
|
||||||
|
|
||||||
1. Remove the code referencing this plugin from `~/.zshrc`.
|
|
||||||
|
|
||||||
2. Remove the git repository from your hard drive
|
|
||||||
|
|
||||||
```sh
|
|
||||||
rm -rf ~/.zsh/zsh-autosuggestions # Or wherever you installed
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
### Build Process
|
|
||||||
|
|
||||||
Edit the source files in `src/`. Run `make` to build `zsh-autosuggestions.zsh` from those source files.
|
|
||||||
|
|
||||||
|
|
||||||
### Pull Requests
|
|
||||||
|
|
||||||
Pull requests are welcome! If you send a pull request, please:
|
|
||||||
|
|
||||||
- Request to merge into the `develop` branch (*NOT* `master`)
|
|
||||||
- Match the existing coding conventions.
|
|
||||||
- Include helpful comments to keep the barrier-to-entry low for people new to the project.
|
|
||||||
- Write tests that cover your code as much as possible.
|
|
||||||
|
|
||||||
|
|
||||||
### Testing
|
|
||||||
|
|
||||||
Tests are written in ruby using the [`rspec`](http://rspec.info/) framework. They use [`tmux`](https://tmux.github.io/) to drive a pseudoterminal, sending simulated keystrokes and making assertions on the terminal content.
|
|
||||||
|
|
||||||
Test files live in `spec/`. To run the tests, run `make test`. To run a specific test, run `TESTS=spec/some_spec.rb make test`. You can also specify a `zsh` binary to use by setting the `TEST_ZSH_BIN` environment variable (ex: `TEST_ZSH_BIN=/bin/zsh make test`).
|
|
||||||
|
|
||||||
It's possible to run the tests for any supported version of zsh in a Docker image by building an image from the provided Dockerfile. To build the docker image for a specific version of zsh (where `<version>` below is substituted with the contents of a line from the [`ZSH_VERSIONS`](ZSH_VERSIONS) file), run:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
docker build --build-arg TEST_ZSH_VERSION=<version> -t zsh-autosuggestions-test .
|
|
||||||
```
|
|
||||||
|
|
||||||
After building the image, run the tests via:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
docker run -it -v $PWD:/zsh-autosuggestions zsh-autosuggestions-test make test
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This project is licensed under [MIT license](http://opensource.org/licenses/MIT).
|
|
||||||
For the full text of the license, see the [LICENSE](LICENSE) file.
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# zsh-autosuggestions
|
|
||||||
|
|
||||||
This plugin suggests commands as you type, based on command history and completions.
|
|
||||||
|
|
||||||
To use it, add `zsh-autosuggestions` to the plugins array in your zshrc file:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(... zsh-autosuggestions)
|
|
||||||
```
|
|
||||||
|
|
||||||
Start a new terminal session after updating your zshrc file.
|
|
||||||
|
|
||||||
Suggestions appear in muted gray text by default. Press <kbd>→</kbd> or <kbd>End</kbd> at the end of the
|
|
||||||
command line to accept the displayed suggestion.
|
|
||||||
|
|
||||||
For configuration options and additional key bindings, see the [upstream documentation](MANUAL.md).
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Async #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_request() {
|
|
||||||
zmodload zsh/system 2>/dev/null # For `$sysparams`
|
|
||||||
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
|
||||||
|
|
||||||
# If we've got a pending request, cancel it
|
|
||||||
if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then
|
|
||||||
# Close the file descriptor and remove the handler
|
|
||||||
builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
|
||||||
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
|
||||||
|
|
||||||
# We won't know the pid unless the user has zsh/system module installed
|
|
||||||
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
|
|
||||||
# Zsh will make a new process group for the child process only if job
|
|
||||||
# control is enabled (MONITOR option)
|
|
||||||
if [[ -o MONITOR ]]; then
|
|
||||||
# Send the signal to the process group to kill any processes that may
|
|
||||||
# have been forked by the suggestion strategy
|
|
||||||
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
|
||||||
else
|
|
||||||
# Kill just the child process since it wasn't placed in a new process
|
|
||||||
# group. If the suggestion strategy forked any child processes they may
|
|
||||||
# be orphaned and left behind.
|
|
||||||
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fork a process to fetch a suggestion and open a pipe to read from it
|
|
||||||
builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}< <(
|
|
||||||
# Tell parent process our pid
|
|
||||||
echo $sysparams[pid]
|
|
||||||
|
|
||||||
# Fetch and print the suggestion
|
|
||||||
local suggestion
|
|
||||||
_zsh_autosuggest_fetch_suggestion "$1"
|
|
||||||
echo -nE "$suggestion"
|
|
||||||
)
|
|
||||||
|
|
||||||
# There's a weird bug here where ^C stops working unless we force a fork
|
|
||||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
|
||||||
autoload -Uz is-at-least
|
|
||||||
is-at-least 5.8 || command true
|
|
||||||
|
|
||||||
# Read the pid from the child process
|
|
||||||
read _ZSH_AUTOSUGGEST_CHILD_PID <&$_ZSH_AUTOSUGGEST_ASYNC_FD
|
|
||||||
|
|
||||||
# When the fd is readable, call the response handler
|
|
||||||
zle -F "$_ZSH_AUTOSUGGEST_ASYNC_FD" _zsh_autosuggest_async_response
|
|
||||||
}
|
|
||||||
|
|
||||||
# Called when new data is ready to be read from the pipe
|
|
||||||
# First arg will be fd ready for reading
|
|
||||||
# Second arg will be passed in case of error
|
|
||||||
_zsh_autosuggest_async_response() {
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
local suggestion
|
|
||||||
|
|
||||||
if [[ -z "$2" || "$2" == "hup" ]]; then
|
|
||||||
# Read everything from the fd and give it as a suggestion
|
|
||||||
IFS='' read -rd '' -u $1 suggestion
|
|
||||||
zle autosuggest-suggest -- "$suggestion"
|
|
||||||
|
|
||||||
# Close the fd
|
|
||||||
builtin exec {1}<&-
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Always remove the handler
|
|
||||||
zle -F "$1"
|
|
||||||
_ZSH_AUTOSUGGEST_ASYNC_FD=
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Widget Helpers #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_incr_bind_count() {
|
|
||||||
typeset -gi bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]+1))
|
|
||||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count
|
|
||||||
}
|
|
||||||
|
|
||||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
|
||||||
_zsh_autosuggest_bind_widget() {
|
|
||||||
typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
|
|
||||||
|
|
||||||
local widget=$1
|
|
||||||
local autosuggest_action=$2
|
|
||||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
|
||||||
|
|
||||||
local -i bind_count
|
|
||||||
|
|
||||||
# Save a reference to the original widget
|
|
||||||
case $widgets[$widget] in
|
|
||||||
# Already bound
|
|
||||||
user:_zsh_autosuggest_(bound|orig)_*)
|
|
||||||
bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$widget]))
|
|
||||||
;;
|
|
||||||
|
|
||||||
# User-defined widget
|
|
||||||
user:*)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:}
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Built-in widget
|
|
||||||
builtin)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
|
|
||||||
zle -N $prefix$bind_count-$widget _zsh_autosuggest_orig_$widget
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Completion widget
|
|
||||||
completion:*)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Pass the original widget's name explicitly into the autosuggest
|
|
||||||
# function. Use this passed in widget name to call the original
|
|
||||||
# widget instead of relying on the $WIDGET variable being set
|
|
||||||
# correctly. $WIDGET cannot be trusted because other plugins call
|
|
||||||
# zle without the `-w` flag (e.g. `zle self-insert` instead of
|
|
||||||
# `zle self-insert -w`).
|
|
||||||
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
|
|
||||||
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
|
|
||||||
}"
|
|
||||||
|
|
||||||
# Create the bound widget
|
|
||||||
zle -N -- $widget _zsh_autosuggest_bound_${bind_count}_$widget
|
|
||||||
}
|
|
||||||
|
|
||||||
# Map all configured widgets to the right autosuggest widgets
|
|
||||||
_zsh_autosuggest_bind_widgets() {
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
local widget
|
|
||||||
local ignore_widgets
|
|
||||||
|
|
||||||
ignore_widgets=(
|
|
||||||
.\*
|
|
||||||
_\*
|
|
||||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
|
||||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
|
||||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
|
||||||
)
|
|
||||||
|
|
||||||
# Find every widget we might want to bind and bind it appropriately
|
|
||||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
|
||||||
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget clear
|
|
||||||
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget accept
|
|
||||||
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget execute
|
|
||||||
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
|
||||||
else
|
|
||||||
# Assume any unspecified widget might modify the buffer
|
|
||||||
_zsh_autosuggest_bind_widget $widget modify
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Given the name of an original widget and args, invoke it, if it exists
|
|
||||||
_zsh_autosuggest_invoke_original_widget() {
|
|
||||||
# Do nothing unless called with at least one arg
|
|
||||||
(( $# )) || return 0
|
|
||||||
|
|
||||||
local original_widget_name="$1"
|
|
||||||
|
|
||||||
shift
|
|
||||||
|
|
||||||
if (( ${+widgets[$original_widget_name]} )); then
|
|
||||||
zle $original_widget_name -- $@
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Global Configuration Variables #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Color to use when highlighting suggestion
|
|
||||||
# Uses format of `region_highlight`
|
|
||||||
# More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE} )) &&
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
|
|
||||||
|
|
||||||
# Prefix to use when saving original versions of bound widgets
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX} )) &&
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
|
||||||
|
|
||||||
# Strategies to use to fetch a suggestion
|
|
||||||
# Will try each strategy in order until a suggestion is returned
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
|
||||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that clear the suggestion
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_CLEAR_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_CLEAR_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
|
||||||
history-search-forward
|
|
||||||
history-search-backward
|
|
||||||
history-beginning-search-forward
|
|
||||||
history-beginning-search-backward
|
|
||||||
history-beginning-search-forward-end
|
|
||||||
history-beginning-search-backward-end
|
|
||||||
history-substring-search-up
|
|
||||||
history-substring-search-down
|
|
||||||
up-line-or-beginning-search
|
|
||||||
down-line-or-beginning-search
|
|
||||||
up-line-or-history
|
|
||||||
down-line-or-history
|
|
||||||
accept-line
|
|
||||||
copy-earlier-word
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that accept the entire suggestion
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
|
||||||
forward-char
|
|
||||||
end-of-line
|
|
||||||
vi-forward-char
|
|
||||||
vi-end-of-line
|
|
||||||
vi-add-eol
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that accept the entire suggestion and execute it
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_EXECUTE_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_EXECUTE_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that accept the suggestion as far as the cursor moves
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
|
||||||
forward-word
|
|
||||||
emacs-forward-word
|
|
||||||
vi-forward-word
|
|
||||||
vi-forward-word-end
|
|
||||||
vi-forward-blank-word
|
|
||||||
vi-forward-blank-word-end
|
|
||||||
vi-find-next-char
|
|
||||||
vi-find-next-char-skip
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_IGNORE_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
|
||||||
orig-\*
|
|
||||||
beep
|
|
||||||
run-help
|
|
||||||
set-local-history
|
|
||||||
which-command
|
|
||||||
yank
|
|
||||||
yank-pop
|
|
||||||
zle-\*
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pty name for capturing completions for completion suggestion strategy
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) &&
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Fetch Suggestion #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Loops through all specified strategies and returns a suggestion
|
|
||||||
# from the first strategy to provide one.
|
|
||||||
#
|
|
||||||
|
|
||||||
_zsh_autosuggest_fetch_suggestion() {
|
|
||||||
typeset -g suggestion
|
|
||||||
local -a strategies
|
|
||||||
local strategy
|
|
||||||
|
|
||||||
# Ensure we are working with an array
|
|
||||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
|
||||||
|
|
||||||
for strategy in $strategies; do
|
|
||||||
# Try to get a suggestion from this strategy
|
|
||||||
_zsh_autosuggest_strategy_$strategy "$1"
|
|
||||||
|
|
||||||
# Ensure the suggestion matches the prefix
|
|
||||||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
|
||||||
|
|
||||||
# Break once we've found a valid suggestion
|
|
||||||
[[ -n "$suggestion" ]] && break
|
|
||||||
done
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Highlighting #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# If there was a highlight, remove it
|
|
||||||
_zsh_autosuggest_highlight_reset() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
|
|
||||||
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
|
||||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# If there's a suggestion, highlight it
|
|
||||||
_zsh_autosuggest_highlight_apply() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
|
|
||||||
if (( $#POSTDISPLAY )); then
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
|
||||||
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
|
||||||
else
|
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Start #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Start the autosuggestion widgets
|
|
||||||
_zsh_autosuggest_start() {
|
|
||||||
# By default we re-bind widgets on every precmd to ensure we wrap other
|
|
||||||
# wrappers. Specifically, highlighting breaks if our widgets are wrapped by
|
|
||||||
# zsh-syntax-highlighting widgets. This also allows modifications to the
|
|
||||||
# widget list variables to take effect on the next precmd. However this has
|
|
||||||
# a decent performance hit, so users can set ZSH_AUTOSUGGEST_MANUAL_REBIND
|
|
||||||
# to disable the automatic re-binding.
|
|
||||||
if (( ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )); then
|
|
||||||
add-zsh-hook -d precmd _zsh_autosuggest_start
|
|
||||||
fi
|
|
||||||
|
|
||||||
_zsh_autosuggest_bind_widgets
|
|
||||||
}
|
|
||||||
|
|
||||||
# Mark for auto-loading the functions that we use
|
|
||||||
autoload -Uz add-zsh-hook is-at-least
|
|
||||||
|
|
||||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
|
||||||
# older versions because there is a bug when using async mode where ^C does not
|
|
||||||
# work immediately after fetching a suggestion.
|
|
||||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
|
||||||
if is-at-least 5.0.8; then
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start the autosuggestion widgets on the next precmd
|
|
||||||
add-zsh-hook precmd _zsh_autosuggest_start
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Completion Suggestion Strategy #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Fetches a suggestion from the completion engine
|
|
||||||
#
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_postcompletion() {
|
|
||||||
# Always insert the first completion into the buffer
|
|
||||||
compstate[insert]=1
|
|
||||||
|
|
||||||
# Don't list completions
|
|
||||||
unset 'compstate[list]'
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_widget() {
|
|
||||||
# Add a post-completion hook to be called after all completions have been
|
|
||||||
# gathered. The hook can modify compstate to affect what is done with the
|
|
||||||
# gathered completions.
|
|
||||||
local -a +h comppostfuncs
|
|
||||||
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
|
||||||
|
|
||||||
# Only capture completions at the end of the buffer
|
|
||||||
CURSOR=$#BUFFER
|
|
||||||
|
|
||||||
# Run the original widget wrapping `.complete-word` so we don't
|
|
||||||
# recursively try to fetch suggestions, since our pty is forked
|
|
||||||
# after autosuggestions is initialized.
|
|
||||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
|
||||||
|
|
||||||
if is-at-least 5.0.3; then
|
|
||||||
# Don't do any cr/lf transformations. We need to do this immediately before
|
|
||||||
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
|
||||||
# vared in the async code path. There is a bug in zpty module in older versions
|
|
||||||
# where the tty is not properly attached to the pty slave, resulting in stty
|
|
||||||
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
|
||||||
# commit f75904a38
|
|
||||||
stty -onlcr -ocrnl -F /dev/tty
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The completion has been added, print the buffer as the suggestion
|
|
||||||
echo -nE - $'\0'$BUFFER$'\0'
|
|
||||||
}
|
|
||||||
|
|
||||||
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_setup() {
|
|
||||||
# There is a bug in zpty module in older zsh versions by which a
|
|
||||||
# zpty that exits will kill all zpty processes that were forked
|
|
||||||
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
|
||||||
# process immediately, before it has a chance to kill any other
|
|
||||||
# zpty processes.
|
|
||||||
if ! is-at-least 5.4; then
|
|
||||||
zshexit() {
|
|
||||||
# The zsh builtin `kill` fails sometimes in older versions
|
|
||||||
# https://unix.stackexchange.com/a/477647/156673
|
|
||||||
kill -KILL $$ 2>&- || command kill -KILL $$
|
|
||||||
|
|
||||||
# Block for long enough for the signal to come through
|
|
||||||
sleep 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try to avoid any suggestions that wouldn't match the prefix
|
|
||||||
zstyle ':completion:*' matcher-list ''
|
|
||||||
zstyle ':completion:*' path-completion false
|
|
||||||
zstyle ':completion:*' max-errors 0 not-numeric
|
|
||||||
|
|
||||||
bindkey '^I' autosuggest-capture-completion
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_sync() {
|
|
||||||
_zsh_autosuggest_capture_setup
|
|
||||||
|
|
||||||
zle autosuggest-capture-completion
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_async() {
|
|
||||||
_zsh_autosuggest_capture_setup
|
|
||||||
|
|
||||||
zmodload zsh/parameter 2>/dev/null || return # For `$functions`
|
|
||||||
|
|
||||||
# Make vared completion work as if for a normal command line
|
|
||||||
# https://stackoverflow.com/a/7057118/154703
|
|
||||||
autoload +X _complete
|
|
||||||
functions[_original_complete]=$functions[_complete]
|
|
||||||
function _complete() {
|
|
||||||
unset 'compstate[vared]'
|
|
||||||
_original_complete "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Open zle with buffer set so we can capture completions for it
|
|
||||||
vared 1
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_completion() {
|
|
||||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Enable extended glob for completion ignore pattern
|
|
||||||
setopt EXTENDED_GLOB
|
|
||||||
|
|
||||||
typeset -g suggestion
|
|
||||||
local line REPLY
|
|
||||||
|
|
||||||
# Exit if we don't have completions
|
|
||||||
whence compdef >/dev/null || return
|
|
||||||
|
|
||||||
# Exit if we don't have zpty
|
|
||||||
zmodload zsh/zpty 2>/dev/null || return
|
|
||||||
|
|
||||||
# Exit if our search string matches the ignore pattern
|
|
||||||
[[ -n "$ZSH_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~ZSH_AUTOSUGGEST_COMPLETION_IGNORE ]] && return
|
|
||||||
|
|
||||||
# Zle will be inactive if we are in async mode
|
|
||||||
if zle; then
|
|
||||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_sync
|
|
||||||
else
|
|
||||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_async "\$1"
|
|
||||||
zpty -w $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t'
|
|
||||||
fi
|
|
||||||
|
|
||||||
{
|
|
||||||
# The completion result is surrounded by null bytes, so read the
|
|
||||||
# content between the first two null bytes.
|
|
||||||
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
|
||||||
|
|
||||||
# Extract the suggestion from between the null bytes. On older
|
|
||||||
# versions of zsh (older than 5.3), we sometimes get extra bytes after
|
|
||||||
# the second null byte, so trim those off the end.
|
|
||||||
# See http://www.zsh.org/mla/workers/2015/msg03290.html
|
|
||||||
suggestion="${${(@0)line}[2]}"
|
|
||||||
} always {
|
|
||||||
# Destroy the pty
|
|
||||||
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# History Suggestion Strategy #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Suggests the most recent history item that matches the given
|
|
||||||
# prefix.
|
|
||||||
#
|
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_history() {
|
|
||||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
|
||||||
setopt EXTENDED_GLOB
|
|
||||||
|
|
||||||
# Escape backslashes and all of the glob operators so we can use
|
|
||||||
# this string as a pattern to search the $history associative array.
|
|
||||||
# - (#m) globbing flag enables setting references for match data
|
|
||||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
|
||||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
|
||||||
|
|
||||||
# Get the history items that match the prefix, excluding those that match
|
|
||||||
# the ignore pattern
|
|
||||||
local pattern="$prefix*"
|
|
||||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
|
||||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Give the first history item matching the pattern as the suggestion
|
|
||||||
# - (r) subscript flag makes the pattern match on values
|
|
||||||
typeset -g suggestion="${history[(r)$pattern]}"
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Match Previous Command Suggestion Strategy #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Suggests the most recent history item that matches the given
|
|
||||||
# prefix and whose preceding history item also matches the most
|
|
||||||
# recently executed command.
|
|
||||||
#
|
|
||||||
# For example, suppose your history has the following entries:
|
|
||||||
# - pwd
|
|
||||||
# - ls foo
|
|
||||||
# - ls bar
|
|
||||||
# - pwd
|
|
||||||
#
|
|
||||||
# Given the history list above, when you type 'ls', the suggestion
|
|
||||||
# will be 'ls foo' rather than 'ls bar' because your most recently
|
|
||||||
# executed command (pwd) was previously followed by 'ls foo'.
|
|
||||||
#
|
|
||||||
# Note that this strategy won't work as expected with ZSH options that don't
|
|
||||||
# preserve the history order such as `HIST_IGNORE_ALL_DUPS` or
|
|
||||||
# `HIST_EXPIRE_DUPS_FIRST`.
|
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_match_prev_cmd() {
|
|
||||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
|
||||||
setopt EXTENDED_GLOB
|
|
||||||
|
|
||||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
|
||||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
|
||||||
|
|
||||||
# Get the history items that match the prefix, excluding those that match
|
|
||||||
# the ignore pattern
|
|
||||||
local pattern="$prefix*"
|
|
||||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
|
||||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get all history event numbers that correspond to history
|
|
||||||
# entries that match the pattern
|
|
||||||
local history_match_keys
|
|
||||||
history_match_keys=(${(k)history[(R)$~pattern]})
|
|
||||||
|
|
||||||
# By default we use the first history number (most recent history entry)
|
|
||||||
local histkey="${history_match_keys[1]}"
|
|
||||||
|
|
||||||
# Get the previously executed command
|
|
||||||
local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
|
|
||||||
|
|
||||||
# Iterate up to the first 200 history event numbers that match $prefix
|
|
||||||
for key in "${(@)history_match_keys[1,200]}"; do
|
|
||||||
# Stop if we ran out of history
|
|
||||||
[[ $key -gt 1 ]] || break
|
|
||||||
|
|
||||||
# See if the history entry preceding the suggestion matches the
|
|
||||||
# previous command, and use it if it does
|
|
||||||
if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then
|
|
||||||
histkey="$key"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Give back the matched history entry
|
|
||||||
typeset -g suggestion="$history[$histkey]"
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Utility Functions #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_escape_command() {
|
|
||||||
setopt localoptions EXTENDED_GLOB
|
|
||||||
|
|
||||||
# Escape special chars in the string (requires EXTENDED_GLOB)
|
|
||||||
echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
|
|
||||||
}
|
|
||||||
@@ -1,231 +0,0 @@
|
|||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Autosuggest Widget Implementations #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Disable suggestions
|
|
||||||
_zsh_autosuggest_disable() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_DISABLED
|
|
||||||
_zsh_autosuggest_clear
|
|
||||||
}
|
|
||||||
|
|
||||||
# Enable suggestions
|
|
||||||
_zsh_autosuggest_enable() {
|
|
||||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
|
||||||
|
|
||||||
if (( $#BUFFER )); then
|
|
||||||
_zsh_autosuggest_fetch
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
|
||||||
_zsh_autosuggest_toggle() {
|
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
|
||||||
_zsh_autosuggest_enable
|
|
||||||
else
|
|
||||||
_zsh_autosuggest_disable
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clear the suggestion
|
|
||||||
_zsh_autosuggest_clear() {
|
|
||||||
# Remove the suggestion
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
}
|
|
||||||
|
|
||||||
# Modify the buffer and get a new suggestion
|
|
||||||
_zsh_autosuggest_modify() {
|
|
||||||
local -i retval
|
|
||||||
|
|
||||||
# Only available in zsh >= 5.4
|
|
||||||
local -i KEYS_QUEUED_COUNT
|
|
||||||
|
|
||||||
# Save the contents of the buffer/postdisplay
|
|
||||||
local orig_buffer="$BUFFER"
|
|
||||||
local orig_postdisplay="$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Clear suggestion while waiting for next one
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
# Original widget may modify the buffer
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
|
||||||
if (( $PENDING > 0 || $KEYS_QUEUED_COUNT > 0 )); then
|
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
|
||||||
return $retval
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Optimize if manually typing in the suggestion or if buffer hasn't changed
|
|
||||||
if [[ "$BUFFER" = "$orig_buffer"* && "$orig_postdisplay" = "${BUFFER:$#orig_buffer}"* ]]; then
|
|
||||||
POSTDISPLAY="${orig_postdisplay:$(($#BUFFER - $#orig_buffer))}"
|
|
||||||
return $retval
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
|
||||||
if (( $#BUFFER > 0 )); then
|
|
||||||
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
|
||||||
_zsh_autosuggest_fetch
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
# Fetch a new suggestion based on what's currently in the buffer
|
|
||||||
_zsh_autosuggest_fetch() {
|
|
||||||
if (( ${+ZSH_AUTOSUGGEST_USE_ASYNC} )); then
|
|
||||||
_zsh_autosuggest_async_request "$BUFFER"
|
|
||||||
else
|
|
||||||
local suggestion
|
|
||||||
_zsh_autosuggest_fetch_suggestion "$BUFFER"
|
|
||||||
_zsh_autosuggest_suggest "$suggestion"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Offer a suggestion
|
|
||||||
_zsh_autosuggest_suggest() {
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
local suggestion="$1"
|
|
||||||
|
|
||||||
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
|
||||||
else
|
|
||||||
POSTDISPLAY=
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Accept the entire suggestion
|
|
||||||
_zsh_autosuggest_accept() {
|
|
||||||
local -i retval max_cursor_pos=$#BUFFER
|
|
||||||
|
|
||||||
# When vicmd keymap is active, the cursor can't move all the way
|
|
||||||
# to the end of the buffer
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If we're not in a valid state to accept a suggestion, just run the
|
|
||||||
# original widget and bail out
|
|
||||||
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
|
||||||
# Add the suggestion to the buffer
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
# Run the original widget before manually moving the cursor so that the
|
|
||||||
# cursor movement doesn't make the widget do something unexpected
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
# Move the cursor to the end of the buffer
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
CURSOR=$(($#BUFFER - 1))
|
|
||||||
else
|
|
||||||
CURSOR=$#BUFFER
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
# Accept the entire suggestion and execute it
|
|
||||||
_zsh_autosuggest_execute() {
|
|
||||||
# Add the suggestion to the buffer
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
# Call the original `accept-line` to handle syntax highlighting or
|
|
||||||
# other potential custom behavior
|
|
||||||
_zsh_autosuggest_invoke_original_widget "accept-line"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Partially accept the suggestion
|
|
||||||
_zsh_autosuggest_partial_accept() {
|
|
||||||
local -i retval cursor_loc
|
|
||||||
|
|
||||||
# Save the contents of the buffer so we can restore later if needed
|
|
||||||
local original_buffer="$BUFFER"
|
|
||||||
|
|
||||||
# Temporarily accept the suggestion.
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Original widget moves the cursor
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
# Normalize cursor location across vi/emacs modes
|
|
||||||
cursor_loc=$CURSOR
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
cursor_loc=$((cursor_loc + 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If we've moved past the end of the original buffer
|
|
||||||
if (( $cursor_loc > $#original_buffer )); then
|
|
||||||
# Set POSTDISPLAY to text right of the cursor
|
|
||||||
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
|
|
||||||
|
|
||||||
# Clip the buffer at the cursor
|
|
||||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
|
||||||
else
|
|
||||||
# Restore the original buffer
|
|
||||||
BUFFER="$original_buffer"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
() {
|
|
||||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
|
||||||
|
|
||||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
|
||||||
clear
|
|
||||||
fetch
|
|
||||||
suggest
|
|
||||||
accept
|
|
||||||
execute
|
|
||||||
enable
|
|
||||||
disable
|
|
||||||
toggle
|
|
||||||
)
|
|
||||||
|
|
||||||
local action
|
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
|
||||||
eval "_zsh_autosuggest_widget_$action() {
|
|
||||||
local -i retval
|
|
||||||
|
|
||||||
_zsh_autosuggest_highlight_reset
|
|
||||||
|
|
||||||
_zsh_autosuggest_$action \$@
|
|
||||||
retval=\$?
|
|
||||||
|
|
||||||
_zsh_autosuggest_highlight_apply
|
|
||||||
|
|
||||||
zle -R
|
|
||||||
|
|
||||||
return \$retval
|
|
||||||
}"
|
|
||||||
done
|
|
||||||
|
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
|
||||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
|
||||||
done
|
|
||||||
}
|
|
||||||
@@ -1,867 +0,0 @@
|
|||||||
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
|
||||||
# https://github.com/zsh-users/zsh-autosuggestions
|
|
||||||
# v0.7.1
|
|
||||||
# Copyright (c) 2013 Thiago de Arruda
|
|
||||||
# Copyright (c) 2016-2021 Eric Freese
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person
|
|
||||||
# obtaining a copy of this software and associated documentation
|
|
||||||
# files (the "Software"), to deal in the Software without
|
|
||||||
# restriction, including without limitation the rights to use,
|
|
||||||
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the
|
|
||||||
# Software is furnished to do so, subject to the following
|
|
||||||
# conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be
|
|
||||||
# included in all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
||||||
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
||||||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||||
# OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Global Configuration Variables #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Color to use when highlighting suggestion
|
|
||||||
# Uses format of `region_highlight`
|
|
||||||
# More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE} )) &&
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
|
|
||||||
|
|
||||||
# Prefix to use when saving original versions of bound widgets
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX} )) &&
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
|
||||||
|
|
||||||
# Strategies to use to fetch a suggestion
|
|
||||||
# Will try each strategy in order until a suggestion is returned
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
|
||||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that clear the suggestion
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_CLEAR_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_CLEAR_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
|
||||||
history-search-forward
|
|
||||||
history-search-backward
|
|
||||||
history-beginning-search-forward
|
|
||||||
history-beginning-search-backward
|
|
||||||
history-beginning-search-forward-end
|
|
||||||
history-beginning-search-backward-end
|
|
||||||
history-substring-search-up
|
|
||||||
history-substring-search-down
|
|
||||||
up-line-or-beginning-search
|
|
||||||
down-line-or-beginning-search
|
|
||||||
up-line-or-history
|
|
||||||
down-line-or-history
|
|
||||||
accept-line
|
|
||||||
copy-earlier-word
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that accept the entire suggestion
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
|
||||||
forward-char
|
|
||||||
end-of-line
|
|
||||||
vi-forward-char
|
|
||||||
vi-end-of-line
|
|
||||||
vi-add-eol
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that accept the entire suggestion and execute it
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_EXECUTE_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_EXECUTE_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that accept the suggestion as far as the cursor moves
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
|
||||||
forward-word
|
|
||||||
emacs-forward-word
|
|
||||||
vi-forward-word
|
|
||||||
vi-forward-word-end
|
|
||||||
vi-forward-blank-word
|
|
||||||
vi-forward-blank-word-end
|
|
||||||
vi-find-next-char
|
|
||||||
vi-find-next-char-skip
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_IGNORE_WIDGETS} )) && {
|
|
||||||
typeset -ga ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
|
||||||
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
|
||||||
orig-\*
|
|
||||||
beep
|
|
||||||
run-help
|
|
||||||
set-local-history
|
|
||||||
which-command
|
|
||||||
yank
|
|
||||||
yank-pop
|
|
||||||
zle-\*
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pty name for capturing completions for completion suggestion strategy
|
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) &&
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Utility Functions #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_escape_command() {
|
|
||||||
setopt localoptions EXTENDED_GLOB
|
|
||||||
|
|
||||||
# Escape special chars in the string (requires EXTENDED_GLOB)
|
|
||||||
echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Widget Helpers #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_incr_bind_count() {
|
|
||||||
typeset -gi bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]+1))
|
|
||||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count
|
|
||||||
}
|
|
||||||
|
|
||||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
|
||||||
_zsh_autosuggest_bind_widget() {
|
|
||||||
typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
|
|
||||||
|
|
||||||
local widget=$1
|
|
||||||
local autosuggest_action=$2
|
|
||||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
|
||||||
|
|
||||||
local -i bind_count
|
|
||||||
|
|
||||||
# Save a reference to the original widget
|
|
||||||
case $widgets[$widget] in
|
|
||||||
# Already bound
|
|
||||||
user:_zsh_autosuggest_(bound|orig)_*)
|
|
||||||
bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$widget]))
|
|
||||||
;;
|
|
||||||
|
|
||||||
# User-defined widget
|
|
||||||
user:*)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:}
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Built-in widget
|
|
||||||
builtin)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
|
|
||||||
zle -N $prefix$bind_count-$widget _zsh_autosuggest_orig_$widget
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Completion widget
|
|
||||||
completion:*)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Pass the original widget's name explicitly into the autosuggest
|
|
||||||
# function. Use this passed in widget name to call the original
|
|
||||||
# widget instead of relying on the $WIDGET variable being set
|
|
||||||
# correctly. $WIDGET cannot be trusted because other plugins call
|
|
||||||
# zle without the `-w` flag (e.g. `zle self-insert` instead of
|
|
||||||
# `zle self-insert -w`).
|
|
||||||
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
|
|
||||||
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
|
|
||||||
}"
|
|
||||||
|
|
||||||
# Create the bound widget
|
|
||||||
zle -N -- $widget _zsh_autosuggest_bound_${bind_count}_$widget
|
|
||||||
}
|
|
||||||
|
|
||||||
# Map all configured widgets to the right autosuggest widgets
|
|
||||||
_zsh_autosuggest_bind_widgets() {
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
local widget
|
|
||||||
local ignore_widgets
|
|
||||||
|
|
||||||
ignore_widgets=(
|
|
||||||
.\*
|
|
||||||
_\*
|
|
||||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
|
||||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
|
||||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
|
||||||
)
|
|
||||||
|
|
||||||
# Find every widget we might want to bind and bind it appropriately
|
|
||||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
|
||||||
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget clear
|
|
||||||
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget accept
|
|
||||||
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget execute
|
|
||||||
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
|
||||||
else
|
|
||||||
# Assume any unspecified widget might modify the buffer
|
|
||||||
_zsh_autosuggest_bind_widget $widget modify
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Given the name of an original widget and args, invoke it, if it exists
|
|
||||||
_zsh_autosuggest_invoke_original_widget() {
|
|
||||||
# Do nothing unless called with at least one arg
|
|
||||||
(( $# )) || return 0
|
|
||||||
|
|
||||||
local original_widget_name="$1"
|
|
||||||
|
|
||||||
shift
|
|
||||||
|
|
||||||
if (( ${+widgets[$original_widget_name]} )); then
|
|
||||||
zle $original_widget_name -- $@
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Highlighting #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# If there was a highlight, remove it
|
|
||||||
_zsh_autosuggest_highlight_reset() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
|
|
||||||
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
|
||||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# If there's a suggestion, highlight it
|
|
||||||
_zsh_autosuggest_highlight_apply() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
|
|
||||||
if (( $#POSTDISPLAY )); then
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
|
||||||
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
|
||||||
else
|
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Autosuggest Widget Implementations #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Disable suggestions
|
|
||||||
_zsh_autosuggest_disable() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_DISABLED
|
|
||||||
_zsh_autosuggest_clear
|
|
||||||
}
|
|
||||||
|
|
||||||
# Enable suggestions
|
|
||||||
_zsh_autosuggest_enable() {
|
|
||||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
|
||||||
|
|
||||||
if (( $#BUFFER )); then
|
|
||||||
_zsh_autosuggest_fetch
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
|
||||||
_zsh_autosuggest_toggle() {
|
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
|
||||||
_zsh_autosuggest_enable
|
|
||||||
else
|
|
||||||
_zsh_autosuggest_disable
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clear the suggestion
|
|
||||||
_zsh_autosuggest_clear() {
|
|
||||||
# Remove the suggestion
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
}
|
|
||||||
|
|
||||||
# Modify the buffer and get a new suggestion
|
|
||||||
_zsh_autosuggest_modify() {
|
|
||||||
local -i retval
|
|
||||||
|
|
||||||
# Only available in zsh >= 5.4
|
|
||||||
local -i KEYS_QUEUED_COUNT
|
|
||||||
|
|
||||||
# Save the contents of the buffer/postdisplay
|
|
||||||
local orig_buffer="$BUFFER"
|
|
||||||
local orig_postdisplay="$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Clear suggestion while waiting for next one
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
# Original widget may modify the buffer
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
|
||||||
if (( $PENDING > 0 || $KEYS_QUEUED_COUNT > 0 )); then
|
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
|
||||||
return $retval
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Optimize if manually typing in the suggestion or if buffer hasn't changed
|
|
||||||
if [[ "$BUFFER" = "$orig_buffer"* && "$orig_postdisplay" = "${BUFFER:$#orig_buffer}"* ]]; then
|
|
||||||
POSTDISPLAY="${orig_postdisplay:$(($#BUFFER - $#orig_buffer))}"
|
|
||||||
return $retval
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
|
||||||
if (( $#BUFFER > 0 )); then
|
|
||||||
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
|
||||||
_zsh_autosuggest_fetch
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
# Fetch a new suggestion based on what's currently in the buffer
|
|
||||||
_zsh_autosuggest_fetch() {
|
|
||||||
if (( ${+ZSH_AUTOSUGGEST_USE_ASYNC} )); then
|
|
||||||
_zsh_autosuggest_async_request "$BUFFER"
|
|
||||||
else
|
|
||||||
local suggestion
|
|
||||||
_zsh_autosuggest_fetch_suggestion "$BUFFER"
|
|
||||||
_zsh_autosuggest_suggest "$suggestion"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Offer a suggestion
|
|
||||||
_zsh_autosuggest_suggest() {
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
local suggestion="$1"
|
|
||||||
|
|
||||||
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
|
||||||
else
|
|
||||||
POSTDISPLAY=
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Accept the entire suggestion
|
|
||||||
_zsh_autosuggest_accept() {
|
|
||||||
local -i retval max_cursor_pos=$#BUFFER
|
|
||||||
|
|
||||||
# When vicmd keymap is active, the cursor can't move all the way
|
|
||||||
# to the end of the buffer
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If we're not in a valid state to accept a suggestion, just run the
|
|
||||||
# original widget and bail out
|
|
||||||
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
|
||||||
# Add the suggestion to the buffer
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
# Run the original widget before manually moving the cursor so that the
|
|
||||||
# cursor movement doesn't make the widget do something unexpected
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
# Move the cursor to the end of the buffer
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
CURSOR=$(($#BUFFER - 1))
|
|
||||||
else
|
|
||||||
CURSOR=$#BUFFER
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
# Accept the entire suggestion and execute it
|
|
||||||
_zsh_autosuggest_execute() {
|
|
||||||
# Add the suggestion to the buffer
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
|
||||||
POSTDISPLAY=
|
|
||||||
|
|
||||||
# Call the original `accept-line` to handle syntax highlighting or
|
|
||||||
# other potential custom behavior
|
|
||||||
_zsh_autosuggest_invoke_original_widget "accept-line"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Partially accept the suggestion
|
|
||||||
_zsh_autosuggest_partial_accept() {
|
|
||||||
local -i retval cursor_loc
|
|
||||||
|
|
||||||
# Save the contents of the buffer so we can restore later if needed
|
|
||||||
local original_buffer="$BUFFER"
|
|
||||||
|
|
||||||
# Temporarily accept the suggestion.
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Original widget moves the cursor
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
# Normalize cursor location across vi/emacs modes
|
|
||||||
cursor_loc=$CURSOR
|
|
||||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
|
||||||
cursor_loc=$((cursor_loc + 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If we've moved past the end of the original buffer
|
|
||||||
if (( $cursor_loc > $#original_buffer )); then
|
|
||||||
# Set POSTDISPLAY to text right of the cursor
|
|
||||||
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
|
|
||||||
|
|
||||||
# Clip the buffer at the cursor
|
|
||||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
|
||||||
else
|
|
||||||
# Restore the original buffer
|
|
||||||
BUFFER="$original_buffer"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
() {
|
|
||||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
|
||||||
|
|
||||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
|
||||||
clear
|
|
||||||
fetch
|
|
||||||
suggest
|
|
||||||
accept
|
|
||||||
execute
|
|
||||||
enable
|
|
||||||
disable
|
|
||||||
toggle
|
|
||||||
)
|
|
||||||
|
|
||||||
local action
|
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
|
||||||
eval "_zsh_autosuggest_widget_$action() {
|
|
||||||
local -i retval
|
|
||||||
|
|
||||||
_zsh_autosuggest_highlight_reset
|
|
||||||
|
|
||||||
_zsh_autosuggest_$action \$@
|
|
||||||
retval=\$?
|
|
||||||
|
|
||||||
_zsh_autosuggest_highlight_apply
|
|
||||||
|
|
||||||
zle -R
|
|
||||||
|
|
||||||
return \$retval
|
|
||||||
}"
|
|
||||||
done
|
|
||||||
|
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
|
||||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Completion Suggestion Strategy #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Fetches a suggestion from the completion engine
|
|
||||||
#
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_postcompletion() {
|
|
||||||
# Always insert the first completion into the buffer
|
|
||||||
compstate[insert]=1
|
|
||||||
|
|
||||||
# Don't list completions
|
|
||||||
unset 'compstate[list]'
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_widget() {
|
|
||||||
# Add a post-completion hook to be called after all completions have been
|
|
||||||
# gathered. The hook can modify compstate to affect what is done with the
|
|
||||||
# gathered completions.
|
|
||||||
local -a +h comppostfuncs
|
|
||||||
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
|
||||||
|
|
||||||
# Only capture completions at the end of the buffer
|
|
||||||
CURSOR=$#BUFFER
|
|
||||||
|
|
||||||
# Run the original widget wrapping `.complete-word` so we don't
|
|
||||||
# recursively try to fetch suggestions, since our pty is forked
|
|
||||||
# after autosuggestions is initialized.
|
|
||||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
|
||||||
|
|
||||||
if is-at-least 5.0.3; then
|
|
||||||
# Don't do any cr/lf transformations. We need to do this immediately before
|
|
||||||
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
|
||||||
# vared in the async code path. There is a bug in zpty module in older versions
|
|
||||||
# where the tty is not properly attached to the pty slave, resulting in stty
|
|
||||||
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
|
||||||
# commit f75904a38
|
|
||||||
stty -onlcr -ocrnl -F /dev/tty
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The completion has been added, print the buffer as the suggestion
|
|
||||||
echo -nE - $'\0'$BUFFER$'\0'
|
|
||||||
}
|
|
||||||
|
|
||||||
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_setup() {
|
|
||||||
# There is a bug in zpty module in older zsh versions by which a
|
|
||||||
# zpty that exits will kill all zpty processes that were forked
|
|
||||||
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
|
||||||
# process immediately, before it has a chance to kill any other
|
|
||||||
# zpty processes.
|
|
||||||
if ! is-at-least 5.4; then
|
|
||||||
zshexit() {
|
|
||||||
# The zsh builtin `kill` fails sometimes in older versions
|
|
||||||
# https://unix.stackexchange.com/a/477647/156673
|
|
||||||
kill -KILL $$ 2>&- || command kill -KILL $$
|
|
||||||
|
|
||||||
# Block for long enough for the signal to come through
|
|
||||||
sleep 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try to avoid any suggestions that wouldn't match the prefix
|
|
||||||
zstyle ':completion:*' matcher-list ''
|
|
||||||
zstyle ':completion:*' path-completion false
|
|
||||||
zstyle ':completion:*' max-errors 0 not-numeric
|
|
||||||
|
|
||||||
bindkey '^I' autosuggest-capture-completion
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_sync() {
|
|
||||||
_zsh_autosuggest_capture_setup
|
|
||||||
|
|
||||||
zle autosuggest-capture-completion
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_async() {
|
|
||||||
_zsh_autosuggest_capture_setup
|
|
||||||
|
|
||||||
zmodload zsh/parameter 2>/dev/null || return # For `$functions`
|
|
||||||
|
|
||||||
# Make vared completion work as if for a normal command line
|
|
||||||
# https://stackoverflow.com/a/7057118/154703
|
|
||||||
autoload +X _complete
|
|
||||||
functions[_original_complete]=$functions[_complete]
|
|
||||||
function _complete() {
|
|
||||||
unset 'compstate[vared]'
|
|
||||||
_original_complete "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Open zle with buffer set so we can capture completions for it
|
|
||||||
vared 1
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_completion() {
|
|
||||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Enable extended glob for completion ignore pattern
|
|
||||||
setopt EXTENDED_GLOB
|
|
||||||
|
|
||||||
typeset -g suggestion
|
|
||||||
local line REPLY
|
|
||||||
|
|
||||||
# Exit if we don't have completions
|
|
||||||
whence compdef >/dev/null || return
|
|
||||||
|
|
||||||
# Exit if we don't have zpty
|
|
||||||
zmodload zsh/zpty 2>/dev/null || return
|
|
||||||
|
|
||||||
# Exit if our search string matches the ignore pattern
|
|
||||||
[[ -n "$ZSH_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~ZSH_AUTOSUGGEST_COMPLETION_IGNORE ]] && return
|
|
||||||
|
|
||||||
# Zle will be inactive if we are in async mode
|
|
||||||
if zle; then
|
|
||||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_sync
|
|
||||||
else
|
|
||||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_async "\$1"
|
|
||||||
zpty -w $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t'
|
|
||||||
fi
|
|
||||||
|
|
||||||
{
|
|
||||||
# The completion result is surrounded by null bytes, so read the
|
|
||||||
# content between the first two null bytes.
|
|
||||||
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
|
||||||
|
|
||||||
# Extract the suggestion from between the null bytes. On older
|
|
||||||
# versions of zsh (older than 5.3), we sometimes get extra bytes after
|
|
||||||
# the second null byte, so trim those off the end.
|
|
||||||
# See http://www.zsh.org/mla/workers/2015/msg03290.html
|
|
||||||
suggestion="${${(@0)line}[2]}"
|
|
||||||
} always {
|
|
||||||
# Destroy the pty
|
|
||||||
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# History Suggestion Strategy #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Suggests the most recent history item that matches the given
|
|
||||||
# prefix.
|
|
||||||
#
|
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_history() {
|
|
||||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
|
||||||
setopt EXTENDED_GLOB
|
|
||||||
|
|
||||||
# Escape backslashes and all of the glob operators so we can use
|
|
||||||
# this string as a pattern to search the $history associative array.
|
|
||||||
# - (#m) globbing flag enables setting references for match data
|
|
||||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
|
||||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
|
||||||
|
|
||||||
# Get the history items that match the prefix, excluding those that match
|
|
||||||
# the ignore pattern
|
|
||||||
local pattern="$prefix*"
|
|
||||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
|
||||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Give the first history item matching the pattern as the suggestion
|
|
||||||
# - (r) subscript flag makes the pattern match on values
|
|
||||||
typeset -g suggestion="${history[(r)$pattern]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Match Previous Command Suggestion Strategy #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Suggests the most recent history item that matches the given
|
|
||||||
# prefix and whose preceding history item also matches the most
|
|
||||||
# recently executed command.
|
|
||||||
#
|
|
||||||
# For example, suppose your history has the following entries:
|
|
||||||
# - pwd
|
|
||||||
# - ls foo
|
|
||||||
# - ls bar
|
|
||||||
# - pwd
|
|
||||||
#
|
|
||||||
# Given the history list above, when you type 'ls', the suggestion
|
|
||||||
# will be 'ls foo' rather than 'ls bar' because your most recently
|
|
||||||
# executed command (pwd) was previously followed by 'ls foo'.
|
|
||||||
#
|
|
||||||
# Note that this strategy won't work as expected with ZSH options that don't
|
|
||||||
# preserve the history order such as `HIST_IGNORE_ALL_DUPS` or
|
|
||||||
# `HIST_EXPIRE_DUPS_FIRST`.
|
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_match_prev_cmd() {
|
|
||||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
|
||||||
setopt EXTENDED_GLOB
|
|
||||||
|
|
||||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
|
||||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
|
||||||
|
|
||||||
# Get the history items that match the prefix, excluding those that match
|
|
||||||
# the ignore pattern
|
|
||||||
local pattern="$prefix*"
|
|
||||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
|
||||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get all history event numbers that correspond to history
|
|
||||||
# entries that match the pattern
|
|
||||||
local history_match_keys
|
|
||||||
history_match_keys=(${(k)history[(R)$~pattern]})
|
|
||||||
|
|
||||||
# By default we use the first history number (most recent history entry)
|
|
||||||
local histkey="${history_match_keys[1]}"
|
|
||||||
|
|
||||||
# Get the previously executed command
|
|
||||||
local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
|
|
||||||
|
|
||||||
# Iterate up to the first 200 history event numbers that match $prefix
|
|
||||||
for key in "${(@)history_match_keys[1,200]}"; do
|
|
||||||
# Stop if we ran out of history
|
|
||||||
[[ $key -gt 1 ]] || break
|
|
||||||
|
|
||||||
# See if the history entry preceding the suggestion matches the
|
|
||||||
# previous command, and use it if it does
|
|
||||||
if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then
|
|
||||||
histkey="$key"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Give back the matched history entry
|
|
||||||
typeset -g suggestion="$history[$histkey]"
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Fetch Suggestion #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Loops through all specified strategies and returns a suggestion
|
|
||||||
# from the first strategy to provide one.
|
|
||||||
#
|
|
||||||
|
|
||||||
_zsh_autosuggest_fetch_suggestion() {
|
|
||||||
typeset -g suggestion
|
|
||||||
local -a strategies
|
|
||||||
local strategy
|
|
||||||
|
|
||||||
# Ensure we are working with an array
|
|
||||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
|
||||||
|
|
||||||
for strategy in $strategies; do
|
|
||||||
# Try to get a suggestion from this strategy
|
|
||||||
_zsh_autosuggest_strategy_$strategy "$1"
|
|
||||||
|
|
||||||
# Ensure the suggestion matches the prefix
|
|
||||||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
|
||||||
|
|
||||||
# Break once we've found a valid suggestion
|
|
||||||
[[ -n "$suggestion" ]] && break
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Async #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_request() {
|
|
||||||
zmodload zsh/system 2>/dev/null # For `$sysparams`
|
|
||||||
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
|
||||||
|
|
||||||
# If we've got a pending request, cancel it
|
|
||||||
if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then
|
|
||||||
# Close the file descriptor and remove the handler
|
|
||||||
builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
|
||||||
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
|
||||||
|
|
||||||
# We won't know the pid unless the user has zsh/system module installed
|
|
||||||
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
|
|
||||||
# Zsh will make a new process group for the child process only if job
|
|
||||||
# control is enabled (MONITOR option)
|
|
||||||
if [[ -o MONITOR ]]; then
|
|
||||||
# Send the signal to the process group to kill any processes that may
|
|
||||||
# have been forked by the suggestion strategy
|
|
||||||
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
|
||||||
else
|
|
||||||
# Kill just the child process since it wasn't placed in a new process
|
|
||||||
# group. If the suggestion strategy forked any child processes they may
|
|
||||||
# be orphaned and left behind.
|
|
||||||
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fork a process to fetch a suggestion and open a pipe to read from it
|
|
||||||
builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}< <(
|
|
||||||
# Tell parent process our pid
|
|
||||||
echo $sysparams[pid]
|
|
||||||
|
|
||||||
# Fetch and print the suggestion
|
|
||||||
local suggestion
|
|
||||||
_zsh_autosuggest_fetch_suggestion "$1"
|
|
||||||
echo -nE "$suggestion"
|
|
||||||
)
|
|
||||||
|
|
||||||
# There's a weird bug here where ^C stops working unless we force a fork
|
|
||||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
|
||||||
autoload -Uz is-at-least
|
|
||||||
is-at-least 5.8 || command true
|
|
||||||
|
|
||||||
# Read the pid from the child process
|
|
||||||
read _ZSH_AUTOSUGGEST_CHILD_PID <&$_ZSH_AUTOSUGGEST_ASYNC_FD
|
|
||||||
|
|
||||||
# When the fd is readable, call the response handler
|
|
||||||
zle -F "$_ZSH_AUTOSUGGEST_ASYNC_FD" _zsh_autosuggest_async_response
|
|
||||||
}
|
|
||||||
|
|
||||||
# Called when new data is ready to be read from the pipe
|
|
||||||
# First arg will be fd ready for reading
|
|
||||||
# Second arg will be passed in case of error
|
|
||||||
_zsh_autosuggest_async_response() {
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
local suggestion
|
|
||||||
|
|
||||||
if [[ -z "$2" || "$2" == "hup" ]]; then
|
|
||||||
# Read everything from the fd and give it as a suggestion
|
|
||||||
IFS='' read -rd '' -u $1 suggestion
|
|
||||||
zle autosuggest-suggest -- "$suggestion"
|
|
||||||
|
|
||||||
# Close the fd
|
|
||||||
builtin exec {1}<&-
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Always remove the handler
|
|
||||||
zle -F "$1"
|
|
||||||
_ZSH_AUTOSUGGEST_ASYNC_FD=
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Start #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Start the autosuggestion widgets
|
|
||||||
_zsh_autosuggest_start() {
|
|
||||||
# By default we re-bind widgets on every precmd to ensure we wrap other
|
|
||||||
# wrappers. Specifically, highlighting breaks if our widgets are wrapped by
|
|
||||||
# zsh-syntax-highlighting widgets. This also allows modifications to the
|
|
||||||
# widget list variables to take effect on the next precmd. However this has
|
|
||||||
# a decent performance hit, so users can set ZSH_AUTOSUGGEST_MANUAL_REBIND
|
|
||||||
# to disable the automatic re-binding.
|
|
||||||
if (( ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )); then
|
|
||||||
add-zsh-hook -d precmd _zsh_autosuggest_start
|
|
||||||
fi
|
|
||||||
|
|
||||||
_zsh_autosuggest_bind_widgets
|
|
||||||
}
|
|
||||||
|
|
||||||
# Mark for auto-loading the functions that we use
|
|
||||||
autoload -Uz add-zsh-hook is-at-least
|
|
||||||
|
|
||||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
|
||||||
# older versions because there is a bug when using async mode where ^C does not
|
|
||||||
# work immediately after fetching a suggestion.
|
|
||||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
|
||||||
if is-at-least 5.0.8; then
|
|
||||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start the autosuggestion widgets on the next precmd
|
|
||||||
add-zsh-hook precmd _zsh_autosuggest_start
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
Copyright (c) 2010-2020 zsh-syntax-highlighting contributors
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
with the distribution.
|
|
||||||
* Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
zsh-syntax-highlighting [![Build Status][build-status-image]][build-status]
|
|
||||||
=======================
|
|
||||||
|
|
||||||
**[Fish shell][fish]-like syntax highlighting for [Zsh][zsh].**
|
|
||||||
|
|
||||||
*Requirements: zsh 4.3.11+.*
|
|
||||||
|
|
||||||
[fish]: https://fishshell.com/
|
|
||||||
[zsh]: https://www.zsh.org/
|
|
||||||
|
|
||||||
This package provides syntax highlighting for the shell zsh. It enables
|
|
||||||
highlighting of commands whilst they are typed at a zsh prompt into an
|
|
||||||
interactive terminal. This helps in reviewing commands before running
|
|
||||||
them, particularly in catching syntax errors.
|
|
||||||
|
|
||||||
Some examples:
|
|
||||||
|
|
||||||
Before: [](images/before1.png)
|
|
||||||
<br/>
|
|
||||||
After: [](images/after1.png)
|
|
||||||
|
|
||||||
Before: [](images/before2.png)
|
|
||||||
<br/>
|
|
||||||
After: [](images/after2.png)
|
|
||||||
|
|
||||||
Before: [](images/before3.png)
|
|
||||||
<br/>
|
|
||||||
After: [](images/after3.png)
|
|
||||||
|
|
||||||
Before: [](images/before4-smaller.png)
|
|
||||||
<br/>
|
|
||||||
After: [](images/after4-smaller.png)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
How to install
|
|
||||||
--------------
|
|
||||||
|
|
||||||
See [the Oh My Zsh plugin README](README.md).
|
|
||||||
|
|
||||||
|
|
||||||
FAQ
|
|
||||||
---
|
|
||||||
|
|
||||||
### Why must `zsh-syntax-highlighting.zsh` be sourced at the end of the `.zshrc` file?
|
|
||||||
|
|
||||||
zsh-syntax-highlighting works by hooking into the Zsh Line Editor (ZLE) and
|
|
||||||
computing syntax highlighting for the command-line buffer as it stands at the
|
|
||||||
time z-sy-h's hook is invoked.
|
|
||||||
|
|
||||||
In zsh 5.2 and older,
|
|
||||||
`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must
|
|
||||||
be sourced after all custom widgets have been created (i.e., after all `zle -N`
|
|
||||||
calls and after running `compinit`) in order to be able to wrap all of them.
|
|
||||||
Widgets created after z-sy-h is sourced will work, but will not update the
|
|
||||||
syntax highlighting.
|
|
||||||
|
|
||||||
In zsh newer than 5.8 (not including 5.8 itself),
|
|
||||||
zsh-syntax-highlighting uses the `add-zle-hook-widget` facility to install
|
|
||||||
a `zle-line-pre-redraw` hook. Hooks are run in order of registration,
|
|
||||||
therefore, z-sy-h must be sourced (and register its hook) after anything else
|
|
||||||
that adds hooks that modify the command-line buffer.
|
|
||||||
|
|
||||||
### Does syntax highlighting work during incremental history search?
|
|
||||||
|
|
||||||
Highlighting the command line during an incremental history search (by default bound to
|
|
||||||
to <kbd>Ctrl+R</kbd> in zsh's emacs keymap) requires zsh 5.4 or newer.
|
|
||||||
|
|
||||||
Under zsh versions older than 5.4, the zsh-default [underlining][zshzle-Character-Highlighting]
|
|
||||||
of the matched portion of the buffer remains available, but zsh-syntax-highlighting's
|
|
||||||
additional highlighting is unavailable. (Those versions of zsh do not provide
|
|
||||||
enough information to allow computing the highlighting correctly.)
|
|
||||||
|
|
||||||
See issues [#288][i288] and [#415][i415] for details.
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
[i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288
|
|
||||||
[i415]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/415
|
|
||||||
|
|
||||||
### How are new releases announced?
|
|
||||||
|
|
||||||
There is currently no "push" announcements channel. However, the following
|
|
||||||
alternatives exist:
|
|
||||||
|
|
||||||
- GitHub's RSS feed of releases: https://github.com/zsh-users/zsh-syntax-highlighting/releases.atom
|
|
||||||
- An anitya entry: https://release-monitoring.org/project/7552/
|
|
||||||
|
|
||||||
|
|
||||||
How to tweak
|
|
||||||
------------
|
|
||||||
|
|
||||||
Syntax highlighting is done by pluggable highlighter scripts. See the
|
|
||||||
[documentation on highlighters](docs/highlighters.md) for details and
|
|
||||||
configuration settings.
|
|
||||||
|
|
||||||
[build-status]: https://github.com/zsh-users/zsh-syntax-highlighting/actions
|
|
||||||
[build-status-image]: https://github.com/zsh-users/zsh-syntax-highlighting/workflows/Tests/badge.svg
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# zsh-syntax-highlighting
|
|
||||||
|
|
||||||
This plugin enables Fish-like syntax highlighting for commands as they are typed at a zsh prompt.
|
|
||||||
|
|
||||||
To use it, add `zsh-syntax-highlighting` to the end of the plugins array in your zshrc file:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(... zsh-autosuggestions zsh-syntax-highlighting)
|
|
||||||
```
|
|
||||||
|
|
||||||
The plugin must be loaded after plugins that create or wrap ZLE widgets, so it should remain the last plugin
|
|
||||||
in the array. Start a new terminal session after updating your zshrc file.
|
|
||||||
|
|
||||||
For available highlighters and configuration options, see the [upstream documentation](MANUAL.md) and the
|
|
||||||
[highlighter documentation](docs/highlighters.md).
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters
|
|
||||||
======================================
|
|
||||||
|
|
||||||
Syntax highlighting is done by pluggable highlighters:
|
|
||||||
|
|
||||||
* `main` - the base highlighter, and the only one [active by default][main].
|
|
||||||
* `brackets` - [matches brackets][brackets] and parenthesis.
|
|
||||||
* `pattern` - matches [user-defined patterns][pattern].
|
|
||||||
* `regexp` - matches [user-defined regular expressions][regexp].
|
|
||||||
* `cursor` - matches [the cursor position][cursor].
|
|
||||||
* `root` - highlights the whole command line [if the current user is root][root].
|
|
||||||
* `line` - applied to [the whole command line][line].
|
|
||||||
|
|
||||||
[main]: highlighters/main.md
|
|
||||||
[brackets]: highlighters/brackets.md
|
|
||||||
[pattern]: highlighters/pattern.md
|
|
||||||
[regexp]: highlighters/regexp.md
|
|
||||||
[cursor]: highlighters/cursor.md
|
|
||||||
[root]: highlighters/root.md
|
|
||||||
[line]: highlighters/line.md
|
|
||||||
|
|
||||||
|
|
||||||
Highlighter-independent settings
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
By default, all command lines are highlighted. However, it is possible to
|
|
||||||
prevent command lines longer than a fixed number of characters from being
|
|
||||||
highlighted by setting the variable `${ZSH_HIGHLIGHT_MAXLENGTH}` to the maximum
|
|
||||||
length (in characters) of command lines to be highlighter. This is useful when
|
|
||||||
editing very long command lines (for example, with the [`fned`][fned] utility
|
|
||||||
function). Example:
|
|
||||||
|
|
||||||
[fned]: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#index-zed
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_HIGHLIGHT_MAXLENGTH=512
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
How to activate highlighters
|
|
||||||
----------------------------
|
|
||||||
|
|
||||||
To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array.
|
|
||||||
By default `ZSH_HIGHLIGHT_HIGHLIGHTERS` is `(main)`. For example to activate
|
|
||||||
`brackets`, `pattern`, and `cursor` highlighters, in `~/.zshrc` do:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(brackets pattern cursor)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
How to tweak highlighters
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` associative array.
|
|
||||||
Navigate into the [individual highlighters' documentation](highlighters/) to
|
|
||||||
see what styles (keys) each highlighter defines; the syntax for values is the
|
|
||||||
same as the syntax of "types of highlighting" of the zsh builtin
|
|
||||||
`$zle_highlight` array, which is documented in [the `zshzle(1)` manual
|
|
||||||
page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
|
|
||||||
Some highlighters support additional configuration parameters; see each
|
|
||||||
highlighter's documentation for details and examples.
|
|
||||||
|
|
||||||
|
|
||||||
How to implement a new highlighter
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
To create your own `acme` highlighter:
|
|
||||||
|
|
||||||
* Create your script at
|
|
||||||
`highlighters/acme/acme-highlighter.zsh`.
|
|
||||||
|
|
||||||
* Implement the `_zsh_highlight_highlighter_acme_predicate` function.
|
|
||||||
This function must return 0 when the highlighter needs to be called and
|
|
||||||
non-zero otherwise, for example:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
_zsh_highlight_highlighter_acme_predicate() {
|
|
||||||
# Call this highlighter in SVN working copies
|
|
||||||
[[ -d .svn ]]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
* Implement the `_zsh_highlight_highlighter_acme_paint` function.
|
|
||||||
This function does the actual syntax highlighting, by calling
|
|
||||||
`_zsh_highlight_add_highlight` with the start and end of the region to
|
|
||||||
be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default
|
|
||||||
style for that key in the highlighter script outside of any function with
|
|
||||||
`: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix
|
|
||||||
the key with your highlighter name and a colon. For example:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green}
|
|
||||||
|
|
||||||
_zsh_highlight_highlighter_acme_paint() {
|
|
||||||
# Colorize the whole buffer with the 'aurora' style
|
|
||||||
_zsh_highlight_add_highlight 0 $#BUFFER acme:aurora
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
If you need to test which options the user has set, test `zsyh_user_options`
|
|
||||||
with a sensible default if the option is not present in supported zsh
|
|
||||||
versions. For example:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
[[ ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]
|
|
||||||
```
|
|
||||||
|
|
||||||
The option name must be all lowercase with no underscores and not an alias.
|
|
||||||
|
|
||||||
* Name your own functions and global variables `_zsh_highlight_acme_*`.
|
|
||||||
|
|
||||||
- In zsh-syntax-highlighting 0.4.0 and earlier, the entrypoints
|
|
||||||
`_zsh_highlight_highlighter_acme_predicate` and
|
|
||||||
`_zsh_highlight_highlighter_acme_paint`
|
|
||||||
were named
|
|
||||||
`_zsh_highlight_acme_highlighter_predicate` and
|
|
||||||
`_zsh_highlight_highlighter_acme_paint` respectively.
|
|
||||||
|
|
||||||
These names are still supported for backwards compatibility;
|
|
||||||
however, support for them will be removed in a future major or minor release (v0.x.0 or v1.0.0).
|
|
||||||
|
|
||||||
* Activate your highlighter in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme)
|
|
||||||
```
|
|
||||||
|
|
||||||
* [Write tests](../tests/README.md).
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters / brackets
|
|
||||||
-------------------------------------------------
|
|
||||||
|
|
||||||
This is the `brackets` highlighter, that highlights brackets and parentheses, and
|
|
||||||
matches them.
|
|
||||||
|
|
||||||
|
|
||||||
### How to tweak it
|
|
||||||
|
|
||||||
This highlighter defines the following styles:
|
|
||||||
|
|
||||||
* `bracket-error` - unmatched brackets
|
|
||||||
* `bracket-level-N` - brackets with nest level N
|
|
||||||
* `cursor-matchingbracket` - the matching bracket, if cursor is on a bracket
|
|
||||||
|
|
||||||
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
|
|
||||||
for example in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
# To define styles for nested brackets up to level 4
|
|
||||||
ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=blue,bold'
|
|
||||||
ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=red,bold'
|
|
||||||
ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold'
|
|
||||||
ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold'
|
|
||||||
```
|
|
||||||
|
|
||||||
The syntax for values is the same as the syntax of "types of highlighting" of
|
|
||||||
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
|
|
||||||
manual page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters / cursor
|
|
||||||
-----------------------------------------------
|
|
||||||
|
|
||||||
This is the `cursor` highlighter, that highlights the cursor.
|
|
||||||
|
|
||||||
|
|
||||||
### How to tweak it
|
|
||||||
|
|
||||||
This highlighter defines the following styles:
|
|
||||||
|
|
||||||
* `cursor` - the style for the current cursor position
|
|
||||||
|
|
||||||
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
|
|
||||||
for example in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue'
|
|
||||||
```
|
|
||||||
|
|
||||||
The syntax for values is the same as the syntax of "types of highlighting" of
|
|
||||||
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
|
|
||||||
manual page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters / line
|
|
||||||
---------------------------------------------
|
|
||||||
|
|
||||||
This is the `line` highlighter, that highlights the whole line.
|
|
||||||
|
|
||||||
|
|
||||||
### How to tweak it
|
|
||||||
|
|
||||||
This highlighter defines the following styles:
|
|
||||||
|
|
||||||
* `line` - the style for the whole line
|
|
||||||
|
|
||||||
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
|
|
||||||
for example in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_HIGHLIGHT_STYLES[line]='bold'
|
|
||||||
```
|
|
||||||
|
|
||||||
The syntax for values is the same as the syntax of "types of highlighting" of
|
|
||||||
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
|
|
||||||
manual page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters / main
|
|
||||||
---------------------------------------------
|
|
||||||
|
|
||||||
This is the `main` highlighter, that highlights:
|
|
||||||
|
|
||||||
* Commands
|
|
||||||
* Options
|
|
||||||
* Arguments
|
|
||||||
* Paths
|
|
||||||
* Strings
|
|
||||||
|
|
||||||
This highlighter is active by default.
|
|
||||||
|
|
||||||
|
|
||||||
### How to tweak it
|
|
||||||
|
|
||||||
This highlighter defines the following styles:
|
|
||||||
|
|
||||||
* `unknown-token` - unknown tokens / errors
|
|
||||||
* `reserved-word` - shell reserved words (`if`, `for`)
|
|
||||||
* `alias` - aliases
|
|
||||||
* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer)
|
|
||||||
* `global-alias` - global aliases
|
|
||||||
* `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`)
|
|
||||||
* `function` - function names
|
|
||||||
* `command` - command names
|
|
||||||
* `precommand` - precommand modifiers (e.g., `noglob`, `builtin`)
|
|
||||||
* `commandseparator` - command separation tokens (`;`, `&&`)
|
|
||||||
* `hashed-command` - hashed commands
|
|
||||||
* `autodirectory` - a directory name in command position when the `AUTO_CD` option is set
|
|
||||||
* `path` - existing filenames
|
|
||||||
* `path_pathseparator` - path separators in filenames (`/`); if unset, `path` is used (default)
|
|
||||||
* `path_prefix` - prefixes of existing filenames
|
|
||||||
* `path_prefix_pathseparator` - path separators in prefixes of existing filenames (`/`); if unset, `path_prefix` is used (default)
|
|
||||||
* `globbing` - globbing expressions (`*.txt`)
|
|
||||||
* `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`)
|
|
||||||
* `command-substitution` - command substitutions (`$(echo foo)`)
|
|
||||||
* `command-substitution-unquoted` - an unquoted command substitution (`$(echo foo)`)
|
|
||||||
* `command-substitution-quoted` - a quoted command substitution (`"$(echo foo)"`)
|
|
||||||
* `command-substitution-delimiter` - command substitution delimiters (`$(` and `)`)
|
|
||||||
* `command-substitution-delimiter-unquoted` - an unquoted command substitution delimiters (`$(` and `)`)
|
|
||||||
* `command-substitution-delimiter-quoted` - a quoted command substitution delimiters (`"$(` and `)"`)
|
|
||||||
* `process-substitution` - process substitutions (`<(echo foo)`)
|
|
||||||
* `process-substitution-delimiter` - process substitution delimiters (`<(` and `)`)
|
|
||||||
* `arithmetic-expansion` - arithmetic expansion `$(( 42 ))`)
|
|
||||||
* `single-hyphen-option` - single-hyphen options (`-o`)
|
|
||||||
* `double-hyphen-option` - double-hyphen options (`--option`)
|
|
||||||
* `back-quoted-argument` - backtick command substitution (`` `foo` ``)
|
|
||||||
* `back-quoted-argument-unclosed` - unclosed backtick command substitution (`` `foo ``)
|
|
||||||
* `back-quoted-argument-delimiter` - backtick command substitution delimiters (`` ` ``)
|
|
||||||
* `single-quoted-argument` - single-quoted arguments (`` 'foo' ``)
|
|
||||||
* `single-quoted-argument-unclosed` - unclosed single-quoted arguments (`` 'foo ``)
|
|
||||||
* `double-quoted-argument` - double-quoted arguments (`` "foo" ``)
|
|
||||||
* `double-quoted-argument-unclosed` - unclosed double-quoted arguments (`` "foo ``)
|
|
||||||
* `dollar-quoted-argument` - dollar-quoted arguments (`` $'foo' ``)
|
|
||||||
* `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``)
|
|
||||||
* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
|
|
||||||
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
|
|
||||||
* `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`)
|
|
||||||
* `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`)
|
|
||||||
* `assign` - parameter assignments (`x=foo` and `x=( )`)
|
|
||||||
* `redirection` - redirection operators (`<`, `>`, etc)
|
|
||||||
* `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`)
|
|
||||||
* `comment` - elided parameters in command position (`$x ls` when `$x` is unset or empty)
|
|
||||||
* `named-fd` - named file descriptor (the `fd` in `echo foo {fd}>&2`)
|
|
||||||
* `numeric-fd` - numeric file descriptor (the `2` in `echo foo {fd}>&2`)
|
|
||||||
* `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command).
|
|
||||||
* `default` - everything else
|
|
||||||
|
|
||||||
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
|
|
||||||
for example in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
# Declare the variable
|
|
||||||
typeset -A ZSH_HIGHLIGHT_STYLES
|
|
||||||
|
|
||||||
# To differentiate aliases from other command types
|
|
||||||
ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold'
|
|
||||||
|
|
||||||
# To have paths colored instead of underlined
|
|
||||||
ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
|
|
||||||
|
|
||||||
# To disable highlighting of globbing expressions
|
|
||||||
ZSH_HIGHLIGHT_STYLES[globbing]='none'
|
|
||||||
```
|
|
||||||
|
|
||||||
The syntax for values is the same as the syntax of "types of highlighting" of
|
|
||||||
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
|
|
||||||
manual page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
|
|
||||||
To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array.
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Useless trivia
|
|
||||||
|
|
||||||
#### Forward compatibility.
|
|
||||||
|
|
||||||
zsh-syntax-highlighting attempts to be forward-compatible with zsh.
|
|
||||||
Specifically, we attempt to facilitate highlighting _command word_ types that
|
|
||||||
had not yet been invented when this version of zsh-syntax-highlighting was
|
|
||||||
released.
|
|
||||||
|
|
||||||
A _command word_ is something like a function name, external command name, et
|
|
||||||
cetera. (See
|
|
||||||
[Simple Commands & Pipelines in `zshmisc(1)`][zshmisc-Simple-Commands-And-Pipelines]
|
|
||||||
for a formal definition.)
|
|
||||||
|
|
||||||
If a new _kind_ of command word is ever added to zsh — something conceptually
|
|
||||||
different than "function" and "alias" and "external command" — then command words
|
|
||||||
of that (new) kind will be highlighted by the style `arg0_$kind`,
|
|
||||||
where `$kind` is the output of `type -w` on the new kind of command word. If that
|
|
||||||
style is not defined, then the style `arg0` will be used instead.
|
|
||||||
|
|
||||||
[zshmisc-Simple-Commands-And-Pipelines]: https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters / pattern
|
|
||||||
------------------------------------------------
|
|
||||||
|
|
||||||
This is the `pattern` highlighter, that highlights user-defined patterns.
|
|
||||||
|
|
||||||
|
|
||||||
### How to tweak it
|
|
||||||
|
|
||||||
To use this highlighter, associate patterns with styles in the
|
|
||||||
`ZSH_HIGHLIGHT_PATTERNS` associative array, for example in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
# Declare the variable
|
|
||||||
typeset -A ZSH_HIGHLIGHT_PATTERNS
|
|
||||||
|
|
||||||
# To have commands starting with `rm -rf` in red:
|
|
||||||
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
|
|
||||||
```
|
|
||||||
|
|
||||||
The syntax for values is the same as the syntax of "types of highlighting" of
|
|
||||||
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
|
|
||||||
manual page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters / regexp
|
|
||||||
------------------------------------------------
|
|
||||||
|
|
||||||
This is the `regexp` highlighter, that highlights user-defined regular
|
|
||||||
expressions. It's similar to the `pattern` highlighter, but allows more complex
|
|
||||||
patterns.
|
|
||||||
|
|
||||||
### How to tweak it
|
|
||||||
|
|
||||||
To use this highlighter, associate regular expressions with styles in the
|
|
||||||
`ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
typeset -A ZSH_HIGHLIGHT_REGEXP
|
|
||||||
ZSH_HIGHLIGHT_REGEXP+=('^rm .*' fg=red,bold)
|
|
||||||
```
|
|
||||||
|
|
||||||
This will highlight lines that start with a call to the `rm` command.
|
|
||||||
|
|
||||||
The regular expressions flavour used is [PCRE][pcresyntax] when the
|
|
||||||
`RE_MATCH_PCRE` option is set and POSIX Extended Regular Expressions (ERE),
|
|
||||||
as implemented by the platform's C library, otherwise. For details on the
|
|
||||||
latter, see [the `zsh/regex` module's documentation][MAN_ZSH_REGEX] and the
|
|
||||||
`regcomp(3)` and `re_format(7)` manual pages on your system.
|
|
||||||
|
|
||||||
For instance, to highlight `sudo` only as a complete word, i.e., `sudo cmd`,
|
|
||||||
but not `sudoedit`, one might use:
|
|
||||||
|
|
||||||
* When the `RE_MATCH_PCRE` is set:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
typeset -A ZSH_HIGHLIGHT_REGEXP
|
|
||||||
ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold)
|
|
||||||
```
|
|
||||||
|
|
||||||
* When the `RE_MATCH_PCRE` is unset, on platforms with GNU `libc` (e.g., many GNU/Linux distributions):
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
typeset -A ZSH_HIGHLIGHT_REGEXP
|
|
||||||
ZSH_HIGHLIGHT_REGEXP+=('\<sudo\>' fg=123,bold)
|
|
||||||
```
|
|
||||||
|
|
||||||
* When the `RE_MATCH_PCRE` is unset, on BSD-based platforms (e.g., macOS):
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
typeset -A ZSH_HIGHLIGHT_REGEXP
|
|
||||||
ZSH_HIGHLIGHT_REGEXP+=('[[:<:]]sudo[[:>:]]' fg=123,bold)
|
|
||||||
```
|
|
||||||
|
|
||||||
Note, however, that PCRE and POSIX ERE have a large common subset:
|
|
||||||
for instance, the regular expressions `[abc]`, `a*`, and `(a|b)` have the same
|
|
||||||
meaning in both flavours.
|
|
||||||
|
|
||||||
The syntax for values is the same as the syntax of "types of highlighting" of
|
|
||||||
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
|
|
||||||
manual page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~`
|
|
||||||
in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions]
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
[perlretut]: https://perldoc.perl.org/perlretut
|
|
||||||
[zshmisc-Conditional-Expressions]: https://zsh.sourceforge.io/Doc/Release/Conditional-Expressions.html#Conditional-Expressions
|
|
||||||
[MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module
|
|
||||||
[pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters / root
|
|
||||||
---------------------------------------------
|
|
||||||
|
|
||||||
This is the `root` highlighter, that highlights the whole line if the current
|
|
||||||
user is root.
|
|
||||||
|
|
||||||
|
|
||||||
### How to tweak it
|
|
||||||
|
|
||||||
This highlighter defines the following styles:
|
|
||||||
|
|
||||||
* `root` - the style for the whole line if the current user is root.
|
|
||||||
|
|
||||||
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
|
|
||||||
for example in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_HIGHLIGHT_STYLES[root]='bg=red'
|
|
||||||
```
|
|
||||||
|
|
||||||
The syntax for values is the same as the syntax of "types of highlighting" of
|
|
||||||
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
|
|
||||||
manual page][zshzle-Character-Highlighting].
|
|
||||||
|
|
||||||
[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
zsh-syntax-highlighting / highlighters
|
|
||||||
======================================
|
|
||||||
|
|
||||||
Navigate into the individual highlighters' documentation to see
|
|
||||||
what styles (`$ZSH_HIGHLIGHT_STYLES` keys) each highlighter defines.
|
|
||||||
|
|
||||||
Refer to the [documentation on highlighters](../docs/highlighters.md) for further
|
|
||||||
information.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../docs/highlighters/brackets.md
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2010-2017 zsh-syntax-highlighting contributors
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
# provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
# and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
# with the distribution.
|
|
||||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
# written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
|
||||||
# vim: ft=zsh sw=2 ts=2 et
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# Define default styles.
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-error]:=fg=red,bold}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-1]:=fg=blue,bold}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-2]:=fg=green,bold}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-3]:=fg=magenta,bold}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-4]:=fg=yellow,bold}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-5]:=fg=cyan,bold}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout}
|
|
||||||
|
|
||||||
# Whether the brackets highlighter should be called or not.
|
|
||||||
_zsh_highlight_highlighter_brackets_predicate()
|
|
||||||
{
|
|
||||||
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified
|
|
||||||
}
|
|
||||||
|
|
||||||
# Brackets highlighting function.
|
|
||||||
_zsh_highlight_highlighter_brackets_paint()
|
|
||||||
{
|
|
||||||
local char style
|
|
||||||
local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 matchingpos pos
|
|
||||||
local -A levelpos lastoflevel matching
|
|
||||||
|
|
||||||
# Find all brackets and remember which one is matching
|
|
||||||
pos=0
|
|
||||||
for char in ${(s..)BUFFER} ; do
|
|
||||||
(( ++pos ))
|
|
||||||
case $char in
|
|
||||||
["([{"])
|
|
||||||
levelpos[$pos]=$((++level))
|
|
||||||
lastoflevel[$level]=$pos
|
|
||||||
;;
|
|
||||||
[")]}"])
|
|
||||||
if (( level > 0 )); then
|
|
||||||
matchingpos=$lastoflevel[$level]
|
|
||||||
levelpos[$pos]=$((level--))
|
|
||||||
if _zsh_highlight_brackets_match $matchingpos $pos; then
|
|
||||||
matching[$matchingpos]=$pos
|
|
||||||
matching[$pos]=$matchingpos
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
levelpos[$pos]=-1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# Now highlight all found brackets
|
|
||||||
for pos in ${(k)levelpos}; do
|
|
||||||
if (( $+matching[$pos] )); then
|
|
||||||
if (( bracket_color_size )); then
|
|
||||||
_zsh_highlight_add_highlight $((pos - 1)) $pos bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
_zsh_highlight_add_highlight $((pos - 1)) $pos bracket-error
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# If cursor is on a bracket, then highlight corresponding bracket, if any.
|
|
||||||
if [[ $WIDGET != zle-line-finish ]]; then
|
|
||||||
pos=$((CURSOR + 1))
|
|
||||||
if (( $+levelpos[$pos] )) && (( $+matching[$pos] )); then
|
|
||||||
local -i otherpos=$matching[$pos]
|
|
||||||
_zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Helper function to differentiate type
|
|
||||||
_zsh_highlight_brackets_match()
|
|
||||||
{
|
|
||||||
case $BUFFER[$1] in
|
|
||||||
\() [[ $BUFFER[$2] == \) ]];;
|
|
||||||
\[) [[ $BUFFER[$2] == \] ]];;
|
|
||||||
\{) [[ $BUFFER[$2] == \} ]];;
|
|
||||||
*) false;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../docs/highlighters/cursor.md
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
# provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
# and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
# with the distribution.
|
|
||||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
# written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
|
||||||
# vim: ft=zsh sw=2 ts=2 et
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# Define default styles.
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[cursor]:=standout}
|
|
||||||
|
|
||||||
# Whether the cursor highlighter should be called or not.
|
|
||||||
_zsh_highlight_highlighter_cursor_predicate()
|
|
||||||
{
|
|
||||||
# remove cursor highlighting when the line is finished
|
|
||||||
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved
|
|
||||||
}
|
|
||||||
|
|
||||||
# Cursor highlighting function.
|
|
||||||
_zsh_highlight_highlighter_cursor_paint()
|
|
||||||
{
|
|
||||||
[[ $WIDGET == zle-line-finish ]] && return
|
|
||||||
|
|
||||||
_zsh_highlight_add_highlight $CURSOR $(( $CURSOR + 1 )) cursor
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../docs/highlighters/line.md
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
# provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
# and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
# with the distribution.
|
|
||||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
# written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
|
||||||
# vim: ft=zsh sw=2 ts=2 et
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# Define default styles.
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[line]:=}
|
|
||||||
|
|
||||||
# Whether the root highlighter should be called or not.
|
|
||||||
_zsh_highlight_highlighter_line_predicate()
|
|
||||||
{
|
|
||||||
_zsh_highlight_buffer_modified
|
|
||||||
}
|
|
||||||
|
|
||||||
# root highlighting function.
|
|
||||||
_zsh_highlight_highlighter_line_paint()
|
|
||||||
{
|
|
||||||
_zsh_highlight_add_highlight 0 $#BUFFER line
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../docs/highlighters/main.md
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../docs/highlighters/pattern.md
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
# provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
# and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
# with the distribution.
|
|
||||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
# written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
|
||||||
# vim: ft=zsh sw=2 ts=2 et
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# List of keyword and color pairs.
|
|
||||||
typeset -gA ZSH_HIGHLIGHT_PATTERNS
|
|
||||||
|
|
||||||
# Whether the pattern highlighter should be called or not.
|
|
||||||
_zsh_highlight_highlighter_pattern_predicate()
|
|
||||||
{
|
|
||||||
_zsh_highlight_buffer_modified
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pattern syntax highlighting function.
|
|
||||||
_zsh_highlight_highlighter_pattern_paint()
|
|
||||||
{
|
|
||||||
setopt localoptions extendedglob
|
|
||||||
local pattern
|
|
||||||
for pattern in ${(k)ZSH_HIGHLIGHT_PATTERNS}; do
|
|
||||||
_zsh_highlight_pattern_highlighter_loop "$BUFFER" "$pattern"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_highlight_pattern_highlighter_loop()
|
|
||||||
{
|
|
||||||
# This does *not* do its job syntactically, sorry.
|
|
||||||
local buf="$1" pat="$2"
|
|
||||||
local -a match mbegin mend
|
|
||||||
local MATCH; integer MBEGIN MEND
|
|
||||||
if [[ "$buf" == (#b)(*)(${~pat})* ]]; then
|
|
||||||
region_highlight+=("$((mbegin[2] - 1)) $mend[2] $ZSH_HIGHLIGHT_PATTERNS[$pat], memo=zsh-syntax-highlighting")
|
|
||||||
"$0" "$match[1]" "$pat"; return $?
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../docs/highlighters/regexp.md
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
# provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
# and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
# with the distribution.
|
|
||||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
# written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
|
||||||
# vim: ft=zsh sw=2 ts=2 et
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# List of keyword and color pairs.
|
|
||||||
typeset -gA ZSH_HIGHLIGHT_REGEXP
|
|
||||||
|
|
||||||
# Whether the pattern highlighter should be called or not.
|
|
||||||
_zsh_highlight_highlighter_regexp_predicate()
|
|
||||||
{
|
|
||||||
_zsh_highlight_buffer_modified
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pattern syntax highlighting function.
|
|
||||||
_zsh_highlight_highlighter_regexp_paint()
|
|
||||||
{
|
|
||||||
setopt localoptions extendedglob
|
|
||||||
local pattern
|
|
||||||
for pattern in ${(k)ZSH_HIGHLIGHT_REGEXP}; do
|
|
||||||
_zsh_highlight_regexp_highlighter_loop "$BUFFER" "$pattern"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_highlight_regexp_highlighter_loop()
|
|
||||||
{
|
|
||||||
local buf="$1" pat="$2"
|
|
||||||
integer OFFSET=0
|
|
||||||
local MATCH; integer MBEGIN MEND
|
|
||||||
local -a match mbegin mend
|
|
||||||
while true; do
|
|
||||||
[[ "$buf" =~ "$pat" ]] || return;
|
|
||||||
region_highlight+=("$((MBEGIN - 1 + OFFSET)) $((MEND + OFFSET)) $ZSH_HIGHLIGHT_REGEXP[$pat], memo=zsh-syntax-highlighting")
|
|
||||||
buf="$buf[$(($MEND+1)),-1]"
|
|
||||||
OFFSET=$((MEND+OFFSET));
|
|
||||||
done
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../docs/highlighters/root.md
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
# provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
# and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
# with the distribution.
|
|
||||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
# written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
|
||||||
# vim: ft=zsh sw=2 ts=2 et
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
# Define default styles.
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[root]:=standout}
|
|
||||||
|
|
||||||
# Whether the root highlighter should be called or not.
|
|
||||||
_zsh_highlight_highlighter_root_predicate()
|
|
||||||
{
|
|
||||||
_zsh_highlight_buffer_modified
|
|
||||||
}
|
|
||||||
|
|
||||||
# root highlighting function.
|
|
||||||
_zsh_highlight_highlighter_root_paint()
|
|
||||||
{
|
|
||||||
if (( EUID == 0 )) { _zsh_highlight_add_highlight 0 $#BUFFER root }
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 763 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 14 KiB |
@@ -1,587 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2010-2020 zsh-syntax-highlighting contributors
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
||||||
# provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
||||||
# and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
||||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
|
||||||
# with the distribution.
|
|
||||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without specific prior
|
|
||||||
# written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
||||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
||||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
|
||||||
# vim: ft=zsh sw=2 ts=2 et
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# First of all, ensure predictable parsing.
|
|
||||||
typeset zsh_highlight__aliases="$(builtin alias -Lm '[^+]*')"
|
|
||||||
# In zsh <= 5.2, aliases that begin with a plus sign ('alias -- +foo=42')
|
|
||||||
# are emitted by `alias -L` without a '--' guard, so they don't round trip.
|
|
||||||
#
|
|
||||||
# Hence, we exclude them from unaliasing:
|
|
||||||
builtin unalias -m '[^+]*'
|
|
||||||
|
|
||||||
# Set $0 to the expected value, regardless of functionargzero.
|
|
||||||
0=${(%):-%N}
|
|
||||||
if true; then
|
|
||||||
# $0 is reliable
|
|
||||||
typeset -g ZSH_HIGHLIGHT_VERSION=0.8.1-dev
|
|
||||||
typeset -g ZSH_HIGHLIGHT_REVISION=HEAD
|
|
||||||
if [[ $ZSH_HIGHLIGHT_REVISION == \$Format:* ]]; then
|
|
||||||
# When running from a source tree without 'make install', $ZSH_HIGHLIGHT_REVISION
|
|
||||||
# would be set to '$Format:%H$' literally. That's an invalid value, and obtaining
|
|
||||||
# the valid value (via `git rev-parse HEAD`, as Makefile does) might be costly, so:
|
|
||||||
ZSH_HIGHLIGHT_REVISION=HEAD
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# This function takes a single argument F and returns True iff F is an autoload stub.
|
|
||||||
_zsh_highlight__function_is_autoload_stub_p() {
|
|
||||||
if zmodload -e zsh/parameter; then
|
|
||||||
#(( ${+functions[$1]} )) &&
|
|
||||||
[[ "$functions[$1]" == *"builtin autoload -X"* ]]
|
|
||||||
else
|
|
||||||
#[[ $(type -wa -- "$1") == *'function'* ]] &&
|
|
||||||
[[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]]
|
|
||||||
fi
|
|
||||||
# Do nothing here: return the exit code of the if.
|
|
||||||
}
|
|
||||||
|
|
||||||
# Return True iff the argument denotes a function name.
|
|
||||||
_zsh_highlight__is_function_p() {
|
|
||||||
if zmodload -e zsh/parameter; then
|
|
||||||
(( ${+functions[$1]} ))
|
|
||||||
else
|
|
||||||
[[ $(type -wa -- "$1") == *'function'* ]]
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# This function takes a single argument F and returns True iff F denotes the
|
|
||||||
# name of a callable function. A function is callable if it is fully defined
|
|
||||||
# or if it is marked for autoloading and autoloading it at the first call to it
|
|
||||||
# will succeed. In particular, if F has been marked for autoloading
|
|
||||||
# but is not available in $fpath, then calling this function on F will return False.
|
|
||||||
#
|
|
||||||
# See users/21671 https://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671
|
|
||||||
_zsh_highlight__function_callable_p() {
|
|
||||||
if _zsh_highlight__is_function_p "$1" &&
|
|
||||||
! _zsh_highlight__function_is_autoload_stub_p "$1"
|
|
||||||
then
|
|
||||||
# Already fully loaded.
|
|
||||||
return 0 # true
|
|
||||||
else
|
|
||||||
# "$1" is either an autoload stub, or not a function at all.
|
|
||||||
#
|
|
||||||
# Use a subshell to avoid affecting the calling shell.
|
|
||||||
#
|
|
||||||
# We expect 'autoload +X' to return non-zero if it fails to fully load
|
|
||||||
# the function.
|
|
||||||
( autoload -U +X -- "$1" 2>/dev/null )
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Core highlighting update system
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Use workaround for bug in ZSH?
|
|
||||||
# zsh-users/zsh@48cadf4 https://www.zsh.org/mla/workers/2017/msg00034.html
|
|
||||||
autoload -Uz is-at-least
|
|
||||||
if is-at-least 5.4; then
|
|
||||||
typeset -g zsh_highlight__pat_static_bug=false
|
|
||||||
else
|
|
||||||
typeset -g zsh_highlight__pat_static_bug=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Array declaring active highlighters names.
|
|
||||||
typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS
|
|
||||||
|
|
||||||
# Update ZLE buffer syntax highlighting.
|
|
||||||
#
|
|
||||||
# Invokes each highlighter that needs updating.
|
|
||||||
# This function is supposed to be called whenever the ZLE state changes.
|
|
||||||
_zsh_highlight()
|
|
||||||
{
|
|
||||||
# Store the previous command return code to restore it whatever happens.
|
|
||||||
local ret=$?
|
|
||||||
# Make it read-only. Can't combine this with the previous line when POSIX_BUILTINS may be set.
|
|
||||||
typeset -r ret
|
|
||||||
|
|
||||||
# $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array.
|
|
||||||
(( ${+region_highlight[@]} )) || {
|
|
||||||
echo >&2 'zsh-syntax-highlighting: error: $region_highlight is not defined'
|
|
||||||
echo >&2 'zsh-syntax-highlighting: (Check whether zsh-syntax-highlighting was installed according to the instructions.)'
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
# Probe the memo= feature, once.
|
|
||||||
(( ${+zsh_highlight__memo_feature} )) || {
|
|
||||||
region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" )
|
|
||||||
case ${region_highlight[-1]} in
|
|
||||||
("0 0 fg=red")
|
|
||||||
# zsh 5.8 or earlier
|
|
||||||
integer -gr zsh_highlight__memo_feature=0
|
|
||||||
;;
|
|
||||||
("0 0 fg=red memo=zsh-syntax-highlighting")
|
|
||||||
# zsh 5.9 or later
|
|
||||||
integer -gr zsh_highlight__memo_feature=1
|
|
||||||
;;
|
|
||||||
(" 0 0 fg=red, memo=zsh-syntax-highlighting") ;&
|
|
||||||
(*)
|
|
||||||
# We can get here in two ways:
|
|
||||||
#
|
|
||||||
# 1. When not running as a widget. In that case, $region_highlight is
|
|
||||||
# not a special variable (= one with custom getter/setter functions
|
|
||||||
# written in C) but an ordinary one, so the third case pattern matches
|
|
||||||
# and we fall through to this block. (The test suite uses this codepath.)
|
|
||||||
#
|
|
||||||
# 2. When running under a future version of zsh that will have changed
|
|
||||||
# the serialization of $region_highlight elements from their underlying
|
|
||||||
# C structs, so that none of the previous case patterns will match.
|
|
||||||
#
|
|
||||||
# In either case, fall back to a version check.
|
|
||||||
if is-at-least 5.9; then
|
|
||||||
integer -gr zsh_highlight__memo_feature=1
|
|
||||||
else
|
|
||||||
integer -gr zsh_highlight__memo_feature=0
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
region_highlight[-1]=()
|
|
||||||
}
|
|
||||||
|
|
||||||
# Reset region_highlight to build it from scratch
|
|
||||||
if (( zsh_highlight__memo_feature )); then
|
|
||||||
region_highlight=( "${(@)region_highlight:#*memo=zsh-syntax-highlighting*}" )
|
|
||||||
else
|
|
||||||
# Legacy codepath. Not very interoperable with other plugins (issue #418).
|
|
||||||
region_highlight=()
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
|
|
||||||
# For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
|
|
||||||
# This disables highlighting during isearch (for reasons explained in README.md) unless zsh is new enough
|
|
||||||
# and doesn't have the pattern matching bug
|
|
||||||
if [[ $WIDGET == zle-isearch-update ]] && { $zsh_highlight__pat_static_bug || ! (( $+ISEARCHMATCH_ACTIVE )) }; then
|
|
||||||
return $ret
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Before we 'emulate -L', save the user's options
|
|
||||||
local -A zsyh_user_options
|
|
||||||
if zmodload -e zsh/parameter; then
|
|
||||||
zsyh_user_options=("${(kv)options[@]}")
|
|
||||||
else
|
|
||||||
local canonical_options onoff option raw_options
|
|
||||||
raw_options=(${(f)"$(emulate -R zsh; set -o)"})
|
|
||||||
canonical_options=(${${${(M)raw_options:#*off}%% *}#no} ${${(M)raw_options:#*on}%% *})
|
|
||||||
for option in "${canonical_options[@]}"; do
|
|
||||||
[[ -o $option ]]
|
|
||||||
case $? in
|
|
||||||
(0) zsyh_user_options+=($option on);;
|
|
||||||
(1) zsyh_user_options+=($option off);;
|
|
||||||
(*) # Can't happen, surely?
|
|
||||||
echo "zsh-syntax-highlighting: warning: '[[ -o $option ]]' returned $?"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
typeset -r zsyh_user_options
|
|
||||||
|
|
||||||
emulate -L zsh
|
|
||||||
setopt localoptions warncreateglobal nobashrematch
|
|
||||||
local REPLY # don't leak $REPLY into global scope
|
|
||||||
|
|
||||||
# Do not highlight if there are more than 300 chars in the buffer. It's most
|
|
||||||
# likely a pasted command or a huge list of files in that case..
|
|
||||||
[[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret
|
|
||||||
|
|
||||||
# Do not highlight if there are pending inputs (copy/paste).
|
|
||||||
(( KEYS_QUEUED_COUNT > 0 )) && return $ret
|
|
||||||
(( PENDING > 0 )) && return $ret
|
|
||||||
|
|
||||||
{
|
|
||||||
local cache_place
|
|
||||||
local -a region_highlight_copy
|
|
||||||
|
|
||||||
# Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked.
|
|
||||||
local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do
|
|
||||||
|
|
||||||
# eval cache place for current highlighter and prepare it
|
|
||||||
cache_place="_zsh_highlight__highlighter_${highlighter}_cache"
|
|
||||||
typeset -ga ${cache_place}
|
|
||||||
|
|
||||||
# If highlighter needs to be invoked
|
|
||||||
if ! type "_zsh_highlight_highlighter_${highlighter}_predicate" >&/dev/null; then
|
|
||||||
echo "zsh-syntax-highlighting: warning: disabling the ${(qq)highlighter} highlighter as it has not been loaded" >&2
|
|
||||||
# TODO: use ${(b)} rather than ${(q)} if supported
|
|
||||||
ZSH_HIGHLIGHT_HIGHLIGHTERS=( ${ZSH_HIGHLIGHT_HIGHLIGHTERS:#${highlighter}} )
|
|
||||||
elif "_zsh_highlight_highlighter_${highlighter}_predicate"; then
|
|
||||||
|
|
||||||
# save a copy, and cleanup region_highlight
|
|
||||||
region_highlight_copy=("${region_highlight[@]}")
|
|
||||||
region_highlight=()
|
|
||||||
|
|
||||||
# Execute highlighter and save result
|
|
||||||
{
|
|
||||||
"_zsh_highlight_highlighter_${highlighter}_paint"
|
|
||||||
} always {
|
|
||||||
: ${(AP)cache_place::="${region_highlight[@]}"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Restore saved region_highlight
|
|
||||||
region_highlight=("${region_highlight_copy[@]}")
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use value form cache if any cached
|
|
||||||
region_highlight+=("${(@P)cache_place}")
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
# Re-apply zle_highlight settings
|
|
||||||
|
|
||||||
# region
|
|
||||||
() {
|
|
||||||
(( REGION_ACTIVE )) || return
|
|
||||||
integer min max
|
|
||||||
if (( MARK > CURSOR )) ; then
|
|
||||||
min=$CURSOR max=$MARK
|
|
||||||
else
|
|
||||||
min=$MARK max=$CURSOR
|
|
||||||
fi
|
|
||||||
if (( REGION_ACTIVE == 1 )); then
|
|
||||||
[[ $KEYMAP = vicmd ]] && (( max++ ))
|
|
||||||
elif (( REGION_ACTIVE == 2 )); then
|
|
||||||
local needle=$'\n'
|
|
||||||
# CURSOR and MARK are 0 indexed between letters like region_highlight
|
|
||||||
# Do not include the newline in the highlight
|
|
||||||
(( min = ${BUFFER[(Ib:min:)$needle]} ))
|
|
||||||
(( max = ${BUFFER[(ib:max:)$needle]} - 1 ))
|
|
||||||
fi
|
|
||||||
_zsh_highlight_apply_zle_highlight region standout "$min" "$max"
|
|
||||||
}
|
|
||||||
|
|
||||||
# yank / paste (zsh-5.1.1 and newer)
|
|
||||||
(( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
|
|
||||||
|
|
||||||
# isearch
|
|
||||||
(( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END"
|
|
||||||
|
|
||||||
# suffix
|
|
||||||
(( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
|
|
||||||
|
|
||||||
|
|
||||||
return $ret
|
|
||||||
|
|
||||||
|
|
||||||
} always {
|
|
||||||
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER"
|
|
||||||
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Apply highlighting based on entries in the zle_highlight array.
|
|
||||||
# This function takes four arguments:
|
|
||||||
# 1. The exact entry (no patterns) in the zle_highlight array:
|
|
||||||
# region, paste, isearch, or suffix
|
|
||||||
# 2. The default highlighting that should be applied if the entry is unset
|
|
||||||
# 3. and 4. Two integer values describing the beginning and end of the
|
|
||||||
# range. The order does not matter.
|
|
||||||
_zsh_highlight_apply_zle_highlight() {
|
|
||||||
local entry="$1" default="$2"
|
|
||||||
integer first="$3" second="$4"
|
|
||||||
|
|
||||||
# read the relevant entry from zle_highlight
|
|
||||||
#
|
|
||||||
# ### In zsh≥5.0.8 we'd use ${(b)entry}, but we support older zsh's, so we don't
|
|
||||||
# ### add (b). The only effect is on the failure mode for callers that violate
|
|
||||||
# ### the precondition.
|
|
||||||
local region="${zle_highlight[(r)${entry}:*]-}"
|
|
||||||
|
|
||||||
if [[ -z "$region" ]]; then
|
|
||||||
# entry not specified at all, use default value
|
|
||||||
region=$default
|
|
||||||
else
|
|
||||||
# strip prefix
|
|
||||||
region="${region#${entry}:}"
|
|
||||||
|
|
||||||
# no highlighting when set to the empty string or to 'none'
|
|
||||||
if [[ -z "$region" ]] || [[ "$region" == none ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
integer start end
|
|
||||||
if (( first < second )); then
|
|
||||||
start=$first end=$second
|
|
||||||
else
|
|
||||||
start=$second end=$first
|
|
||||||
fi
|
|
||||||
region_highlight+=("$start $end $region, memo=zsh-syntax-highlighting")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# API/utility functions for highlighters
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Array used by highlighters to declare user overridable styles.
|
|
||||||
typeset -gA ZSH_HIGHLIGHT_STYLES
|
|
||||||
|
|
||||||
# Whether the command line buffer has been modified or not.
|
|
||||||
#
|
|
||||||
# Returns 0 if the buffer has changed since _zsh_highlight was last called.
|
|
||||||
_zsh_highlight_buffer_modified()
|
|
||||||
{
|
|
||||||
[[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Whether the cursor has moved or not.
|
|
||||||
#
|
|
||||||
# Returns 0 if the cursor has moved since _zsh_highlight was last called.
|
|
||||||
_zsh_highlight_cursor_moved()
|
|
||||||
{
|
|
||||||
[[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR))
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add a highlight defined by ZSH_HIGHLIGHT_STYLES.
|
|
||||||
#
|
|
||||||
# Should be used by all highlighters aside from 'pattern' (cf. ZSH_HIGHLIGHT_PATTERN).
|
|
||||||
# Overwritten in tests/test-highlighting.zsh when testing.
|
|
||||||
_zsh_highlight_add_highlight()
|
|
||||||
{
|
|
||||||
local -i start end
|
|
||||||
local highlight
|
|
||||||
start=$1
|
|
||||||
end=$2
|
|
||||||
shift 2
|
|
||||||
for highlight; do
|
|
||||||
if (( $+ZSH_HIGHLIGHT_STYLES[$highlight] )); then
|
|
||||||
region_highlight+=("$start $end $ZSH_HIGHLIGHT_STYLES[$highlight], memo=zsh-syntax-highlighting")
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Setup functions
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Helper for _zsh_highlight_bind_widgets
|
|
||||||
# $1 is name of widget to call
|
|
||||||
_zsh_highlight_call_widget()
|
|
||||||
{
|
|
||||||
builtin zle "$@" &&
|
|
||||||
_zsh_highlight
|
|
||||||
}
|
|
||||||
|
|
||||||
# Decide whether to use the zle-line-pre-redraw codepath (colloquially known as
|
|
||||||
# "feature/redrawhook", after the topic branch's name) or the legacy "bind all
|
|
||||||
# widgets" codepath.
|
|
||||||
#
|
|
||||||
# We use the new codepath under two conditions:
|
|
||||||
#
|
|
||||||
# 1. If it's available, which we check by testing for add-zle-hook-widget's availability.
|
|
||||||
#
|
|
||||||
# 2. If zsh has the memo= feature, which is required for interoperability reasons.
|
|
||||||
# See issues #579 and #735, and the issues referenced from them.
|
|
||||||
#
|
|
||||||
# We check this with a plain version number check, since a functional check,
|
|
||||||
# as done by _zsh_highlight, can only be done from inside a widget
|
|
||||||
# function — a catch-22.
|
|
||||||
if is-at-least 5.9 && _zsh_highlight__function_callable_p add-zle-hook-widget
|
|
||||||
then
|
|
||||||
autoload -U add-zle-hook-widget
|
|
||||||
_zsh_highlight__zle-line-finish() {
|
|
||||||
# Reset $WIDGET since the 'main' highlighter depends on it.
|
|
||||||
#
|
|
||||||
# Since $WIDGET is declared by zle as read-only in this function's scope,
|
|
||||||
# a nested function is required in order to shadow its built-in value;
|
|
||||||
# see "User-defined widgets" in zshall.
|
|
||||||
() {
|
|
||||||
local -h -r WIDGET=zle-line-finish
|
|
||||||
_zsh_highlight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_zsh_highlight__zle-line-pre-redraw() {
|
|
||||||
# Set $? to 0 for _zsh_highlight. Without this, subsequent
|
|
||||||
# zle-line-pre-redraw hooks won't run, since add-zle-hook-widget happens to
|
|
||||||
# call us with $? == 1 in the common case.
|
|
||||||
true && _zsh_highlight "$@"
|
|
||||||
}
|
|
||||||
_zsh_highlight_bind_widgets(){}
|
|
||||||
if [[ -o zle ]]; then
|
|
||||||
add-zle-hook-widget zle-line-pre-redraw _zsh_highlight__zle-line-pre-redraw
|
|
||||||
add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
|
|
||||||
_zsh_highlight_bind_widgets()
|
|
||||||
{
|
|
||||||
setopt localoptions noksharrays
|
|
||||||
typeset -F SECONDS
|
|
||||||
local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once
|
|
||||||
|
|
||||||
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
|
|
||||||
zmodload zsh/zleparameter 2>/dev/null || {
|
|
||||||
print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.'
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Override ZLE widgets to make them invoke _zsh_highlight.
|
|
||||||
local -U widgets_to_bind
|
|
||||||
widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|yank-pop)})
|
|
||||||
|
|
||||||
# Always wrap special zle-line-finish widget. This is needed to decide if the
|
|
||||||
# current line ends and special highlighting logic needs to be applied.
|
|
||||||
# E.g. remove cursor imprint, don't highlight partial paths, ...
|
|
||||||
widgets_to_bind+=(zle-line-finish)
|
|
||||||
|
|
||||||
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
|
|
||||||
# This is needed because we need to disable highlighting in that case.
|
|
||||||
widgets_to_bind+=(zle-isearch-update)
|
|
||||||
|
|
||||||
local cur_widget
|
|
||||||
for cur_widget in $widgets_to_bind; do
|
|
||||||
case ${widgets[$cur_widget]:-""} in
|
|
||||||
|
|
||||||
# Already rebound event: do nothing.
|
|
||||||
user:_zsh_highlight_widget_*);;
|
|
||||||
|
|
||||||
# The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function
|
|
||||||
# definition time is used.
|
|
||||||
#
|
|
||||||
# We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with
|
|
||||||
# NO_function_argzero, regardless of the option's setting here.
|
|
||||||
|
|
||||||
# User defined widget: override and rebind old one with prefix "orig-".
|
|
||||||
user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:}
|
|
||||||
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
|
|
||||||
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
|
|
||||||
|
|
||||||
# Completion widget: override and rebind old one with prefix "orig-".
|
|
||||||
completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]}
|
|
||||||
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
|
|
||||||
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
|
|
||||||
|
|
||||||
# Builtin widget: override and make it call the builtin ".widget".
|
|
||||||
builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }"
|
|
||||||
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
|
|
||||||
|
|
||||||
# Incomplete or nonexistent widget: Bind to z-sy-h directly.
|
|
||||||
*)
|
|
||||||
if [[ $cur_widget == zle-* ]] && (( ! ${+widgets[$cur_widget]} )); then
|
|
||||||
_zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight }
|
|
||||||
zle -N $cur_widget _zsh_highlight_widget_$cur_widget
|
|
||||||
else
|
|
||||||
# Default: unhandled case.
|
|
||||||
print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}"
|
|
||||||
print -r -- >&2 "zsh-syntax-highlighting: (This is sometimes caused by doing \`bindkey <keys> ${(q-)cur_widget}\` without creating the ${(qq)cur_widget} widget with \`zle -N\` or \`zle -C\`.)"
|
|
||||||
fi
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Load highlighters from directory.
|
|
||||||
#
|
|
||||||
# Arguments:
|
|
||||||
# 1) Path to the highlighters directory.
|
|
||||||
_zsh_highlight_load_highlighters()
|
|
||||||
{
|
|
||||||
setopt localoptions noksharrays bareglobqual
|
|
||||||
|
|
||||||
# Check the directory exists.
|
|
||||||
[[ -d "$1" ]] || {
|
|
||||||
print -r -- >&2 "zsh-syntax-highlighting: highlighters directory ${(qq)1} not found."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load highlighters from highlighters directory and check they define required functions.
|
|
||||||
local highlighter highlighter_dir
|
|
||||||
for highlighter_dir ($1/*/(/)); do
|
|
||||||
highlighter="${highlighter_dir:t}"
|
|
||||||
[[ -f "$highlighter_dir${highlighter}-highlighter.zsh" ]] &&
|
|
||||||
. "$highlighter_dir${highlighter}-highlighter.zsh"
|
|
||||||
if type "_zsh_highlight_highlighter_${highlighter}_paint" &> /dev/null &&
|
|
||||||
type "_zsh_highlight_highlighter_${highlighter}_predicate" &> /dev/null;
|
|
||||||
then
|
|
||||||
# New (0.5.0) function names
|
|
||||||
elif type "_zsh_highlight_${highlighter}_highlighter" &> /dev/null &&
|
|
||||||
type "_zsh_highlight_${highlighter}_highlighter_predicate" &> /dev/null;
|
|
||||||
then
|
|
||||||
# Old (0.4.x) function names
|
|
||||||
if false; then
|
|
||||||
# TODO: only show this warning for plugin authors/maintainers, not for end users
|
|
||||||
print -r -- >&2 "zsh-syntax-highlighting: warning: ${(qq)highlighter} highlighter uses deprecated entry point names; please ask its maintainer to update it: https://github.com/zsh-users/zsh-syntax-highlighting/issues/329"
|
|
||||||
fi
|
|
||||||
# Make it work.
|
|
||||||
eval "_zsh_highlight_highlighter_${(q)highlighter}_paint() { _zsh_highlight_${(q)highlighter}_highlighter \"\$@\" }"
|
|
||||||
eval "_zsh_highlight_highlighter_${(q)highlighter}_predicate() { _zsh_highlight_${(q)highlighter}_highlighter_predicate \"\$@\" }"
|
|
||||||
else
|
|
||||||
print -r -- >&2 "zsh-syntax-highlighting: ${(qq)highlighter} highlighter should define both required functions '_zsh_highlight_highlighter_${highlighter}_paint' and '_zsh_highlight_highlighter_${highlighter}_predicate' in ${(qq):-"$highlighter_dir${highlighter}-highlighter.zsh"}."
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Setup
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Try binding widgets.
|
|
||||||
_zsh_highlight_bind_widgets || {
|
|
||||||
print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.'
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Resolve highlighters directory location.
|
|
||||||
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
|
|
||||||
print -r -- >&2 'zsh-syntax-highlighting: failed loading highlighters, exiting.'
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Reset scratch variables when commandline is done.
|
|
||||||
_zsh_highlight_preexec_hook()
|
|
||||||
{
|
|
||||||
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
|
|
||||||
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=
|
|
||||||
}
|
|
||||||
autoload -Uz add-zsh-hook
|
|
||||||
add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
|
|
||||||
print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load zsh/parameter module if available
|
|
||||||
zmodload zsh/parameter 2>/dev/null || true
|
|
||||||
|
|
||||||
# Initialize the array of active highlighters if needed.
|
|
||||||
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main)
|
|
||||||
|
|
||||||
if (( $+X_ZSH_HIGHLIGHT_DIRS_BLACKLIST )); then
|
|
||||||
print >&2 'zsh-syntax-highlighting: X_ZSH_HIGHLIGHT_DIRS_BLACKLIST is deprecated. Please use ZSH_HIGHLIGHT_DIRS_BLACKLIST.'
|
|
||||||
ZSH_HIGHLIGHT_DIRS_BLACKLIST=($X_ZSH_HIGHLIGHT_DIRS_BLACKLIST)
|
|
||||||
unset X_ZSH_HIGHLIGHT_DIRS_BLACKLIST
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Restore the aliases we unned
|
|
||||||
eval "$zsh_highlight__aliases"
|
|
||||||
builtin unset zsh_highlight__aliases
|
|
||||||
|
|
||||||
# Set $?.
|
|
||||||
true
|
|
||||||
@@ -28,12 +28,9 @@ ZSH_THEME="robbyrussell"
|
|||||||
# zstyle ':omz:update' mode auto # update automatically without asking
|
# zstyle ':omz:update' mode auto # update automatically without asking
|
||||||
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
||||||
|
|
||||||
# Uncomment the following line to change the frequency the auto-updater is run (in days).
|
# Uncomment the following line to change how often to auto-update (in days).
|
||||||
# zstyle ':omz:update' frequency 13
|
# zstyle ':omz:update' frequency 13
|
||||||
|
|
||||||
# Uncomment the following line to set how old an update must be before it's applied, manually or via the auto-updater (in days).
|
|
||||||
# zstyle ':omz:update' cooldown 10
|
|
||||||
|
|
||||||
# Uncomment the following line if pasting URLs and other text is messed up.
|
# Uncomment the following line if pasting URLs and other text is messed up.
|
||||||
# DISABLE_MAGIC_FUNCTIONS="true"
|
# DISABLE_MAGIC_FUNCTIONS="true"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
PROMPT="${FG[117]}%~%{$reset_color%}\$(git_prompt_info)\$(virtualenv_prompt_info)${FG[133]}\$(git_prompt_status) ${FG[077]}%(?..${FG[160]}[%?] )ᐅ%{$reset_color%} "
|
PROMPT="${FG[117]}%~%{$reset_color%}\$(git_prompt_info)\$(virtualenv_prompt_info)${FG[133]}\$(git_prompt_status) ${FG[077]}ᐅ%{$reset_color%} "
|
||||||
|
|
||||||
ZSH_THEME_GIT_PROMPT_PREFIX=" ${FG[012]}("
|
ZSH_THEME_GIT_PROMPT_PREFIX=" ${FG[012]}("
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX="${FG[012]})%{$reset_color%}"
|
ZSH_THEME_GIT_PROMPT_SUFFIX="${FG[012]})%{$reset_color%}"
|
||||||
|
|||||||
@@ -67,26 +67,6 @@ function is_update_available() {
|
|||||||
remote=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
|
remote=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
|
||||||
remote_url=$(builtin cd -q "$ZSH"; git config remote.$remote.url)
|
remote_url=$(builtin cd -q "$ZSH"; git config remote.$remote.url)
|
||||||
|
|
||||||
local cooldown_days
|
|
||||||
zstyle -s ':omz:update' cooldown cooldown_days || cooldown_days=0
|
|
||||||
[[ $cooldown_days == <-> ]] || cooldown_days=0
|
|
||||||
|
|
||||||
if (( cooldown_days > 0 )); then
|
|
||||||
local local_head cutoff_epoch cooldown_ref
|
|
||||||
local_head=$(builtin cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
|
|
||||||
(builtin cd -q "$ZSH"; LANG= git fetch --quiet $remote $branch) || return 1
|
|
||||||
zmodload zsh/datetime
|
|
||||||
cutoff_epoch=$(( EPOCHSECONDS - cooldown_days * 86400 ))
|
|
||||||
cooldown_ref=$(builtin cd -q "$ZSH"; git log --first-parent --format="%H %ct" FETCH_HEAD \
|
|
||||||
| awk -v c="$cutoff_epoch" '$2 <= c { print $1; exit }')
|
|
||||||
[[ -n "$cooldown_ref" ]] || return 1
|
|
||||||
[[ "$cooldown_ref" != "$local_head" ]] || return 1
|
|
||||||
if (builtin cd -q "$ZSH"; git merge-base --is-ancestor "$cooldown_ref" "$local_head" 2>/dev/null); then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
local repo
|
local repo
|
||||||
case "$remote_url" in
|
case "$remote_url" in
|
||||||
https://github.com/*) repo=${${remote_url#https://github.com/}%.git} ;;
|
https://github.com/*) repo=${${remote_url#https://github.com/}%.git} ;;
|
||||||
@@ -149,10 +129,8 @@ EOD
|
|||||||
}
|
}
|
||||||
|
|
||||||
function update_ohmyzsh() {
|
function update_ohmyzsh() {
|
||||||
local verbose_mode cooldown_days
|
local verbose_mode
|
||||||
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
||||||
zstyle -s ':omz:update' cooldown cooldown_days || cooldown_days=0
|
|
||||||
[[ $cooldown_days == <-> ]] || cooldown_days=0
|
|
||||||
|
|
||||||
# Force verbose mode to silent if p10k instant prompt is enabled
|
# Force verbose mode to silent if p10k instant prompt is enabled
|
||||||
if [[ ${POWERLEVEL9K_INSTANT_PROMPT:-off} != "off" ]]; then
|
if [[ ${POWERLEVEL9K_INSTANT_PROMPT:-off} != "off" ]]; then
|
||||||
@@ -160,13 +138,13 @@ function update_ohmyzsh() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$update_mode" != background-alpha ]] \
|
if [[ "$update_mode" != background-alpha ]] \
|
||||||
&& LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode -c $cooldown_days; then
|
&& LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then
|
||||||
update_last_updated_file
|
update_last_updated_file
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local exit_status error
|
local exit_status error
|
||||||
if error=$(LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v silent -c $cooldown_days 2>&1); then
|
if error=$(LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v silent 2>&1); then
|
||||||
update_last_updated_file 0 "Update successful"
|
update_last_updated_file 0 "Update successful"
|
||||||
else
|
else
|
||||||
exit_status=$?
|
exit_status=$?
|
||||||
@@ -185,7 +163,7 @@ function has_typed_input() {
|
|||||||
# Consider that no input can be typed if stty fails
|
# Consider that no input can be typed if stty fails
|
||||||
# (this might happen if stdin is not a terminal)
|
# (this might happen if stdin is not a terminal)
|
||||||
local termios
|
local termios
|
||||||
termios=$(stty -g 2>/dev/null) || return 1
|
termios=$(stty --save 2>/dev/null) || return 1
|
||||||
{
|
{
|
||||||
# Disable canonical mode so that typed input counts
|
# Disable canonical mode so that typed input counts
|
||||||
# regardless of whether Enter was pressed
|
# regardless of whether Enter was pressed
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ case "$ZSH_EVAL_CONTEXT" in
|
|||||||
*:file) echo "error: this file should not be sourced" && return 1 ;;
|
*:file) echo "error: this file should not be sourced" && return 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
zmodload zsh/datetime
|
|
||||||
|
|
||||||
# Define "$ZSH" if not defined -- in theory this should be `export`ed by the calling script
|
# Define "$ZSH" if not defined -- in theory this should be `export`ed by the calling script
|
||||||
if [[ -z "$ZSH" ]]; then
|
if [[ -z "$ZSH" ]]; then
|
||||||
ZSH="${0:a:h:h}"
|
ZSH="${0:a:h:h}"
|
||||||
@@ -24,9 +22,8 @@ cd "$ZSH"
|
|||||||
|
|
||||||
verbose_mode="default"
|
verbose_mode="default"
|
||||||
interactive=false
|
interactive=false
|
||||||
cooldown_days=0
|
|
||||||
|
|
||||||
while getopts "v:ic:" opt; do
|
while getopts "v:i" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
v)
|
v)
|
||||||
if [[ $OPTARG == default || $OPTARG == minimal || $OPTARG == silent ]]; then
|
if [[ $OPTARG == default || $OPTARG == minimal || $OPTARG == silent ]]; then
|
||||||
@@ -37,14 +34,6 @@ while getopts "v:ic:" opt; do
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
i) interactive=true ;;
|
i) interactive=true ;;
|
||||||
c)
|
|
||||||
if [[ $OPTARG == <-> ]]; then
|
|
||||||
cooldown_days=$OPTARG
|
|
||||||
else
|
|
||||||
echo "[oh-my-zsh] update cooldown '$OPTARG' is not valid"
|
|
||||||
echo "[oh-my-zsh] valid options are a non-negative integer (days)"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -242,28 +231,6 @@ local ret=0
|
|||||||
remote=${"$(git config --local oh-my-zsh.remote)":-origin}
|
remote=${"$(git config --local oh-my-zsh.remote)":-origin}
|
||||||
branch=${"$(git config --local oh-my-zsh.branch)":-master}
|
branch=${"$(git config --local oh-my-zsh.branch)":-master}
|
||||||
|
|
||||||
update_with_cooldown() {
|
|
||||||
local cutoff_epoch cooldown_ref
|
|
||||||
|
|
||||||
cutoff_epoch=$(( EPOCHSECONDS - cooldown_days * 86400 ))
|
|
||||||
LANG= git fetch --quiet $remote $branch || return $?
|
|
||||||
|
|
||||||
cooldown_ref=$(git log --first-parent --format="%H %ct" FETCH_HEAD \
|
|
||||||
| awk -v c="$cutoff_epoch" '$2 <= c { print $1; exit }')
|
|
||||||
|
|
||||||
[[ -n "$cooldown_ref" ]] || return 0
|
|
||||||
|
|
||||||
LANG= git merge --ff-only --quiet "$cooldown_ref"
|
|
||||||
}
|
|
||||||
|
|
||||||
perform_update() {
|
|
||||||
if (( cooldown_days > 0 )); then
|
|
||||||
update_with_cooldown
|
|
||||||
else
|
|
||||||
LANG= git pull --quiet --rebase $remote $branch
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# repository state
|
# repository state
|
||||||
last_head=$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)
|
last_head=$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)
|
||||||
# checkout update branch
|
# checkout update branch
|
||||||
@@ -275,17 +242,10 @@ last_commit=$(git rev-parse "$branch")
|
|||||||
if [[ $verbose_mode != silent ]]; then
|
if [[ $verbose_mode != silent ]]; then
|
||||||
printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
|
printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
|
||||||
fi
|
fi
|
||||||
if perform_update; then
|
if LANG= git pull --quiet --rebase $remote $branch; then
|
||||||
# Check if it was really updated or not
|
# Check if it was really updated or not
|
||||||
if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
|
if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
|
||||||
if (( cooldown_days > 0 )); then
|
message="Oh My Zsh is already at the latest version."
|
||||||
head_ct=$(git log -1 --format=%ct HEAD)
|
|
||||||
age_days=$(( (EPOCHSECONDS - head_ct) / 86400 ))
|
|
||||||
(( age_days < 0 )) && age_days=0
|
|
||||||
message="Oh My Zsh is already at a version ${age_days} days old."
|
|
||||||
else
|
|
||||||
message="Oh My Zsh is already at the latest version."
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
message="Hooray! Oh My Zsh has been updated!"
|
message="Hooray! Oh My Zsh has been updated!"
|
||||||
|
|
||||||
|
|||||||