From dd30cf104c9ca42d89d26a134382ca421869ce7e Mon Sep 17 00:00:00 2001 From: Aleksandr Kozlov Date: Mon, 22 Jan 2018 12:54:02 +0300 Subject: [PATCH 001/848] Added kgpall alias --- plugins/kubectl/kubectl.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 88177b5a0..3c6e8045c 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -24,6 +24,7 @@ alias klp='k logs pods' alias kep='k edit pods' alias kdp='k describe pods' alias kdelp='k delete pods' +alias kgpall='k get pods --all-namespaces -o wide' # Service management. alias kgs='k get svc' From edbd86cd956266ee80f6b128588f5673f0cdb3c7 Mon Sep 17 00:00:00 2001 From: Sayan Roy Date: Sun, 7 Jun 2020 12:14:55 +0530 Subject: [PATCH 002/848] Updating some gem command reference # Updating some gem command reference gem_info,gem help , etc. --- plugins/ruby/ruby.plugin.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index 177b35b31..88e769d39 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -12,3 +12,14 @@ alias rb="ruby" alias gin="gem install" alias gun="gem uninstall" alias gli="gem list" +alias gi="gem info" +alias giall="gem info --all" +alias gca="gem cert --add" +alias gcr="gem cert --remove" +alias gcb="gem cert --build" +alias gclup="gem cleanup -n" +alias ggi="gem generate_index" +alias gh="gem help" +alias gl="gem lock" +alias go="gem open" +alias goe="gem open -e" From c268d176bf5e1efbf31bb1f3c00c182c1b369e9b Mon Sep 17 00:00:00 2001 From: Sayan Roy Date: Tue, 9 Jun 2020 00:48:50 +0530 Subject: [PATCH 003/848] Updating the README.md --- plugins/ruby/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/ruby/README.md b/plugins/ruby/README.md index ad2755bbf..a4a9c5036 100644 --- a/plugins/ruby/README.md +++ b/plugins/ruby/README.md @@ -18,3 +18,14 @@ plugins=(... ruby) | gin | `gem install` | Install a gem into the local repository | | gun | `gem uninstall` | Uninstall gems from the local repository | | gli | `gem list` | Display gems installed locally | +| gi | `gem info` | Show information for the given gem | +| giall | `gem info --all` | Display all gem versions | +| gca | `gem cert --add` | Add a trusted certificate | +| gcr | `gem cert --remove` | Remove a trusted certificate | +| gcb | `gem cert --build` | Build private key and self-signed certificate | +| gclup | `gem cleanup -n` | Do not uninstall gem | +| ggi | `gem generate_index` | Generate index file for gem server | +| gh | `gem help` | Provide additional help | +| gl | `gem lock` | Generate a lockdown list of gems | +| go | `gem open` | Open gem source in default editor | +| goe | `gem open -e` | Open gem sources in preferred editor | From e751d2519d586a2c022beeb0b40dfe9b7a1ed6eb Mon Sep 17 00:00:00 2001 From: Sayan Roy Date: Wed, 1 Jul 2020 08:58:27 +0530 Subject: [PATCH 004/848] spacing changed --- plugins/ruby/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ruby/README.md b/plugins/ruby/README.md index a4a9c5036..a2de11991 100644 --- a/plugins/ruby/README.md +++ b/plugins/ruby/README.md @@ -19,7 +19,7 @@ plugins=(... ruby) | gun | `gem uninstall` | Uninstall gems from the local repository | | gli | `gem list` | Display gems installed locally | | gi | `gem info` | Show information for the given gem | -| giall | `gem info --all` | Display all gem versions | +| giall | `gem info --all` | Display all gem versions | | gca | `gem cert --add` | Add a trusted certificate | | gcr | `gem cert --remove` | Remove a trusted certificate | | gcb | `gem cert --build` | Build private key and self-signed certificate | From f30daa76efa3e35f269c5a5a993c82e94799a074 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 7 Aug 2020 14:35:58 +0000 Subject: [PATCH 005/848] aliases: Don't overshadow fd --- plugins/common-aliases/common-aliases.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/common-aliases/common-aliases.plugin.zsh b/plugins/common-aliases/common-aliases.plugin.zsh index 023b1a51e..8f3045db4 100644 --- a/plugins/common-aliases/common-aliases.plugin.zsh +++ b/plugins/common-aliases/common-aliases.plugin.zsh @@ -34,7 +34,9 @@ alias -g P="2>&1| pygmentize -l pytb" alias dud='du -d 1 -h' alias duf='du -sh *' -alias fd='find . -type d -name' +if ! which fd >/dev/null 2>%1; then + alias fd='find . -type d -name' +fi alias ff='find . -type f -name' alias h='history' From 2d97e102b27135febd43fc6fdaa5dea84780973d Mon Sep 17 00:00:00 2001 From: hasheddan Date: Sat, 22 Aug 2020 09:00:06 -0500 Subject: [PATCH 006/848] Remove missing screenshots from kube-ps1 README Removes missing screenshots from README for kube-ps1 plugin. Signed-off-by: hasheddan --- plugins/kube-ps1/README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/plugins/kube-ps1/README.md b/plugins/kube-ps1/README.md index a14337278..b08997b0f 100644 --- a/plugins/kube-ps1/README.md +++ b/plugins/kube-ps1/README.md @@ -6,14 +6,6 @@ configured on `kubectl` to your Bash/Zsh prompt strings (i.e. the `$PS1`). Inspired by several tools used to simplify usage of `kubectl`. -![prompt](img/screenshot2.png) - -![prompt_sol_light](img/screenshot-sol-light.png) - -![prompt_img](img/screenshot-img.png) - -![prompt demo](img/kube-ps1.gif) - ## Installing ### MacOS From b4093819a801e9c982b61718af75a188f34bd2bd Mon Sep 17 00:00:00 2001 From: "Matsievskiy S.V" Date: Mon, 5 Oct 2020 12:42:22 +0300 Subject: [PATCH 007/848] fino: fix dangling "using" and clean up (#9307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matsievskiy S.V Co-authored-by: Marc Cornellà --- themes/fino.zsh-theme | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/themes/fino.zsh-theme b/themes/fino.zsh-theme index 1d8bb30e1..c5589f13a 100644 --- a/themes/fino.zsh-theme +++ b/themes/fino.zsh-theme @@ -11,26 +11,35 @@ # # Also borrowing from http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/ +function virtualenv_prompt_info { + [[ -n ${VIRTUAL_ENV} ]] || return + echo "${ZSH_THEME_VIRTUALENV_PREFIX:=[}${VIRTUAL_ENV:t}${ZSH_THEME_VIRTUALENV_SUFFIX:=]}" +} + function prompt_char { - git branch >/dev/null 2>/dev/null && echo "±" && return - echo '○' + command git branch &>/dev/null && echo "±" || echo '○' } function box_name { - [ -f ~/.box-name ] && cat ~/.box-name || echo ${SHORT_HOST:-$HOST} + [ -f ~/.box-name ] && cat ~/.box-name || echo ${SHORT_HOST:-$HOST} } -local ruby_env='using%{$FG[243]%} $(ruby_prompt_info)' +local ruby_env='$(ruby_prompt_info)' local git_info='$(git_prompt_info)' +local virtualenv_info='$(virtualenv_prompt_info)' local prompt_char='$(prompt_char)' - -PROMPT="╭─%{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(box_name)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}%~%{$reset_color%}${git_info} %{$FG[239]%}${ruby_env} +PROMPT="╭─${FG[040]}%n ${FG[239]}at ${FG[033]}$(box_name) ${FG[239]}in %B${FG[226]}%~%{$reset_color%}${git_info}${ruby_env}${virtualenv_info} ╰─${prompt_char}%{$reset_color%} " -ZSH_THEME_GIT_PROMPT_PREFIX=" %{$FG[239]%}on%{$reset_color%} %{$fg[255]%}" +ZSH_THEME_GIT_PROMPT_PREFIX=" ${FG[239]}on%{$reset_color%} ${FG[255]}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$FG[202]%}✘✘✘" -ZSH_THEME_GIT_PROMPT_CLEAN="%{$FG[040]%}✔" -ZSH_THEME_RUBY_PROMPT_PREFIX="‹" +ZSH_THEME_GIT_PROMPT_DIRTY="${FG[202]}✘✘✘" +ZSH_THEME_GIT_PROMPT_CLEAN="${FG[040]}✔" + +ZSH_THEME_RUBY_PROMPT_PREFIX=" ${FG[239]}using${FG[243]} ‹" ZSH_THEME_RUBY_PROMPT_SUFFIX="›%{$reset_color%}" + +export VIRTUAL_ENV_DISABLE_PROMPT=1 +ZSH_THEME_VIRTUALENV_PREFIX=" ${FG[239]}using${FG[243]} «" +ZSH_THEME_VIRTUALENV_SUFFIX="»%{$reset_color%}" From fbb2b56c7ecd3c4873be805e004f70fa442e7c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 5 Oct 2020 12:05:47 +0200 Subject: [PATCH 008/848] fino: stop bold with prompt sequence Fixes weird bug when completing. --- themes/fino.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/fino.zsh-theme b/themes/fino.zsh-theme index c5589f13a..2523c1776 100644 --- a/themes/fino.zsh-theme +++ b/themes/fino.zsh-theme @@ -29,7 +29,7 @@ local git_info='$(git_prompt_info)' local virtualenv_info='$(virtualenv_prompt_info)' local prompt_char='$(prompt_char)' -PROMPT="╭─${FG[040]}%n ${FG[239]}at ${FG[033]}$(box_name) ${FG[239]}in %B${FG[226]}%~%{$reset_color%}${git_info}${ruby_env}${virtualenv_info} +PROMPT="╭─${FG[040]}%n ${FG[239]}at ${FG[033]}$(box_name) ${FG[239]}in %B${FG[226]}%~%b${git_info}${ruby_env}${virtualenv_info} ╰─${prompt_char}%{$reset_color%} " ZSH_THEME_GIT_PROMPT_PREFIX=" ${FG[239]}on%{$reset_color%} ${FG[255]}" From 6ebf27b8d34c760e25749790ea78dcb0c220d76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 5 Oct 2020 17:20:02 +0200 Subject: [PATCH 009/848] Revert "Remove redundant bashcompinit calls" This reverts commit f776af2a1f5d5ced17bdeb00f7adb64ccfaa99a6. Fixes #9314 --- plugins/aws/aws.plugin.zsh | 1 + plugins/compleat/compleat.plugin.zsh | 7 +++++-- plugins/drush/drush.plugin.zsh | 2 ++ plugins/stack/stack.plugin.zsh | 1 + plugins/wp-cli/wp-cli.plugin.zsh | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index ecf78b2c2..7994963c3 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -64,6 +64,7 @@ fi # AWS CLI v2 comes with its own autocompletion. Check if that is there, otherwise fall back if command -v aws_completer &> /dev/null; then + autoload -Uz bashcompinit && bashcompinit complete -C aws_completer aws else function _awscli-homebrew-installed() { diff --git a/plugins/compleat/compleat.plugin.zsh b/plugins/compleat/compleat.plugin.zsh index 247240c20..38f1b396a 100644 --- a/plugins/compleat/compleat.plugin.zsh +++ b/plugins/compleat/compleat.plugin.zsh @@ -10,8 +10,11 @@ if (( ${+commands[compleat]} )); then local setup="${prefix}/share/compleat-1.0/compleat_setup" if [[ -f "$setup" ]]; then + if ! bashcompinit >/dev/null 2>&1; then + autoload -U bashcompinit + bashcompinit -i + fi + source "$setup" fi - - unset prefix setup fi diff --git a/plugins/drush/drush.plugin.zsh b/plugins/drush/drush.plugin.zsh index 178750c24..8a20d79f2 100644 --- a/plugins/drush/drush.plugin.zsh +++ b/plugins/drush/drush.plugin.zsh @@ -99,4 +99,6 @@ alias drvg="drush variable-get" alias drvs="drush variable-set" # Enable drush autocomplete support +autoload bashcompinit +bashcompinit source $(dirname $0)/drush.complete.sh diff --git a/plugins/stack/stack.plugin.zsh b/plugins/stack/stack.plugin.zsh index e3b6503a5..45ef38761 100644 --- a/plugins/stack/stack.plugin.zsh +++ b/plugins/stack/stack.plugin.zsh @@ -1,3 +1,4 @@ (( $+commands[stack] )) || return +autoload -U +X bashcompinit && bashcompinit source <(stack --bash-completion-script stack) diff --git a/plugins/wp-cli/wp-cli.plugin.zsh b/plugins/wp-cli/wp-cli.plugin.zsh index 05ecc4b8a..97bed406e 100644 --- a/plugins/wp-cli/wp-cli.plugin.zsh +++ b/plugins/wp-cli/wp-cli.plugin.zsh @@ -138,6 +138,7 @@ alias wpwm='wp widget move' alias wpwu='wp widget update' +autoload -U +X bashcompinit && bashcompinit # bash completion for the `wp` command _wp_complete() { From 01ce52e6814c27a61945ed4406059c14f0c5d548 Mon Sep 17 00:00:00 2001 From: Michele Bologna Date: Wed, 7 Oct 2020 17:15:29 +0200 Subject: [PATCH 010/848] z: upgrade plugin to the latest version (#9310) Commit-id: 125f4dc47e15891739dd8262d5b23077fe8fb9ab https://github.com/rupa/z/commit/125f4dc47e15891739dd8262d5b23077fe8fb9ab --- plugins/z/README | 8 ++++++-- plugins/z/z.1 | 3 +++ plugins/z/z.sh | 44 ++++++++++++++++++++++++-------------------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/plugins/z/README b/plugins/z/README index 56261cff4..47e54c57a 100644 --- a/plugins/z/README +++ b/plugins/z/README @@ -23,6 +23,8 @@ DESCRIPTION OPTIONS -c restrict matches to subdirectories of the current directory + -e echo the best match, don't cd + -h show a brief help message -l list only @@ -57,6 +59,8 @@ NOTES Optionally: Set $_Z_CMD to change the command name (default z). Set $_Z_DATA to change the datafile (default $HOME/.z). + Set $_Z_MAX_SCORE lower to age entries out faster (default + 9000). Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution. Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd your- self. @@ -64,8 +68,8 @@ NOTES Set $_Z_OWNER to allow usage when in 'sudo -s' mode. (These settings should go in .bashrc/.zshrc before the line added above.) - Install the provided man page z.1 somewhere like - /usr/local/man/man1. + Install the provided man page z.1 somewhere in your MANPATH, + like /usr/local/man/man1. Aging: The rank of directories maintained by z undergoes aging based on a sim- diff --git a/plugins/z/z.1 b/plugins/z/z.1 index d4cac1ac2..182f98176 100644 --- a/plugins/z/z.1 +++ b/plugins/z/z.1 @@ -78,6 +78,9 @@ Set \fB$_Z_CMD\fR to change the command name (default \fBz\fR). Set \fB$_Z_DATA\fR to change the datafile (default \fB$HOME/.z\fR). .RE .RS +Set \fB$_Z_MAX_SCORE\fR lower to age entries out faster (default \fB9000\fR). +.RE +.RS Set \fB$_Z_NO_RESOLVE_SYMLINKS\fR to prevent symlink resolution. .RE .RS diff --git a/plugins/z/z.sh b/plugins/z/z.sh index 5c5771d62..13008a60e 100644 --- a/plugins/z/z.sh +++ b/plugins/z/z.sh @@ -10,6 +10,7 @@ # * optionally: # set $_Z_CMD in .bashrc/.zshrc to change the command (default z). # set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z). +# set $_Z_MAX_SCORE lower to age entries out faster (default 9000). # set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution. # set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself. # set $_Z_EXCLUDE_DIRS to an array of directories to exclude. @@ -23,6 +24,8 @@ # * z -l foo # list matches instead of cd # * z -e foo # echo the best match, don't cd # * z -c foo # restrict matches to subdirs of $PWD +# * z -x # remove the current directory from the datafile +# * z -h # show a brief help message [ -d "${_Z_DATA:-$HOME/.z}" ] && { echo "ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory." @@ -62,7 +65,8 @@ _z() { # maintain the data file local tempfile="$datafile.$RANDOM" - _z_dirs | awk -v path="$*" -v now="$(date +%s)" -F"|" ' + local score=${_Z_MAX_SCORE:-9000} + _z_dirs | awk -v path="$*" -v now="$(date +%s)" -v score=$score -F"|" ' BEGIN { rank[path] = 1 time[path] = now @@ -79,7 +83,7 @@ _z() { count += $2 } END { - if( count > 9000 ) { + if( count > score ) { # aging for( x in rank ) print x "|" 0.99*rank[x] "|" time[x] } else for( x in rank ) print x "|" rank[x] "|" time[x] @@ -138,27 +142,24 @@ _z() { local cd cd="$( < <( _z_dirs ) awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" ' function frecent(rank, time) { - # relate frequency and time - dx = t - time - if( dx < 3600 ) return rank * 4 - if( dx < 86400 ) return rank * 2 - if( dx < 604800 ) return rank / 2 - return rank / 4 + # relate frequency and time + dx = t - time + return int(10000 * rank * (3.75/((0.0001 * dx + 1) + 0.25))) } function output(matches, best_match, common) { # list or return the desired directory if( list ) { - cmd = "sort -g >&2" + if( common ) { + printf "%-10s %s\n", "common:", common > "/dev/stderr" + } + cmd = "sort -n >&2" for( x in matches ) { if( matches[x] ) { printf "%-10s %s\n", matches[x], x | cmd } } - if( common ) { - printf "%-10s %s\n", "common:", common > "/dev/stderr" - } } else { - if( common ) best_match = common + if( common && !typ ) best_match = common print best_match } } @@ -200,15 +201,22 @@ _z() { # prefer case sensitive if( best_match ) { output(matches, best_match, common(matches)) + exit } else if( ibest_match ) { output(imatches, ibest_match, common(imatches)) + exit } + exit(1) } ')" - [ $? -eq 0 ] && [ "$cd" ] && { - if [ "$echo" ]; then echo "$cd"; else builtin cd "$cd"; fi - } + if [ "$?" -eq 0 ]; then + if [ "$cd" ]; then + if [ "$echo" ]; then echo "$cd"; else builtin cd "$cd"; fi + fi + else + return $? + fi fi } @@ -223,15 +231,11 @@ if type compctl >/dev/null 2>&1; then if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then _z_precmd() { (_z --add "${PWD:a}" &) - # Reference $RANDOM to refresh its value inside the subshell - # Otherwise, multiple runs get the same value : $RANDOM } else _z_precmd() { (_z --add "${PWD:A}" &) - # Reference $RANDOM to refresh its value inside the subshell - # Otherwise, multiple runs get the same value : $RANDOM } fi From 27857e66d0dab0bd05790307dfe5388f3cb2c51a Mon Sep 17 00:00:00 2001 From: davidfmatheson Date: Thu, 8 Oct 2020 11:21:34 -0400 Subject: [PATCH 011/848] nvm: add Homebrew's nvm setup (#8316) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/nvm/README.md | 11 ++++++++++- plugins/nvm/nvm.plugin.zsh | 23 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index 079cf0009..2515da9e8 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -1,9 +1,18 @@ # nvm plugin -This plugin adds autocompletions for [nvm](https://github.com/creationix/nvm) — a Node.js version manager. +This plugin adds autocompletions for [nvm](https://github.com/nvm-sh/nvm) — a Node.js version manager. It also automatically sources nvm, so you don't need to do it manually in your `.zshrc`. To use it, add `nvm` to the plugins array of your zshrc file: + ```zsh plugins=(... nvm) ``` + +## Settings + +- **`NVM_DIR`**: if you have installed nvm in a directory other than `$HOME/.nvm`, set and export `NVM_DIR` + to be the directory where you installed nvm. + +- **`NVM_HOMEBREW`**: if you installed nvm via Homebrew, in a directory other than `/usr/local/opt/nvm`, you + can set `NVM_HOMEBREW` to be the directory where you installed it. diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 4bab8e9d7..2264a2420 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -1,8 +1,23 @@ # Set NVM_DIR if it isn't already defined [[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm" -# Try to load nvm only if command not already available -if ! type "nvm" &> /dev/null; then - # Load nvm if it exists - [[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" +# Don't try to load nvm if command already available +type "nvm" &> /dev/null && return + +# Load nvm if it exists in $NVM_DIR +if [[ -f "$NVM_DIR/nvm.sh" ]]; then + source "$NVM_DIR/nvm.sh" + return +fi + +# Otherwise try to load nvm installed via Homebrew + +# User can set this if they have an unusual Homebrew setup +NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}" +# Load nvm from Homebrew location if it exists +[[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" +# Load nvm bash completion from Homebrew if it exists +if [[ -f "$NVM_HOMEBREW/etc/bash_completion.d/nvm" ]]; then + autoload -U +X bashcompinit && bashcompinit + source "$NVM_HOMEBREW/etc/bash_completion.d/nvm" fi From 68f809448a08d2c93d13650157fd0500a329a16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Thu, 8 Oct 2020 19:18:43 +0200 Subject: [PATCH 012/848] kubectl: add wrappers for colorized output in JSON and YAML (#9316) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/kubectl/README.md | 8 ++++++++ plugins/kubectl/kubectl.plugin.zsh | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/kubectl/README.md b/plugins/kubectl/README.md index ee05a8af1..84f5f8d89 100644 --- a/plugins/kubectl/README.md +++ b/plugins/kubectl/README.md @@ -106,3 +106,11 @@ plugins=(... kubectl) | kdelss | `kubectl delete statefulset` | Delete the statefulset | | ksss | `kubectl scale statefulset` | Scale a statefulset | | krsss | `kubectl rollout status statefulset`| Check the rollout status of a deployment | + +## Wrappers + +This plugin provides 3 wrappers to colorize kubectl output in JSON and YAML using various tools (which must be installed): + +- `kj`: JSON, colorized with [`jq`](https://stedolan.github.io/jq/). +- `kjx`: JSON, colorized with [`fx`](https://github.com/antonmedv/fx). +- `ky`: YAML, colorized with [`yh`](https://github.com/andreazorzetto/yh). diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 647d029c1..6292a0b2f 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -150,3 +150,19 @@ alias kepvc='kubectl edit pvc' alias kdpvc='kubectl describe pvc' alias kdelpvc='kubectl delete pvc' +# Colored JSON output +kj() { + kubectl "$@" -o json | jq +} +compdef kj=kubectl + +kjx() { + kubectl "$@" -o json | fx +} +compdef kjx=kubectl + +# Colored YAML output +ky() { + kubectl "$@" -o yaml | yh +} +compdef ky=kubectl From 58ff4e1d2e6a81ea97a05b142c28a931a9924b70 Mon Sep 17 00:00:00 2001 From: Michele Bologna Date: Thu, 8 Oct 2020 19:20:47 +0200 Subject: [PATCH 013/848] lib: follow standards in window title (#9320) In Ubuntu and Debian, in scp, and in rsync the prompt is by default specified as in user@hostname:/path/to/directory while the previous title in ohmyzsh was user@hostname: /path/to/directory --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 8cb2389e2..778f12bca 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -42,7 +42,7 @@ function title { } ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD -ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~" +ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~" # Avoid duplication of directory in terminals with independent dir display if [[ "$TERM_PROGRAM" == Apple_Terminal ]]; then ZSH_THEME_TERM_TITLE_IDLE="%n@%m" From 8ad9b315a389c741d93aece3ed6eae6b6829f951 Mon Sep 17 00:00:00 2001 From: Duc Nguyen Date: Fri, 9 Oct 2020 17:35:13 +0700 Subject: [PATCH 014/848] Add git-lfs plugin (#9077) --- .github/CODEOWNERS | 1 + plugins/git-lfs/README.md | 24 ++++++++++++++++++++++++ plugins/git-lfs/git-lfs.plugin.zsh | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 plugins/git-lfs/README.md create mode 100644 plugins/git-lfs/git-lfs.plugin.zsh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index cba8e93af..c3990c4ee 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,4 @@ # Plugin owners plugins/gitfast/ @felipec plugins/sdk/ @rgoldberg +plugins/git-lfs/ @vietduc01100001 diff --git a/plugins/git-lfs/README.md b/plugins/git-lfs/README.md new file mode 100644 index 000000000..1222b2767 --- /dev/null +++ b/plugins/git-lfs/README.md @@ -0,0 +1,24 @@ +# git lfs plugin + +The git lfs plugin provides [aliases](#aliases) and [functions](#functions) for [git-lfs](https://github.com/git-lfs/git-lfs). + +To use it, add `git-lfs` to the plugins array in your zshrc file: + +```zsh +plugins=(... git-lfs) +``` + +## Aliases + +| Alias | Command | +| :------- | :---------------------------------- | +| `glfsi` | `git lfs install` | +| `glfst` | `git lfs track` | +| `glfsls` | `git lfs ls-files` | +| `glfsmi` | `git lfs migrate import --include=` | + +## Functions + +| Function | Command | +| :------- | :---------------------------------------------- | +| `gplfs` | `git lfs push origin "$(current_branch)" --all` | diff --git a/plugins/git-lfs/git-lfs.plugin.zsh b/plugins/git-lfs/git-lfs.plugin.zsh new file mode 100644 index 000000000..e7bb67603 --- /dev/null +++ b/plugins/git-lfs/git-lfs.plugin.zsh @@ -0,0 +1,17 @@ +# +# Aliases +# + +alias glfsi='git lfs install' +alias glfst='git lfs track' +alias glfsls='git lfs ls-files' +alias glfsmi='git lfs migrate import --include=' + +# +# Functions +# + +function gplfs() { + local b="$(git_current_branch)" + git lfs push origin "$b" --all +} From df58625ca62ebb6ff5b7730717fdd55afdd28e63 Mon Sep 17 00:00:00 2001 From: Tom Hale Date: Fri, 9 Oct 2020 17:39:23 +0700 Subject: [PATCH 015/848] safe-paste: refresh plugin (update for zsh 5.1 and vi keymaps) (#7887) --- plugins/safe-paste/safe-paste.plugin.zsh | 122 ++++++++++++++++------- 1 file changed, 84 insertions(+), 38 deletions(-) diff --git a/plugins/safe-paste/safe-paste.plugin.zsh b/plugins/safe-paste/safe-paste.plugin.zsh index 75f1791d7..db524538c 100644 --- a/plugins/safe-paste/safe-paste.plugin.zsh +++ b/plugins/safe-paste/safe-paste.plugin.zsh @@ -1,54 +1,100 @@ +# A good summary of the zsh 5.1 Bracketed Paste Mode changes is at: +# https://archive.zhimingwang.org/blog/2015-09-21-zsh-51-and-bracketed-paste.html + +# zsh 5.1 (September 2015) introduced built-in support for Bracketed Paste Mode +# https://github.com/zsh-users/zsh/blob/68405f31a043bdd5bf338eb06688ed3e1f740937/README#L38-L45 +# +# zsh 5.1 breaks url-quote-magic and other widgets replacing self-insert +# zsh-users' bracketed-paste-magic resolves these issues: +# https://github.com/zsh-users/zsh/blob/f702e17b14d75aa21bff014168fa9048124db286/Functions/Zle/bracketed-paste-magic#L9-L12 + +# Load bracketed-paste-magic if zsh version is >= 5.1 +if [[ ${ZSH_VERSION:0:3} -ge 5.1 ]]; then + set zle_bracketed_paste # Explicitly restore this zsh default + autoload -Uz bracketed-paste-magic + zle -N bracketed-paste bracketed-paste-magic + return ### The rest of this file is NOT executed on zsh version >= 5.1 ### +fi + +###################################################################### +# The rest of this file is ONLY executed if zsh version < 5.1 +###################################################################### + # Code from Mikael Magnusson: https://www.zsh.org/mla/users/2011/msg00367.html # -# Requires xterm, urxvt, iTerm2 or any other terminal that supports bracketed -# paste mode as documented: https://www.xfree86.org/current/ctlseqs.html +# Requires xterm, urxvt, iTerm2 or any other terminal that supports +# Bracketed Paste Mode as documented: +# https://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode +# +# For tmux, use: bind ] paste-buffer -p +# +# Additional technical details: https://cirw.in/blog/bracketed-paste -# create a new keymap to use while pasting -bindkey -N paste -# make everything in this keymap call our custom widget -bindkey -R -M paste "^@"-"\M-^?" paste-insert -# these are the codes sent around the pasted text in bracketed -# paste mode. -# do the first one with both -M viins and -M vicmd in vi mode -bindkey '^[[200~' _start_paste -bindkey -M paste '^[[201~' _end_paste -# insert newlines rather than carriage returns when pasting newlines -bindkey -M paste -s '^M' '^J' +# Create a new keymap to use while pasting +bindkey -N bracketed-paste +# Make everything in this new keymap enqueue characters for pasting +bindkey -RM bracketed-paste '\x00-\xFF' bracketed-paste-enqueue +# These are the codes sent around the pasted text in bracketed paste mode +bindkey -M main '^[[200~' _bracketed_paste_begin +bindkey -M bracketed-paste '^[[201~' _bracketed_paste_end +# Insert newlines rather than carriage returns when pasting newlines +bindkey -M bracketed-paste -s '^M' '^J' -zle -N _start_paste -zle -N _end_paste -zle -N zle-line-init _zle_line_init -zle -N zle-line-finish _zle_line_finish -zle -N paste-insert _paste_insert +zle -N _bracketed_paste_begin +zle -N _bracketed_paste_end +zle -N bracketed-paste-enqueue _bracketed_paste_enqueue -# switch the active keymap to paste mode -function _start_paste() { - bindkey -A paste main +# Attempt to not clobber zle_line_{init,finish} +# Use https://github.com/willghatch/zsh-hooks if available +if typeset -f hooks-add-hook > /dev/null; then + hooks-add-hook zle_line_init_hook _bracketed_paste_zle_init + hooks-add-hook zle_line_finish_hook _bracketed_paste_zle_finish +else + zle -N zle-line-init _bracketed_paste_zle_init + zle -N zle-line-finish _bracketed_paste_zle_finish +fi + +# Switch the active keymap to paste mode +_bracketed_paste_begin() { + # Save the bindkey command to restore the active ("main") keymap + # Tokenise the restorative bindkey command into an array + _bracketed_paste_restore_keymap=( ${(z)"$(bindkey -lL main)"} ) + bindkey -A bracketed-paste main } -# go back to our normal keymap, and insert all the pasted text in the -# command line. this has the nice effect of making the whole paste be +# Go back to our normal keymap, and insert all the pasted text in the +# command line. This has the nice effect of making the whole paste be # a single undo/redo event. -function _end_paste() { -#use bindkey -v here with vi mode probably. maybe you want to track -#if you were in ins or cmd mode and restore the right one. - bindkey -e - LBUFFER+=$_paste_content - unset _paste_content +_bracketed_paste_end() { + # Only execute the restore command if it starts with 'bindkey' + # Allow for option KSH_ARRAYS being set (indexing starts at 0) + if [ ${_bracketed_paste_restore_keymap[@]:0:1} = 'bindkey' ]; then + $_bracketed_paste_restore_keymap + fi + LBUFFER+=$_bracketed_paste_content + unset _bracketed_paste_content _bracketed_paste_restore_keymap } -function _paste_insert() { - _paste_content+=$KEYS +# Append a pasted character to the content which is later inserted as a whole +_bracketed_paste_enqueue() { + _bracketed_paste_content+=$KEYS } -function _zle_line_init() { - # Tell terminal to send escape codes around pastes. - [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM = screen-256color ]] && printf '\e[?2004h' +# Run at zle-line-init +_bracketed_paste_zle_init() { + _bracketed_paste_content='' + # Tell terminal to send escape codes around pastes + if [ $TERM =~ '^(rxvt-unicode|xterm(-256color)?|screen(-256color)?)$' ]; then + printf '\e[?2004h' + fi } -function _zle_line_finish() { - # Tell it to stop when we leave zle, so pasting in other programs - # doesn't get the ^[[200~ codes around the pasted text. - [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM = screen-256color ]] && printf '\e[?2004l' +# Run at zle-line-finish +_bracketed_paste_zle_finish() { + # Turn off bracketed paste when we leave ZLE, so pasting in other programs + # doesn't get the ^[[200~ codes around the pasted text + if [ $TERM =~ '^(rxvt-unicode|xterm(-256color)?|screen(-256color)?)$' ]; then + printf '\e[?2004l' + fi } From 297238b739fd51f03ab9b3ffcc6c644daa4a1401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20D=C4=99bski?= Date: Fri, 11 Mar 2016 16:59:40 +0100 Subject: [PATCH 016/848] lib: hide git_prompt_status when hide-status is set Closes #4912 Closes #5137 Closes #8071 --- lib/git.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/git.zsh b/lib/git.zsh index ffc7c01a1..b3b25f802 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -151,6 +151,8 @@ function git_prompt_long_sha() { function git_prompt_status() { emulate -L zsh + [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return + local INDEX STATUS INDEX=$(__git_prompt_git status --porcelain -b 2> /dev/null) || return 0 STATUS="" From 45a954cb0f8b67e35529efbcdf60f0621d95f4a1 Mon Sep 17 00:00:00 2001 From: Billy Conn Date: Thu, 13 Oct 2016 22:31:44 -0500 Subject: [PATCH 017/848] git_prompt_status now uses hash lookups instead of multiple greps --- lib/git.zsh | 124 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 91 insertions(+), 33 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index b3b25f802..578f319e4 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -147,46 +147,104 @@ function git_prompt_long_sha() { SHA=$(__git_prompt_git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" } -# Get the status of the working tree function git_prompt_status() { - emulate -L zsh - [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return - local INDEX STATUS - INDEX=$(__git_prompt_git status --porcelain -b 2> /dev/null) || return 0 - STATUS="" - if [[ "${INDEX}" =~ $'(^|\n)\\?\\? ' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS" - fi - if [[ "${INDEX}" =~ $'(^|\n)(A |M |MM) ' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" - fi - if [[ "${INDEX}" =~ $'(^|\n)([ AM]M| T) ' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" - fi - if [[ "${INDEX}" =~ $'(^|\n)R ' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS" - fi - if [[ "${INDEX}" =~ $'(^|\n)([A ]D|D ) ' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + local status_prompt="" + + # A lookup table of each git status encountered + local -A statuses_seen + + # Maps a git status prefix to an internal constant + # This cannot use the prompt constants, as they may be empty + local -A prefix_constant_map=( + '?? ' 'UNTRACKED' + 'A ' 'ADDED' + 'M ' 'ADDED' + 'MM ' 'ADDED' + ' M ' 'MODIFIED' + 'AM ' 'MODIFIED' + ' T ' 'MODIFIED' + 'R ' 'RENAMED' + ' D ' 'DELETED' + 'D ' 'DELETED' + 'UU ' 'UNMERGED' + 'ahead' 'AHEAD' + 'behind' 'BEHIND' + 'diverged' 'DIVERGED' + 'stashed' 'STASHED' + ) + + # Maps the internal constant to the prompt theme + local -A constant_prompt_map=( + 'UNTRACKED' "$ZSH_THEME_GIT_PROMPT_UNTRACKED" + 'ADDED' "$ZSH_THEME_GIT_PROMPT_ADDED" + 'MODIFIED' "$ZSH_THEME_GIT_PROMPT_MODIFIED" + 'RENAMED' "$ZSH_THEME_GIT_PROMPT_RENAMED" + 'DELETED' "$ZSH_THEME_GIT_PROMPT_DELETED" + 'UNMERGED' "$ZSH_THEME_GIT_PROMPT_UNMERGED" + 'AHEAD' "$ZSH_THEME_GIT_PROMPT_AHEAD" + 'BEHIND' "$ZSH_THEME_GIT_PROMPT_BEHIND" + 'DIVERGED' "$ZSH_THEME_GIT_PROMPT_DIVERGED" + 'STASHED' "$ZSH_THEME_GIT_PROMPT_STASHED" + ) + + # The order that the prompt displays should be added to the prompt + local status_constants=(UNTRACKED ADDED MODIFIED RENAMED DELETED STASHED + UNMERGED AHEAD BEHIND DIVERGED) + + local status_text=$(__git_prompt_git status --porcelain -b 2> /dev/null) + + # Don't continue on a catastrophic failure + if [[ $? -eq 128 ]]; then + return 1 fi + if $(__git_prompt_git rev-parse --verify refs/stash >/dev/null 2>&1); then - STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS" + statuses_seen['STASHED']=1 fi - if [[ "${INDEX}" =~ $'(^|\n)UU ' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" + + local status_lines=("${(@f)${status_text}}"); + + # If the tracking line exists, get and parse it + if [[ $status_lines[1] =~ "^## [^ ]+ \[(.*)\]" ]]; then + local branch_statuses=("${(@s/,/)match}") + for branch_status in $branch_statuses; do + if [[ ! $branch_status =~ "(behind|diverged|ahead) ([0-9]+)?" ]]; then + continue + fi + local last_parsed_status=$prefix_constant_map[$match[1]] + statuses_seen[$last_parsed_status]=$match[2] + done + shift status_lines fi - if [[ "${INDEX}" =~ $'(^|\n)## [^ ]\+ .*ahead' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" - fi - if [[ "${INDEX}" =~ $'(^|\n)## [^ ]\+ .*behind' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" - fi - if [[ "${INDEX}" =~ $'(^|\n)## [^ ]\+ .*diverged' ]]; then - STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" - fi - echo $STATUS + + # This not only gives us a status lookup, but the count of each type + for status_line in ${status_lines}; do + local status_prefix=${status_line[1, 3]} + local status_constant=${(v)prefix_constant_map[$status_prefix]} + + if [[ -z $status_constant ]]; then + continue + fi + + (( statuses_seen[$status_constant]++ )) + done + + # At this point, the statuses_seen hash contains: + # - Tracking => The difference between tracked and current + # - Modifications => The count of that type of modification + # - Stash => Whether or not a stash exists + # Might be useful for someone? + + for status_constant in $status_constants; do + if [[ ${+statuses_seen[$status_constant]} -eq 1 ]]; then + local next_display=$constant_prompt_map[$status_constant] + status_prompt="$next_display$status_prompt" + fi + done + + echo $status_prompt } # Outputs the name of the current user From 865f6572d586e7ba1231333cadf808002688603e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 14 Apr 2018 23:37:45 +0200 Subject: [PATCH 018/848] Fix performance drop of iterating over lines and other stuff - Fix 'STASHED' key and unsupported syntax in 5.0.2 - Optimise `if` statement to make it more idiomatic. --- lib/git.zsh | 62 ++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index 578f319e4..f9b27949e 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -150,15 +150,11 @@ function git_prompt_long_sha() { function git_prompt_status() { [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return - local status_prompt="" - - # A lookup table of each git status encountered - local -A statuses_seen - # Maps a git status prefix to an internal constant # This cannot use the prompt constants, as they may be empty - local -A prefix_constant_map=( - '?? ' 'UNTRACKED' + local -A prefix_constant_map + prefix_constant_map=( + '\?\? ' 'UNTRACKED' 'A ' 'ADDED' 'M ' 'ADDED' 'MM ' 'ADDED' @@ -176,7 +172,8 @@ function git_prompt_status() { ) # Maps the internal constant to the prompt theme - local -A constant_prompt_map=( + local -A constant_prompt_map + constant_prompt_map=( 'UNTRACKED' "$ZSH_THEME_GIT_PROMPT_UNTRACKED" 'ADDED' "$ZSH_THEME_GIT_PROMPT_ADDED" 'MODIFIED' "$ZSH_THEME_GIT_PROMPT_MODIFIED" @@ -190,25 +187,33 @@ function git_prompt_status() { ) # The order that the prompt displays should be added to the prompt - local status_constants=(UNTRACKED ADDED MODIFIED RENAMED DELETED STASHED - UNMERGED AHEAD BEHIND DIVERGED) + local status_constants + status_constants=( + UNTRACKED ADDED MODIFIED RENAMED DELETED + STASHED UNMERGED AHEAD BEHIND DIVERGED + ) - local status_text=$(__git_prompt_git status --porcelain -b 2> /dev/null) + local status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)" # Don't continue on a catastrophic failure if [[ $? -eq 128 ]]; then return 1 fi - if $(__git_prompt_git rev-parse --verify refs/stash >/dev/null 2>&1); then - statuses_seen['STASHED']=1 + # A lookup table of each git status encountered + local -A statuses_seen + + if __git_prompt_git rev-parse --verify refs/stash &>/dev/null; then + statuses_seen[STASHED]=1 fi - local status_lines=("${(@f)${status_text}}"); + local status_lines + status_lines=("${(@f)${status_text}}") # If the tracking line exists, get and parse it - if [[ $status_lines[1] =~ "^## [^ ]+ \[(.*)\]" ]]; then - local branch_statuses=("${(@s/,/)match}") + if [[ "$status_lines[1]" =~ "^## [^ ]+ \[(.*)\]" ]]; then + local branch_statuses + branch_statuses=("${(@s/,/)match}") for branch_status in $branch_statuses; do if [[ ! $branch_status =~ "(behind|diverged|ahead) ([0-9]+)?" ]]; then continue @@ -216,29 +221,22 @@ function git_prompt_status() { local last_parsed_status=$prefix_constant_map[$match[1]] statuses_seen[$last_parsed_status]=$match[2] done - shift status_lines fi - # This not only gives us a status lookup, but the count of each type - for status_line in ${status_lines}; do - local status_prefix=${status_line[1, 3]} - local status_constant=${(v)prefix_constant_map[$status_prefix]} + # For each status prefix, do a regex comparison + for status_prefix in ${(k)prefix_constant_map}; do + local status_constant="${prefix_constant_map[$status_prefix]}" + local status_regex="(^|\n)$status_prefix" - if [[ -z $status_constant ]]; then - continue + if [[ "$status_text" =~ $status_regex ]]; then + statuses_seen[$status_constant]=1 fi - - (( statuses_seen[$status_constant]++ )) done - # At this point, the statuses_seen hash contains: - # - Tracking => The difference between tracked and current - # - Modifications => The count of that type of modification - # - Stash => Whether or not a stash exists - # Might be useful for someone? - + # Display the seen statuses in the order specified + local status_prompt for status_constant in $status_constants; do - if [[ ${+statuses_seen[$status_constant]} -eq 1 ]]; then + if (( ${+statuses_seen[$status_constant]} )); then local next_display=$constant_prompt_map[$status_constant] status_prompt="$next_display$status_prompt" fi From 1bb402190d53c118f47a0851f5714dd4faa52809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 9 Oct 2020 13:55:56 +0200 Subject: [PATCH 019/848] lib: add plugin and theme subcommands and fix `omz pr clean` - Add plugin and theme subcommand Fixes #8961 - Add confirmation prompt to `omz pr clean` command - Correct behavior on invalid answers on confirmation prompts If an invalid option is supplied, don't proceed with the potentially destructive action. Co-authored-by: Rishabh Bohra --- lib/cli.zsh | 174 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 156 insertions(+), 18 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index c1ae2bdf2..0c0f3f623 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -23,16 +23,27 @@ function _omz { local -a cmds subcmds cmds=( 'help:Usage information' + 'plugin:Commands for Oh My Zsh plugins management' + 'pr:Commands for Oh My Zsh Pull Requests management' + 'theme:Commands for Oh My Zsh themes management' 'update:Update Oh My Zsh' - 'pr:Commands for Oh My Zsh Pull Requests' ) if (( CURRENT == 2 )); then _describe 'command' cmds elif (( CURRENT == 3 )); then case "$words[2]" in - pr) subcmds=( 'test:Test a Pull Request' 'clean:Delete all Pull Request branches' ) + plugin) subcmds=('list:List plugins') _describe 'command' subcmds ;; + pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches') + _describe 'command' subcmds ;; + theme) subcmds=('use:Load a theme' 'list:List themes') + _describe 'command' subcmds ;; + esac + elif (( CURRENT == 4 )); then + case "$words[2]::$words[3]" in + theme::use) compadd "$ZSH"/themes/*.zsh-theme(.N:t:r) \ + "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::) ;; esac fi @@ -49,23 +60,40 @@ Usage: omz [options] Available commands: help Print this help message + pr Commands for Oh My Zsh Pull Requests management + theme Commands for Oh My Zsh themes management update Update Oh My Zsh - pr Commands for Oh My Zsh Pull Requests EOF } +function _omz::confirm { + # If question supplied, ask it before reading the answer + # NOTE: uses the logname of the caller function + if [[ -n "$1" ]]; then + _omz::log prompt "$1" "${${functrace[1]#_}%:*}" + fi + + # Read one character + read -r -k 1 + + # If no newline entered, add a newline + if [[ "$REPLY" != $'\n' ]]; then + echo + fi +} + function _omz::log { # if promptsubst is set, a message with `` or $() # will be run even if quoted due to `print -P` setopt localoptions nopromptsubst # $1 = info|warn|error|debug - # $@ = text + # $2 = text + # $3 = (optional) name of the logger local logtype=$1 - local logname=${${functrace[1]#_}%:*} - shift + local logname=${3:-${${functrace[1]#_}%:*}} # Don't print anything if debug is not active if [[ $logtype = debug && -z $_OMZ_DEBUG ]]; then @@ -74,14 +102,52 @@ function _omz::log { # Choose coloring based on log type case "$logtype" in - prompt) print -Pn "%S%F{blue}$logname%f%s: $@" ;; - debug) print -P "%F{white}$logname%f: $@" ;; - info) print -P "%F{green}$logname%f: $@" ;; - warn) print -P "%S%F{yellow}$logname%f%s: $@" ;; - error) print -P "%S%F{red}$logname%f%s: $@" ;; + prompt) print -Pn "%S%F{blue}$logname%f%s: $2" ;; + debug) print -P "%F{white}$logname%f: $2" ;; + info) print -P "%F{green}$logname%f: $2" ;; + warn) print -P "%S%F{yellow}$logname%f%s: $2" ;; + error) print -P "%S%F{red}$logname%f%s: $2" ;; esac >&2 } +function _omz::plugin { + (( $# > 0 && $+functions[_omz::plugin::$1] )) || { + cat < [options] + +Available commands: + + list List all available Oh My Zsh plugins + +EOF + return 1 + } + + local command="$1" + shift + + _omz::plugin::$command "$@" +} + +function _omz::plugin::list { + local -a custom_plugins builtin_plugins + custom_plugins=("$ZSH_CUSTOM"/plugins/*(/N:t)) + builtin_plugins=("$ZSH"/plugins/*(/N:t)) + + (( ${#custom_plugins} )) && { + print -Pn "%U%BCustom plugins%b%u: " + print -l ${(q-)custom_plugins} + } | fmt -w $COLUMNS + + (( ${#builtin_plugins} )) && { + # add a line of separation + (( ${#custom_plugins} )) && echo + + print -Pn "%U%BBuilt-in plugins%b%u: " + print -l ${(q-)builtin_plugins} + } | fmt -w $COLUMNS +} + function _omz::pr { (( $# > 0 && $+functions[_omz::pr::$1] )) || { cat < 0 && $+functions[_omz::theme::$1] )) || { + cat < [options] + +Available commands: + + list List all available Oh My Zsh themes + use Load an Oh My Zsh theme + +EOF + return 1 + } + + local command="$1" + shift + + _omz::theme::$command "$@" +} + +function _omz::theme::list { + local -a custom_themes builtin_themes + custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)) + builtin_themes=("$ZSH"/themes/*.zsh-theme(.N:t:r)) + + (( ${#custom_themes} )) && { + print -Pn "%U%BCustom themes%b%u: " + print -l ${(q-)custom_themes} + } | fmt -w $COLUMNS + + (( ${#builtin_themes} )) && { + # add a line of separation + (( ${#custom_themes} )) && echo + + print -Pn "%U%BBuilt-in themes%b%u: " + print -l ${(q-)builtin_themes} + } | fmt -w $COLUMNS +} + +function _omz::theme::use { + if [[ -z "$1" ]]; then + echo >&2 "Usage: omz theme use " + return 1 + fi + + # Respect compatibility with old lookup order + if [[ -f "$ZSH_CUSTOM/$1.zsh-theme" ]]; then + source "$ZSH_CUSTOM/$1.zsh-theme" + elif [[ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]]; then + source "$ZSH_CUSTOM/themes/$1.zsh-theme" + elif [[ -f "$ZSH/themes/$1.zsh-theme" ]]; then + source "$ZSH/themes/$1.zsh-theme" + else + _omz::log error "theme '$1' not found" + return 1 + fi +} + function _omz::update { # Run update script env ZSH="$ZSH" sh "$ZSH/tools/upgrade.sh" From fc6c9ca4b40ee1c9ba7fb4b1c8862fb54a8cb1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 9 Oct 2020 15:03:03 +0200 Subject: [PATCH 020/848] lib: fix formatting in `omz pr clean` CLI command --- lib/cli.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 0c0f3f623..5d6c31aef 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -175,7 +175,7 @@ function _omz::pr::clean { # Check if there are PR branches local fmt branches - fmt="%(align:19,right)%(color:bold blue)%(refname:short)%(end)%(color:reset) %(color:dim bold red)%(objectname:short)%(color:reset) %(color:yellow)%(contents:subject)" + fmt="%(color:bold blue)%(align:18,right)%(refname:short)%(end)%(color:reset) %(color:dim bold red)%(objectname:short)%(color:reset) %(color:yellow)%(contents:subject)" branches="$(command git for-each-ref --sort=-committerdate --color --format="$fmt" "refs/heads/ohmyzsh/pull-*")" # Exit if there are no PR branches From ef44416df2e2ae819b13764dbf6ca87ce099ec36 Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Thu, 10 Sep 2015 04:10:18 -0400 Subject: [PATCH 021/848] nvm: use `nvm current` in nvm_prompt_info and look in alternate install locations This makes it work regardless of where nvm is loaded from. And it uses nvm's version strings, which distinguish the "system" and "none" NVM environments, instead of reporting the specific version of the system node.js or erroring, respectively. Fixes #4336 Closes #4338 --- lib/nvm.zsh | 9 +++--- plugins/nvm/nvm.plugin.zsh | 62 ++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/lib/nvm.zsh b/lib/nvm.zsh index 4a8b6811e..c4f70c849 100644 --- a/lib/nvm.zsh +++ b/lib/nvm.zsh @@ -1,9 +1,8 @@ -# get the node.js version +# get the nvm-controlled node.js version function nvm_prompt_info() { - [[ -f "$NVM_DIR/nvm.sh" ]] || return local nvm_prompt - nvm_prompt=$(node -v 2>/dev/null) - [[ "${nvm_prompt}x" == "x" ]] && return - nvm_prompt=${nvm_prompt:1} + which nvm &>/dev/null || return + nvm_prompt=$(nvm current) + nvm_prompt=${nvm_prompt#v} echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}" } diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 2264a2420..ee8d2324b 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -1,23 +1,45 @@ -# Set NVM_DIR if it isn't already defined -[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm" +# nvm +# +# This plugin locates and loads nvm, looking for it in well-known locations. -# Don't try to load nvm if command already available -type "nvm" &> /dev/null && return +() { + emulate -L zsh + local nvm_install_dir="" dir install_locations + if [[ -n $NVM_INSTALL_DIR ]]; then + # User-specified path + nvm_install_dir=$NVM_INSTALL_DIR + else + # Well-known common installation locations for NVM + install_locations=( ~/.nvm ) + [[ -n $NVM_DIR ]] && install_locations=($NVM_DIR $install_locations) + # Mac Homebrew sticks + which brew &>/dev/null && install_locations+=$(brew --prefix nvm) + for dir ($install_locations); do + if [[ -s $dir/nvm.sh ]]; then + nvm_install_dir=$dir + break + fi + done + fi -# Load nvm if it exists in $NVM_DIR -if [[ -f "$NVM_DIR/nvm.sh" ]]; then - source "$NVM_DIR/nvm.sh" - return -fi + if [[ -n $nvm_install_dir ]]; then + source $nvm_install_dir/nvm.sh + else + # No NVM installation found + return 0 + fi -# Otherwise try to load nvm installed via Homebrew - -# User can set this if they have an unusual Homebrew setup -NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}" -# Load nvm from Homebrew location if it exists -[[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" -# Load nvm bash completion from Homebrew if it exists -if [[ -f "$NVM_HOMEBREW/etc/bash_completion.d/nvm" ]]; then - autoload -U +X bashcompinit && bashcompinit - source "$NVM_HOMEBREW/etc/bash_completion.d/nvm" -fi + # Locate and use the completion file shipped with NVM, instead of this + # plugin's completion + # (Their bash completion file has zsh portability support) + if [[ $ZSH_NVM_BUNDLED_COMPLETION == true ]]; then + local bash_comp_file + # Homebrew relocates the bash completion file, so look multiple places + for bash_comp_file ( bash_completion etc/bash_completion.d/nvm ); do + if [[ -s $nvm_install_dir/$bash_comp_file ]]; then + source $nvm_install_dir/$bash_comp_file + break; + fi + done + fi +} From d8cb67023540c1e2e7e4e211e2f7c9fc2d4e0c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 9 Oct 2020 16:12:03 +0200 Subject: [PATCH 022/848] nvm: simplify nvm.sh and bash completion loading --- lib/nvm.zsh | 4 +-- plugins/nvm/nvm.plugin.zsh | 67 +++++++++++++++----------------------- 2 files changed, 27 insertions(+), 44 deletions(-) diff --git a/lib/nvm.zsh b/lib/nvm.zsh index c4f70c849..2fe57a8f4 100644 --- a/lib/nvm.zsh +++ b/lib/nvm.zsh @@ -1,8 +1,6 @@ # get the nvm-controlled node.js version function nvm_prompt_info() { - local nvm_prompt which nvm &>/dev/null || return - nvm_prompt=$(nvm current) - nvm_prompt=${nvm_prompt#v} + local nvm_prompt=${$(nvm current)#v} echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}" } diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index ee8d2324b..2c137894b 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -1,45 +1,30 @@ -# nvm -# -# This plugin locates and loads nvm, looking for it in well-known locations. +# Set NVM_DIR if it isn't already defined +[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm" -() { - emulate -L zsh - local nvm_install_dir="" dir install_locations - if [[ -n $NVM_INSTALL_DIR ]]; then - # User-specified path - nvm_install_dir=$NVM_INSTALL_DIR - else - # Well-known common installation locations for NVM - install_locations=( ~/.nvm ) - [[ -n $NVM_DIR ]] && install_locations=($NVM_DIR $install_locations) - # Mac Homebrew sticks - which brew &>/dev/null && install_locations+=$(brew --prefix nvm) - for dir ($install_locations); do - if [[ -s $dir/nvm.sh ]]; then - nvm_install_dir=$dir - break - fi - done - fi +# Don't try to load nvm if command already available +which nvm &> /dev/null && return - if [[ -n $nvm_install_dir ]]; then - source $nvm_install_dir/nvm.sh - else - # No NVM installation found - return 0 - fi +if [[ -f "$NVM_DIR/nvm.sh" ]]; then + # Load nvm if it exists in $NVM_DIR + source "$NVM_DIR/nvm.sh" +else + # Otherwise try to load nvm installed via Homebrew + # User can set this if they have an unusual Homebrew setup + NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}" + # Load nvm from Homebrew location if it exists + [[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" +fi - # Locate and use the completion file shipped with NVM, instead of this - # plugin's completion - # (Their bash completion file has zsh portability support) - if [[ $ZSH_NVM_BUNDLED_COMPLETION == true ]]; then - local bash_comp_file - # Homebrew relocates the bash completion file, so look multiple places - for bash_comp_file ( bash_completion etc/bash_completion.d/nvm ); do - if [[ -s $nvm_install_dir/$bash_comp_file ]]; then - source $nvm_install_dir/$bash_comp_file - break; - fi - done +# Load nvm bash completion +for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do + if [[ -f "$nvm_completion" ]]; then + # Load bashcompinit + autoload -U +X bashcompinit && bashcompinit + # Bypass compinit call in nvm bash completion script. See: + # https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93 + ZSH_VERSION= source "$nvm_completion" + break fi -} +done + +unset NVM_HOMEBREW nvm_completion From d6f3630932f364370c08b5a02b88c74aed577463 Mon Sep 17 00:00:00 2001 From: Chigozirim C Date: Sat, 27 Apr 2019 01:38:14 -0600 Subject: [PATCH 023/848] nvm: check $XDG_CONFIG_HOME/nvm for an nvm installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #7807 Co-authored-by: Marc Cornellà --- plugins/nvm/nvm.plugin.zsh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 2c137894b..21fb3112b 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -1,5 +1,11 @@ -# Set NVM_DIR if it isn't already defined -[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm" +# See https://github.com/nvm-sh/nvm#installation-and-update +if [[ -z "$NVM_DIR" ]]; then + if [[ -d "$HOME/.nvm" ]]; then + export NVM_DIR="$HOME/.nvm" + elif [[ -d "${XDG_CONFIG_HOME:-$HOME/.config}/nvm" ]]; then + export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvm" + fi +fi # Don't try to load nvm if command already available which nvm &> /dev/null && return From 3e973080037ae68ac25a08545e7cdc60ba128900 Mon Sep 17 00:00:00 2001 From: Keith Yao Date: Mon, 17 Sep 2018 11:14:29 +0200 Subject: [PATCH 024/848] nvm: speed-up nvm loading with `--no-use` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #7138 Co-authored-by: Marc Cornellà --- plugins/nvm/nvm.plugin.zsh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 21fb3112b..640f1d45c 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -12,15 +12,22 @@ which nvm &> /dev/null && return if [[ -f "$NVM_DIR/nvm.sh" ]]; then # Load nvm if it exists in $NVM_DIR - source "$NVM_DIR/nvm.sh" + source "$NVM_DIR/nvm.sh" --no-use else # Otherwise try to load nvm installed via Homebrew # User can set this if they have an unusual Homebrew setup NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}" # Load nvm from Homebrew location if it exists - [[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" + [[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" --no-use fi +# Call nvm when first using node, npm or yarn +function node npm yarn { + unfunction node npm yarn + nvm use default + command "$0" "$@" +} + # Load nvm bash completion for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do if [[ -f "$nvm_completion" ]]; then From a33c0cdb46badcc1df9a37da015a82f7f7b0a7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 9 Oct 2020 16:35:47 +0200 Subject: [PATCH 025/848] nvm: only lazy-load nvm if the NVM_LAZY setting is set --- plugins/nvm/README.md | 4 ++++ plugins/nvm/nvm.plugin.zsh | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index 2515da9e8..ab71185cb 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -16,3 +16,7 @@ plugins=(... nvm) - **`NVM_HOMEBREW`**: if you installed nvm via Homebrew, in a directory other than `/usr/local/opt/nvm`, you can set `NVM_HOMEBREW` to be the directory where you installed it. + +- **`NVM_LAZY`**: if you want the plugin to defer the load of nvm to speed-up the start of your zsh session, + set `NVM_LAZY` to `1`. This will use the `--no-use` parameter when loading nvm, and will create a function + for `node`, `npm` and `yarn`, so when you call either of these three, nvm will load with `nvm use default`. diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 640f1d45c..164be5907 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -12,21 +12,23 @@ which nvm &> /dev/null && return if [[ -f "$NVM_DIR/nvm.sh" ]]; then # Load nvm if it exists in $NVM_DIR - source "$NVM_DIR/nvm.sh" --no-use + source "$NVM_DIR/nvm.sh" ${NVM_LAZY+"--no-use"} else # Otherwise try to load nvm installed via Homebrew # User can set this if they have an unusual Homebrew setup NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}" # Load nvm from Homebrew location if it exists - [[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" --no-use + [[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" ${NVM_LAZY+"--no-use"} fi # Call nvm when first using node, npm or yarn -function node npm yarn { - unfunction node npm yarn - nvm use default - command "$0" "$@" -} +if (( $+NVM_LAZY )); then + function node npm yarn { + unfunction node npm yarn + nvm use default + command "$0" "$@" + } +fi # Load nvm bash completion for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do From 8163f65084b86d5e63c1867d076ecdc8faca2f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 9 Oct 2020 16:40:13 +0200 Subject: [PATCH 026/848] nvm: exit the plugin if the nvm loading script wasn't found --- plugins/nvm/nvm.plugin.zsh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 164be5907..b2355b7ef 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -18,7 +18,12 @@ else # User can set this if they have an unusual Homebrew setup NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}" # Load nvm from Homebrew location if it exists - [[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" ${NVM_LAZY+"--no-use"} + if [[ -f "$NVM_HOMEBREW/nvm.sh" ]]; then + source "$NVM_HOMEBREW/nvm.sh" ${NVM_LAZY+"--no-use"} + else + # Exit the plugin if we couldn't find nvm + return + fi fi # Call nvm when first using node, npm or yarn @@ -42,4 +47,4 @@ for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_complet fi done -unset NVM_HOMEBREW nvm_completion +unset NVM_HOMEBREW NVM_LAZY nvm_completion From 8c8fe2a1715df916f0b5d785fee32c8a4a40c05b Mon Sep 17 00:00:00 2001 From: Danny Grove Date: Fri, 13 Jan 2017 17:15:12 -0800 Subject: [PATCH 027/848] nvm: add autoloading of nvm version in .nvmrc Closes #5782 Fixes #8959 Closes #8976 --- plugins/nvm/README.md | 4 ++++ plugins/nvm/nvm.plugin.zsh | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index ab71185cb..749a43403 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -20,3 +20,7 @@ plugins=(... nvm) - **`NVM_LAZY`**: if you want the plugin to defer the load of nvm to speed-up the start of your zsh session, set `NVM_LAZY` to `1`. This will use the `--no-use` parameter when loading nvm, and will create a function for `node`, `npm` and `yarn`, so when you call either of these three, nvm will load with `nvm use default`. + +- **`NVM_AUTOLOAD`**: if `NVM_AUTOLOAD` is set to `1`, the plugin will automatically load a node version when + if finds a [`.nvmrc` file](https://github.com/nvm-sh/nvm#nvmrc) in the current working directory indicating + which node version to load. diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index b2355b7ef..1e9b26e7a 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -35,6 +35,33 @@ if (( $+NVM_LAZY )); then } fi +# Autoload nvm when finding a .nvmrc file in the current directory +# Adapted from: https://github.com/nvm-sh/nvm#zsh +if (( $+NVM_AUTOLOAD )); then + load-nvmrc() { + local node_version="$(nvm version)" + local nvmrc_path="$(nvm_find_nvmrc)" + + if [[ -n "$nvmrc_path" ]]; then + local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") + + if [[ "$nvmrc_node_version" = "N/A" ]]; then + nvm install + elif [[ "$nvmrc_node_version" != "$node_version" ]]; then + nvm use + fi + elif [[ "$node_version" != "$(nvm version default)" ]]; then + echo "Reverting to nvm default version" + nvm use default + fi + } + + autoload -U add-zsh-hook + add-zsh-hook chpwd load-nvmrc + + load-nvmrc +fi + # Load nvm bash completion for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do if [[ -f "$nvm_completion" ]]; then @@ -47,4 +74,4 @@ for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_complet fi done -unset NVM_HOMEBREW NVM_LAZY nvm_completion +unset NVM_HOMEBREW NVM_LAZY NVM_AUTOLOAD nvm_completion From 2abe4d6a2576f064c09ce78b32005e7437a93ee0 Mon Sep 17 00:00:00 2001 From: Atk Date: Fri, 9 Oct 2020 16:38:02 +0100 Subject: [PATCH 028/848] wd: update to v0.5.1 (#9273) --- plugins/wd/wd.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/wd/wd.sh b/plugins/wd/wd.sh index d5d38f25b..9085c5b7b 100644 --- a/plugins/wd/wd.sh +++ b/plugins/wd/wd.sh @@ -71,7 +71,7 @@ wd_print_msg() wd_print_usage() { - cat <<- EOF + command cat <<- EOF Usage: wd [command] [point] Commands: @@ -175,9 +175,9 @@ wd_add() elif [[ $point =~ "[[:space:]]+" ]] then wd_exit_fail "Warp point should not contain whitespace" - elif [[ $point == *:* ]] + elif [[ $point =~ : ]] || [[ $point =~ / ]] then - wd_exit_fail "Warp point cannot contain colons" + wd_exit_fail "Warp point contains illegal character (:/)" elif [[ ${points[$point]} == "" ]] || [ ! -z "$force" ] then wd_remove "$point" > /dev/null @@ -185,7 +185,7 @@ wd_add() if (whence sort >/dev/null); then local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX") # use 'cat' below to ensure we respect $WD_CONFIG as a symlink - sort -o "${config_tmp}" "$WD_CONFIG" && cat "${config_tmp}" > "$WD_CONFIG" && rm "${config_tmp}" + command sort -o "${config_tmp}" "$WD_CONFIG" && command cat "${config_tmp}" > "$WD_CONFIG" && command rm "${config_tmp}" fi wd_export_static_named_directories @@ -270,7 +270,7 @@ wd_ls() wd_path() { wd_getdir "$1" - echo "$(echo "$dir" | sed "s:${HOME}:~:g")" + echo "$(echo "$dir" | sed "s:~:${HOME}:g")" } wd_show() From e93a2dca0e893cd1518e98cce44b55a6dbf29c1a Mon Sep 17 00:00:00 2001 From: Geoffrey GREBERT Date: Fri, 9 Oct 2020 17:42:44 +0200 Subject: [PATCH 029/848] mvn: add Quarkus support in mvn completion (#9037) Co-authored-by: Geoffrey GREBERT --- plugins/mvn/README.md | 1 + plugins/mvn/mvn.plugin.zsh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/plugins/mvn/README.md b/plugins/mvn/README.md index cbe7f30fa..815dfd57c 100644 --- a/plugins/mvn/README.md +++ b/plugins/mvn/README.md @@ -19,6 +19,7 @@ if it's found, or the mvn command otherwise. | `mvn!` | `mvn -f /pom.xml` | | `mvnag` | `mvn archetype:generate` | | `mvnboot` | `mvn spring-boot:run` | +| `mvnqdev` | `mvn quarkus:dev` | | `mvnc` | `mvn clean` | | `mvncd` | `mvn clean deploy` | | `mvnce` | `mvn clean eclipse:clean eclipse:eclipse` | diff --git a/plugins/mvn/mvn.plugin.zsh b/plugins/mvn/mvn.plugin.zsh index 7cb94b42f..c616da789 100644 --- a/plugins/mvn/mvn.plugin.zsh +++ b/plugins/mvn/mvn.plugin.zsh @@ -62,6 +62,7 @@ alias mvne='mvn eclipse:eclipse' alias mvnfmt='mvn fmt:format' alias mvnjetty='mvn jetty:run' alias mvnp='mvn package' +alias mvnqdev='mvn quarkus:dev' alias mvns='mvn site' alias mvnsrc='mvn dependency:sources' alias mvnt='mvn test' @@ -184,6 +185,8 @@ function listMavenCompletions { tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy # spring-boot spring-boot:run spring-boot:repackage + # quarkus + quarkus:dev quarkus:list-extensions quarkus:add-extension quarkus:add-extensions quarkus:generate-config quarkus:help # exec exec:exec exec:java # versions From a5e706d749e4218820391cb7ea374c6ddd248933 Mon Sep 17 00:00:00 2001 From: James Zhang Date: Fri, 9 Oct 2020 23:45:30 +0800 Subject: [PATCH 030/848] mvn: list modules (directories with pom.xml) (#8478) Co-authored-by: zhangjinyan1 --- plugins/mvn/mvn.plugin.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/mvn/mvn.plugin.zsh b/plugins/mvn/mvn.plugin.zsh index c616da789..27d63a6f9 100644 --- a/plugins/mvn/mvn.plugin.zsh +++ b/plugins/mvn/mvn.plugin.zsh @@ -73,7 +73,7 @@ alias mvn-updates='mvn versions:display-dependency-updates' function listMavenCompletions { local file new_file - local -a profiles POM_FILES + local -a profiles POM_FILES modules # Root POM POM_FILES=(~/.m2/settings.xml) @@ -109,6 +109,9 @@ function listMavenCompletions { profiles+=($(sed 's///' "$file" | sed '//d' | grep -e "" -A 1 | grep -e ".*" | sed 's?.*\(.*\)<\/id>.*?-P\1?')) done + # List modules + modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|')) + reply=( # common lifecycle clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site @@ -271,8 +274,8 @@ function listMavenCompletions { stage:copy # toolchain toolchain:toolchain - #liberty - liberty:clean-server liberty:compile-jsp liberty:configure-arquillian liberty:create-server liberty:debug liberty:debug-server liberty:deploy liberty:dev liberty:display-url liberty:dump-server liberty:install-apps liberty:install-feature liberty:install-server liberty:java-dump-server liberty:package-server liberty:run liberty:run-server liberty:server-status liberty:start liberty:start-server liberty:status liberty:stop liberty:stop-server liberty:test-start-server liberty:test-stop-server liberty:undeploy liberty:uninstall-feature + #liberty + liberty:clean-server liberty:compile-jsp liberty:configure-arquillian liberty:create-server liberty:debug liberty:debug-server liberty:deploy liberty:dev liberty:display-url liberty:dump-server liberty:install-apps liberty:install-feature liberty:install-server liberty:java-dump-server liberty:package-server liberty:run liberty:run-server liberty:server-status liberty:start liberty:start-server liberty:status liberty:stop liberty:stop-server liberty:test-start-server liberty:test-stop-server liberty:undeploy liberty:uninstall-feature # options "-Dmaven.test.skip=true" -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile "-Dpmd.skip=true" "-Dcheckstyle.skip=true" "-Dtycho.mode=maven" "-Dmaven.test.failure.ignore=true" "-DgroupId=" "-DartifactId=" "-Dversion=" "-Dpackaging=jar" "-Dfile=" @@ -323,6 +326,7 @@ function listMavenCompletions { -Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi) $profiles + $modules ) } From 4cd5f7f9202bd062871662836ea837c9abea6e5d Mon Sep 17 00:00:00 2001 From: Joshua Bedford Date: Fri, 9 Oct 2020 16:13:00 -0500 Subject: [PATCH 031/848] Add lando plugin (#8748) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joshua Bedford Co-authored-by: Marc Cornellà --- plugins/lando/LICENSE | 21 ++++++++++++++++++ plugins/lando/README.md | 37 +++++++++++++++++++++++++++++++ plugins/lando/lando.plugin.zsh | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 plugins/lando/LICENSE create mode 100644 plugins/lando/README.md create mode 100644 plugins/lando/lando.plugin.zsh diff --git a/plugins/lando/LICENSE b/plugins/lando/LICENSE new file mode 100644 index 000000000..1d4983163 --- /dev/null +++ b/plugins/lando/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Joshua Bedford + +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. \ No newline at end of file diff --git a/plugins/lando/README.md b/plugins/lando/README.md new file mode 100644 index 000000000..928a42bca --- /dev/null +++ b/plugins/lando/README.md @@ -0,0 +1,37 @@ +# Lando ZSH (lando-zsh) + +This plugin adds aliases for using various languages and frameworks with [Lando](https://docs.lando.dev/basics/) for Docker. It will only run within lando-driven project directories. + +To use it, add `lando` to the plugins array in your zshrc file: + +```zsh +plugins=(... lando) +``` + +## ALIASES: + +| Alias | Description | +|:----------:|:----------------:| +| `artisan` | `lando artisan` | +| `composer` | `lando composer` | +| `drush` | `lando drush` | +| `gulp` | `lando gulp` | +| `npm` | `lando npm` | +| `wp` | `lando wp` | +| `yarn` | `lando yarn` | + +## How It Works: + +This plugin removes the requirement to type `lando` before a command. It utilizes the lando version of supported commands run within directories with the following criteria: +- The `.lando.yml` file is found in the current directory or any parent directory within `$LANDO_ZSH_SITES_DIRECTORY`. +- The current directory is within `$LANDO_ZSH_SITES_DIRECTORY` but is not `$LANDO_ZSH_SITES_DIRECTORY` itself. + +## Settings: + +- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory. +- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando. + +## Author: + +- Author: Joshua Bedford +- URL: [https://github.com/joshuabedford/lando-zsh](https://github.com/joshuabedford/lando-zsh) diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh new file mode 100644 index 000000000..aa74c9924 --- /dev/null +++ b/plugins/lando/lando.plugin.zsh @@ -0,0 +1,40 @@ +# Settings +: ${LANDO_ZSH_SITES_DIRECTORY:="$HOME/Sites"} +: ${LANDO_ZSH_CONFIG_FILE:=.lando.yml} + +# Enable multiple commands with lando. +function artisan \ + composer \ + drush \ + gulp \ + npm \ + wp \ + yarn { + if checkForLandoFile; then + lando "$0" "$@" + else + command "$0" "$@" + fi +} + +# Check for the file in the current and parent directories. +checkForLandoFile() { + # Only bother checking for lando within the Sites directory. + if [[ "$PWD/" != "$LANDO_ZSH_SITES_DIRECTORY"/* ]]; then + # Not within $LANDO_ZSH_SITES_DIRECTORY + return 1 + fi + + local curr_dir="$PWD" + # Checking for file: $LANDO_ZSH_CONFIG_FILE within $LANDO_ZSH_SITES_DIRECTORY... + while [[ "$curr_dir" != "$LANDO_ZSH_SITES_DIRECTORY" ]]; do + if [[ -f "$curr_dir/$LANDO_ZSH_CONFIG_FILE" ]]; then + return 0 + fi + curr_dir="${curr_dir:h}" + done + + # Could not find $LANDO_ZSH_CONFIG_FILE in the current directory + # or in any of its parents up to $LANDO_ZSH_SITES_DIRECTORY. + return 1 +} \ No newline at end of file From 982d010be5fdb1cff471978634f8ff374deba9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 10 Oct 2020 11:47:09 +0200 Subject: [PATCH 032/848] lib: fix fmt removing ESC characters in theme and plugin list CLI commands --- lib/cli.zsh | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 5d6c31aef..c9ee159bc 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -134,18 +134,20 @@ function _omz::plugin::list { custom_plugins=("$ZSH_CUSTOM"/plugins/*(/N:t)) builtin_plugins=("$ZSH"/plugins/*(/N:t)) - (( ${#custom_plugins} )) && { - print -Pn "%U%BCustom plugins%b%u: " - print -l ${(q-)custom_plugins} - } | fmt -w $COLUMNS + { + (( ${#custom_plugins} )) && { + print -Pn "%U%BCustom plugins%b%u: " + print -l ${(q-)custom_plugins} + } - (( ${#builtin_plugins} )) && { - # add a line of separation - (( ${#custom_plugins} )) && echo + (( ${#builtin_plugins} )) && { + # add a line of separation + (( ${#custom_plugins} )) && echo - print -Pn "%U%BBuilt-in plugins%b%u: " - print -l ${(q-)builtin_plugins} - } | fmt -w $COLUMNS + print -Pn "%U%BBuilt-in plugins%b%u: " + print -l ${(q-)builtin_plugins} + } + } | fmt -w $COLUMNS | sed -E $'s/\e?(\\[[0-9]*m)/\e\\1/g' # deal with fmt removing ESC } function _omz::pr { @@ -305,18 +307,20 @@ function _omz::theme::list { custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)) builtin_themes=("$ZSH"/themes/*.zsh-theme(.N:t:r)) - (( ${#custom_themes} )) && { - print -Pn "%U%BCustom themes%b%u: " - print -l ${(q-)custom_themes} - } | fmt -w $COLUMNS + { + (( ${#custom_themes} )) && { + print -Pn "%U%BCustom themes%b%u: " + print -l ${(q-)custom_themes} + } - (( ${#builtin_themes} )) && { - # add a line of separation - (( ${#custom_themes} )) && echo + (( ${#builtin_themes} )) && { + # add a line of separation + (( ${#custom_themes} )) && echo - print -Pn "%U%BBuilt-in themes%b%u: " - print -l ${(q-)builtin_themes} - } | fmt -w $COLUMNS + print -Pn "%U%BBuilt-in themes%b%u: " + print -l ${(q-)builtin_themes} + } + } | fmt -w $COLUMNS | sed -E $'s/\e?(\\[[0-9]*m)/\e\\1/g' # deal with fmt removing ESC } function _omz::theme::use { From 75ae0e905fcb928555df122ec1ec29a8a546130d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 10 Oct 2020 12:12:22 +0200 Subject: [PATCH 033/848] lib: fix `omz help` and reword --- lib/cli.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index c9ee159bc..ff865093d 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -60,8 +60,9 @@ Usage: omz [options] Available commands: help Print this help message - pr Commands for Oh My Zsh Pull Requests management - theme Commands for Oh My Zsh themes management + plugin Manage plugins + pr Manage Oh My Zsh Pull Requests + theme Manage themes update Update Oh My Zsh EOF From 23760228908d14a4644718869d5ebfb7b0dde6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 10 Oct 2020 12:38:17 +0200 Subject: [PATCH 034/848] lib: remove share_history Related: #2537, #9324 --- lib/history.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/history.zsh b/lib/history.zsh index 0ee8cfe7a..8d922a30b 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -36,4 +36,3 @@ setopt hist_expire_dups_first # delete duplicates first when HISTFILE size excee setopt hist_ignore_dups # ignore duplicated commands history list setopt hist_ignore_space # ignore commands that start with space setopt hist_verify # show command with history expansion to user before running it -setopt share_history # share command history data From 6e7b861675c4568931e91255abc62a7c45660e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 10 Oct 2020 19:14:30 +0200 Subject: [PATCH 035/848] lib: fix regex bug in git_prompt_status Fixes #9326 --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index f9b27949e..53d39609e 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -226,7 +226,7 @@ function git_prompt_status() { # For each status prefix, do a regex comparison for status_prefix in ${(k)prefix_constant_map}; do local status_constant="${prefix_constant_map[$status_prefix]}" - local status_regex="(^|\n)$status_prefix" + local status_regex=$'(^|\n)'"$status_prefix" if [[ "$status_text" =~ $status_regex ]]; then statuses_seen[$status_constant]=1 From c66d8a841d231895be37721220f23b537d90c5a5 Mon Sep 17 00:00:00 2001 From: Sreekanth S Date: Sat, 10 Oct 2020 12:39:21 -0700 Subject: [PATCH 036/848] agnoster: fix icon for unstaged git status (#9164) --- themes/agnoster.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index 79748e45e..99707f684 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -131,7 +131,7 @@ prompt_git() { zstyle ':vcs_info:*' get-revision true zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:*' stagedstr '✚' - zstyle ':vcs_info:*' unstagedstr '●' + zstyle ':vcs_info:*' unstagedstr '±' zstyle ':vcs_info:*' formats ' %u%c' zstyle ':vcs_info:*' actionformats ' %u%c' vcs_info From 1744277a68101916d51cda2c67951f5981f1f216 Mon Sep 17 00:00:00 2001 From: Joshua Pratt Date: Sun, 11 Oct 2020 23:17:21 +1100 Subject: [PATCH 037/848] systemadmin: correct sort order for psmem aliases (#6253) --- plugins/systemadmin/README.md | 4 ++-- plugins/systemadmin/systemadmin.plugin.zsh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/systemadmin/README.md b/plugins/systemadmin/README.md index edca4d87d..243db03f2 100644 --- a/plugins/systemadmin/README.md +++ b/plugins/systemadmin/README.md @@ -16,8 +16,8 @@ plugins=(... systemadmin) | clr | `clear; echo Currently logged in on $TTY, as $USER in directory $PWD.` | Clears the screen and prints the current user, TTY, and directory | | path | `print -l $path` | Displays PATH with each entry on a separate line | | mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output | -| psmem | `ps -e -orss=,args= \| sort -b -k1,1n` | Display the processes using the most memory | -| psmem10 | `ps -e -orss=,args= \| sort -b -k1,1n \| head -10` | Display the top 10 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 -10` | Display the top 10 processes using the most memory | | 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 -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 | diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh index ded25c3a9..03064c035 100644 --- a/plugins/systemadmin/systemadmin.plugin.zsh +++ b/plugins/systemadmin/systemadmin.plugin.zsh @@ -25,8 +25,8 @@ alias clr='clear; echo Currently logged in on $TTY, as $USER in directory $PWD.' alias path='print -l $path' alias mkdir='mkdir -pv' # get top process eating memory -alias psmem='ps -e -orss=,args= | sort -b -k1,1n' -alias psmem10='ps -e -orss=,args= | sort -b -k1,1n| head -10' +alias psmem='ps -e -orss=,args= | sort -b -k1 -nr' +alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -10' # get top process eating cpu if not work try excute : export LC_ALL='C' 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 -10' From fb80eb8e05e13cfb224114688fc7d20960e26b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Dario=20Piernagorda=20Pe=C3=B1a?= <48845582+IVAN-DPP@users.noreply.github.com> Date: Sun, 11 Oct 2020 11:05:14 -0500 Subject: [PATCH 038/848] emacs: add ansi-term directory tracking (#9218) --- plugins/emacs/emacs.plugin.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/emacs/emacs.plugin.zsh b/plugins/emacs/emacs.plugin.zsh index db0ab13af..0b602d12a 100644 --- a/plugins/emacs/emacs.plugin.zsh +++ b/plugins/emacs/emacs.plugin.zsh @@ -26,6 +26,16 @@ if "$ZSH/tools/require_tool.sh" emacsclient 24 2>/dev/null ; then # create a new X frame alias eframe='emacsclient --alternate-editor "" --create-frame' + # Emacs ANSI Term tracking + if [[ -n "$INSIDE_EMACS" ]]; then + chpwd_emacs() { print -P "\033AnSiTc %d"; } + print -P "\033AnSiTc %d" # Track current working directory + print -P "\033AnSiTu %n" # Track username + + # add chpwd hook + autoload -Uz add-zsh-hook + add-zsh-hook chpwd chpwd_emacs + fi # Write to standard output the path to the file # opened in the current buffer. From 82856bfbd86ac77f0f28ab741a399a04495ed3bc Mon Sep 17 00:00:00 2001 From: VectorW <15570764+VectorWpl@users.noreply.github.com> Date: Sun, 11 Oct 2020 21:23:21 +0200 Subject: [PATCH 039/848] globalias: allow filtering values not to be expanded (#9331) --- plugins/globalias/README.md | 19 ++++++++++++++++++- plugins/globalias/globalias.plugin.zsh | 6 ++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/plugins/globalias/README.md b/plugins/globalias/README.md index 0b064105d..cd7fc3cb2 100644 --- a/plugins/globalias/README.md +++ b/plugins/globalias/README.md @@ -17,6 +17,9 @@ Then just press `SPACE` to trigger the expansion of a command you've written. If you only want to insert a space without expanding the command line, press `CTRL`+`SPACE`. +if you would like to filter out any values from expanding set `GLOBALIAS_FILTER_VALUES` to +an array of said values. See [Filtered values](#filtered-values). + ## Examples #### Glob expressions @@ -37,7 +40,6 @@ $ ls folder/file.json anotherfolder/another.json $ mkdir "`date -R`" # expands to $ mkdir Tue,\ 04\ Oct\ 2016\ 13:54:03\ +0300 - ``` #### Aliases @@ -60,3 +62,18 @@ $ S # expands to: $ sudo systemctl ``` + +#### Filtered values + +``` +# .zshrc +alias l='ls -lh' +alias la='ls --color=auto -lah' +GLOBALIAS_FILTER_VALUES=(l) + +$ l +# does not expand +$ la +# expands to: +$ ls --color=auto -lah +``` diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index 9602a9606..f8c07ce43 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -1,6 +1,8 @@ globalias() { - zle _expand_alias - zle expand-word + if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$LBUFFER] -eq 0 ]]; then + zle _expand_alias + zle expand-word + fi zle self-insert } zle -N globalias From 2657c87f0aa1fe7f66062bc3452ad68347be356f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 11 Oct 2020 20:12:16 +0200 Subject: [PATCH 040/848] Add gitpod integration Fixes #8212 Co-authored-by: Sean Hellum --- .gitpod.Dockerfile | 5 +++++ .gitpod.yml | 9 +++++++++ README.md | 1 + 3 files changed, 15 insertions(+) create mode 100644 .gitpod.Dockerfile create mode 100644 .gitpod.yml diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 000000000..b35c80dfb --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,5 @@ +FROM gitpod/workspace-full + +RUN sudo apt-get update && \ + sudo apt-get install -y zsh && \ + sudo rm -rf /var/lib/apt/lists/* diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 000000000..ccc57242c --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,9 @@ +image: + file: .gitpod.Dockerfile + +tasks: + - init: | + export EDITOR="command gp open -w" VISUAL="command gp open -w" + cp -f /workspace/ohmyzsh/templates/zshrc.zsh-template ~/.zshrc + ln -sf /workspace/ohmyzsh ~/.oh-my-zsh + command: exec zsh diff --git a/README.md b/README.md index 0c292e100..86037f199 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi [![CI](https://github.com/ohmyzsh/ohmyzsh/workflows/CI/badge.svg)](https://github.com/ohmyzsh/ohmyzsh/actions?query=workflow%3ACI) [![Follow @ohmyzsh](https://img.shields.io/twitter/follow/ohmyzsh?label=Follow+@ohmyzsh&style=flat)](https://twitter.com/intent/follow?screen_name=ohmyzsh) [![Discord server](https://img.shields.io/discord/642496866407284746)](https://discord.gg/ohmyzsh) +[![Gitpod ready](https://img.shields.io/badge/Gitpod-ready-blue?logo=gitpod)](https://gitpod.io/#https://github.com/ohmyzsh/ohmyzsh) ## Getting Started From 1e25abacad6cdf380b7b1df9fc758290d969d99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 13 Oct 2020 11:27:14 +0200 Subject: [PATCH 041/848] meta: add checklist instructions on Pull Request template --- .github/PULL_REQUEST_TEMPLATE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6bcb90efe..1abae8913 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,7 @@ ## Standards checklist: + + - [ ] The PR title is descriptive. - [ ] The PR doesn't replicate another PR which is already open. - [ ] I have read the contribution guide and followed all the instructions. From a39bee8d11aca960651403dddbb7dba38b00183e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Queir=C3=B3s?= Date: Tue, 13 Oct 2020 10:28:51 +0100 Subject: [PATCH 042/848] git-prompt: document Python prerequisite in README (#9336) --- plugins/git-prompt/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/git-prompt/README.md b/plugins/git-prompt/README.md index e3b2d623a..83948f536 100644 --- a/plugins/git-prompt/README.md +++ b/plugins/git-prompt/README.md @@ -11,6 +11,9 @@ plugins=(... git-prompt) See the [original repository](https://github.com/olivierverdier/zsh-git-prompt). +## Prerequisites +This plugin uses `python`, so your host needs to have it installed + ## Examples The prompt may look like the following: From 568a977d2076b4210a9a925c53abcf0a831e4003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 13 Oct 2020 20:32:42 +0200 Subject: [PATCH 043/848] safe-paste: fix _bracketed_paste_zle_init/finish error Fixes #9337 --- plugins/safe-paste/safe-paste.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/safe-paste/safe-paste.plugin.zsh b/plugins/safe-paste/safe-paste.plugin.zsh index db524538c..d443ae8a2 100644 --- a/plugins/safe-paste/safe-paste.plugin.zsh +++ b/plugins/safe-paste/safe-paste.plugin.zsh @@ -84,7 +84,7 @@ _bracketed_paste_enqueue() { _bracketed_paste_zle_init() { _bracketed_paste_content='' # Tell terminal to send escape codes around pastes - if [ $TERM =~ '^(rxvt-unicode|xterm(-256color)?|screen(-256color)?)$' ]; then + if [[ $TERM =~ '^(rxvt-unicode|xterm(-256color)?|screen(-256color)?)$' ]]; then printf '\e[?2004h' fi } @@ -93,7 +93,7 @@ _bracketed_paste_zle_init() { _bracketed_paste_zle_finish() { # Turn off bracketed paste when we leave ZLE, so pasting in other programs # doesn't get the ^[[200~ codes around the pasted text - if [ $TERM =~ '^(rxvt-unicode|xterm(-256color)?|screen(-256color)?)$' ]; then + if [[ $TERM =~ '^(rxvt-unicode|xterm(-256color)?|screen(-256color)?)$' ]]; then printf '\e[?2004l' fi } From e75aa2875eea94fcf7ceb3f246db96cc3bc61a2e Mon Sep 17 00:00:00 2001 From: "Patrick W. Healy" Date: Wed, 14 Oct 2020 09:57:59 -0500 Subject: [PATCH 044/848] globalias: expand filtering to anywhere in the command (#9338) --- plugins/globalias/globalias.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index f8c07ce43..d4d40c863 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -1,5 +1,7 @@ globalias() { - if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$LBUFFER] -eq 0 ]]; then + # Get last word to the left of the cursor + local word=${${(A)=LBUFFER}[-1]} + if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then zle _expand_alias zle expand-word fi From 53cbd658f5ae6874af0d804cee6748dfba69e786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 14 Oct 2020 17:23:03 +0200 Subject: [PATCH 045/848] globalias: use ${(z)var} to split into words using shell parsing --- plugins/globalias/globalias.plugin.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index d4d40c863..bd27d589d 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -1,6 +1,8 @@ globalias() { - # Get last word to the left of the cursor - local word=${${(A)=LBUFFER}[-1]} + # Get last word to the left of the cursor: + # (z) splits into words using shell parsing + # (A) makes it an array even if there's only one element + local word=${${(Az)LBUFFER}[-1]} if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then zle _expand_alias zle expand-word From 5b717ab3e4bfb627a936d7c04367a39867734d63 Mon Sep 17 00:00:00 2001 From: IsThisTheMatrix <46820823+causalityloop@users.noreply.github.com> Date: Thu, 15 Oct 2020 18:52:34 -0400 Subject: [PATCH 046/848] kubectl: verify kubectl is installed before running compdef (#9346) --- plugins/kubectl/kubectl.plugin.zsh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 6292a0b2f..7a0c47945 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -150,19 +150,13 @@ alias kepvc='kubectl edit pvc' alias kdpvc='kubectl describe pvc' alias kdelpvc='kubectl delete pvc' -# Colored JSON output -kj() { - kubectl "$@" -o json | jq -} -compdef kj=kubectl +# Only run if the user actually has kubectl installed +if (( $+commands[kubectl] )); then + kj() { kubectl "$@" -o json | jq; } + kjx() { kubectl "$@" -o json | fx; } + ky() { kubectl "$@" -o yaml | yh; } -kjx() { - kubectl "$@" -o json | fx -} -compdef kjx=kubectl - -# Colored YAML output -ky() { - kubectl "$@" -o yaml | yh -} -compdef ky=kubectl + compdef kj=kubectl + compdef kjx=kubectl + compdef ky=kubectl +fi From 176376cbc026bb5339a00a6486882649d250469a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 17 Oct 2020 23:14:58 +0200 Subject: [PATCH 047/848] kubectl: check for empty cache completion file --- plugins/kubectl/kubectl.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 7a0c47945..0b1edb450 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -1,7 +1,7 @@ if (( $+commands[kubectl] )); then __KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion" - if [[ ! -f $__KUBECTL_COMPLETION_FILE ]]; then + if [[ ! -f $__KUBECTL_COMPLETION_FILE || ! -s $__KUBECTL_COMPLETION_FILE ]]; then kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE fi @@ -151,7 +151,7 @@ alias kdpvc='kubectl describe pvc' alias kdelpvc='kubectl delete pvc' # Only run if the user actually has kubectl installed -if (( $+commands[kubectl] )); then +if (( ${+_comps[kubectl]} )); then kj() { kubectl "$@" -o json | jq; } kjx() { kubectl "$@" -o json | fx; } ky() { kubectl "$@" -o yaml | yh; } From 902954d1cc4438e98149d72c878a4fbac3b3d7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 18 Oct 2020 21:14:05 +0200 Subject: [PATCH 048/848] lib: use `column` to format plugin and theme list CLI commands --- lib/cli.zsh | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index ff865093d..9421fd19a 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -135,20 +135,17 @@ function _omz::plugin::list { custom_plugins=("$ZSH_CUSTOM"/plugins/*(/N:t)) builtin_plugins=("$ZSH"/plugins/*(/N:t)) - { - (( ${#custom_plugins} )) && { - print -Pn "%U%BCustom plugins%b%u: " - print -l ${(q-)custom_plugins} - } + if (( ${#custom_plugins} )); then + print -P "%U%BCustom plugins%b%u:" + print -l ${(q-)custom_plugins} | column + fi - (( ${#builtin_plugins} )) && { - # add a line of separation - (( ${#custom_plugins} )) && echo + if (( ${#builtin_plugins} )); then + (( ${#custom_plugins} )) && echo # add a line of separation - print -Pn "%U%BBuilt-in plugins%b%u: " - print -l ${(q-)builtin_plugins} - } - } | fmt -w $COLUMNS | sed -E $'s/\e?(\\[[0-9]*m)/\e\\1/g' # deal with fmt removing ESC + print -P "%U%BBuilt-in plugins%b%u:" + print -l ${(q-)builtin_plugins} | column + fi } function _omz::pr { @@ -308,20 +305,17 @@ function _omz::theme::list { custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)) builtin_themes=("$ZSH"/themes/*.zsh-theme(.N:t:r)) - { - (( ${#custom_themes} )) && { - print -Pn "%U%BCustom themes%b%u: " - print -l ${(q-)custom_themes} - } + if (( ${#custom_themes} )); then + print -P "%U%BCustom themes%b%u:" + print -l ${(q-)custom_themes} | column + fi - (( ${#builtin_themes} )) && { - # add a line of separation - (( ${#custom_themes} )) && echo + if (( ${#builtin_themes} )); then + (( ${#custom_themes} )) && echo # add a line of separation - print -Pn "%U%BBuilt-in themes%b%u: " - print -l ${(q-)builtin_themes} - } - } | fmt -w $COLUMNS | sed -E $'s/\e?(\\[[0-9]*m)/\e\\1/g' # deal with fmt removing ESC + print -P "%U%BBuilt-in themes%b%u:" + print -l ${(q-)builtin_themes} | column + fi } function _omz::theme::use { From 7525b1d533b927bc40e3cfb29e399e5f2e0828d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 18 Oct 2020 21:25:03 +0200 Subject: [PATCH 049/848] lib: allow bare output in theme and plugins list command --- lib/cli.zsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/cli.zsh b/lib/cli.zsh index 9421fd19a..82a2a3985 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -135,6 +135,12 @@ function _omz::plugin::list { custom_plugins=("$ZSH_CUSTOM"/plugins/*(/N:t)) builtin_plugins=("$ZSH"/plugins/*(/N:t)) + # If the command is being piped, print all found line by line + if [[ ! -t 1 ]]; then + print -l ${(q-)custom_plugins} ${(q-)builtin_plugins} + return + fi + if (( ${#custom_plugins} )); then print -P "%U%BCustom plugins%b%u:" print -l ${(q-)custom_plugins} | column @@ -305,6 +311,12 @@ function _omz::theme::list { custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)) builtin_themes=("$ZSH"/themes/*.zsh-theme(.N:t:r)) + # If the command is being piped, print all found line by line + if [[ ! -t 1 ]]; then + print -l ${(q-)custom_themes} ${(q-)builtin_themes} + return + fi + if (( ${#custom_themes} )); then print -P "%U%BCustom themes%b%u:" print -l ${(q-)custom_themes} | column From f9f45ca222a0ec6fa867ab3733f15911d1b894e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 20 Oct 2020 15:57:11 +0200 Subject: [PATCH 050/848] lib: follow symlinked plugins in `plugin list` CLI command See https://github.com/ohmyzsh/ohmyzsh/issues/9087#issuecomment-712460275 --- lib/cli.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 82a2a3985..b1478a89f 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -132,8 +132,8 @@ EOF function _omz::plugin::list { local -a custom_plugins builtin_plugins - custom_plugins=("$ZSH_CUSTOM"/plugins/*(/N:t)) - builtin_plugins=("$ZSH"/plugins/*(/N:t)) + custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t)) + builtin_plugins=("$ZSH"/plugins/*(-/N:t)) # If the command is being piped, print all found line by line if [[ ! -t 1 ]]; then From 7d73908223222d3df7f36ed5a362fcfccd770ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 20 Oct 2020 23:48:59 +0200 Subject: [PATCH 051/848] fzf: add check for OpenSUSE and OpenBSD packages (#9327) --- plugins/fzf/README.md | 57 ++++++++++------ plugins/fzf/fzf.plugin.zsh | 133 ++++++++++++++++++++++++++----------- 2 files changed, 131 insertions(+), 59 deletions(-) diff --git a/plugins/fzf/README.md b/plugins/fzf/README.md index d9617563a..791a3eb6f 100644 --- a/plugins/fzf/README.md +++ b/plugins/fzf/README.md @@ -1,33 +1,52 @@ # fzf -This plugin enables [junegunn's fzf](https://github.com/junegunn/fzf) fuzzy auto-completion and key bindings +This plugin tries to find [junegunn's fzf](https://github.com/junegunn/fzf) based on where +it's been installed, and enables its fuzzy auto-completion and key bindings. To use it, add `fzf` to the plugins array in your zshrc file: + ```zsh plugins=(... fzf) ``` ## Settings -Add these before the `plugins=()` line in your zshrc file: +All these settings should go in your zshrc file, before Oh My Zsh is sourced. + +### `FZF_BASE` + +Set to fzf installation directory path: ```zsh -# Set fzf installation directory path -# export FZF_BASE=/path/to/fzf/install/dir - -# Uncomment to set the FZF_DEFAULT_COMMAND -# export FZF_DEFAULT_COMMAND='' - -# Uncomment the following line to disable fuzzy completion -# DISABLE_FZF_AUTO_COMPLETION="true" - -# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C) -# DISABLE_FZF_KEY_BINDINGS="true" +export FZF_BASE=/path/to/fzf/install/dir ``` -| Setting | Example value | Description | -|-----------------------------|----------------------------|-------------------------------------------------------------| -| FZF_BASE | `/path/to/fzf/install/dir` | Set fzf installation directory path (**export**) | -| FZF_DEFAULT_COMMAND | `fd --type f` | Set default command to use when input is tty (**export**) | -| DISABLE_FZF_AUTO_COMPLETION | `true` | Set whether to load fzf auto-completion | -| DISABLE_FZF_KEY_BINDINGS | `true` | Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C) | +### `FZF_DEFAULT_COMMAND` + +Set default command to use when input is tty: + +```zsh +export FZF_DEFAULT_COMMAND='' +``` + +If not set, the plugin will try to set it to these, in the order in which they're found: + +- [`rg`](https://github.com/BurntSushi/ripgrep) +- [`fd`](https://github.com/sharkdp/fd) +- [`ag`](https://github.com/ggreer/the_silver_searcher) + +### `DISABLE_FZF_AUTO_COMPLETION` + +Set whether to load fzf auto-completion: + +```zsh +DISABLE_FZF_AUTO_COMPLETION="true" +``` + +### `DISABLE_FZF_KEY_BINDINGS` + +Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C): + +```zsh +DISABLE_FZF_KEY_BINDINGS="true" +``` diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index 0b831b7f7..2f48215d5 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -1,9 +1,5 @@ function setup_using_base_dir() { - # Declare all variables local not no mess with outside env in any way - local fzf_base - local fzf_shell - local fzfdirs - local dir + local fzf_base fzf_shell fzfdirs dir test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}" @@ -31,38 +27,37 @@ function setup_using_base_dir() { fi fi - if [[ -d "${fzf_base}" ]]; then - # Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages - if [[ ! -d "${fzf_base}/shell" ]]; then - fzf_shell="${fzf_base}" - else - fzf_shell="${fzf_base}/shell" - fi - - # Setup fzf binary path - if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then - export PATH="$PATH:$fzf_base/bin" - fi - - # Auto-completion - if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then - [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null - fi - - # Key bindings - if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then - source "${fzf_shell}/key-bindings.zsh" - fi - else + if [[ ! -d "${fzf_base}" ]]; then return 1 fi + + # Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages + if [[ ! -d "${fzf_base}/shell" ]]; then + fzf_shell="${fzf_base}" + else + fzf_shell="${fzf_base}/shell" + fi + + # Setup fzf binary path + if (( ! ${+commands[fzf]} )) && [[ "$PATH" != *$fzf_base/bin* ]]; then + export PATH="$PATH:$fzf_base/bin" + fi + + # Auto-completion + if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then + source "${fzf_shell}/completion.zsh" 2> /dev/null + fi + + # Key bindings + if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then + source "${fzf_shell}/key-bindings.zsh" + fi } function setup_using_debian_package() { - (( $+commands[dpkg] )) && dpkg -s fzf &> /dev/null - if (( $? )); then - # Either not a debian based distro, or no fzf installed. In any case skip ahead + if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then + # Either not a debian based distro, or no fzf installed return 1 fi @@ -76,8 +71,8 @@ function setup_using_debian_package() { local key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh" # Auto-completion - if [[ $- == *i* ]] && [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then - source $completions 2> /dev/null + if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then + source $completions 2> /dev/null fi # Key bindings @@ -88,16 +83,74 @@ function setup_using_debian_package() { return 0 } -function indicate_error() { - print "[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.\n"\ - "Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2 +function setup_using_opensuse_package() { + # OpenSUSE installs fzf in /usr/bin/fzf + # If the command is not found, the package isn't installed + (( $+commands[fzf] )) || return 1 + + # The fzf-zsh-completion package installs the auto-completion in + local completions="/usr/share/zsh/site-functions/_fzf" + # The fzf-zsh-completion package installs the key-bindings file in + local key_bindings="/etc/zsh_completion.d/fzf-key-bindings" + + # If these are not found: (1) maybe we're not on OpenSUSE, or + # (2) maybe the fzf-zsh-completion package isn't installed. + if [[ ! -f "$completions" || ! -f "$key_bindings" ]]; then + return 1 + fi + + # Auto-completion + if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then + source "$completions" 2>/dev/null + fi + + # Key bindings + if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then + source "$key_bindings" 2>/dev/null + fi + + return 0 } -# Check for debian package first, because it easy to short cut -# Indicate to user that fzf installation not found if nothing worked -setup_using_debian_package || setup_using_base_dir || indicate_error +function setup_using_openbsd_package() { + # openBSD installs fzf in /usr/local/bin/fzf + if [[ "$OSTYPE" != openbsd* ]] || (( ! $+commands[fzf] )); then + return 1 + fi -unset -f setup_using_debian_package setup_using_base_dir indicate_error + # The fzf package installs the auto-completion in + local completions="/usr/local/share/zsh/site-functions/_fzf_completion" + # The fzf package installs the key-bindings file in + local key_bindings="/usr/local/share/zsh/site-functions/_fzf_key_bindings" + + # Auto-completion + if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then + source "$completions" 2>/dev/null + fi + + # Key bindings + if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then + source "$key_bindings" 2>/dev/null + fi + + return 0 +} + +function indicate_error() { + cat >&2 < Date: Wed, 21 Oct 2020 16:01:36 +0200 Subject: [PATCH 052/848] Revert "lib: treat _ and - as part of a word" This reverts commit 50dc4ab3574f4e265dff816d8d9a0195cd260152. The community has spoken: - https://github.com/ohmyzsh/ohmyzsh/issues/9367 - https://github.com/ohmyzsh/ohmyzsh/issues/8743 Fixes #9367 --- lib/completion.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/completion.zsh b/lib/completion.zsh index a3873cd08..2b62785d5 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -1,7 +1,7 @@ # fixme - the load process here seems a bit bizarre zmodload -i zsh/complist -WORDCHARS='_-' +WORDCHARS='' unsetopt menu_complete # do not autoselect the first completion entry unsetopt flowcontrol From bf5574fc93166d7c1915b9f3ae78aba1959a8403 Mon Sep 17 00:00:00 2001 From: Wenli Wan Date: Wed, 21 Oct 2020 22:09:54 +0800 Subject: [PATCH 053/848] kubectl: add aliases for serviceaccount, daemonsets and cronjob (#9344) --- plugins/kubectl/README.md | 23 +++++++++++++++++++---- plugins/kubectl/kubectl.plugin.zsh | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/plugins/kubectl/README.md b/plugins/kubectl/README.md index 84f5f8d89..7a6cdaa59 100644 --- a/plugins/kubectl/README.md +++ b/plugins/kubectl/README.md @@ -22,7 +22,7 @@ plugins=(... kubectl) | kcsc | `kubectl config set-context` | Set a context entry in kubeconfig | | kcdc | `kubectl config delete-context` | Delete the specified context from the kubeconfig | | kccc | `kubectl config current-context` | Display the current-context | -| kcgc | `kubectl config get-contexts` | List of contexts available +| kcgc | `kubectl config get-contexts` | List of contexts available | | | **General aliases** | | kdel | `kubectl delete` | Delete resources by filenames, stdin, resources and names, or by resources and label selector | | kdelf | `kubectl delete -f` | Delete a pod using the type and name specified in -f argument | @@ -91,13 +91,13 @@ plugins=(... kubectl) | keno | `kubectl edit node` | Edit nodes resource from the default editor | | kdno | `kubectl describe node` | Describe node resource in detail | | kdelno | `kubectl delete node` | Delete the node | -| | | **Persistent Volume Claim management** | +| | | **Persistent Volume Claim management** | | kgpvc | `kubectl get pvc` | List all PVCs | | kgpvcw | `kgpvc --watch` | After listing/getting the requested object, watch for changes | | kepvc | `kubectl edit pvc` | Edit pvcs from the default editor | -| kdpvc | `kubectl describe pvc` | Descirbe all pvcs | +| kdpvc | `kubectl describe pvc` | Describe all pvcs | | kdelpvc | `kubectl delete pvc` | Delete all pvcs matching passed arguments | -| | | | +| | | **StatefulSets management** | | kgss | `kubectl get statefulset` | List the statefulsets in ps format | | kgssw | `kgss --watch` | After getting the list of statefulsets, watch for changes | | kgsswide| `kgss -o wide` | After getting the statefulsets, output in plain-text format with any additional information | @@ -106,6 +106,21 @@ plugins=(... kubectl) | kdelss | `kubectl delete statefulset` | Delete the statefulset | | ksss | `kubectl scale statefulset` | Scale a statefulset | | krsss | `kubectl rollout status statefulset`| Check the rollout status of a deployment | +| | | **Service Accounts management** | +| kgsa | `kubectl get sa` | List all service accounts | +| kdsa | `kubectl describe sa` | Describe a service account in details | +| kdelsa | `kubectl delete sa` | Delete the service account | +| | | **DaemonSet management** | +| kgds | `kubectl get daemonset` | List all DaemonSets in ps output format | +| kgdsw | `kgds --watch` | After listing all DaemonSets, watch for changes | +| keds | `kubectl edit daemonset` | Edit DaemonSets from the default editor | +| kdds | `kubectl describe daemonset` | Describe all DaemonSets in detail | +| kdelds | `kubectl delete daemonset` | Delete all DaemonSets matching passed argument | +| | | **CronJob management** | +| kgcj | `kubectl get cronjob` | List all CronJobs in ps output format | +| kecj | `kubectl edit cronjob` | Edit CronJob from the default editor | +| kdcj | `kubectl describe cronjob` | Describe a CronJob in details | +| kdelcj | `kubectl delete cronjob` | Delete the CronJob | ## Wrappers diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 0b1edb450..d509d8795 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -150,6 +150,24 @@ alias kepvc='kubectl edit pvc' alias kdpvc='kubectl describe pvc' alias kdelpvc='kubectl delete pvc' +# Service account management. +alias kgsa="kubectl get sa" +alias kdsa="kubectl describe sa" +alias kdelsa="kubectl delete sa" + +# DaemonSet management. +alias kgds='kubectl get daemonset' +alias kgdsw='kgds --watch' +alias keds='kubectl edit daemonset' +alias kdds='kubectl describe daemonset' +alias kdelds='kubectl delete daemonset' + +# CronJob management. +alias kgcj='kubectl get cronjob' +alias kecj='kubectl edit cronjob' +alias kdcj='kubectl describe cronjob' +alias kdelcj='kubectl delete cronjob' + # Only run if the user actually has kubectl installed if (( ${+_comps[kubectl]} )); then kj() { kubectl "$@" -o json | jq; } From 80d2e4336b85c070e021571f8724032b204f3c4f Mon Sep 17 00:00:00 2001 From: Lucas Larson <91468+LucasLarson@users.noreply.github.com> Date: Wed, 21 Oct 2020 10:22:32 -0400 Subject: [PATCH 054/848] =?UTF-8?q?Grammar:=20remove=20hyphens=20from=20pr?= =?UTF-8?q?edicate=C2=A0adjective=C2=A0=E2=80=9Cup=C2=A0to=C2=A0date?= =?UTF-8?q?=E2=80=9D=20(#9356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://english.stackexchange.com/a/180617 https://web.archive.org/web/20190728053012id_/grammarist.com/usage/up-to-date/#text-60 --- plugins/cargo/_cargo | 4 ++-- plugins/golang/golang.plugin.zsh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 12694901e..ffc9fcdc8 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -12,8 +12,8 @@ _cargo() { '(-q --quiet)*'{-v,--verbose}'[use verbose output]' '(-q --quiet -v --verbose)'{-q,--quiet}'[no output printed to stdout]' '-Z+[pass unstable (nightly-only) flags to cargo]: :_cargo_unstable_flags' - '--frozen[require that Cargo.lock and cache are up-to-date]' - '--locked[require that Cargo.lock is up-to-date]' + '--frozen[require that Cargo.lock and cache are up to date]' + '--locked[require that Cargo.lock is up to date]' '--color=[specify colorization option]:coloring:(auto always never)' '(- 1 *)'{-h,--help}'[show help message]' ) diff --git a/plugins/golang/golang.plugin.zsh b/plugins/golang/golang.plugin.zsh index 47b10988e..398bd966f 100644 --- a/plugins/golang/golang.plugin.zsh +++ b/plugins/golang/golang.plugin.zsh @@ -41,7 +41,7 @@ __go_tool_complete() { return fi build_flags=( - '-a[force reinstallation of packages that are already up-to-date]' + '-a[force reinstallation of packages that are already up to date]' '-n[print the commands but do not run them]' '-p[number of parallel builds]:number' '-race[enable data race detection]' From 3b1699b59527ee8095397b9909a37d55689a0481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 21 Oct 2020 20:01:10 +0200 Subject: [PATCH 055/848] npx: deprecate plugin Fixes #9366 --- plugins/npx/README.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/plugins/npx/README.md b/plugins/npx/README.md index 1c052930b..41e4c1352 100644 --- a/plugins/npx/README.md +++ b/plugins/npx/README.md @@ -1,21 +1,15 @@ # NPX Plugin -> npx(1) -- execute npm package binaries. ([more info](https://github.com/zkat/npx)) + +> npx(1) -- execute npm package binaries. ([more info](https://github.com/npm/npx)) This plugin automatically registers npx command-not-found handler if `npx` exists in your `$PATH`. -## Setup +To use it, add `npx` to the plugins array in your zshrc file: -- Add plugin to `~/.zshrc` - -```bash +```zsh plugins=(.... npx) ``` -- Globally install npx binary (npx will be auto installed with recent versions of Node.js) -```bash -sudo npm install -g npx -``` - ## Note The shell auto-fallback doesn't auto-install plain packages. In order to get it to install something, you need to add `@`: @@ -29,3 +23,17 @@ Started It does it this way so folks using the fallback don't accidentally try to install regular typoes. +## Deprecation + +Since npm v7, `npx` has been moved to `npm exec`. With the move, [the `--shell-auto-fallback` argument +for `npx` has been removed](https://github.com/npm/cli/blob/v7.0.0/docs/content/cli-commands/npm-exec.md#compatibility-with-older-npx-versions): + +> Shell fallback functionality is removed, as it is not advisable. + +When using npm v7, you'll get this error: + +> npx: the --shell-auto-fallback argument has been removed + +If you get this error, just disable the plugin by removing it from the plugins array in your zshrc file. +This plugin will no longer be maintained and will be removed in the future, when the older `npx` versions +are no longer available. From a32564e0ae87686702570f3f942977bc9280f178 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 07:12:23 -0500 Subject: [PATCH 056/848] gitfast: update to latest upstream and more (#9382) --- plugins/gitfast/_git | 128 +- plugins/gitfast/git-completion.bash | 2218 +++++++++++++++------------ plugins/gitfast/git-prompt.sh | 72 +- plugins/gitfast/update | 11 +- plugins/gitfast/updates.patch | 56 - 5 files changed, 1423 insertions(+), 1062 deletions(-) delete mode 100644 plugins/gitfast/updates.patch diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git index 78a6dbb3d..46d10d6f9 100644 --- a/plugins/gitfast/_git +++ b/plugins/gitfast/_git @@ -2,25 +2,24 @@ # zsh completion wrapper for git # -# Copyright (c) 2012-2013 Felipe Contreras +# Copyright (c) 2012-2020 Felipe Contreras # -# You need git's bash completion script installed somewhere, by default it -# would be the location bash-completion uses. +# The recommended way to install this script is to make a copy of it as a +# file named '_git' inside any directory in your fpath. # -# If your script is somewhere else, you can configure it on your ~/.zshrc: -# -# zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh -# -# The recommended way to install this script is to copy to '~/.zsh/_git', and -# then add the following to your ~/.zshrc file: +# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git', +# and then add the following to your ~/.zshrc file: # # fpath=(~/.zsh $fpath) - -complete () -{ - # do nothing - return 0 -} +# +# You need git's bash completion script installed. By default bash-completion's +# location will be used (e.g. pkg-config --variable=completionsdir bash-completion). +# +# If your bash completion script is somewhere else, you can specify the +# location in your ~/.zshrc: +# +# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash +# zstyle -T ':completion:*:*:git:*' tag-order && \ zstyle ':completion:*:*:git:*' tag-order 'common-commands' @@ -30,16 +29,17 @@ if [ -z "$script" ]; then local -a locations local e locations=( - "$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash" - '/etc/bash_completion.d/git' # fedora, old debian - '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian - '/usr/share/bash-completion/git' # gentoo + "$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash + "$HOME/.local/share/bash-completion/completions/git" + "$(pkg-config --variable=completionsdir bash-completion)"/git + '/usr/share/bash-completion/completions/git' + '/etc/bash_completion.d/git' # old debian ) for e in $locations; do test -f $e && script="$e" && break done fi -ZSH_VERSION='' . "$script" +GIT_SOURCING_ZSH_COMPLETION=y . "$script" __gitcomp () { @@ -50,13 +50,35 @@ __gitcomp () case "$cur_" in --*=) ;; + --no-*) + local c IFS=$' \t\n' + local -a array + for c in ${=1}; do + if [[ $c == "--" ]]; then + continue + fi + c="$c${4-}" + case $c in + --*=|*.) ;; + *) c="$c " ;; + esac + array+=("$c") + done + compset -P '*[=:]' + compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 + ;; *) local c IFS=$' \t\n' local -a array for c in ${=1}; do + if [[ $c == "--" ]]; then + c="--no-...${4-}" + array+=("$c ") + break + fi c="$c${4-}" case $c in - --*=*|*.) ;; + --*=|*.) ;; *) c="$c " ;; esac array+=("$c") @@ -71,35 +93,57 @@ __gitcomp_direct () { emulate -L zsh - local IFS=$'\n' compset -P '*[=:]' - compadd -Q -- ${=1} && _ret=0 + compadd -Q -S '' -- ${(f)1} && _ret=0 } __gitcomp_nl () { emulate -L zsh - local IFS=$'\n' compset -P '*[=:]' - compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 + compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 } __gitcomp_nl_append () { emulate -L zsh - local IFS=$'\n' - compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 + compset -P '*[=:]' + compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 +} + +__gitcomp_file_direct () +{ + emulate -L zsh + + compadd -f -- ${(f)1} && _ret=0 } __gitcomp_file () { emulate -L zsh - local IFS=$'\n' - compset -P '*[=:]' - compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 + compadd -f -p "${2-}" -- ${(f)1} && _ret=0 +} + +_git_zsh () +{ + __gitcomp "v1.0" +} + +__git_complete_command () +{ + emulate -L zsh + + local command="$1" + local completion_func="_git_${command//-/_}" + if (( $+functions[$completion_func] )); then + emulate ksh -c $completion_func + return 0 + else + return 1 + fi } __git_zsh_bash_func () @@ -108,14 +152,12 @@ __git_zsh_bash_func () local command=$1 - local completion_func="_git_${command//-/_}" - declare -f $completion_func >/dev/null && $completion_func && return + __git_complete_command "$command" && return local expansion=$(__git_aliased_command "$command") if [ -n "$expansion" ]; then words[1]=$expansion - completion_func="_git_${expansion//-/_}" - declare -f $completion_func >/dev/null && $completion_func + __git_complete_command "$expansion" fi } @@ -140,9 +182,11 @@ __git_zsh_cmd_common () push:'update remote refs along with associated objects' rebase:'forward-port local commits to the updated upstream head' reset:'reset current HEAD to the specified state' + restore:'restore working tree files' rm:'remove files from the working tree and from the index' show:'show various types of objects' status:'show the working tree status' + switch:'switch branches' tag:'create, list, delete or verify a tag object signed with GPG') _describe -t common-commands 'common commands' list && _ret=0 } @@ -150,8 +194,9 @@ __git_zsh_cmd_common () __git_zsh_cmd_alias () { local -a list - list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*}) - _describe -t alias-commands 'aliases' list $* && _ret=0 + list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.}) + list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"}) + _describe -t alias-commands 'aliases' list && _ret=0 } __git_zsh_cmd_all () @@ -189,10 +234,13 @@ __git_zsh_main () case $state in (command) - _alternative \ - 'alias-commands:alias:__git_zsh_cmd_alias' \ - 'common-commands:common:__git_zsh_cmd_common' \ - 'all-commands:all:__git_zsh_cmd_all' && _ret=0 + _tags common-commands alias-commands all-commands + while _tags; do + _requested common-commands && __git_zsh_cmd_common + _requested alias-commands && __git_zsh_cmd_alias + _requested all-commands && __git_zsh_cmd_all + let _ret || break + done ;; (arg) local command="${words[1]}" __git_dir diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash index b6ff5dc08..76ba7e79f 100644 --- a/plugins/gitfast/git-completion.bash +++ b/plugins/gitfast/git-completion.bash @@ -29,13 +29,21 @@ # tell the completion to use commit completion. This also works with aliases # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". # +# Compatible with bash 3.2.57. +# # You can set the following environment variables to influence the behavior of # the completion routines: # # GIT_COMPLETION_CHECKOUT_NO_GUESS # # When set to "1", do not include "DWIM" suggestions in git-checkout -# completion (e.g., completing "foo" when "origin/foo" exists). +# and git-switch completion (e.g., completing "foo" when "origin/foo" +# exists). +# +# GIT_COMPLETION_SHOW_ALL +# +# When set to "1" suggest all options, including options which are +# typically hidden (e.g. '--allow-empty' for 'git commit'). case "$COMP_WORDBREAKS" in *:*) : great ;; @@ -47,7 +55,7 @@ esac # variable. __git_find_repo_path () { - if [ -n "$__git_repo_path" ]; then + if [ -n "${__git_repo_path-}" ]; then # we already know where it is return fi @@ -92,6 +100,70 @@ __git () ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null } +# Removes backslash escaping, single quotes and double quotes from a word, +# stores the result in the variable $dequoted_word. +# 1: The word to dequote. +__git_dequote () +{ + local rest="$1" len ch + + dequoted_word="" + + while test -n "$rest"; do + len=${#dequoted_word} + dequoted_word="$dequoted_word${rest%%[\\\'\"]*}" + rest="${rest:$((${#dequoted_word}-$len))}" + + case "${rest:0:1}" in + \\) + ch="${rest:1:1}" + case "$ch" in + $'\n') + ;; + *) + dequoted_word="$dequoted_word$ch" + ;; + esac + rest="${rest:2}" + ;; + \') + rest="${rest:1}" + len=${#dequoted_word} + dequoted_word="$dequoted_word${rest%%\'*}" + rest="${rest:$((${#dequoted_word}-$len+1))}" + ;; + \") + rest="${rest:1}" + while test -n "$rest" ; do + len=${#dequoted_word} + dequoted_word="$dequoted_word${rest%%[\\\"]*}" + rest="${rest:$((${#dequoted_word}-$len))}" + case "${rest:0:1}" in + \\) + ch="${rest:1:1}" + case "$ch" in + \"|\\|\$|\`) + dequoted_word="$dequoted_word$ch" + ;; + $'\n') + ;; + *) + dequoted_word="$dequoted_word\\$ch" + ;; + esac + rest="${rest:2}" + ;; + \") + rest="${rest:1}" + break + ;; + esac + done + ;; + esac + done +} + # The following function is based on code from: # # bash_completion - programmable completion functions for bash 3.2+ @@ -234,6 +306,19 @@ __gitcomp_direct () COMPREPLY=($1) } +# Similar to __gitcomp_direct, but appends to COMPREPLY instead. +# Callers must take care of providing only words that match the current word +# to be completed and adding any prefix and/or suffix (trailing space!), if +# necessary. +# 1: List of newline-separated matching completion words, complete with +# prefix and suffix. +__gitcomp_direct_append () +{ + local IFS=$'\n' + + COMPREPLY+=($1) +} + __gitcompappend () { local x i=${#COMPREPLY[@]} @@ -264,13 +349,36 @@ __gitcomp () case "$cur_" in --*=) ;; - *) + --no-*) local c i=0 IFS=$' \t\n' for c in $1; do + if [[ $c == "--" ]]; then + continue + fi c="$c${4-}" if [[ $c == "$cur_"* ]]; then case $c in - --*=*|*.) ;; + --*=|*.) ;; + *) c="$c " ;; + esac + COMPREPLY[i++]="${2-}$c" + fi + done + ;; + *) + local c i=0 IFS=$' \t\n' + for c in $1; do + if [[ $c == "--" ]]; then + c="--no-...${4-}" + if [[ $c == "$cur_"* ]]; then + COMPREPLY[i++]="${2-}$c " + fi + break + fi + c="$c${4-}" + if [[ $c == "$cur_"* ]]; then + case $c in + *=|*.) ;; *) c="$c " ;; esac COMPREPLY[i++]="${2-}$c" @@ -280,6 +388,163 @@ __gitcomp () esac } +# Clear the variables caching builtins' options when (re-)sourcing +# the completion script. +if [[ -n ${ZSH_VERSION-} ]]; then + unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null +else + unset $(compgen -v __gitcomp_builtin_) +fi + +__gitcomp_builtin_add_default=" --dry-run --verbose --interactive --patch --edit --force --update --renormalize --intent-to-add --all --ignore-removal --refresh --ignore-errors --ignore-missing --chmod= --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-verbose --no-interactive --no-patch --no-edit --no-force --no-update --no-renormalize --no-intent-to-add --no-all --no-ignore-removal --no-refresh --no-ignore-errors --no-ignore-missing --no-chmod --no-pathspec-from-file --no-pathspec-file-nul" +__gitcomp_builtin_am_default=" --interactive --3way --quiet --signoff --utf8 --keep --keep-non-patch --message-id --keep-cr --no-keep-cr --scissors --whitespace= --ignore-space-change --ignore-whitespace --directory= --exclude= --include= --patch-format= --reject --resolvemsg= --continue --resolved --skip --abort --quit --show-current-patch --committer-date-is-author-date --ignore-date --rerere-autoupdate --gpg-sign -- --no-interactive --no-3way --no-quiet --no-signoff --no-utf8 --no-keep --no-keep-non-patch --no-message-id --no-scissors --no-whitespace --no-ignore-space-change --no-ignore-whitespace --no-directory --no-exclude --no-include --no-patch-format --no-reject --no-resolvemsg --no-committer-date-is-author-date --no-ignore-date --no-rerere-autoupdate --no-gpg-sign" +__gitcomp_builtin_apply_default=" --exclude= --include= --no-add --stat --numstat --summary --check --index --intent-to-add --cached --apply --3way --build-fake-ancestor= --whitespace= --ignore-space-change --ignore-whitespace --reverse --unidiff-zero --reject --allow-overlap --verbose --inaccurate-eof --recount --directory= --add -- --no-stat --no-numstat --no-summary --no-check --no-index --no-intent-to-add --no-cached --no-apply --no-3way --no-build-fake-ancestor --no-whitespace --no-ignore-space-change --no-ignore-whitespace --no-reverse --no-unidiff-zero --no-reject --no-allow-overlap --no-verbose --no-inaccurate-eof --no-recount --no-directory" +__gitcomp_builtin_archive_default=" --output= --remote= --exec= --no-output -- --no-remote --no-exec" +__gitcomp_builtin_bisect__helper_default=" --next-all --write-terms --bisect-clean-state --check-expected-revs --bisect-reset --bisect-write --check-and-set-terms --bisect-next-check --bisect-terms --bisect-start --bisect-next --bisect-auto-next --bisect-autostart --no-log --log" +__gitcomp_builtin_blame_default=" --incremental --root --show-stats --progress --score-debug --show-name --show-number --porcelain --line-porcelain --show-email --ignore-rev= --ignore-revs-file= --color-lines --color-by-age --minimal --contents= --abbrev --no-incremental -- --no-root --no-show-stats --no-progress --no-score-debug --no-show-name --no-show-number --no-porcelain --no-line-porcelain --no-show-email --no-ignore-rev --no-ignore-revs-file --no-color-lines --no-color-by-age --no-minimal --no-contents --no-abbrev" +__gitcomp_builtin_branch_default=" --verbose --quiet --track --set-upstream-to= --unset-upstream --color --remotes --contains --no-contains --abbrev --all --delete --move --copy --list --show-current --create-reflog --edit-description --merged --no-merged --column --sort= --points-at= --ignore-case --format= -- --no-verbose --no-quiet --no-track --no-set-upstream-to --no-unset-upstream --no-color --no-remotes --no-abbrev --no-all --no-delete --no-move --no-copy --no-list --no-show-current --no-create-reflog --no-edit-description --no-column --no-points-at --no-ignore-case --no-format" +__gitcomp_builtin_bugreport_default=" --output-directory= --suffix= --no-output-directory -- --no-suffix" +__gitcomp_builtin_cat_file_default=" --textconv --filters --path= --allow-unknown-type --buffer --batch --batch-check --follow-symlinks --batch-all-objects --unordered --no-path -- --no-allow-unknown-type --no-buffer --no-follow-symlinks --no-batch-all-objects --no-unordered" +__gitcomp_builtin_check_attr_default=" --all --cached --stdin --no-all -- --no-cached --no-stdin" +__gitcomp_builtin_check_ignore_default=" --quiet --verbose --stdin --non-matching --no-index --index -- --no-quiet --no-verbose --no-stdin --no-non-matching" +__gitcomp_builtin_check_mailmap_default=" --stdin --no-stdin" +__gitcomp_builtin_checkout_default=" --guess --overlay --quiet --recurse-submodules --progress --merge --conflict= --detach --track --orphan= --ignore-other-worktrees --ours --theirs --patch --ignore-skip-worktree-bits --pathspec-from-file= --pathspec-file-nul --no-guess -- --no-overlay --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-detach --no-track --no-orphan --no-ignore-other-worktrees --no-patch --no-ignore-skip-worktree-bits --no-pathspec-from-file --no-pathspec-file-nul" +__gitcomp_builtin_checkout_index_default=" --all --force --quiet --no-create --index --stdin --temp --prefix= --stage= --create -- --no-all --no-force --no-quiet --no-index --no-stdin --no-temp --no-prefix" +__gitcomp_builtin_cherry_default=" --abbrev --verbose --no-abbrev -- --no-verbose" +__gitcomp_builtin_cherry_pick_default=" --quit --continue --abort --skip --cleanup= --no-commit --edit --signoff --mainline= --rerere-autoupdate --strategy= --strategy-option= --gpg-sign --ff --allow-empty --allow-empty-message --keep-redundant-commits --commit -- --no-cleanup --no-edit --no-signoff --no-mainline --no-rerere-autoupdate --no-strategy --no-strategy-option --no-gpg-sign --no-ff --no-allow-empty --no-allow-empty-message --no-keep-redundant-commits" +__gitcomp_builtin_clean_default=" --quiet --dry-run --interactive --exclude= --no-quiet -- --no-dry-run --no-interactive" +__gitcomp_builtin_clone_default=" --verbose --quiet --progress --no-checkout --bare --mirror --local --no-hardlinks --shared --recurse-submodules --recursive --jobs= --template= --reference= --reference-if-able= --dissociate --origin= --branch= --upload-pack= --depth= --shallow-since= --shallow-exclude= --single-branch --no-tags --shallow-submodules --separate-git-dir= --config= --server-option= --ipv4 --ipv6 --filter= --remote-submodules --sparse --checkout --hardlinks --tags -- --no-verbose --no-quiet --no-progress --no-bare --no-mirror --no-local --no-shared --no-recurse-submodules --no-recursive --no-jobs --no-template --no-reference --no-reference-if-able --no-dissociate --no-origin --no-branch --no-upload-pack --no-depth --no-shallow-since --no-shallow-exclude --no-single-branch --no-shallow-submodules --no-separate-git-dir --no-config --no-server-option --no-ipv4 --no-ipv6 --no-filter --no-remote-submodules --no-sparse" +__gitcomp_builtin_column_default=" --command= --mode --raw-mode= --width= --indent= --nl= --padding= --no-command -- --no-mode --no-raw-mode --no-width --no-indent --no-nl --no-padding" +__gitcomp_builtin_commit_default=" --quiet --verbose --file= --author= --date= --message= --reedit-message= --reuse-message= --fixup= --squash= --reset-author --signoff --template= --edit --cleanup= --status --gpg-sign --all --include --interactive --patch --only --no-verify --dry-run --short --branch --ahead-behind --porcelain --long --null --amend --no-post-rewrite --untracked-files --pathspec-from-file= --pathspec-file-nul --verify --post-rewrite -- --no-quiet --no-verbose --no-file --no-author --no-date --no-message --no-reedit-message --no-reuse-message --no-fixup --no-squash --no-reset-author --no-signoff --no-template --no-edit --no-cleanup --no-status --no-gpg-sign --no-all --no-include --no-interactive --no-patch --no-only --no-dry-run --no-short --no-branch --no-ahead-behind --no-porcelain --no-long --no-null --no-amend --no-untracked-files --no-pathspec-from-file --no-pathspec-file-nul" +__gitcomp_builtin_commit_graph_default=" --object-dir= --no-object-dir" +__gitcomp_builtin_config_default=" --global --system --local --worktree --file= --blob= --get --get-all --get-regexp --get-urlmatch --replace-all --add --unset --unset-all --rename-section --remove-section --list --edit --get-color --get-colorbool --type= --bool --int --bool-or-int --bool-or-str --path --expiry-date --null --name-only --includes --show-origin --show-scope --default= --no-global -- --no-system --no-local --no-worktree --no-file --no-blob --no-get --no-get-all --no-get-regexp --no-get-urlmatch --no-replace-all --no-add --no-unset --no-unset-all --no-rename-section --no-remove-section --no-list --no-edit --no-get-color --no-get-colorbool --no-type --no-null --no-name-only --no-includes --no-show-origin --no-show-scope --no-default" +__gitcomp_builtin_count_objects_default=" --verbose --human-readable --no-verbose -- --no-human-readable" +__gitcomp_builtin_credential_cache_default=" --timeout= --socket= --no-timeout -- --no-socket" +__gitcomp_builtin_credential_cache__daemon_default=" --debug --no-debug" +__gitcomp_builtin_credential_store_default=" --file= --no-file" +__gitcomp_builtin_describe_default=" --contains --debug --all --tags --long --first-parent --abbrev --exact-match --candidates= --match= --exclude= --always --dirty --broken --no-contains -- --no-debug --no-all --no-tags --no-long --no-first-parent --no-abbrev --no-exact-match --no-candidates --no-match --no-exclude --no-always --no-dirty --no-broken" +__gitcomp_builtin_difftool_default=" --gui --dir-diff --no-prompt --symlinks --tool= --tool-help --trust-exit-code --extcmd= --no-index -- --no-gui --no-dir-diff --no-symlinks --no-tool --no-tool-help --no-trust-exit-code --no-extcmd" +__gitcomp_builtin_env__helper_default=" --type= --default= --exit-code --no-default -- --no-exit-code" +__gitcomp_builtin_fast_export_default=" --progress= --signed-tags= --tag-of-filtered-object= --reencode= --export-marks= --import-marks= --import-marks-if-exists= --fake-missing-tagger --full-tree --use-done-feature --no-data --refspec= --anonymize --anonymize-map= --reference-excluded-parents --show-original-ids --mark-tags --data -- --no-progress --no-signed-tags --no-tag-of-filtered-object --no-reencode --no-export-marks --no-import-marks --no-import-marks-if-exists --no-fake-missing-tagger --no-full-tree --no-use-done-feature --no-refspec --no-anonymize --no-reference-excluded-parents --no-show-original-ids --no-mark-tags" +__gitcomp_builtin_fetch_default=" --verbose --quiet --all --set-upstream --append --upload-pack= --force --multiple --tags --jobs= --prune --prune-tags --recurse-submodules --dry-run --write-fetch-head --keep --update-head-ok --progress --depth= --shallow-since= --shallow-exclude= --deepen= --unshallow --update-shallow --refmap= --server-option= --ipv4 --ipv6 --negotiation-tip= --filter= --auto-maintenance --auto-gc --show-forced-updates --write-commit-graph --stdin --no-verbose -- --no-quiet --no-all --no-set-upstream --no-append --no-upload-pack --no-force --no-multiple --no-tags --no-jobs --no-prune --no-prune-tags --no-recurse-submodules --no-dry-run --no-write-fetch-head --no-keep --no-update-head-ok --no-progress --no-depth --no-shallow-since --no-shallow-exclude --no-deepen --no-update-shallow --no-server-option --no-ipv4 --no-ipv6 --no-negotiation-tip --no-filter --no-auto-maintenance --no-auto-gc --no-show-forced-updates --no-write-commit-graph --no-stdin" +__gitcomp_builtin_fmt_merge_msg_default=" --log --message= --file= --no-log -- --no-message --no-file" +__gitcomp_builtin_for_each_ref_default=" --shell --perl --python --tcl --count= --format= --color --sort= --points-at= --merged --no-merged --contains --no-contains --ignore-case -- --no-shell --no-perl --no-python --no-tcl --no-count --no-format --no-color --no-points-at --no-ignore-case" +__gitcomp_builtin_format_patch_default=" --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --to= --cc= --from --in-reply-to= --attach --inline --thread --signature= --base= --signature-file= --quiet --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-numbered --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-to --no-cc --no-from --no-in-reply-to --no-attach --no-thread --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor" +__gitcomp_builtin_fsck_default=" --verbose --unreachable --dangling --tags --root --cache --reflogs --full --connectivity-only --strict --lost-found --progress --name-objects --no-verbose -- --no-unreachable --no-dangling --no-tags --no-root --no-cache --no-reflogs --no-full --no-connectivity-only --no-strict --no-lost-found --no-progress --no-name-objects" +__gitcomp_builtin_fsck_objects_default=" --verbose --unreachable --dangling --tags --root --cache --reflogs --full --connectivity-only --strict --lost-found --progress --name-objects --no-verbose -- --no-unreachable --no-dangling --no-tags --no-root --no-cache --no-reflogs --no-full --no-connectivity-only --no-strict --no-lost-found --no-progress --no-name-objects" +__gitcomp_builtin_gc_default=" --quiet --prune --aggressive --keep-largest-pack --no-quiet -- --no-prune --no-aggressive --no-keep-largest-pack" +__gitcomp_builtin_grep_default=" --cached --no-index --untracked --exclude-standard --recurse-submodules --invert-match --ignore-case --word-regexp --text --textconv --recursive --max-depth= --extended-regexp --basic-regexp --fixed-strings --perl-regexp --line-number --column --full-name --files-with-matches --name-only --files-without-match --only-matching --count --color --break --heading --context= --before-context= --after-context= --threads= --show-function --function-context --and --or --not --quiet --all-match --index -- --no-cached --no-untracked --no-exclude-standard --no-recurse-submodules --no-invert-match --no-ignore-case --no-word-regexp --no-text --no-textconv --no-recursive --no-extended-regexp --no-basic-regexp --no-fixed-strings --no-perl-regexp --no-line-number --no-column --no-full-name --no-files-with-matches --no-name-only --no-files-without-match --no-only-matching --no-count --no-color --no-break --no-heading --no-context --no-before-context --no-after-context --no-threads --no-show-function --no-function-context --no-or --no-quiet --no-all-match" +__gitcomp_builtin_hash_object_default=" --stdin --stdin-paths --no-filters --literally --path= --filters -- --no-stdin --no-stdin-paths --no-literally --no-path" +__gitcomp_builtin_help_default=" --all --guides --config --man --web --info --verbose --no-all -- --no-guides --no-config --no-man --no-web --no-info --no-verbose" +__gitcomp_builtin_init_default=" --template= --bare --shared --quiet --separate-git-dir= --initial-branch= --object-format= --no-template -- --no-bare --no-quiet --no-separate-git-dir --no-initial-branch --no-object-format" +__gitcomp_builtin_init_db_default=" --template= --bare --shared --quiet --separate-git-dir= --initial-branch= --object-format= --no-template -- --no-bare --no-quiet --no-separate-git-dir --no-initial-branch --no-object-format" +__gitcomp_builtin_interpret_trailers_default=" --in-place --trim-empty --where= --if-exists= --if-missing= --only-trailers --only-input --unfold --parse --no-divider --trailer= --divider -- --no-in-place --no-trim-empty --no-where --no-if-exists --no-if-missing --no-only-trailers --no-only-input --no-unfold --no-trailer" +__gitcomp_builtin_log_default=" --quiet --source --use-mailmap --mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate" +__gitcomp_builtin_ls_files_default=" --cached --deleted --modified --others --ignored --stage --killed --directory --eol --empty-directory --unmerged --resolve-undo --exclude= --exclude-from= --exclude-per-directory= --exclude-standard --full-name --recurse-submodules --error-unmatch --with-tree= --abbrev --debug --no-cached -- --no-deleted --no-modified --no-others --no-ignored --no-stage --no-killed --no-directory --no-eol --no-empty-directory --no-unmerged --no-resolve-undo --no-exclude-per-directory --no-recurse-submodules --no-error-unmatch --no-with-tree --no-abbrev --no-debug" +__gitcomp_builtin_ls_remote_default=" --quiet --upload-pack= --tags --heads --refs --get-url --sort= --symref --server-option= --no-quiet -- --no-upload-pack --no-tags --no-heads --no-refs --no-get-url --no-symref --no-server-option" +__gitcomp_builtin_ls_tree_default=" --long --name-only --name-status --full-name --full-tree --abbrev --no-long -- --no-name-only --no-name-status --no-full-name --no-full-tree --no-abbrev" +__gitcomp_builtin_merge_default=" --stat --summary --log --squash --commit --edit --cleanup= --ff --ff-only --rerere-autoupdate --verify-signatures --strategy= --strategy-option= --message= --file --verbose --quiet --abort --quit --continue --allow-unrelated-histories --progress --gpg-sign --autostash --overwrite-ignore --signoff --no-verify --verify -- --no-stat --no-summary --no-log --no-squash --no-commit --no-edit --no-cleanup --no-ff --no-rerere-autoupdate --no-verify-signatures --no-strategy --no-strategy-option --no-message --no-verbose --no-quiet --no-abort --no-quit --no-continue --no-allow-unrelated-histories --no-progress --no-gpg-sign --no-autostash --no-overwrite-ignore --no-signoff" +__gitcomp_builtin_merge_base_default=" --all --octopus --independent --is-ancestor --fork-point --no-all" +__gitcomp_builtin_merge_file_default=" --stdout --diff3 --ours --theirs --union --marker-size= --quiet --no-stdout -- --no-diff3 --no-ours --no-theirs --no-union --no-marker-size --no-quiet" +__gitcomp_builtin_mktree_default=" --missing --batch --no-missing -- --no-batch" +__gitcomp_builtin_multi_pack_index_default=" --object-dir= --progress --batch-size= --no-object-dir -- --no-progress" +__gitcomp_builtin_mv_default=" --verbose --dry-run --no-verbose -- --no-dry-run" +__gitcomp_builtin_name_rev_default=" --name-only --tags --refs= --exclude= --all --stdin --undefined --always --no-name-only -- --no-tags --no-refs --no-exclude --no-all --no-stdin --no-undefined --no-always" +__gitcomp_builtin_notes_default=" --ref= --no-ref" +__gitcomp_builtin_pack_objects_default=" --quiet --progress --all-progress --all-progress-implied --index-version= --max-pack-size= --local --incremental --window= --window-memory= --depth= --reuse-delta --reuse-object --delta-base-offset --threads= --non-empty --revs --unpacked --all --reflog --indexed-objects --stdout --include-tag --keep-unreachable --pack-loose-unreachable --unpack-unreachable --sparse --thin --shallow --honor-pack-keep --keep-pack= --compression= --keep-true-parents --use-bitmap-index --write-bitmap-index --filter= --missing= --exclude-promisor-objects --delta-islands --uri-protocol= --no-quiet -- --no-progress --no-all-progress --no-all-progress-implied --no-local --no-incremental --no-window --no-depth --no-reuse-delta --no-reuse-object --no-delta-base-offset --no-threads --no-non-empty --no-revs --no-stdout --no-include-tag --no-keep-unreachable --no-pack-loose-unreachable --no-unpack-unreachable --no-sparse --no-thin --no-shallow --no-honor-pack-keep --no-keep-pack --no-compression --no-keep-true-parents --no-use-bitmap-index --no-write-bitmap-index --no-filter --no-exclude-promisor-objects --no-delta-islands --no-uri-protocol" +__gitcomp_builtin_pack_refs_default=" --all --prune --no-all -- --no-prune" +__gitcomp_builtin_pickaxe_default=" --incremental --root --show-stats --progress --score-debug --show-name --show-number --porcelain --line-porcelain --show-email --ignore-rev= --ignore-revs-file= --color-lines --color-by-age --minimal --contents= --abbrev --no-incremental -- --no-root --no-show-stats --no-progress --no-score-debug --no-show-name --no-show-number --no-porcelain --no-line-porcelain --no-show-email --no-ignore-rev --no-ignore-revs-file --no-color-lines --no-color-by-age --no-minimal --no-contents --no-abbrev" +__gitcomp_builtin_prune_default=" --dry-run --verbose --progress --expire= --exclude-promisor-objects --no-dry-run -- --no-verbose --no-progress --no-expire --no-exclude-promisor-objects" +__gitcomp_builtin_prune_packed_default=" --dry-run --quiet --no-dry-run -- --no-quiet" +__gitcomp_builtin_pull_default=" --verbose --quiet --progress --recurse-submodules --rebase --stat --log --signoff --squash --commit --edit --cleanup= --ff --ff-only --verify-signatures --autostash --strategy= --strategy-option= --gpg-sign --allow-unrelated-histories --all --append --upload-pack= --force --tags --prune --jobs --dry-run --keep --depth= --shallow-since= --shallow-exclude= --deepen= --unshallow --update-shallow --refmap= --server-option= --ipv4 --ipv6 --negotiation-tip= --show-forced-updates --set-upstream --no-verbose -- --no-quiet --no-progress --no-recurse-submodules --no-rebase --no-stat --no-log --no-signoff --no-squash --no-commit --no-edit --no-cleanup --no-ff --no-verify-signatures --no-autostash --no-strategy --no-strategy-option --no-gpg-sign --no-allow-unrelated-histories --no-all --no-append --no-upload-pack --no-force --no-tags --no-prune --no-jobs --no-dry-run --no-keep --no-depth --no-shallow-since --no-shallow-exclude --no-deepen --no-update-shallow --no-server-option --no-ipv4 --no-ipv6 --no-negotiation-tip --no-show-forced-updates --no-set-upstream" +__gitcomp_builtin_push_default=" --verbose --quiet --repo= --all --mirror --delete --tags --dry-run --porcelain --force --force-with-lease --recurse-submodules= --receive-pack= --exec= --set-upstream --progress --prune --no-verify --follow-tags --signed --atomic --push-option= --ipv4 --ipv6 --verify -- --no-verbose --no-quiet --no-repo --no-all --no-mirror --no-delete --no-tags --no-dry-run --no-porcelain --no-force --no-force-with-lease --no-recurse-submodules --no-receive-pack --no-exec --no-set-upstream --no-progress --no-prune --no-follow-tags --no-signed --no-atomic --no-push-option --no-ipv4 --no-ipv6" +__gitcomp_builtin_range_diff_default=" --creation-factor= --no-dual-color --notes --patch --no-patch --unified --function-context --raw --patch-with-raw --patch-with-stat --numstat --shortstat --dirstat --cumulative --dirstat-by-file --check --summary --name-only --name-status --stat --stat-width= --stat-name-width= --stat-graph-width= --stat-count= --compact-summary --binary --full-index --color --ws-error-highlight= --abbrev --src-prefix= --dst-prefix= --line-prefix= --no-prefix --inter-hunk-context= --output-indicator-new= --output-indicator-old= --output-indicator-context= --break-rewrites --find-renames --irreversible-delete --find-copies --find-copies-harder --no-renames --rename-empty --follow --minimal --ignore-all-space --ignore-space-change --ignore-space-at-eol --ignore-cr-at-eol --ignore-blank-lines --indent-heuristic --patience --histogram --diff-algorithm= --anchored= --word-diff --word-diff-regex= --color-words --color-moved --color-moved-ws= --relative --text --exit-code --quiet --ext-diff --textconv --ignore-submodules --submodule --ita-invisible-in-index --ita-visible-in-index --pickaxe-all --pickaxe-regex --find-object= --diff-filter= --output= --dual-color -- --no-creation-factor --no-notes --no-function-context --no-compact-summary --no-full-index --no-color --no-abbrev --no-find-copies-harder --no-rename-empty --no-follow --no-minimal --no-indent-heuristic --no-color-moved --no-color-moved-ws --no-relative --no-text --no-exit-code --no-quiet --no-ext-diff --no-textconv" +__gitcomp_builtin_read_tree_default=" --index-output= --empty --verbose --trivial --aggressive --reset --prefix= --exclude-per-directory= --dry-run --no-sparse-checkout --debug-unpack --recurse-submodules --quiet --sparse-checkout -- --no-empty --no-verbose --no-trivial --no-aggressive --no-reset --no-dry-run --no-debug-unpack --no-recurse-submodules --no-quiet" +__gitcomp_builtin_rebase_default=" --onto= --keep-base --no-verify --quiet --verbose --no-stat --signoff --committer-date-is-author-date --reset-author-date --ignore-whitespace --whitespace= --force-rebase --no-ff --continue --skip --abort --quit --edit-todo --show-current-patch --apply --merge --interactive --rerere-autoupdate --empty= --autosquash --gpg-sign --autostash --exec= --rebase-merges --fork-point --strategy= --strategy-option= --root --reschedule-failed-exec --reapply-cherry-picks --verify --stat --ff -- --no-onto --no-keep-base --no-quiet --no-verbose --no-signoff --no-committer-date-is-author-date --no-reset-author-date --no-ignore-whitespace --no-whitespace --no-force-rebase --no-rerere-autoupdate --no-autosquash --no-gpg-sign --no-autostash --no-exec --no-rebase-merges --no-fork-point --no-strategy --no-strategy-option --no-root --no-reschedule-failed-exec --no-reapply-cherry-picks" +__gitcomp_builtin_rebase__interactive_default=" --ff --rebase-merges --rebase-cousins --autosquash --signoff --verbose --continue --skip --edit-todo --show-current-patch --shorten-ids --expand-ids --check-todo-list --rearrange-squash --add-exec-commands --onto= --restrict-revision= --squash-onto= --upstream= --head-name= --gpg-sign --strategy= --strategy-opts= --switch-to= --onto-name= --cmd= --rerere-autoupdate --reschedule-failed-exec --no-ff -- --no-rebase-merges --no-rebase-cousins --no-autosquash --no-signoff --no-verbose --no-head-name --no-gpg-sign --no-strategy --no-strategy-opts --no-switch-to --no-onto-name --no-cmd --no-rerere-autoupdate --no-reschedule-failed-exec" +__gitcomp_builtin_receive_pack_default=" --quiet --no-quiet" +__gitcomp_builtin_reflog_default=" --quiet --source --use-mailmap --mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate" +__gitcomp_builtin_remote_default=" --verbose --no-verbose" +__gitcomp_builtin_repack_default=" --quiet --local --write-bitmap-index --delta-islands --unpack-unreachable= --keep-unreachable --window= --window-memory= --depth= --threads= --max-pack-size= --pack-kept-objects --keep-pack= --no-quiet -- --no-local --no-write-bitmap-index --no-delta-islands --no-unpack-unreachable --no-keep-unreachable --no-window --no-window-memory --no-depth --no-threads --no-max-pack-size --no-pack-kept-objects --no-keep-pack" +__gitcomp_builtin_replace_default=" --list --delete --edit --graft --convert-graft-file --raw --format= --no-raw -- --no-format" +__gitcomp_builtin_rerere_default=" --rerere-autoupdate --no-rerere-autoupdate" +__gitcomp_builtin_reset_default=" --quiet --mixed --soft --hard --merge --keep --recurse-submodules --patch --intent-to-add --pathspec-from-file= --pathspec-file-nul --no-quiet -- --no-mixed --no-soft --no-hard --no-merge --no-keep --no-recurse-submodules --no-patch --no-intent-to-add --no-pathspec-from-file --no-pathspec-file-nul" +__gitcomp_builtin_restore_default=" --source= --staged --worktree --ignore-unmerged --overlay --quiet --recurse-submodules --progress --merge --conflict= --ours --theirs --patch --ignore-skip-worktree-bits --pathspec-from-file= --pathspec-file-nul --no-source -- --no-staged --no-worktree --no-ignore-unmerged --no-overlay --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-patch --no-ignore-skip-worktree-bits --no-pathspec-from-file --no-pathspec-file-nul" +__gitcomp_builtin_revert_default=" --quit --continue --abort --skip --cleanup= --no-commit --edit --signoff --mainline= --rerere-autoupdate --strategy= --strategy-option= --gpg-sign --commit -- --no-cleanup --no-edit --no-signoff --no-mainline --no-rerere-autoupdate --no-strategy --no-strategy-option --no-gpg-sign" +__gitcomp_builtin_rm_default=" --dry-run --quiet --cached --ignore-unmatch --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-quiet --no-cached --no-ignore-unmatch --no-pathspec-from-file --no-pathspec-file-nul" +__gitcomp_builtin_send_pack_default=" --verbose --quiet --receive-pack= --exec= --remote= --all --dry-run --mirror --force --signed --push-option= --progress --thin --atomic --stateless-rpc --stdin --helper-status --force-with-lease --no-verbose -- --no-quiet --no-receive-pack --no-exec --no-remote --no-all --no-dry-run --no-mirror --no-force --no-signed --no-push-option --no-progress --no-thin --no-atomic --no-stateless-rpc --no-stdin --no-helper-status --no-force-with-lease" +__gitcomp_builtin_shortlog_default=" --committer --numbered --summary --email --group= --no-committer -- --no-numbered --no-summary --no-email --no-group" +__gitcomp_builtin_show_default=" --quiet --source --use-mailmap --mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate" +__gitcomp_builtin_show_branch_default=" --all --remotes --color --more --list --no-name --current --sha1-name --merge-base --independent --topo-order --topics --sparse --date-order --reflog --name -- --no-all --no-remotes --no-color --no-more --no-list --no-current --no-sha1-name --no-merge-base --no-independent --no-topo-order --no-topics --no-sparse --no-date-order" +__gitcomp_builtin_show_index_default=" --object-format= --no-object-format" +__gitcomp_builtin_show_ref_default=" --tags --heads --verify --head --dereference --hash --abbrev --quiet --exclude-existing --no-tags -- --no-heads --no-verify --no-head --no-dereference --no-hash --no-abbrev --no-quiet" +__gitcomp_builtin_sparse_checkout_default="" +__gitcomp_builtin_stage_default=" --dry-run --verbose --interactive --patch --edit --force --update --renormalize --intent-to-add --all --ignore-removal --refresh --ignore-errors --ignore-missing --chmod= --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-verbose --no-interactive --no-patch --no-edit --no-force --no-update --no-renormalize --no-intent-to-add --no-all --no-ignore-removal --no-refresh --no-ignore-errors --no-ignore-missing --no-chmod --no-pathspec-from-file --no-pathspec-file-nul" +__gitcomp_builtin_stash_default="" +__gitcomp_builtin_status_default=" --verbose --short --branch --show-stash --ahead-behind --porcelain --long --null --untracked-files --ignored --ignore-submodules --column --no-renames --find-renames --renames -- --no-verbose --no-short --no-branch --no-show-stash --no-ahead-behind --no-porcelain --no-long --no-null --no-untracked-files --no-ignored --no-ignore-submodules --no-column" +__gitcomp_builtin_stripspace_default=" --strip-comments --comment-lines" +__gitcomp_builtin_switch_default=" --create= --force-create= --guess --discard-changes --quiet --recurse-submodules --progress --merge --conflict= --detach --track --orphan= --ignore-other-worktrees --no-create -- --no-force-create --no-guess --no-discard-changes --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-detach --no-track --no-orphan --no-ignore-other-worktrees" +__gitcomp_builtin_symbolic_ref_default=" --quiet --delete --short --no-quiet -- --no-delete --no-short" +__gitcomp_builtin_tag_default=" --list --delete --verify --annotate --message= --file= --edit --sign --cleanup= --local-user= --force --create-reflog --column --contains --no-contains --merged --no-merged --sort= --points-at --format= --color --ignore-case -- --no-annotate --no-file --no-edit --no-sign --no-cleanup --no-local-user --no-force --no-create-reflog --no-column --no-points-at --no-format --no-color --no-ignore-case" +__gitcomp_builtin_update_index_default=" --ignore-submodules --add --replace --remove --unmerged --refresh --really-refresh --cacheinfo --chmod= --assume-unchanged --no-assume-unchanged --skip-worktree --no-skip-worktree --ignore-skip-worktree-entries --info-only --force-remove --stdin --index-info --unresolve --again --ignore-missing --verbose --clear-resolve-undo --index-version= --split-index --untracked-cache --test-untracked-cache --force-untracked-cache --force-write-index --fsmonitor --fsmonitor-valid --no-fsmonitor-valid -- --no-ignore-submodules --no-add --no-replace --no-remove --no-unmerged --no-ignore-skip-worktree-entries --no-info-only --no-force-remove --no-ignore-missing --no-verbose --no-index-version --no-split-index --no-untracked-cache --no-test-untracked-cache --no-force-untracked-cache --no-force-write-index --no-fsmonitor" +__gitcomp_builtin_update_ref_default=" --no-deref --stdin --create-reflog --deref -- --no-stdin --no-create-reflog" +__gitcomp_builtin_update_server_info_default=" --force --no-force" +__gitcomp_builtin_upload_pack_default=" --stateless-rpc --advertise-refs --strict --timeout= --no-stateless-rpc -- --no-advertise-refs --no-strict --no-timeout" +__gitcomp_builtin_verify_commit_default=" --verbose --raw --no-verbose -- --no-raw" +__gitcomp_builtin_verify_pack_default=" --verbose --stat-only --object-format= --no-verbose -- --no-stat-only --no-object-format" +__gitcomp_builtin_verify_tag_default=" --verbose --raw --format= --no-verbose -- --no-raw --no-format" +__gitcomp_builtin_version_default=" --build-options --no-build-options" +__gitcomp_builtin_whatchanged_default=" --quiet --source --use-mailmap --mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate" +__gitcomp_builtin_write_tree_default=" --missing-ok --prefix= --no-missing-ok -- --no-prefix" +__gitcomp_builtin_send_email_default=" --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --to= --cc= --from --in-reply-to= --attach --inline --thread --signature= --base= --signature-file= --quiet --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-numbered --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-to --no-cc --no-from --no-in-reply-to --no-attach --no-thread --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor" + +__gitcomp_builtin_get_default () +{ + eval "test -n \"\$${1}_default\" && echo \"\$${1}_default\"" +} + +# This function is equivalent to +# +# __gitcomp "$(git xxx --git-completion-helper) ..." +# +# except that the output is cached. Accept 1-3 arguments: +# 1: the git command to execute, this is also the cache key +# 2: extra options to be added on top (e.g. negative forms) +# 3: options to be excluded +__gitcomp_builtin () +{ + # spaces must be replaced with underscore for multi-word + # commands, e.g. "git remote add" becomes remote_add. + local cmd="$1" + local incl="${2-}" + local excl="${3-}" + + local var=__gitcomp_builtin_"${cmd/-/_}" + local options + eval "options=\${$var-}" + + if [ -z "$options" ]; then + local completion_helper + if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then + completion_helper="--git-completion-helper-all" + else + completion_helper="--git-completion-helper" + fi + completion="$(__git ${cmd/_/ } $completion_helper || + __gitcomp_builtin_get_default $var)" || return + # leading and trailing spaces are significant to make + # option removal work correctly. + options=" $incl $completion " + + for i in $excl; do + options="${options/ $i / }" + done + eval "$var=\"$options\"" + fi + + __gitcomp "$options" +} + # Variation of __gitcomp_nl () that appends to the existing list of # completion candidates, COMPREPLY. __gitcomp_nl_append () @@ -303,6 +568,24 @@ __gitcomp_nl () __gitcomp_nl_append "$@" } +# Fills the COMPREPLY array with prefiltered paths without any additional +# processing. +# Callers must take care of providing only paths that match the current path +# to be completed and adding any prefix path components, if necessary. +# 1: List of newline-separated matching paths, complete with all prefix +# path components. +__gitcomp_file_direct () +{ + local IFS=$'\n' + + COMPREPLY=($1) + + # use a hack to enable file mode in bash < 4 + compopt -o filenames +o nospace 2>/dev/null || + compgen -f /non-existing-dir/ >/dev/null || + true +} + # Generates completion reply with compgen from newline-separated possible # completion filenames. # It accepts 1 to 3 arguments: @@ -322,7 +605,8 @@ __gitcomp_file () # use a hack to enable file mode in bash < 4 compopt -o filenames +o nospace 2>/dev/null || - compgen -f /non-existing-dir/ > /dev/null + compgen -f /non-existing-dir/ >/dev/null || + true } # Execute 'git ls-files', unless the --committable option is specified, in @@ -332,10 +616,12 @@ __gitcomp_file () __git_ls_files_helper () { if [ "$2" == "--committable" ]; then - __git -C "$1" diff-index --name-only --relative HEAD + __git -C "$1" -c core.quotePath=false diff-index \ + --name-only --relative HEAD -- "${3//\\/\\\\}*" else # NOTE: $2 is not quoted in order to support multiple options - __git -C "$1" ls-files --exclude-standard $2 + __git -C "$1" -c core.quotePath=false ls-files \ + --exclude-standard $2 -- "${3//\\/\\\\}*" fi } @@ -346,17 +632,103 @@ __git_ls_files_helper () # If provided, only files within the specified directory are listed. # Sub directories are never recursed. Path must have a trailing # slash. +# 3: List only paths matching this path component (optional). __git_index_files () { - local root="${2-.}" file + local root="$2" match="$3" - __git_ls_files_helper "$root" "$1" | - while read -r file; do - case "$file" in - ?*/*) echo "${file%%/*}" ;; - *) echo "$file" ;; - esac - done | sort | uniq + __git_ls_files_helper "$root" "$1" "${match:-?}" | + awk -F / -v pfx="${2//\\/\\\\}" '{ + paths[$1] = 1 + } + END { + for (p in paths) { + if (substr(p, 1, 1) != "\"") { + # No special characters, easy! + print pfx p + continue + } + + # The path is quoted. + p = dequote(p) + if (p == "") + continue + + # Even when a directory name itself does not contain + # any special characters, it will still be quoted if + # any of its (stripped) trailing path components do. + # Because of this we may have seen the same directory + # both quoted and unquoted. + if (p in paths) + # We have seen the same directory unquoted, + # skip it. + continue + else + print pfx p + } + } + function dequote(p, bs_idx, out, esc, esc_idx, dec) { + # Skip opening double quote. + p = substr(p, 2) + + # Interpret backslash escape sequences. + while ((bs_idx = index(p, "\\")) != 0) { + out = out substr(p, 1, bs_idx - 1) + esc = substr(p, bs_idx + 1, 1) + p = substr(p, bs_idx + 2) + + if ((esc_idx = index("abtvfr\"\\", esc)) != 0) { + # C-style one-character escape sequence. + out = out substr("\a\b\t\v\f\r\"\\", + esc_idx, 1) + } else if (esc == "n") { + # Uh-oh, a newline character. + # We cannot reliably put a pathname + # containing a newline into COMPREPLY, + # and the newline would create a mess. + # Skip this path. + return "" + } else { + # Must be a \nnn octal value, then. + dec = esc * 64 + \ + substr(p, 1, 1) * 8 + \ + substr(p, 2, 1) + out = out sprintf("%c", dec) + p = substr(p, 3) + } + } + # Drop closing double quote, if there is one. + # (There is not any if this is a directory, as it was + # already stripped with the trailing path components.) + if (substr(p, length(p), 1) == "\"") + out = out substr(p, 1, length(p) - 1) + else + out = out p + + return out + }' +} + +# __git_complete_index_file requires 1 argument: +# 1: the options to pass to ls-file +# +# The exception is --committable, which finds the files appropriate commit. +__git_complete_index_file () +{ + local dequoted_word pfx="" cur_ + + __git_dequote "$cur" + + case "$dequoted_word" in + ?*/*) + pfx="${dequoted_word%/*}/" + cur_="${dequoted_word##*/}" + ;; + *) + cur_="$dequoted_word" + esac + + __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")" } # Lists branches from the local repository. @@ -372,6 +744,19 @@ __git_heads () "refs/heads/$cur_*" "refs/heads/$cur_*/**" } +# Lists branches from remote repositories. +# 1: A prefix to be added to each listed branch (optional). +# 2: List only branches matching this word (optional; list all branches if +# unset or empty). +# 3: A suffix to be appended to each listed branch (optional). +__git_remote_heads () +{ + local pfx="${1-}" cur_="${2-}" sfx="${3-}" + + __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + "refs/remotes/$cur_*" "refs/remotes/$cur_*/**" +} + # Lists tags from the local repository. # Accepts the same positional parameters as __git_heads() above. __git_tags () @@ -382,6 +767,26 @@ __git_tags () "refs/tags/$cur_*" "refs/tags/$cur_*/**" } +# List unique branches from refs/remotes used for 'git checkout' and 'git +# switch' tracking DWIMery. +# 1: A prefix to be added to each listed branch (optional) +# 2: List only branches matching this word (optional; list all branches if +# unset or empty). +# 3: A suffix to be appended to each listed branch (optional). +__git_dwim_remote_heads () +{ + local pfx="${1-}" cur_="${2-}" sfx="${3-}" + local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers + + # employ the heuristic used by git checkout and git switch + # Try to find a remote branch that cur_es the completion word + # but only output if the branch name is unique + __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ + --sort="refname:strip=3" \ + "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \ + uniq -u +} + # Lists refs from the local (by default) or from a remote repository. # It accepts 0, 1 or 2 arguments: # 1: The remote to list refs from (optional; ignored, if set but empty). @@ -439,7 +844,7 @@ __git_refs () track="" ;; *) - for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do + for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do case "$i" in $match*) if [ -e "$dir/$i" ]; then @@ -457,13 +862,7 @@ __git_refs () __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \ "${refs[@]}" if [ -n "$track" ]; then - # employ the heuristic used by git checkout - # Try to find a remote branch that matches the completion word - # but only output if the branch name is unique - __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ - --sort="refname:strip=3" \ - "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \ - uniq -u + __git_dwim_remote_heads "$pfx" "$match" "$sfx" fi return fi @@ -510,29 +909,51 @@ __git_refs () # Usage: __git_complete_refs [