From 82d261603d968dfe5e86a44464c38fd88dda802c Mon Sep 17 00:00:00 2001 From: vladislav doster <10052309+vladdoster@users.noreply.github.com> Date: Mon, 20 Mar 2023 02:11:03 -0500 Subject: feat(gnu-utils): add `gindent` (#11569) --- plugins/gnu-utils/gnu-utils.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/gnu-utils/gnu-utils.plugin.zsh b/plugins/gnu-utils/gnu-utils.plugin.zsh index 6bd3e8463..6023bf2b4 100644 --- a/plugins/gnu-utils/gnu-utils.plugin.zsh +++ b/plugins/gnu-utils/gnu-utils.plugin.zsh @@ -19,7 +19,7 @@ __gnu_utils() { 'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate' 'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand' 'gexpr' 'gfactor' 'gfalse' 'gfmt' 'gfold' 'ggroups' 'ghead' 'ghostid' - 'gid' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum' + 'gid' 'gindent' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum' 'gmkdir' 'gmkfifo' 'gmknod' 'gmktemp' 'gmv' 'gnice' 'gnl' 'gnohup' 'gnproc' 'god' 'gpaste' 'gpathchk' 'gpinky' 'gpr' 'gprintenv' 'gprintf' 'gptx' 'gpwd' 'greadlink' 'grm' 'grmdir' 'gruncon' 'gseq' 'gsha1sum' 'gsha224sum' -- cgit v1.2.3-70-g09d2 From 4a39779067eda369152bfd6b653f843286c930c0 Mon Sep 17 00:00:00 2001 From: Yu Xiang Zhang Date: Tue, 14 Mar 2023 19:02:54 +0000 Subject: feat(aws): set region when AWS_REGION is not set --- plugins/aws/README.md | 2 +- plugins/aws/aws.plugin.zsh | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/aws/README.md b/plugins/aws/README.md index e1e355741..846bf1414 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -12,7 +12,7 @@ plugins=(... aws) ## Plugin commands * `asp []`: sets `$AWS_PROFILE` and `$AWS_DEFAULT_PROFILE` (legacy) to ``. - It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. + It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`. Run `asp` without arguments to clear the profile. * `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 1c386a3e1..39c47d572 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -9,7 +9,7 @@ function agr() { # AWS profile selection function asp() { if [[ -z "$1" ]]; then - unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE + unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE AWS_PROFILE_REGION echo AWS profile cleared. return fi @@ -26,6 +26,8 @@ function asp() { export AWS_PROFILE=$1 export AWS_EB_PROFILE=$1 + export AWS_PROFILE_REGION=$(aws configure get region) + if [[ "$2" == "login" ]]; then aws sso login fi @@ -195,7 +197,8 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { if [[ -z $AWS_REGION && -z $AWS_PROFILE ]];then return; fi - echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" + region=${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}} + echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then -- cgit v1.2.3-70-g09d2 From f9f01e48a890ad4359a6973d1b8a7039f57b2d08 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 21 Mar 2023 15:29:48 +0100 Subject: fix(aws): do not print region if it's not defined Closes #11568 Closes #11570 --- plugins/aws/aws.plugin.zsh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 39c47d572..0242be97e 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -196,9 +196,15 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { - if [[ -z $AWS_REGION && -z $AWS_PROFILE ]];then return; fi - region=${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}} - echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" + local _aws_to_show + if [[ -n $AWS_PROFILE ]];then + _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" + fi + if [[ -n $AWS_REGION ]]; then + [[ -n $AWS_PROFILE ]] && _aws_to_show+=" " + _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX:=}" + fi + echo "$_aws_to_show" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then -- cgit v1.2.3-70-g09d2 From 5efcfc39735c818a9778172356f82ec0eb3e5916 Mon Sep 17 00:00:00 2001 From: "Jose C. Massón" <939888+Abuelodelanada@users.noreply.github.com> Date: Thu, 23 Mar 2023 05:42:20 -0300 Subject: feat(juju): add functions to get current controller and model (#11572) --- plugins/juju/README.md | 2 ++ plugins/juju/juju.plugin.zsh | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/juju/README.md b/plugins/juju/README.md index f0c65309c..6ee333f50 100644 --- a/plugins/juju/README.md +++ b/plugins/juju/README.md @@ -126,5 +126,7 @@ Naming convention: - `jaddr [unit_num]`: display app or unit IP address. - `jreld `: display app and unit relation data. - `jclean`: destroy all controllers +- `jcontroller`: display the controller your are connected to. +- `jmodel`: display the model your are connected to. - `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval (default: 5s); you may pass additional arguments to `watch`. diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh index be8a2c7ae..0c60e35ce 100644 --- a/plugins/juju/juju.plugin.zsh +++ b/plugins/juju/juju.plugin.zsh @@ -163,10 +163,40 @@ jreld() { juju run "relation-get -r $relid - $2" --unit $2/$3 } +# Return Juju current controller +jcontroller() { + local controller="$(awk '/current-controller/ {print $2}' ~/.local/share/juju/controllers.yaml)" + if [[ -z "$controller" ]]; then + return 1 + fi + + echo $controller + return 0 +} + +# Return Juju current model +jmodel() { + local yqbin="$(whereis yq | awk '{print $2}')" + + if [[ -z "$yqbin" ]]; then + echo "--" + return 1 + fi + + local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)" + + if [[ -z "$model" ]]; then + echo "--" + return 1 + fi + + echo $model + return 0 +} + # Watch juju status, with optional interval (default: 5 sec) wjst() { local interval="${1:-5}" shift $(( $# > 0 )) watch -n "$interval" --color juju status --relations --color "$@" } - -- cgit v1.2.3-70-g09d2 From c08b925d282e35ea7bd9a8f4c29de2ece0debb49 Mon Sep 17 00:00:00 2001 From: Michele Bologna Date: Thu, 23 Mar 2023 14:34:43 +0100 Subject: fix(uninstall): abort uninstall if unable to change shell (#10357) --- tools/uninstall.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 6a0e7b4c7..6e3df7aca 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,3 +1,15 @@ +if hash chsh >/dev/null 2>&1 && [ -f ~/.shell.pre-oh-my-zsh ]; then + old_shell=$(cat ~/.shell.pre-oh-my-zsh) + echo "Switching your shell back to '$old_shell':" + if chsh -s "$old_shell"; then + rm -f ~/.shell.pre-oh-my-zsh + else + echo "Could not change default shell. Change it manually by running chsh" + echo "or editing the /etc/passwd file." + exit + fi +fi + read -r -p "Are you sure you want to remove Oh My Zsh? [y/N] " confirmation if [ "$confirmation" != y ] && [ "$confirmation" != Y ]; then echo "Uninstall cancelled" @@ -25,16 +37,5 @@ else echo "No original zsh config found" fi -if hash chsh >/dev/null 2>&1 && [ -f ~/.shell.pre-oh-my-zsh ]; then - old_shell=$(cat ~/.shell.pre-oh-my-zsh) - echo "Switching your shell back to '$old_shell':" - if chsh -s "$old_shell"; then - rm -f ~/.shell.pre-oh-my-zsh - else - echo "Could not change default shell. Change it manually by running chsh" - echo "or editing the /etc/passwd file." - fi -fi - echo "Thanks for trying out Oh My Zsh. It's been uninstalled." echo "Don't forget to restart your terminal!" -- cgit v1.2.3-70-g09d2 From 8f6fbe238969ecb22fbdae75450a9f8705c9f979 Mon Sep 17 00:00:00 2001 From: Håvard Bartnes Date: Tue, 28 Mar 2023 12:50:05 +0200 Subject: feat(upgrade): add verbosity settings Co-authored-by: Carlo Sala Closes #11574 Closes #11579 --- README.md | 12 +++++++++++ lib/cli.zsh | 5 +++-- tools/check_for_upgrade.sh | 3 ++- tools/upgrade.sh | 53 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4042c8c26..4f0aeb7b4 100644 --- a/README.md +++ b/README.md @@ -317,6 +317,18 @@ zstyle ':omz:update' frequency 7 zstyle ':omz:update' frequency 0 ``` +### Updates verbosity + +You can also limit the update verbosity with the following settings: + +```sh +zstyle ':omz:update' verbose default # default update prompt + +zstyle ':omz:update' verbose minimal # only few lines + +zstyle ':omz:update' verbose silent # only errors +``` + ### Manual Updates If you'd like to update at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run: diff --git a/lib/cli.zsh b/lib/cli.zsh index fed00d21d..ba3e39eb5 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -776,10 +776,11 @@ function _omz::update { local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD) # Run update script + zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default if [[ "$1" != --unattended ]]; then - ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" --interactive || return $? + ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $? else - ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" || return $? + ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -v $verbose_mode || return $? fi # Update last updated file diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 734714c94..81c371b3f 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -95,7 +95,8 @@ function update_last_updated_file() { } function update_ohmyzsh() { - if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive; then + zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default + if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then update_last_updated_file fi } diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 596a59302..684ad894a 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -12,6 +12,23 @@ esac cd "$ZSH" +verbose_mode="default" +interactive=false + +while getopts "v:i" opt; do + case $opt in + v) + if [[ $OPTARG == default || $OPTARG == minimal || $OPTARG == silent ]]; then + verbose_mode=$OPTARG + else + echo "[oh-my-zsh] update verbosity '$OPTARG' is not valid" + echo "[oh-my-zsh] valid options are 'default', 'minimal' and 'silent'" + fi + ;; + i) interactive=true ;; + esac +done + # Use colors, but only if connected to a terminal # and that terminal supports them. @@ -203,7 +220,9 @@ git checkout -q "$branch" -- || exit 1 last_commit=$(git rev-parse "$branch") # Update Oh My Zsh -printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh" +if [[ $verbose_mode != silent ]]; then + printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh" +fi if LANG= git pull --quiet --rebase $remote $branch; then # Check if it was really updated or not if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then @@ -215,24 +234,30 @@ if LANG= git pull --quiet --rebase $remote $branch; then git config oh-my-zsh.lastVersion "$last_commit" # Print changelog to the terminal - if [[ "$1" = --interactive ]]; then + if [[ interactive == true && $verbose_mode == default ]] ; then "$ZSH/tools/changelog.sh" HEAD "$last_commit" fi - printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog" + if [[ $verbose_mode != silent ]]; then + printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog" + fi fi - printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET - printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET - printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $RAINBOW $RESET - printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET - printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET - printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET - printf '\n' - printf "${BLUE}%s${RESET}\n\n" "$message" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)" + if [[ $verbose_mode == default ]]; then + printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET + printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET + printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $RAINBOW $RESET + printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET + printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET + printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET + printf '\n' + printf "${BLUE}%s${RESET}\n\n" "$message" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)" + elif [[ $verbose_mode == minimal ]]; then + printf "${BLUE}%s${RESET}\n" "$message" + fi else ret=$? printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?' -- cgit v1.2.3-70-g09d2 From fcbdc330ff50617c8b84d39ce069cc75df41108f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 28 Mar 2023 16:55:53 +0200 Subject: fix(aws): restore accidentally deleted variable Closes #11589 --- plugins/aws/aws.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 0242be97e..a379eaa18 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -197,6 +197,7 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { local _aws_to_show + local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}" if [[ -n $AWS_PROFILE ]];then _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" fi @@ -211,7 +212,6 @@ if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; th RPROMPT='$(aws_prompt_info)'"$RPROMPT" fi - # Load awscli completions # AWS CLI v2 comes with its own autocompletion. Check if that is there, otherwise fall back -- cgit v1.2.3-70-g09d2 From 7837ba6a993fb2243b3e69fdbd63b437a8674b4c Mon Sep 17 00:00:00 2001 From: Webpage-gh <70434775+Webpage-gh@users.noreply.github.com> Date: Fri, 31 Mar 2023 13:37:01 +0800 Subject: fix(installer): don't use `sudo` when user is in Termux (#11591) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- tools/install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/install.sh b/tools/install.sh index f4ef16a0c..efdb7d482 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -84,6 +84,11 @@ command_exists() { user_can_sudo() { # Check if sudo is installed command_exists sudo || return 1 + # Termux can't run sudo unless the device is rooted. Either way, `chsh` works + # without sudo, so we can detect it and exit the function early. + case "$PREFIX" in + *com.termux*) return 1 ;; + esac # The following command has 3 parts: # # 1. Run `sudo` with `-v`. Does the following: -- cgit v1.2.3-70-g09d2 From b9c4e2e82337594c2899db1f9ca005bb02fe20cd Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Fri, 31 Mar 2023 18:49:59 +1300 Subject: feat(changelog): provide links in changelog (#11578) --- tools/changelog.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index a5cc468f2..5f7a14d03 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -157,6 +157,89 @@ function parse-commit { fi } +################################ +# SUPPORTS HYPERLINKS FUNCTION # +################################ + +# The code for checking if a terminal supports hyperlinks is copied from install.sh + +# The [ -t 1 ] check only works when the function is not called from +# a subshell (like in `$(...)` or `(...)`, so this hack redefines the +# function at the top level to always return false when stdout is not +# a tty. +if [ -t 1 ]; then + is_tty() { + true + } +else + is_tty() { + false + } +fi + +# This function uses the logic from supports-hyperlinks[1][2], which is +# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0. +# [1] https://github.com/zkat/supports-hyperlinks +# [2] https://crates.io/crates/supports-hyperlinks +# +# Copyright (c) 2021 Kat Marchán +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +supports_hyperlinks() { + # $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass) + if [ -n "$FORCE_HYPERLINK" ]; then + [ "$FORCE_HYPERLINK" != 0 ] + return $? + fi + + # If stdout is not a tty, it doesn't support hyperlinks + is_tty || return 1 + + # DomTerm terminal emulator (domterm.org) + if [ -n "$DOMTERM" ]; then + return 0 + fi + + # VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc) + if [ -n "$VTE_VERSION" ]; then + [ $VTE_VERSION -ge 5000 ] + return $? + fi + + # If $TERM_PROGRAM is set, these terminals support hyperlinks + case "$TERM_PROGRAM" in + Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + esac + + # kitty supports hyperlinks + if [ "$TERM" = xterm-kitty ]; then + return 0 + fi + + # Windows Terminal also supports hyperlinks + if [ -n "$WT_SESSION" ]; then + return 0 + fi + + # Konsole supports hyperlinks, but it's an opt-in setting that can't be detected + # https://github.com/ohmyzsh/ohmyzsh/issues/10964 + # if [ -n "$KONSOLE_VERSION" ]; then + # return 0 + # fi + + return 1 +} + ############################# # RELEASE CHANGELOG DISPLAY # ############################# @@ -208,7 +291,13 @@ function display-release { local hash="${1:-$hash}" case "$output" in raw) printf '%s' "$hash" ;; - text) printf '\e[33m%s\e[0m' "$hash" ;; # red + text) + local text="\e[33m$hash\e[0m"; # red + if supports_hyperlinks; then + printf "\e]8;;%s\a%s\e]8;;\a" "https://github.com/ohmyzsh/ohmyzsh/commit/$hash" $text; + else + echo $text; + fi ;; md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$hash" "$hash" ;; esac } @@ -272,7 +361,12 @@ function display-release { case "$output" in raw) printf '%s' "$subject" ;; # In text mode, highlight (#) and dim text between `backticks` - text) sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" ;; + text) + if supports_hyperlinks; then + sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g' <<< "$subject" + else + sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" + fi ;; # In markdown mode, link to (#) issues md) sed -E 's|#([0-9]+)|[#\1](https://github.com/ohmyzsh/ohmyzsh/issues/\1)|g' <<< "$subject" ;; esac -- cgit v1.2.3-70-g09d2 From cc9913210498e2d527486310f1e8a53b93f55ca8 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 31 Mar 2023 07:51:10 +0200 Subject: fix(vi-mode): fix check for prompt redisplay on mode change (#11547) --- plugins/vi-mode/vi-mode.plugin.zsh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 9a410c1fb..d44be69d4 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -43,12 +43,25 @@ function _vi-mode-set-cursor-shape-for-keymap() { printf $'\e[%d q' "${_shape}" } +function _vi-mode-should-reset-prompt() { + # If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE is unset (default), dynamically + # check whether we're using the prompt to display vi-mode info + if [[ -z "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" ]]; then + [[ "${PS1} ${RPS1}" = *'$(vi_mode_prompt_info)'* ]] + return $? + fi + + # If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE was manually set, let's check + # if it was specifically set to true or it was disabled with any other value + [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE}" = true ]] +} + # Updates editor information when the keymap changes. function zle-keymap-select() { # update keymap variable for the prompt typeset -g VI_KEYMAP=$KEYMAP - if [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]]; then + if _vi-mode-should-reset-prompt; then zle reset-prompt zle -R fi @@ -59,10 +72,9 @@ zle -N zle-keymap-select # These "echoti" statements were originally set in lib/key-bindings.zsh # Not sure the best way to extend without overriding. function zle-line-init() { - local prev_vi_keymap - prev_vi_keymap="${VI_KEYMAP:-}" + local prev_vi_keymap="${VI_KEYMAP:-}" typeset -g VI_KEYMAP=main - [[ "$prev_vi_keymap" != 'main' ]] && [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]] && zle reset-prompt + [[ "$prev_vi_keymap" != 'main' ]] && _vi-mode-should-reset-prompt && zle reset-prompt (( ! ${+terminfo[smkx]} )) || echoti smkx _vi-mode-set-cursor-shape-for-keymap "${VI_KEYMAP}" } @@ -138,13 +150,6 @@ if [[ -z "$MODE_INDICATOR" ]]; then fi function vi_mode_prompt_info() { - # If we're using the prompt to display mode info, and we haven't explicitly - # disabled "reset prompt on mode change", then set it here. - # - # We do that here instead of the `if` statement below because the user may - # set RPS1/RPROMPT to something else in their custom config. - : "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:=true}" - echo "${${VI_KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/$INSERT_MODE_INDICATOR}" } -- cgit v1.2.3-70-g09d2 From 029a6d2de8681d52142129eb8b6ff0f20be9f0a6 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Fri, 31 Mar 2023 15:30:19 +0200 Subject: fix(upgrade): typo in variable check --- tools/upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 684ad894a..d9a372d13 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -234,7 +234,7 @@ if LANG= git pull --quiet --rebase $remote $branch; then git config oh-my-zsh.lastVersion "$last_commit" # Print changelog to the terminal - if [[ interactive == true && $verbose_mode == default ]] ; then + if [[ $interactive == true && $verbose_mode == default ]]; then "$ZSH/tools/changelog.sh" HEAD "$last_commit" fi -- cgit v1.2.3-70-g09d2 From 6ef236dd99f2090b54911f9135d00ac37d6757ff Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 1 Apr 2023 10:14:18 +0200 Subject: fix(updater): search for upstream remote if using non-conventional name (#11135) Fixes #11135 --- tools/upgrade.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tools/upgrade.sh b/tools/upgrade.sh index d9a372d13..34ff3f027 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -1,5 +1,7 @@ #!/usr/bin/env zsh +local ret=0 # exit code + # Protect against running with shells other than zsh if [ -z "$ZSH_VERSION" ]; then exec zsh "$0" "$@" @@ -181,17 +183,23 @@ fi # Update upstream remote to ohmyzsh org git remote -v | while read remote url extra; do case "$url" in + git://github.com/robbyrussell/oh-my-zsh(|.git)) + # Update out-of-date "unauthenticated git protocol on port 9418" to https + git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git" ;; https://github.com/robbyrussell/oh-my-zsh(|.git)) - git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git" - break ;; + git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git" ;; git@github.com:robbyrussell/oh-my-zsh(|.git)) - git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git" - break ;; - # Update out-of-date "unauthenticated git protocol on port 9418" to https - git://github.com/robbyrussell/oh-my-zsh(|.git)) - git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git" - break ;; + git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git" ;; + https://github.com/ohmyzsh/ohmyzsh(|.git)) ;; + git@github.com:ohmyzsh/ohmyzsh(|.git)) ;; + *) continue ;; esac + + # If we reach this point we have found the proper ohmyzsh upstream remote. If we don't, + # we'll only update from the set remote if `oh-my-zsh.remote` has been set to a remote, + # as when installing from a fork. + git config --local oh-my-zsh.remote "$remote" + break done # Set git-config values known to fix git errors -- cgit v1.2.3-70-g09d2 From 68005b887055ddd1c6d3fd1381b6eb7b786a0a38 Mon Sep 17 00:00:00 2001 From: Saverio Guzzo Date: Sun, 2 Apr 2023 12:54:55 +0200 Subject: docs(spotify): fix link (#11593) --- plugins/macos/spotify | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/macos/spotify b/plugins/macos/spotify index 491a60686..5fb40517c 100644 --- a/plugins/macos/spotify +++ b/plugins/macos/spotify @@ -43,7 +43,7 @@ showAPIHelp() { echo " find music by name. It is very likely you want this feature!"; echo; echo " To get this to work, you need to sign up (or in) and create an 'Application' at:"; - echo " https://developer.spotify.com/my-applications/#!/applications/create"; + echo " https://developer.spotify.com/dashboard/create"; echo; echo " Once you've created an application, find the 'Client ID' and 'Client Secret'"; echo " values, and enter them into your shpotify config file at '${USER_CONFIG_FILE}'"; -- cgit v1.2.3-70-g09d2 From f7d903f3a31567f326d0f8ec2414722d0e3b992a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 2 Apr 2023 13:40:49 +0200 Subject: fix(vi-mode): fix cursor change on visual mode (#11586) Fixes #11586 --- plugins/vi-mode/vi-mode.plugin.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index d44be69d4..cc9817a74 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -43,6 +43,13 @@ function _vi-mode-set-cursor-shape-for-keymap() { printf $'\e[%d q' "${_shape}" } +function _visual-mode { + typeset -g VI_KEYMAP=visual + _vi-mode-set-cursor-shape-for-keymap "$VI_KEYMAP" + zle .visual-mode +} +zle -N visual-mode _visual-mode + function _vi-mode-should-reset-prompt() { # If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE is unset (default), dynamically # check whether we're using the prompt to display vi-mode info -- cgit v1.2.3-70-g09d2 From 75405b7b0ae03a1fdf2fdb172d2a50cd5f570162 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 2 Apr 2023 14:28:01 +0200 Subject: feat(extract): always extract files into its own folder (#11596) --- plugins/extract/extract.plugin.zsh | 84 +++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index 7b7a2fa4f..c416f49ce 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -29,61 +29,79 @@ EOF local success=0 local extract_dir="${1:t:r}" local file="$1" full_path="${1:A}" + + # Create an extraction directory based on the file name + command mkdir -p "$extract_dir" + builtin cd -q "$extract_dir" + case "${file:l}" in (*.tar.gz|*.tgz) - (( $+commands[pigz] )) && { tar -I pigz -xvf "$file" } || tar zxvf "$file" ;; + (( $+commands[pigz] )) && { tar -I pigz -xvf "$full_path" } || tar zxvf "$full_path" ;; (*.tar.bz2|*.tbz|*.tbz2) - (( $+commands[pbzip2] )) && { tar -I pbzip2 -xvf "$file" } || tar xvjf "$file" ;; + (( $+commands[pbzip2] )) && { tar -I pbzip2 -xvf "$full_path" } || tar xvjf "$full_path" ;; (*.tar.xz|*.txz) - (( $+commands[pixz] )) && { tar -I pixz -xvf "$file" } || { + (( $+commands[pixz] )) && { tar -I pixz -xvf "$full_path" } || { tar --xz --help &> /dev/null \ - && tar --xz -xvf "$file" \ - || xzcat "$file" | tar xvf - } ;; + && tar --xz -xvf "$full_path" \ + || xzcat "$full_path" | tar xvf - } ;; (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \ - && tar --lzma -xvf "$file" \ - || lzcat "$file" | tar xvf - ;; + && tar --lzma -xvf "$full_path" \ + || lzcat "$full_path" | tar xvf - ;; (*.tar.zst|*.tzst) tar --zstd --help &> /dev/null \ - && tar --zstd -xvf "$file" \ - || zstdcat "$file" | tar xvf - ;; - (*.tar) tar xvf "$file" ;; - (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$file" ;; - (*.tar.lz4) lz4 -c -d "$file" | tar xvf - ;; - (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$file" ;; - (*.gz) (( $+commands[pigz] )) && pigz -dk "$file" || gunzip -k "$file" ;; - (*.bz2) bunzip2 "$file" ;; - (*.xz) unxz "$file" ;; - (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$file" ;; - (*.lz4) lz4 -d "$file" ;; - (*.lzma) unlzma "$file" ;; - (*.z) uncompress "$file" ;; - (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$file" -d "$extract_dir" ;; - (*.rar) unrar x -ad "$file" ;; + && tar --zstd -xvf "$full_path" \ + || zstdcat "$full_path" | tar xvf - ;; + (*.tar) tar xvf "$full_path" ;; + (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;; + (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;; + (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;; + (*.gz) (( $+commands[pigz] )) && pigz -dk "$full_path" || gunzip -k "$full_path" ;; + (*.bz2) bunzip2 "$full_path" ;; + (*.xz) unxz "$full_path" ;; + (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;; + (*.lz4) lz4 -d "$full_path" ;; + (*.lzma) unlzma "$full_path" ;; + (*.z) uncompress "$full_path" ;; + (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$full_path" ;; + (*.rar) unrar x -ad "$full_path" ;; (*.rpm) - command mkdir -p "$extract_dir" && builtin cd -q "$extract_dir" \ - && rpm2cpio "$full_path" | cpio --quiet -id ;; - (*.7z) 7za x "$file" ;; + rpm2cpio "$full_path" | cpio --quiet -id ;; + (*.7z) 7za x "$full_path" ;; (*.deb) - command mkdir -p "$extract_dir/control" "$extract_dir/data" - builtin cd -q "$extract_dir"; ar vx "$full_path" > /dev/null + command mkdir -p "control" "data" + ar vx "$full_path" > /dev/null builtin cd -q control; extract ../control.tar.* builtin cd -q ../data; extract ../data.tar.* builtin cd -q ..; command rm *.tar.* debian-binary ;; - (*.zst) unzstd "$file" ;; - (*.cab) cabextract -d "$extract_dir" "$file" ;; - (*.cpio|*.obscpio) cpio -idmvF "$file" ;; - (*.zpaq) zpaq x "$file" ;; + (*.zst) unzstd "$full_path" ;; + (*.cab) cabextract "$full_path" ;; + (*.cpio|*.obscpio) cpio -idmvF "$full_path" ;; + (*.zpaq) zpaq x "$full_path" ;; (*) echo "extract: '$file' cannot be extracted" >&2 success=1 ;; esac (( success = success > 0 ? success : $? )) - (( success == 0 && remove_archive == 0 )) && rm "$full_path" + (( success == 0 && remove_archive == 0 )) && command rm "$full_path" shift - # Go back to original working directory in case we ran cd previously + # Go back to original working directory + # and remove extraction directory if there was an error builtin cd -q "$pwd" + (( success > 0 )) && command rm -r "$extract_dir" + + # If content of extract dir is a single directory, move its contents up + # Glob flags: + # - D: include files starting with . + # - N: no error if directory is empty + # - Y2: at most give 2 files + local -a content + content=("${extract_dir}"/*(DNY2)) + if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then + command mv -f "${content[1]}" . + command rmdir "$extract_dir" + fi done } -- cgit v1.2.3-70-g09d2 From d47e1d65f66f9bb2e7a96ba58797b33f0e91a623 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 2 Apr 2023 16:33:54 +0200 Subject: fix(extract): safely remove extract directory The previous code would remove the extract directory if the command failed. This could be bad because we're not checking if the extract directory already existed (since we're using `mkdir -p`), so it could be possible that the extract operation failed, and we'd be removing a directory that already existed and had files in it. This change only removes the directory if there are no files in it, regardless of whether the extract operation was successful or not. This is much safer. --- plugins/extract/extract.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index c416f49ce..40e67575f 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -88,9 +88,7 @@ EOF shift # Go back to original working directory - # and remove extraction directory if there was an error builtin cd -q "$pwd" - (( success > 0 )) && command rm -r "$extract_dir" # If content of extract dir is a single directory, move its contents up # Glob flags: @@ -102,6 +100,8 @@ EOF if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then command mv -f "${content[1]}" . command rmdir "$extract_dir" + elif [[ ${#content} -eq 0 ]]; then + command rmdir "$extract_dir" fi done } -- cgit v1.2.3-70-g09d2 From f8bf88edca7a3246e065f13cefac2c5f1ab396e0 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 3 Apr 2023 22:21:49 +0200 Subject: chore(installer): remove words triggering false positives in antiviruses --- tools/install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index efdb7d482..fcfbcf778 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -84,8 +84,7 @@ command_exists() { user_can_sudo() { # Check if sudo is installed command_exists sudo || return 1 - # Termux can't run sudo unless the device is rooted. Either way, `chsh` works - # without sudo, so we can detect it and exit the function early. + # Termux can't run sudo, so we can detect it and exit the function early. case "$PREFIX" in *com.termux*) return 1 ;; esac -- cgit v1.2.3-70-g09d2 From 1ad167dfac325a9f92e0693c70d0ab3f7c4c574b Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 3 Apr 2023 23:14:36 +0200 Subject: feat(init)!: allow turning off aliases for libs and plugins (#11550) BREAKING CHANGE: the previous zstyle setting to disable `lib/directories.zsh` aliases has been changed to the new syntax: `zstyle ':omz:lib:directories' aliases no`. See https://github.com/ohmyzsh/ohmyzsh#skip-aliases to see other ways you can use this setting. Co-authored-by: Carlo Sala --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++----- lib/directories.zsh | 6 ------ oh-my-zsh.sh | 45 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 86 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4f0aeb7b4..556d4c8c5 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,9 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi - [Manual Installation](#manual-installation) - [Installation Problems](#installation-problems) - [Custom Plugins and Themes](#custom-plugins-and-themes) + - [Skip aliases](#skip-aliases) - [Getting Updates](#getting-updates) + - [Updates verbosity](#updates-verbosity) - [Manual Updates](#manual-updates) - [Uninstalling Oh My Zsh](#uninstalling-oh-my-zsh) - [How do I contribute to Oh My Zsh?](#how-do-i-contribute-to-oh-my-zsh) @@ -276,16 +278,58 @@ If you have many functions that go well together, you can put them as a `XYZ.plu If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`. -### Remove directories aliases +### Skip aliases -If you want to skip ohmyzsh default -[directories aliases](https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/directories.zsh) you can add the -following snippet to your `zshrc`, before loading `oh-my-zsh.sh` script: + -```zsh +If you want to skip default Oh My Zsh aliases (those defined in `lib/*` files) or plugin aliases, +you can use the settings below in your `~/.zshrc` file, **before Oh My Zsh is loaded**. Note that +there are many different ways to skip aliases, depending on your needs. + +```sh +# Skip all aliases, in lib files and enabled plugins +zstyle ':omz:*' aliases no + +# Skip all aliases in lib files +zstyle ':omz:lib:*' aliases no +# Skip only aliases defined in the directories.zsh lib file +zstyle ':omz:lib:directories' aliases no + +# Skip all plugin aliases +zstyle ':omz:plugins:*' aliases no +# Skip only the aliases from the git plugin +zstyle ':omz:plugins:git' aliases no +``` + +You can combine these in other ways taking into account that more specific scopes takes precedence: + +```sh +# Skip all plugin aliases, except for the git plugin +zstyle ':omz:plugins:*' aliases no +zstyle ':omz:plugins:git' aliases yes +``` + +A previous version of this feature was using the setting below, which has been removed: + +```sh zstyle ':omz:directories' aliases no ``` +Instead, you can now use the following: + +```sh +zstyle ':omz:lib:directories' aliases no +``` + +#### Notice + +> This feature is currently in a testing phase and it may be subject to change in the future. +> It is also not currently compatible with plugin managers such as zpm or zinit, which don't +> source the init script (`oh-my-zsh.sh`) where this feature is implemented in. + +> It is also not currently aware of "aliases" that are defined as functions. Example of such +> are `gccd`, `ggf`, or `ggl` functions from the git plugin. + ## Getting Updates By default, you will be prompted to check for updates every 2 weeks. You can choose other update modes by adding a line to your `~/.zshrc` file, **before Oh My Zsh is loaded**: diff --git a/lib/directories.zsh b/lib/directories.zsh index 13b680c19..8927a56ad 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -4,12 +4,6 @@ setopt auto_pushd setopt pushd_ignore_dups setopt pushdminus -# add (uncommented): -# zstyle ':omz:directories' aliases no -# to your `zshrc` before loading `oh-my-zsh.sh` -# to disable the following aliases and functions - -zstyle -T ':omz:directories' aliases || return 0 alias -g ...='../..' alias -g ....='../../..' diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 363cfca8b..20d2e354c 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -146,22 +146,51 @@ if command mkdir "${ZSH_COMPDUMP}.lock" 2>/dev/null; then command rm -rf "$ZSH_COMPDUMP.zwc.old" "${ZSH_COMPDUMP}.lock" fi +_omz_source() { + local context filepath="$1" + + # Construct zstyle context based on path + case "$filepath" in + lib/*) context="lib:${filepath:t:r}" ;; # :t = lib_name.zsh, :r = lib_name + plugins/*) context="plugins:${filepath:h2:t}" ;; # :h2 = plugins/plugin_name, :t = plugin_name + esac + + local disable_aliases=0 + zstyle -T ":omz:${context}" aliases || disable_aliases=1 + + # Back up alias names prior to sourcing + local -a aliases_pre galiases_pre + if (( disable_aliases )); then + aliases_pre=("${(@k)aliases}") + galiases_pre=("${(@k)galiases}") + fi + + # Source file from $ZSH_CUSTOM if it exists, otherwise from $ZSH + if [[ -f "$ZSH_CUSTOM/$filepath" ]]; then + source "$ZSH_CUSTOM/$filepath" + elif [[ -f "$ZSH/$filepath" ]]; then + source "$ZSH/$filepath" + fi + + # Unset all aliases that don't appear in the backed up list of aliases + if (( disable_aliases )); then + local -a disabled + # ${var:|array} gets the list of items in var not in array + disabled=("${(@k)aliases:|aliases_pre}" "${(@k)galiases:|galiases_pre}") + (( $#disabled == 0 )) || unalias "${(@)disabled}" + fi +} + # Load all of the config files in ~/oh-my-zsh that end in .zsh # TIP: Add files you don't want in git to .gitignore for config_file ("$ZSH"/lib/*.zsh); do - custom_config_file="$ZSH_CUSTOM/lib/${config_file:t}" - [[ -f "$custom_config_file" ]] && config_file="$custom_config_file" - source "$config_file" + _omz_source "${config_file:t2}" done unset custom_config_file # Load all of the plugins that were defined in ~/.zshrc for plugin ($plugins); do - if [[ -f "$ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh" ]]; then - source "$ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh" - elif [[ -f "$ZSH/plugins/$plugin/$plugin.plugin.zsh" ]]; then - source "$ZSH/plugins/$plugin/$plugin.plugin.zsh" - fi + _omz_source "plugins/$plugin/$plugin.plugin.zsh" done unset plugin -- cgit v1.2.3-70-g09d2 From c7bb88f9ad3eb742aecca2e36b615819cead10f4 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 3 Apr 2023 23:27:14 +0200 Subject: fix(changelog): ignore lines containing whitespace in breaking change commits --- tools/changelog.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/changelog.sh b/tools/changelog.sh index 5f7a14d03..1af74e42d 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -106,6 +106,9 @@ function parse-commit { message="${match[1]}" # remove CR characters (might be inserted in GitHub UI commit description form) message="${message//$'\r'/}" + # remove lines containing only whitespace + local nlnl=$'\n\n' + message="${message//$'\n'[[:space:]]##$'\n'/$nlnl}" # skip next paragraphs (separated by two newlines or more) message="${message%%$'\n\n'*}" # ... and replace newlines with spaces -- cgit v1.2.3-70-g09d2 From 9233ef75f28423d147a2f9f64a45a77b1886ee5d Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 3 Apr 2023 23:36:44 +0200 Subject: fix(init): don't use digits in parameter modifiers for compatibility (#11598) Digit modifiers were introduced in zsh 5.7.1 [1]. This commit uses readily available alternatives for backwards compatibility. [1] https://github.com/zsh-users/zsh/commit/b8dc5a7f6d Fixes #11598 --- oh-my-zsh.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 20d2e354c..e047d4834 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -151,8 +151,8 @@ _omz_source() { # Construct zstyle context based on path case "$filepath" in - lib/*) context="lib:${filepath:t:r}" ;; # :t = lib_name.zsh, :r = lib_name - plugins/*) context="plugins:${filepath:h2:t}" ;; # :h2 = plugins/plugin_name, :t = plugin_name + lib/*) context="lib:${filepath:t:r}" ;; # :t = lib_name.zsh, :r = lib_name + plugins/*) context="plugins:${filepath:h:t}" ;; # :h = plugins/plugin_name, :t = plugin_name esac local disable_aliases=0 @@ -184,7 +184,7 @@ _omz_source() { # Load all of the config files in ~/oh-my-zsh that end in .zsh # TIP: Add files you don't want in git to .gitignore for config_file ("$ZSH"/lib/*.zsh); do - _omz_source "${config_file:t2}" + _omz_source "lib/${config_file:t}" done unset custom_config_file -- cgit v1.2.3-70-g09d2 From 8d23fbd6964b8446bbc73ff04507362d1fd49eb5 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Tue, 4 Apr 2023 16:47:13 +0200 Subject: feat(termsupport): add contour terminal (#11599) Signed-off-by: Christian Parpart --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 80ca7ef78..5bc418761 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -17,7 +17,7 @@ function title { : ${2=$1} case "$TERM" in - cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot) + cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot|contour*) print -Pn "\e]2;${2:q}\a" # set window name print -Pn "\e]1;${1:q}\a" # set tab name ;; -- cgit v1.2.3-70-g09d2 From 33aadeced0bf17b8abc7d680b424de7c5e71dd45 Mon Sep 17 00:00:00 2001 From: Richard Mitchell Date: Tue, 4 Apr 2023 17:52:16 -0400 Subject: feat(term_tab): add support for macOS (#11391) --- plugins/term_tab/term_tab.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/term_tab/term_tab.plugin.zsh b/plugins/term_tab/term_tab.plugin.zsh index 1b612df68..89acd9103 100644 --- a/plugins/term_tab/term_tab.plugin.zsh +++ b/plugins/term_tab/term_tab.plugin.zsh @@ -28,6 +28,7 @@ function _term_list(){ case $OSTYPE in solaris*) dirs=( ${(M)${${(f)"$(pgrep -U $UID -x zsh|xargs pwdx)"}:#$$:*}%%/*} ) ;; linux*) dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) ) ;; + darwin*) dirs=( $( lsof -d cwd -c zsh -a -w -Fn | sed -n 's/^n//p' ) ) ;; esac dirs=( ${(D)dirs} ) -- cgit v1.2.3-70-g09d2 From 25c2c3a4683be60c3526858be960ee6ce1249245 Mon Sep 17 00:00:00 2001 From: Alexander Schlarb Date: Sun, 16 May 2021 18:58:38 +0200 Subject: feat(lib): send OSC 7 on directory change for more supported terminals (#9914) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously this was only emitted on macOS with Apple's Terminal.app (and compatible clones like iTerm2), but it is used by other terminal emulators as well to obtain the actual current working directory wiht symlinks intact. All non-supporting terminal emulators tested gracefully ignored this value, so emit this on these as well in case they (or some other app masquarading as them) add future support for this value. Closes #9914 Co-authored-by: Marc Cornellà --- lib/termsupport.zsh | 72 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 5bc418761..cf8f08741 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -109,28 +109,52 @@ if [[ -z "$INSIDE_EMACS" || "$INSIDE_EMACS" = vterm ]]; then add-zsh-hook preexec omz_termsupport_preexec fi -# Keep Apple Terminal.app's current working directory updated -# Based on this answer: https://superuser.com/a/315029 -# With extra fixes to handle multibyte chars and non-UTF-8 locales - -if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then - # Emits the control sequence to notify Terminal.app of the cwd - # Identifies the directory using a file: URI scheme, including - # the host name to disambiguate local vs. remote paths. - function update_terminalapp_cwd() { - emulate -L zsh - - # Percent-encode the host and path names. - local URL_HOST URL_PATH - URL_HOST="$(omz_urlencode -P $HOST)" || return 1 - URL_PATH="$(omz_urlencode -P $PWD)" || return 1 - - # Undocumented Terminal.app-specific control sequence - printf '\e]7;%s\a' "file://$URL_HOST$URL_PATH" - } - - # Use a precmd hook instead of a chpwd hook to avoid contaminating output - add-zsh-hook precmd update_terminalapp_cwd - # Run once to get initial cwd set - update_terminalapp_cwd +# Keep terminal emulator's current working directory correct, +# even if the current working directory path contains symbolic links +# +# References: +# - Apple's Terminal.app: https://superuser.com/a/315029 +# - iTerm2: https://iterm2.com/documentation-escape-codes.html (iTerm2 Extension / CurrentDir+RemoteHost) +# - Konsole: https://bugs.kde.org/show_bug.cgi?id=327720#c1 +# - libvte (gnome-terminal, mate-terminal, …): https://bugzilla.gnome.org/show_bug.cgi?id=675987#c14 +# Apparently it had a bug before ~2012 were it would display the unknown OSC 7 code +# +# As of May 2021 mlterm, PuTTY, rxvt, screen, termux & xterm simply ignore the unknown OSC. + +# Don't define the function if we're inside Emacs +if [[ -n "$INSIDE_EMACS" ]]; then + return fi + +# Don't define the function if we're in an unsupported terminal +case "$TERM" in + # all of these either process OSC 7 correctly or ignore entirely + xterm*|putty*|rxvt*|konsole*|mlterm*|alacritty|screen*|tmux*) ;; + contour*|foot*) ;; + *) + # Terminal.app and iTerm2 process OSC 7 correctly + case "$TERM_PROGRAM" in + Apple_Terminal|iTerm.app) ;; + *) return ;; + esac ;; +esac + +# Emits the control sequence to notify many terminal emulators +# of the cwd +# +# Identifies the directory using a file: URI scheme, including +# the host name to disambiguate local vs. remote paths. +function omz_termsupport_cwd { + # Percent-encode the host and path names. + local URL_HOST URL_PATH + URL_HOST="$(omz_urlencode -P $HOST)" || return 1 + URL_PATH="$(omz_urlencode -P $PWD)" || return 1 + + # common control sequence (OSC 7) to set current host and path + printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" +} + +# Use a precmd hook instead of a chpwd hook to avoid contaminating output +# i.e. when a script or function changes directory without `cd -q`, chpwd +# will be called the output may be swallowed by the script or function. +add-zsh-hook precmd omz_termsupport_cwd -- cgit v1.2.3-70-g09d2 From cf0c80049288d1029aee824bf975016c4201a3ef Mon Sep 17 00:00:00 2001 From: François M Date: Thu, 6 Apr 2023 15:11:52 +0200 Subject: feat(toolbox)!: rename and add aliases (#11580) --- plugins/toolbox/README.md | 3 ++- plugins/toolbox/toolbox.plugin.zsh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/toolbox/README.md b/plugins/toolbox/README.md index abaca31f4..bc04a906b 100644 --- a/plugins/toolbox/README.md +++ b/plugins/toolbox/README.md @@ -22,4 +22,5 @@ RPROMPT='$(toolbox_prompt_info)' | Alias | Command | Description | |-------|----------------------|----------------------------------------| -| tb | `toolbox enter` | Enters the toolbox environment | +| tbe | `toolbox enter` | Enters the toolbox environment | +| tbr | `toolbox run` | Run a command in an existing toolbox | diff --git a/plugins/toolbox/toolbox.plugin.zsh b/plugins/toolbox/toolbox.plugin.zsh index d24d6d396..377e498cd 100644 --- a/plugins/toolbox/toolbox.plugin.zsh +++ b/plugins/toolbox/toolbox.plugin.zsh @@ -2,4 +2,5 @@ function toolbox_prompt_info() { [[ -f /run/.toolboxenv ]] && echo "⬢" } -alias tb="toolbox enter" +alias tbe="toolbox enter" +alias tbr="toolbox run" -- cgit v1.2.3-70-g09d2 From 49d34d00cdaf132f318700398bf42120ff1af8e7 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 6 Apr 2023 21:06:16 +0200 Subject: fix(extract): fix conflict if compressed file has a folder of the same name This change fixes the case where the compressed file (e.g. tools.tgz) only contains a folder with the same name (e.g. tools) in its root folder. tools.tgz: |- tools |- fileA.txt |- fileB.txt \- fileC.txt In that case, the "smart" folder creation mechanism will extract the files in a folder "tools", and this extraction folder will contain a single folder with the same name. Before this fix, the tool would try to move out the inside folder to the parent one, but there would already be a folder named "tools", so it would generate a conflict. This change first renames the inside folder to a random string, and only then it is moved outside and the old extraction folder is deleted. --- plugins/extract/extract.plugin.zsh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index 40e67575f..34c080653 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -98,8 +98,22 @@ EOF local -a content content=("${extract_dir}"/*(DNY2)) if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then - command mv -f "${content[1]}" . - command rmdir "$extract_dir" + # The extracted folder (${content[1]}) may have the same name as $extract_dir + # If so, we need to rename it to avoid conflicts in a 3-step process + # + # 1. Move and rename the extracted folder to a temporary random name + # 2. Delete the empty folder + # 3. Rename the extracted folder to the original name + if [[ "${content[1]:t}" == "$extract_dir" ]]; then + # =(:) gives /tmp/zsh, with :t it gives zsh + local tmp_dir==(:); tmp_dir="${tmp_dir:t}" + command mv -f "${content[1]}" "$tmp_dir" \ + && command rmdir "$extract_dir" \ + && command mv -f "$tmp_dir" "$extract_dir" + else + command mv -f "${content[1]}" . \ + && command rmdir "$extract_dir" + fi elif [[ ${#content} -eq 0 ]]; then command rmdir "$extract_dir" fi -- cgit v1.2.3-70-g09d2 From 01c82c381d90f10239908ace41df9532c8c45495 Mon Sep 17 00:00:00 2001 From: Alexander Huynh Date: Fri, 7 Apr 2023 07:35:12 -0400 Subject: fix(jump): even spacing between marks (#11601) --- plugins/jump/jump.plugin.zsh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index c2da1144e..829c9d9cb 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -35,12 +35,11 @@ marks() { max=${#link:t} fi done - local printf_markname_template="$(printf -- "%%%us " "$max")" + local printf_markname_template="$(printf -- "%%%us" "$max")" for link in $MARKPATH/{,.}*(@N); do - local markname="$fg[cyan]${link:t}$reset_color" + local markname="$fg[cyan]$(printf -- "$printf_markname_template" "${link:t}")$reset_color" local markpath="$fg[blue]$(readlink $link)$reset_color" - printf -- "$printf_markname_template" "$markname" - printf -- "-> %s\n" "$markpath" + printf -- "%s -> %s\n" "$markname" "$markpath" done } -- cgit v1.2.3-70-g09d2 From 9b1ef262bcc8d47a6d20b4efc673557560df6647 Mon Sep 17 00:00:00 2001 From: deimosian Date: Fri, 7 Apr 2023 11:43:45 +0000 Subject: feat(archlinux): unify `upgrade` function (#11597) Co-authored-by: Carlo Sala --- plugins/archlinux/archlinux.plugin.zsh | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index 4f1364779..e3b1b1261 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -23,7 +23,6 @@ alias pacfiles='pacman -F' alias pacls='pacman -Ql' alias pacown='pacman -Qo' alias pacupd="sudo pacman -Sy" -alias upgrade='sudo pacman -Syu' function paclist() { # Based on https://bbs.archlinux.org/viewtopic.php?id=93683 @@ -109,7 +108,6 @@ if (( $+commands[aura] )); then alias auupd="sudo aura -Sy" alias auupg='sudo sh -c "aura -Syu && aura -Au"' alias ausu='sudo sh -c "aura -Syu --no-confirm && aura -Au --no-confirm"' - alias upgrade='sudo aura -Syu' # extra bonus specially for aura alias auown="aura -Qqo" @@ -136,7 +134,6 @@ if (( $+commands[pacaur] )); then alias painsd='pacaur -S --asdeps' alias pamir='pacaur -Syy' alias paupd="pacaur -Sy" - alias upgrade='pacaur -Syu' fi if (( $+commands[trizen] )); then @@ -158,7 +155,6 @@ if (( $+commands[trizen] )); then alias trinsd='trizen -S --asdeps' alias trmir='trizen -Syy' alias trupd="trizen -Sy" - alias upgrade='trizen -Syu' fi if (( $+commands[yay] )); then @@ -180,5 +176,30 @@ if (( $+commands[yay] )); then alias yainsd='yay -S --asdeps' alias yamir='yay -Syy' alias yaupd="yay -Sy" - alias upgrade='yay -Syu' fi + +# Check Arch Linux PGP Keyring before System Upgrade to prevent failure. +function upgrade() { + echo "[oh-my-zsh] Checking Arch Linux PGP Keyring" + local installedver="$(sudo pacman -Qi archlinux-keyring | grep -Po '(?<=Version : ).*')" + local currentver="$(sudo pacman -Si archlinux-keyring | grep -Po '(?<=Version : ).*')" + if [ $installedver != $currentver ]; then + echo "[oh-my-zsh] Arch Linux PGP Keyring is out of date." + echo "[oh-my-zsh] Updating before full system upgrade." + sudo pacman -Syu --needed --noconfirm archlinux-keyring + else + echo "[oh-my-zsh] Arch Linux PGP Keyring is up to date." + fi + echo "[oh-mh-zsh] Proceeding with full system upgrade." + if (( $+commands[yay] )); then + yay -Syu + elif (( $+commands[trizen] )); then + trizen -Syu + elif (( $+commands[pacaur] )); then + pacaur -Syu + elif (( $+commands[aura] )); then + sudo aura -Syu + else + sudo pacman -Syu + fi +} -- cgit v1.2.3-70-g09d2 From e906a3130eb5031a2c82d9187ea17387881631db Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Sat, 8 Apr 2023 11:13:30 +0200 Subject: fix(azure): look properly for azure config file Closes #11606 --- plugins/azure/azure.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/azure/azure.plugin.zsh b/plugins/azure/azure.plugin.zsh index 51b54dbc1..8fec3c1f7 100644 --- a/plugins/azure/azure.plugin.zsh +++ b/plugins/azure/azure.plugin.zsh @@ -18,10 +18,10 @@ compctl -K _az_subscriptions azss # Azure prompt function azure_prompt_info() { - [[ ! -f "${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json}" ]] && return + [[ ! -f "${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json" ]] && return # azgs is too expensive, if we have jq, we enable the prompt (( $+commands[jq] )) || return 1 - azgs=$(jq -r '.subscriptions[] | select(.isDefault==true) .name' ${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json}) + azgs=$(jq -r '.subscriptions[] | select(.isDefault==true) .name' "${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json") echo "${ZSH_THEME_AZURE_PREFIX:=}" } -- cgit v1.2.3-70-g09d2 From ad99f0c164111fa3cfcbfc5b9cda321800541936 Mon Sep 17 00:00:00 2001 From: Aleks Date: Sat, 8 Apr 2023 13:36:54 +0200 Subject: feat(git): add merge squash alias (`gms`) (#10937) --- plugins/git/README.md | 1 + plugins/git/git.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index 0895ce39c..f87d3fbca 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -116,6 +116,7 @@ plugins=(... git) | gloga | git log --oneline --decorate --graph --all | | glp | git log --pretty=\ | | gm | git merge | +| gms | git merge --squash | | gmom | git merge origin/$(git_main_branch) | | gmtl | git mergetool --no-prompt | | gmtlvim | git mergetool --no-prompt --tool=vimdiff | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index ed17436e8..3c8d53c8c 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -237,6 +237,7 @@ alias gmtl='git mergetool --no-prompt' alias gmtlvim='git mergetool --no-prompt --tool=vimdiff' alias gmum='git merge upstream/$(git_main_branch)' alias gma='git merge --abort' +alias gms="git merge --squash" alias gp='git push' alias gpd='git push --dry-run' -- cgit v1.2.3-70-g09d2 From 90ec2d1a68049d8b7e57b87c3661d8cacf54655c Mon Sep 17 00:00:00 2001 From: deimosian Date: Sun, 9 Apr 2023 04:24:55 -0400 Subject: fix(archlinux): keyring update function (#11607) --- plugins/archlinux/archlinux.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index e3b1b1261..ce7bfdf23 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -186,7 +186,7 @@ function upgrade() { if [ $installedver != $currentver ]; then echo "[oh-my-zsh] Arch Linux PGP Keyring is out of date." echo "[oh-my-zsh] Updating before full system upgrade." - sudo pacman -Syu --needed --noconfirm archlinux-keyring + sudo pacman -Sy --needed --noconfirm archlinux-keyring else echo "[oh-my-zsh] Arch Linux PGP Keyring is up to date." fi -- cgit v1.2.3-70-g09d2 From 4586808f86bf3bfdf97685380472b63597ce43c0 Mon Sep 17 00:00:00 2001 From: deimosian Date: Sun, 9 Apr 2023 06:58:38 -0400 Subject: feat(archlinux): improve update function messages (#11608) --- plugins/archlinux/archlinux.plugin.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index ce7bfdf23..da170f488 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -180,17 +180,17 @@ fi # Check Arch Linux PGP Keyring before System Upgrade to prevent failure. function upgrade() { - echo "[oh-my-zsh] Checking Arch Linux PGP Keyring" + echo ":: Checking Arch Linux PGP Keyring..." local installedver="$(sudo pacman -Qi archlinux-keyring | grep -Po '(?<=Version : ).*')" local currentver="$(sudo pacman -Si archlinux-keyring | grep -Po '(?<=Version : ).*')" if [ $installedver != $currentver ]; then - echo "[oh-my-zsh] Arch Linux PGP Keyring is out of date." - echo "[oh-my-zsh] Updating before full system upgrade." + echo " Arch Linux PGP Keyring is out of date." + echo " Updating before full system upgrade." sudo pacman -Sy --needed --noconfirm archlinux-keyring else - echo "[oh-my-zsh] Arch Linux PGP Keyring is up to date." + echo " Arch Linux PGP Keyring is up to date." + echo " Proceeding with full system upgrade." fi - echo "[oh-mh-zsh] Proceeding with full system upgrade." if (( $+commands[yay] )); then yay -Syu elif (( $+commands[trizen] )); then -- cgit v1.2.3-70-g09d2 From b4f9698733d7b29cc495e649e26fd6c3a5dcfcae Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Tue, 11 Apr 2023 01:41:00 -0700 Subject: docs(ssh-agent): macOS and p10k advices (#11612) --- plugins/ssh-agent/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugins/ssh-agent/README.md b/plugins/ssh-agent/README.md index fa6a996d4..8c118e65b 100644 --- a/plugins/ssh-agent/README.md +++ b/plugins/ssh-agent/README.md @@ -99,6 +99,33 @@ ssh-add -K -c -a /run/user/1000/ssh-auth For valid `ssh-add` arguments run `ssh-add --help` or `man ssh-add`. +### Powerline 10k specific settings + +Powerline10k has an instant prompt setting that doesn't like when this plugin +writes to the console. Consider using the following settings if you're using +p10k (documented above): + +``` +zstyle :omz:plugins:ssh-agent quiet yes +zstyle :omz:plugins:ssh-agent lazy yes +``` + +### macOS specific settings + +macOS supports using passphrases stored in the keychain when adding identities +to the ssh-agent. + +``` +ssh-add --apple-use-keychain ~/.ssh/id_rsa ... +``` + + +This plugin can be configured to use the keychain when loading using the following: + +``` +zstyle :omz:plugins:ssh-agent ssh-add-args --apple-load-keychain +``` + ## Credits Based on code from Joseph M. Reagle: https://www.cygwin.com/ml/cygwin/2001-06/msg00537.html -- cgit v1.2.3-70-g09d2 From bd5ebba834c53e730671d9d24d93eb98b812a579 Mon Sep 17 00:00:00 2001 From: Eddie Romanov <81505200+SnoopDraugg@users.noreply.github.com> Date: Sun, 16 Apr 2023 03:49:04 -0400 Subject: feat(pipenv): add pupd alias (#11616) --- plugins/pipenv/README.md | 1 + plugins/pipenv/pipenv.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/pipenv/README.md b/plugins/pipenv/README.md index ab1c1e442..4329feb32 100644 --- a/plugins/pipenv/README.md +++ b/plugins/pipenv/README.md @@ -23,6 +23,7 @@ This plugin provides some features to simplify the use of Pipenv while working o - `psh` is aliased to `pipenv shell` - `psy` is aliased to `pipenv sync` - `pu` is aliased to `pipenv uninstall` + - `pupd` is aliased to `pipenv update` - `pwh` is aliased to `pipenv --where` - `pvenv` is aliased to `pipenv --venv` - `ppy` is aliased to `pipenv --py` diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh index 244bd6b7c..22d1a3131 100644 --- a/plugins/pipenv/pipenv.plugin.zsh +++ b/plugins/pipenv/pipenv.plugin.zsh @@ -47,6 +47,7 @@ alias prun="pipenv run" alias psh="pipenv shell" alias psy="pipenv sync" alias pu="pipenv uninstall" +alias pupd="pipenv update" alias pwh="pipenv --where" alias pvenv="pipenv --venv" alias ppy="pipenv --py" -- cgit v1.2.3-70-g09d2 From d889eca72633b7a66d6c832736a5460c5f1a1833 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 17 Apr 2023 20:09:30 +0200 Subject: fix(check_for_upgrade): update properly `LAST_EPOCH` Fixes #11617 --- tools/check_for_upgrade.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 81c371b3f..3210e4375 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -180,6 +180,7 @@ function has_typed_input() { # Check if there are updates available before proceeding if ! is_update_available; then + update_last_updated_file return fi -- cgit v1.2.3-70-g09d2 From 673b9fc3317d48a169fe612575186b3eb1a42a13 Mon Sep 17 00:00:00 2001 From: Mark Keisler Date: Tue, 18 Apr 2023 03:36:07 -0500 Subject: feat(aws)!: improve `aws_change_access_key` (#11378) BREAKING CHANGE: This commit removes compatibility for `aws` cli v1. Now only v2 is supported. --- plugins/aws/README.md | 11 ++++++----- plugins/aws/aws.plugin.zsh | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/plugins/aws/README.md b/plugins/aws/README.md index 846bf1414..54bc7a44d 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -1,7 +1,8 @@ # aws -This plugin provides completion support for [awscli](https://docs.aws.amazon.com/cli/latest/reference/index.html) +This plugin provides completion support for [awscli v2](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/index.html) and a few utilities to manage AWS profiles/regions and display them in the prompt. +[awscli v1](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html) is no longer supported. To use it, add `aws` to the plugins array in your zshrc file. @@ -12,9 +13,9 @@ plugins=(... aws) ## Plugin commands * `asp []`: sets `$AWS_PROFILE` and `$AWS_DEFAULT_PROFILE` (legacy) to ``. - It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`. + It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`. Run `asp` without arguments to clear the profile. -* `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. +* `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. * `asr []`: sets `$AWS_REGION` and `$AWS_DEFAULT_REGION` (legacy) to ``. Run `asr` without arguments to clear the profile. @@ -65,7 +66,7 @@ the current `$AWS_PROFILE` and `$AWS_REGION`. It uses four variables to control Source profile credentials in `~/.aws/credentials`: -``` +```ini [source-profile-name] aws_access_key_id = ... aws_secret_access_key = ... @@ -73,7 +74,7 @@ aws_secret_access_key = ... Role configuration in `~/.aws/config`: -``` +```ini [profile source-profile-name] mfa_serial = arn:aws:iam::111111111111:mfa/myuser region = us-east-1 diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index a379eaa18..d45abba57 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -160,14 +160,39 @@ function aws_change_access_key() { return 1 fi - echo "Insert the credentials when asked." - asp "$1" || return 1 - AWS_PAGER="" aws iam create-access-key - AWS_PAGER="" aws configure --profile "$1" + local profile="$1" + # Get current access key + local original_aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)" + + asp "$profile" || return 1 + echo "Generating a new access key pair for you now." + if aws --no-cli-pager iam create-access-key; then + echo "Insert the newly generated credentials when asked." + aws --no-cli-pager configure --profile $profile + else + echo "Current access keys:" + aws --no-cli-pager iam list-access-keys + echo "Profile \"${profile}\" is currently using the $original_aws_access_key_id key. You can delete an old access key by running \`aws --profile $profile iam delete-access-key --access-key-id AccessKeyId\`" + return 1 + fi - echo "You can now safely delete the old access key running \`aws iam delete-access-key --access-key-id ID\`" + read -q "yn?Would you like to disable your previous access key (${original_aws_access_key_id}) now? " + case $yn in + [Yy]*) + echo -n "\nDisabling access key ${original_aws_access_key_id}..." + if aws --no-cli-pager update-access-key --access-key-id ${original_aws_access_key_id} --status Inactive; then + echo "done." + else + echo "\nFailed to disable ${original_aws_access_key_id} key." + fi + ;; + *) + echo "" + ;; + esac + echo "You can now safely delete the old access key by running \`aws --profile $profile iam delete-access-key --access-key-id ${original_aws_access_key_id}\`" echo "Your current keys are:" - AWS_PAGER="" aws iam list-access-keys + aws --no-cli-pager iam list-access-keys } function aws_regions() { -- cgit v1.2.3-70-g09d2 From 9139d30ca30f8f687cc21121ed9b4f5238bc5260 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Wed, 19 Apr 2023 22:46:10 +0900 Subject: feat(aws): allow more customisation in prompt function (#11619) --- plugins/aws/README.md | 2 ++ plugins/aws/aws.plugin.zsh | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/aws/README.md b/plugins/aws/README.md index 54bc7a44d..9e1e055b8 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -58,6 +58,8 @@ the current `$AWS_PROFILE` and `$AWS_REGION`. It uses four variables to control * ZSH_THEME_AWS_REGION_SUFFIX: sets the suffix of the AWS_REGION. Defaults to `>`. +* ZSH_THEME_AWS_DIVIDER: sets the divider between ZSH_THEME_AWS_PROFILE_SUFFIX and ZSH_THEME_AWS_REGION_PREFIX. Defaults to ` ` (single space). + ## Configuration [Configuration and credential file settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) by AWS diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index d45abba57..0da91bc22 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -223,13 +223,16 @@ compctl -K _aws_profiles asp acp aws_change_access_key function aws_prompt_info() { local _aws_to_show local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}" + if [[ -n $AWS_PROFILE ]];then - _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" + _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX=""}" fi + if [[ -n $AWS_REGION ]]; then - [[ -n $AWS_PROFILE ]] && _aws_to_show+=" " - _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX:=}" + [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=' '}" + _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX=""}" fi + echo "$_aws_to_show" } -- cgit v1.2.3-70-g09d2 From 18c837b136a9591117ef059eb8266c490d5eeee1 Mon Sep 17 00:00:00 2001 From: Erin Schlarb Date: Thu, 20 Apr 2023 13:30:49 +0200 Subject: fix(dirhistory): run properly if `ksh_arrays` is set (#11630) --- plugins/dirhistory/dirhistory.plugin.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index 7021fc03a..8d67c6188 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -19,15 +19,17 @@ export DIRHISTORY_SIZE=30 # Returns the element if the array was not empty, # otherwise returns empty string. function pop_past() { - typeset -g $1="${dirhistory_past[$#dirhistory_past]}" + setopt localoptions no_ksh_arrays if [[ $#dirhistory_past -gt 0 ]]; then + typeset -g $1="${dirhistory_past[$#dirhistory_past]}" dirhistory_past[$#dirhistory_past]=() fi } function pop_future() { - typeset -g $1="${dirhistory_future[$#dirhistory_future]}" + setopt localoptions no_ksh_arrays if [[ $#dirhistory_future -gt 0 ]]; then + typeset -g $1="${dirhistory_future[$#dirhistory_future]}" dirhistory_future[$#dirhistory_future]=() fi } @@ -35,6 +37,7 @@ function pop_future() { # Push a new element onto the end of dirhistory_past. If the size of the array # is >= DIRHISTORY_SIZE, the array is shifted function push_past() { + setopt localoptions no_ksh_arrays if [[ $#dirhistory_past -ge $DIRHISTORY_SIZE ]]; then shift dirhistory_past fi @@ -44,6 +47,7 @@ function push_past() { } function push_future() { + setopt localoptions no_ksh_arrays if [[ $#dirhistory_future -ge $DIRHISTORY_SIZE ]]; then shift dirhistory_future fi -- cgit v1.2.3-70-g09d2 From 5b11e70a9617c6e248fd6947e84016bd8c37028e Mon Sep 17 00:00:00 2001 From: Erin Schlarb Date: Thu, 20 Apr 2023 13:32:32 +0200 Subject: fix(cli): execute as expected if `ksh_arrays` is set (#11629) --- lib/cli.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index ba3e39eb5..561c1b98b 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -11,7 +11,7 @@ function omz { # Subcommand functions start with _ so that they don't # appear as completion entries when looking for `omz` - (( $+functions[_omz::$command] )) || { + (( ${+functions[_omz::$command]} )) || { _omz::help return 1 } -- cgit v1.2.3-70-g09d2 From 91c7ed45a312a71b7d3b856228047ddcd51d4651 Mon Sep 17 00:00:00 2001 From: Nathanial Spearing Date: Thu, 20 Apr 2023 07:42:47 -0400 Subject: feat(npm): add `npmrd` alias (#11627) --- plugins/npm/README.md | 1 + plugins/npm/npm.plugin.zsh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/plugins/npm/README.md b/plugins/npm/README.md index 8eafc6d61..420dd710a 100644 --- a/plugins/npm/README.md +++ b/plugins/npm/README.md @@ -29,6 +29,7 @@ plugins=(... npm) | `npmI` | `npm init` | Run npm init | | `npmi` | `npm info` | Run npm info | | `npmSe` | `npm search` | Run npm search | +| `npmrd` | `npm run dev` | Run npm run dev | ## `npm install` / `npm uninstall` toggle diff --git a/plugins/npm/npm.plugin.zsh b/plugins/npm/npm.plugin.zsh index e0dcbf142..3cba18f6c 100644 --- a/plugins/npm/npm.plugin.zsh +++ b/plugins/npm/npm.plugin.zsh @@ -70,6 +70,9 @@ alias npmi="npm info" # Run npm search alias npmSe="npm search" +# Run npm run dev +alias npmrd="npm run dev" + npm_toggle_install_uninstall() { # Look up to the previous 2 history commands local line -- cgit v1.2.3-70-g09d2 From 07454029bd67239ce42aaa68b427fbbe8e428e7d Mon Sep 17 00:00:00 2001 From: Andrew Xie <62098008+axieax@users.noreply.github.com> Date: Fri, 21 Apr 2023 16:59:58 +1000 Subject: feat(starship): create plugin (#10947) Co-authored-by: Carlo Sala --- .github/CODEOWNERS | 1 + plugins/starship/README.md | 21 +++++++++++++++++++++ plugins/starship/starship.plugin.zsh | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 plugins/starship/README.md create mode 100644 plugins/starship/starship.plugin.zsh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6668cd7ce..599b765ca 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -9,3 +9,4 @@ plugins/shell-proxy/ @septs plugins/universalarchive/ @Konfekt plugins/wp-cli/ @joshmedeski plugins/zoxide/ @ajeetdsouza +plugins/starship/ @axieax diff --git a/plugins/starship/README.md b/plugins/starship/README.md new file mode 100644 index 000000000..0e66c5294 --- /dev/null +++ b/plugins/starship/README.md @@ -0,0 +1,21 @@ +# starship plugin + +Initializes [starship prompt](https://starship.rs) - a minimal, blazing-fast and infinitely customizable cross-shell prompt. + +[Demo](https://user-images.githubusercontent.com/62098008/169764279-50b48262-9506-4651-ba89-f6611a88ebf0.mp4) + +[External repository](https://github.com/axieax/zsh-starship) for this zsh plugin. + +# Installation + +**Note:** you have to [install starship](https://starship.rs/guide/#%F0%9F%9A%80-installation) first. + +## [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) + +Add `starship` to the plugins array in your `.zshrc` file: + +```zsh +plugins=(... starship) +``` + +## ⚠️ ENABLING THIS PLUGIN WILL UNSET YOUR ZSH_THEME VARIABLE diff --git a/plugins/starship/starship.plugin.zsh b/plugins/starship/starship.plugin.zsh new file mode 100644 index 000000000..8c5d9135e --- /dev/null +++ b/plugins/starship/starship.plugin.zsh @@ -0,0 +1,8 @@ +# ignore oh-my-zsh theme +unset ZSH_THEME + +if (( $+commands[starship] )); then + eval "$(starship init zsh)" +else + echo '[oh-my-zsh] starship not found, please install it from https://starship.rs' +fi -- cgit v1.2.3-70-g09d2 From 5d3e86e2a48adf7a308773f8f1b725d187c7c5ef Mon Sep 17 00:00:00 2001 From: Miguel Sempere Date: Fri, 21 Apr 2023 08:15:31 +0100 Subject: feat(dbt): create plugin (#11635) Co-authored-by: Carlo Sala --- .github/CODEOWNERS | 1 + plugins/dbt/README.md | 29 +++++++++++++++++++++++++++++ plugins/dbt/dbt.plugin.zsh | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 plugins/dbt/README.md create mode 100644 plugins/dbt/dbt.plugin.zsh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 599b765ca..0c5f3acee 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -10,3 +10,4 @@ plugins/universalarchive/ @Konfekt plugins/wp-cli/ @joshmedeski plugins/zoxide/ @ajeetdsouza plugins/starship/ @axieax +plugins/dbt/ @msempere diff --git a/plugins/dbt/README.md b/plugins/dbt/README.md new file mode 100644 index 000000000..e05d79cc3 --- /dev/null +++ b/plugins/dbt/README.md @@ -0,0 +1,29 @@ +# dbt plugin + +## Introduction + +The `dbt plugin` adds several aliases for useful [dbt](https://docs.getdbt.com/) commands and +[aliases](#aliases). + +To use it, add `dbt` to the plugins array of your zshrc file: + +``` +plugins=(... dbt) +``` + +## Aliases + +| Alias | Command | Description | +| ------ | ------------------------------------------------ | ---------------------------------------------------- | +| dbtlm | `dbt ls -s state:modified` | List modified models only | +| dbtrm | `dbt run -s state:modified` | Run modified models only | +| dbttm | `dbt test -m state:modified` | Test modified models only | +| dbtrtm | `dbtrm && dbttm` | Run and test modified models only | +| dbtrs | `dbt clean; dbt deps; dbt seed` | Re-seed data | +| dbtfrt | `dbtrs; dbt run --full-refresh; dbt test` | Perform a full fresh run with tests | +| dbtcds | `dbt docs generate; dbt docs serve` | Generate docs without compiling | +| dbtds | `dbt docs generate --no-compile; dbt docs serve` | Generate and serve docs skipping doc. re-compilation | + +## Maintainer + +### [msempere](https://github.com/msempere) diff --git a/plugins/dbt/dbt.plugin.zsh b/plugins/dbt/dbt.plugin.zsh new file mode 100644 index 000000000..6fcc2eecf --- /dev/null +++ b/plugins/dbt/dbt.plugin.zsh @@ -0,0 +1,23 @@ +# list modified models only +alias dbtlm="dbt ls -s state:modified" + +# run modified models only +alias dbtrm="dbt run -s state:modified" + +# test modified models only +alias dbttm="dbt test -m state:modified" + +# run and test modified models only +alias dbtrtm="dbtrm && dbttm" + +# re-seed data +alias dbtrs="dbt clean; dbt deps; dbt seed" + +# perform a full fresh run with tests +alias dbtfrt="dbtrs; dbt run --full-refresh; dbt test" + +# generate and serve docs +alias dbtcds="dbt docs generate; dbt docs serve" + +# generate and serve docs skipping doc. re-compilation +alias dbtds="dbt docs generate --no-compile; dbt docs serve" -- cgit v1.2.3-70-g09d2 From 343c78ae91ff03ea66517b1d69b25fa262ce5408 Mon Sep 17 00:00:00 2001 From: Idan Fishman Date: Thu, 27 Apr 2023 11:49:26 +0200 Subject: fix(aws): set properly set divider to space Closes #11649 Co-authored-by: Carlo Sala --- plugins/aws/aws.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 0da91bc22..a437dc8e8 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -229,7 +229,7 @@ function aws_prompt_info() { fi if [[ -n $AWS_REGION ]]; then - [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=' '}" + [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=" "}" _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX=""}" fi -- cgit v1.2.3-70-g09d2 From 65699912be974d36b732b63e32c3b9428d23ace8 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 27 Apr 2023 09:57:44 +0200 Subject: fix(azure): recognize properly linuxbrew Closes #11644 --- plugins/azure/azure.plugin.zsh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/azure/azure.plugin.zsh b/plugins/azure/azure.plugin.zsh index 8fec3c1f7..22fbea80f 100644 --- a/plugins/azure/azure.plugin.zsh +++ b/plugins/azure/azure.plugin.zsh @@ -31,11 +31,9 @@ function _az-homebrew-installed() { # check if Homebrew is installed (( $+commands[brew] )) || return 1 - # speculatively check default brew prefix - if [[ -d /usr/local ]]; then - _brew_prefix=/usr/local - elif [[ -d /opt/homebrew ]]; then - _brew_prefix=/opt/homebrew + # if so, we assume it's default way to install brew + if [[ ${commands[brew]:t2} == bin/brew ]]; then + _brew_prefix="${commands[brew]:h:h}" # remove trailing /bin/brew else # ok, it is not in the default prefix # this call to brew is expensive (about 400 ms), so at least let's make it only once -- cgit v1.2.3-70-g09d2 From 5fc1118fd240a0d87ad022d36f48cb31d869ab2e Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 27 Apr 2023 19:42:55 +0200 Subject: chore(azure): fix typo --- plugins/azure/azure.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/azure/azure.plugin.zsh b/plugins/azure/azure.plugin.zsh index 22fbea80f..b33b0f805 100644 --- a/plugins/azure/azure.plugin.zsh +++ b/plugins/azure/azure.plugin.zsh @@ -1,4 +1,4 @@ -# AZ Get Subscritions +# AZ Get Subscriptions function azgs() { az account show --output tsv --query 'name' 2>/dev/null } -- cgit v1.2.3-70-g09d2 From 2e7a247cab663fbc0aafdefa15bf10eb4dd64563 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Fri, 28 Apr 2023 09:05:36 +0200 Subject: feat(z): update to latest upstream version Mirror of https://github.com/agkozak/zsh-z/commit/6bfe418332866d15373392164df11b4fbec2083f Closes #11652 Co-authored-by: Carlo Sala --- plugins/z/LICENSE | 2 +- plugins/z/MANUAL.md | 21 ++++++++++++--- plugins/z/_z | 2 +- plugins/z/img/mit_license.svg | 1 + plugins/z/img/zsh_4.3.11_plus.svg | 1 + plugins/z/z.plugin.zsh | 54 +++++++++++++++++++++++++++++++-------- 6 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 plugins/z/img/mit_license.svg create mode 100644 plugins/z/img/zsh_4.3.11_plus.svg diff --git a/plugins/z/LICENSE b/plugins/z/LICENSE index d1cca7ae5..6af13b9e0 100644 --- a/plugins/z/LICENSE +++ b/plugins/z/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018-2022 Alexandros Kozak +Copyright (c) 2018-2023 Alexandros Kozak Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/plugins/z/MANUAL.md b/plugins/z/MANUAL.md index dcca3c452..d367c3026 100644 --- a/plugins/z/MANUAL.md +++ b/plugins/z/MANUAL.md @@ -1,5 +1,9 @@ # Zsh-z +[![MIT License](img/mit_license.svg)](https://opensource.org/licenses/MIT) +![Zsh version 4.3.11 and higher](img/zsh_4.3.11_plus.svg) +[![GitHub stars](https://img.shields.io/github/stars/agkozak/zsh-z.svg)](https://github.com/agkozak/zsh-z/stargazers) + Zsh-z is a command line tool that allows you to jump quickly to directories that you have visited frequently in the past, or recently -- but most often a combination of the two (a concept known as ["frecency"](https://en.wikipedia.org/wiki/Frecency)). It works by keeping track of when you go to directories and how much time you spend in them. It is then in the position to guess where you want to go when you type a partial string, e.g., `z src` might take you to `~/src/zsh`. `z zsh` might also get you there, and `z c/z` might prove to be even more specific -- it all depends on your habits and how much time you have been using Zsh-z to build up a database. After using Zsh-z for a little while, you will get to where you want to be by typing considerably less than you would need if you were using `cd`. Zsh-z is a native Zsh port of [rupa/z](https://github.com/rupa/z), a tool written for `bash` and Zsh that uses embedded `awk` scripts to do the heavy lifting. It was quite possibly my most used command line tool for a couple of years. I decided to translate it, `awk` parts and all, into pure Zsh script, to see if by eliminating calls to external tools (`awk`, `sort`, `date`, `sed`, `mv`, `rm`, and `chown`) and reducing forking through subshells I could make it faster. The performance increase is impressive, particularly on systems where forking is slow, such as Cygwin, MSYS2, and WSL. I have found that, in those environments, switching directories using Zsh-z can be over 100% faster than it is using `rupa/z`. @@ -28,6 +32,10 @@ Zsh-z is a drop-in replacement for `rupa/z` and will, by default, use the same d
Here are the latest features and updates. +- April 27, 2023 + + Zsh-z now allows the user to specify the directory-changing command using the `ZSHZ_CD` environment variable (default: `builtin cd`; props @basnijholt). +- January 27, 2023 + + If the datafile directory specified by `ZSHZ_DATA` or `_Z_DATA` does not already exist, create it (props @mattmc3). - June 29, 2022 + Zsh-z is less likely to leave temporary files sitting around (props @mafredri). - June 27, 2022 @@ -118,13 +126,19 @@ Add the line to your `.zshrc`, somewhere above the line that says `antigen apply`. -### For [oh-my-zsh](http://ohmyz.sh/) users +### For [Oh My Zsh](http://ohmyz.sh/) users -Execute the following command: +Zsh-z is now included as part of Oh My Zsh! As long as you are using an up-to-date installation of Oh My Zsh, you can activate Zsh-z simply by adding `z` to your `plugins` array in your `.zshrc`, e.g., + + plugins=( git z ) + +It is as simple as that. + +If, however, you prefer always to use the latest version of Zsh-z from the `agkozak/zsh-z` repo, you may install it thus: git clone https://github.com/agkozak/zsh-z ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-z -and add `zsh-z` to the line of your `.zshrc` that specifies `plugins=()`, e.g., `plugins=( git zsh-z )`. +and activate it by adding `zsh-z` to the line of your `.zshrc` that specifies `plugins=()`, e.g., `plugins=( git zsh-z )`. ### For [prezto](https://github.com/sorin-ionescu/prezto) users @@ -246,6 +260,7 @@ to install `zsh-z`. Zsh-z has environment variables (they all begin with `ZSHZ_`) that change its behavior if you set them; you can also keep your old ones if you have been using `rupa/z` (they begin with `_Z_`). * `ZSHZ_CMD` changes the command name (default: `z`) +* `ZSHZ_CD` specifies the default directory-changing command (default: `builtin cd`) * `ZSHZ_COMPLETION` can be `'frecent'` (default) or `'legacy'`, depending on whether you want your completion results sorted according to frecency or simply sorted alphabetically * `ZSHZ_DATA` changes the database file (default: `~/.z`) * `ZSHZ_ECHO` displays the new path name when changing directories (default: `0`) diff --git a/plugins/z/_z b/plugins/z/_z index 9891a52ed..a493f35ba 100644 --- a/plugins/z/_z +++ b/plugins/z/_z @@ -5,7 +5,7 @@ # # https://github.com/agkozak/zsh-z # -# Copyright (c) 2018-2022 Alexandros Kozak +# Copyright (c) 2018-2023 Alexandros Kozak # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/plugins/z/img/mit_license.svg b/plugins/z/img/mit_license.svg new file mode 100644 index 000000000..1c02079d7 --- /dev/null +++ b/plugins/z/img/mit_license.svg @@ -0,0 +1 @@ +licenselicenseMITMIT \ No newline at end of file diff --git a/plugins/z/img/zsh_4.3.11_plus.svg b/plugins/z/img/zsh_4.3.11_plus.svg new file mode 100644 index 000000000..f46d947d0 --- /dev/null +++ b/plugins/z/img/zsh_4.3.11_plus.svg @@ -0,0 +1 @@ +zshzsh4.3.11+4.3.11+ \ No newline at end of file diff --git a/plugins/z/z.plugin.zsh b/plugins/z/z.plugin.zsh index 209edfea7..60a630624 100644 --- a/plugins/z/z.plugin.zsh +++ b/plugins/z/z.plugin.zsh @@ -4,7 +4,7 @@ # # https://github.com/agkozak/zsh-z # -# Copyright (c) 2018-2022 Alexandros Kozak +# Copyright (c) 2018-2023 Alexandros Kozak # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -52,6 +52,7 @@ # ZSHZ_CASE -> if `ignore', pattern matching is case-insensitive; if `smart', # pattern matching is case-insensitive only when the pattern is all # lowercase +# ZSHZ_CD -> the directory-changing command that is used (default: builtin cd) # ZSHZ_CMD -> name of command (default: z) # ZSHZ_COMPLETION -> completion method (default: 'frecent'; 'legacy' for # alphabetic sorting) @@ -129,6 +130,7 @@ is-at-least 5.3.0 && ZSHZ[PRINTV]=1 # Globals: # ZSHZ # ZSHZ_CASE +# ZSHZ_CD # ZSHZ_COMPLETION # ZSHZ_DATA # ZSHZ_DEBUG @@ -149,9 +151,19 @@ zshz() { local REPLY local -a lines - # Allow the user to specify the datafile name in $ZSHZ_DATA (default: ~/.z) + # Allow the user to specify a custom datafile in $ZSHZ_DATA (or legacy $_Z_DATA) + local custom_datafile="${ZSHZ_DATA:-$_Z_DATA}" + + # If a datafile was provided as a standalone file without a directory path + # print a warning and exit + if [[ -n ${custom_datafile} && ${custom_datafile} != */* ]]; then + print "ERROR: You configured a custom Zsh-z datafile (${custom_datafile}), but have not specified its directory." >&2 + exit + fi + + # If the user specified a datafile, use that or default to ~/.z # If the datafile is a symlink, it gets dereferenced - local datafile=${${ZSHZ_DATA:-${_Z_DATA:-${HOME}/.z}}:A} + local datafile=${${custom_datafile:-$HOME/.z}:A} # If the datafile is a directory, print a warning and exit if [[ -d $datafile ]]; then @@ -161,7 +173,7 @@ zshz() { # Make sure that the datafile exists before attempting to read it or lock it # for writing - [[ -f $datafile ]] || touch "$datafile" + [[ -f $datafile ]] || { mkdir -p "${datafile:h}" && touch "$datafile" } # Bail if we don't own the datafile and $ZSHZ_OWNER is not set [[ -z ${ZSHZ_OWNER:-${_Z_OWNER}} && -f $datafile && ! -O $datafile ]] && @@ -620,7 +632,7 @@ zshz() { *) # Frecency routine (( dx = EPOCHSECONDS - time_field )) - rank=$(( 10000 * rank_field * (3.75/((0.0001 * dx + 1) + 0.25)) )) + rank=$(( 10000 * rank_field * (3.75/( (0.0001 * dx + 1) + 0.25)) )) ;; esac @@ -756,6 +768,26 @@ zshz() { [[ $output_format != 'completion' ]] && output_format='list' } + ######################################################### + # Allow the user to specify directory-changing command + # using $ZSHZ_CD (default: builtin cd). + # + # Globals: + # ZSHZ_CD + # + # Arguments: + # $* Path + ######################################################### + zshz_cd() { + setopt LOCAL_OPTIONS NO_WARN_CREATE_GLOBAL + + if [[ -z $ZSHZ_CD ]]; then + builtin cd "$*" + else + ${=ZSHZ_CD} "$*" + fi + } + ######################################################### # If $ZSHZ_ECHO == 1, display paths as you jump to them. # If it is also the case that $ZSHZ_TILDE == 1, display @@ -773,7 +805,7 @@ zshz() { if [[ ${@: -1} == /* ]] && (( ! $+opts[-e] && ! $+opts[-l] )); then # cd if possible; echo the new path if $ZSHZ_ECHO == 1 - [[ -d ${@: -1} ]] && builtin cd ${@: -1} && _zshz_echo && return + [[ -d ${@: -1} ]] && zshz_cd ${@: -1} && _zshz_echo && return fi # With option -c, make sure query string matches beginning of matches; @@ -830,12 +862,12 @@ zshz() { print -- "$cd" else # cd if possible; echo the new path if $ZSHZ_ECHO == 1 - [[ -d $cd ]] && builtin cd "$cd" && _zshz_echo + [[ -d $cd ]] && zshz_cd "$cd" && _zshz_echo fi else # if $req is a valid path, cd to it; echo the new path if $ZSHZ_ECHO == 1 if ! (( $+opts[-e] || $+opts[-l] )) && [[ -d $req ]]; then - builtin cd "$req" && _zshz_echo + zshz_cd "$req" && _zshz_echo else return $ret2 fi @@ -900,9 +932,9 @@ add-zsh-hook chpwd _zshz_chpwd ############################################################ # Standarized $0 handling -# (See https://github.com/agkozak/Zsh-100-Commits-Club/blob/master/Zsh-Plugin-Standard.adoc) -0=${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}} -0=${${(M)0:#/*}:-$PWD/$0} +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" (( ${fpath[(ie)${0:A:h}]} <= ${#fpath} )) || fpath=( "${0:A:h}" "${fpath[@]}" ) -- cgit v1.2.3-70-g09d2 From b22593cf179bae479ab32700c5a7b94d3053762d Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 1 May 2023 22:21:01 +0200 Subject: fix(init): avoid overwriting existing aliases Fix regression introduced in #11550. If an existing alias was present in the moment of sourcing, and oh-my-zsh aliases were disabled for that file, it'd be overwritten aswell. See #11658. --- oh-my-zsh.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index e047d4834..a577c1f41 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -159,10 +159,10 @@ _omz_source() { zstyle -T ":omz:${context}" aliases || disable_aliases=1 # Back up alias names prior to sourcing - local -a aliases_pre galiases_pre + local -A aliases_pre galiases_pre if (( disable_aliases )); then - aliases_pre=("${(@k)aliases}") - galiases_pre=("${(@k)galiases}") + aliases_pre=("${(@kv)aliases}") + galiases_pre=("${(@kv)galiases}") fi # Source file from $ZSH_CUSTOM if it exists, otherwise from $ZSH @@ -174,10 +174,16 @@ _omz_source() { # Unset all aliases that don't appear in the backed up list of aliases if (( disable_aliases )); then - local -a disabled - # ${var:|array} gets the list of items in var not in array - disabled=("${(@k)aliases:|aliases_pre}" "${(@k)galiases:|galiases_pre}") - (( $#disabled == 0 )) || unalias "${(@)disabled}" + if (( #aliases_pre )); then + aliases=("${(@kv)aliases_pre}") + else + (( #aliases )) && unalias "${(@k)aliases}" + fi + if (( #galiases_pre )); then + galiases=("${(@kv)galiases_pre}") + else + (( #galiases )) && unalias "${(@k)galiases}" + fi fi } -- cgit v1.2.3-70-g09d2 From 693e3dcc447b5d6fa611eea43166ea2b4e0ed877 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 2 May 2023 10:03:24 +0200 Subject: fix(apple): replace deprecated nerdfonts icon --- themes/apple.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/apple.zsh-theme b/themes/apple.zsh-theme index 0c183258e..65a2b80fe 100644 --- a/themes/apple.zsh-theme +++ b/themes/apple.zsh-theme @@ -1,5 +1,5 @@ function toon { - echo -n "" + echo -n "󰐀" } autoload -Uz vcs_info -- cgit v1.2.3-70-g09d2 From dab09cc0eec220f5c1a541ccb75449c62c20bdb4 Mon Sep 17 00:00:00 2001 From: Oleg Grigoriev Date: Tue, 2 May 2023 13:27:57 +0300 Subject: feat(rake-fast): show task descriptions in autocomplete (#11653) --- plugins/rake-fast/rake-fast.plugin.zsh | 39 +++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/plugins/rake-fast/rake-fast.plugin.zsh b/plugins/rake-fast/rake-fast.plugin.zsh index 19dab154b..86e5ed586 100644 --- a/plugins/rake-fast/rake-fast.plugin.zsh +++ b/plugins/rake-fast/rake-fast.plugin.zsh @@ -1,5 +1,28 @@ +# The version of the format of .rake_tasks. If the output of _rake_generate +# changes, incrementing this number will force it to regenerate +_rake_tasks_version=2 + _rake_does_task_list_need_generating () { - [[ ! -f .rake_tasks ]] || [[ Rakefile -nt .rake_tasks ]] || { _is_rails_app && _tasks_changed } + _rake_tasks_missing || _rake_tasks_version_changed || _rakefile_has_changes || { _is_rails_app && _tasks_changed } +} + +_rake_tasks_missing () { + [[ ! -f .rake_tasks ]] +} + +_rake_tasks_version_changed () { + local -a file_version + file_version=`head -n 1 .rake_tasks | sed "s/^version\://"` + + if ! [[ $file_version =~ '^[0-9]*$' ]]; then + return true + fi + + [[ $file_version -ne $_rake_tasks_version ]] +} + +_rakefile_has_changes () { + [[ Rakefile -nt .rake_tasks ]] } _is_rails_app () { @@ -20,7 +43,14 @@ _tasks_changed () { } _rake_generate () { - rake --silent --tasks | cut -d " " -f 2 | sed 's/\[.*\]//g' > .rake_tasks + echo "version:$_rake_tasks_version" > .rake_tasks + + rake --silent --tasks --all \ + | sed "s/^rake //" | sed "s/\:/\\\:/g" \ + | sed "s/\[[^]]*\]//g" \ + | sed "s/ *# /\:/" \ + | sed "s/\:$//" \ + >> .rake_tasks } _rake () { @@ -29,7 +59,10 @@ _rake () { echo "\nGenerating .rake_tasks..." >&2 _rake_generate fi - compadd $(cat .rake_tasks) + local -a rake_options + rake_options=("${(@f)$(cat .rake_tasks)}") + shift rake_options + _describe 'rake tasks' rake_options fi } compdef _rake rake -- cgit v1.2.3-70-g09d2 From 85fdbfe21692a3fa7bdd7bc509163e23fb385279 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 3 May 2023 11:17:47 +0200 Subject: fix(apple): go back to previous icon Turns out that is a reserved unicode code that is Apple logo in Apple systems. Nerd fonts was overwritting that code to other stuff in v2 and that's why I thought it needed to be replaced. Closes #11665 This reverts commit 693e3dcc447b5d6fa611eea43166ea2b4e0ed877. --- themes/apple.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/apple.zsh-theme b/themes/apple.zsh-theme index 65a2b80fe..0c183258e 100644 --- a/themes/apple.zsh-theme +++ b/themes/apple.zsh-theme @@ -1,5 +1,5 @@ function toon { - echo -n "󰐀" + echo -n "" } autoload -Uz vcs_info -- cgit v1.2.3-70-g09d2 From 5a3f565e7d4371db92ba574f231b396c2c8c9a19 Mon Sep 17 00:00:00 2001 From: kang <1115610574@qq.com> Date: Wed, 3 May 2023 23:48:37 +0800 Subject: feat(deno): add `dru` alias for `--unstable` (#11667) --- plugins/deno/README.md | 27 ++++++++++++++------------- plugins/deno/deno.plugin.zsh | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/deno/README.md b/plugins/deno/README.md index 691318397..38f9f2033 100644 --- a/plugins/deno/README.md +++ b/plugins/deno/README.md @@ -4,16 +4,17 @@ This plugin sets up completion and aliases for [Deno](https://deno.land). ## Aliases -| Alias | Full command | -| ----- | ---------------- | -| db | deno bundle | -| dc | deno compile | -| dca | deno cache | -| dfmt | deno fmt | -| dh | deno help | -| dli | deno lint | -| drn | deno run | -| drA | deno run -A | -| drw | deno run --watch | -| dts | deno test | -| dup | deno upgrade | +| Alias | Full command | +| ----- | ------------------- | +| db | deno bundle | +| dc | deno compile | +| dca | deno cache | +| dfmt | deno fmt | +| dh | deno help | +| dli | deno lint | +| drn | deno run | +| drA | deno run -A | +| drw | deno run --watch | +| dru | deno run --unstable | +| dts | deno test | +| dup | deno upgrade | diff --git a/plugins/deno/deno.plugin.zsh b/plugins/deno/deno.plugin.zsh index 7708f84df..bf97d6f03 100644 --- a/plugins/deno/deno.plugin.zsh +++ b/plugins/deno/deno.plugin.zsh @@ -8,6 +8,7 @@ alias dli='deno lint' alias drn='deno run' alias drA='deno run -A' alias drw='deno run --watch' +alias dru='deno run --unstable' alias dts='deno test' alias dup='deno upgrade' -- cgit v1.2.3-70-g09d2 From c5208867f1eb46f722e040b239150817abec87a6 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 2 May 2023 12:41:01 +0200 Subject: feat(theme-and-appearance): allow disabling gnu-ls in bsd To disable gnu-ls (`gls`) even if it's installed in freeBSD and macOS you can set it up with: ```zsh zstyle ':omz:lib:theme-and-appearance' gnu-ls no ``` Closes #11647 --- README.md | 13 +++++++++++++ lib/theme-and-appearance.zsh | 36 +++++++++++++++++------------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 556d4c8c5..650fb00ea 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi - [Manual Installation](#manual-installation) - [Installation Problems](#installation-problems) - [Custom Plugins and Themes](#custom-plugins-and-themes) + - [Disable GNU ls in macOS and freeBSD systems](#disable-gnu-ls) - [Skip aliases](#skip-aliases) - [Getting Updates](#getting-updates) - [Updates verbosity](#updates-verbosity) @@ -278,6 +279,18 @@ If you have many functions that go well together, you can put them as a `XYZ.plu If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`. +### Disable GNU ls in macOS and freeBSD systems + + + +The default behaviour in Oh My Zsh is to use GNU `ls` even in macOS and freeBSD systems if it's installed (as +`gls` command) when enabling colorized `ls` in `lib/theme-and-appearance.zsh`. If you want to disable this +behaviour you can use zstyle-based config before sourcing `oh-my-zsh.sh`: + +```zsh +zstyle ':omz:lib:theme-and-appearance' gnu-ls no +``` + ### Skip aliases diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index d8859b04c..96bdb00e5 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -20,10 +20,25 @@ if command diff --color /dev/null{,} &>/dev/null; then } fi - # Don't set ls coloring if disabled [[ "$DISABLE_LS_COLORS" != true ]] || return 0 +# Default coloring for BSD-based ls +export LSCOLORS="Gxfxcxdxbxegedabagacad" + +# Default coloring for GNU-based ls +if [[ -z "$LS_COLORS" ]]; then + # Define LS_COLORS via dircolors if available. Otherwise, set a default + # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors) + if (( $+commands[dircolors] )); then + [[ -f "$HOME/.dircolors" ]] \ + && source <(dircolors -b "$HOME/.dircolors") \ + || source <(dircolors -b) + else + export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43" + fi +fi + function test-ls-args { local cmd="$1" # ls, gls, colorls, ... local args="${@[2,-1]}" # arguments except the first one @@ -50,7 +65,7 @@ case "$OSTYPE" in test-ls-args ls -G && alias ls='ls -G' # Only use GNU ls if installed and there are user defaults for $LS_COLORS, # as the default coloring scheme is not very pretty - [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] \ + zstyle -T ':omz:lib:theme-and-appearance' gnu-ls \ && test-ls-args gls --color \ && alias ls='gls --color=tty' ;; @@ -64,20 +79,3 @@ case "$OSTYPE" in esac unfunction test-ls-args - - -# Default coloring for BSD-based ls -export LSCOLORS="Gxfxcxdxbxegedabagacad" - -# Default coloring for GNU-based ls -if [[ -z "$LS_COLORS" ]]; then - # Define LS_COLORS via dircolors if available. Otherwise, set a default - # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors) - if (( $+commands[dircolors] )); then - [[ -f "$HOME/.dircolors" ]] \ - && source <(dircolors -b "$HOME/.dircolors") \ - || source <(dircolors -b) - else - export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43" - fi -fi -- cgit v1.2.3-70-g09d2 From 017e288560ef7bdfb8835516d6b3b77bbdcdde6c Mon Sep 17 00:00:00 2001 From: Mark Keisler Date: Sat, 6 May 2023 06:40:06 -0500 Subject: fix(aws): correct access key disable command (#11671) --- plugins/aws/aws.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index a437dc8e8..b2415b737 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -180,7 +180,7 @@ function aws_change_access_key() { case $yn in [Yy]*) echo -n "\nDisabling access key ${original_aws_access_key_id}..." - if aws --no-cli-pager update-access-key --access-key-id ${original_aws_access_key_id} --status Inactive; then + if aws --no-cli-pager iam update-access-key --access-key-id ${original_aws_access_key_id} --status Inactive; then echo "done." else echo "\nFailed to disable ${original_aws_access_key_id} key." -- cgit v1.2.3-70-g09d2 From dcff7a7f0854591ee1b4f25266f292ec1b1904eb Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 9 May 2023 12:05:15 +0200 Subject: fix(theme-and-appearance): make bsd `ls` to be default --- lib/theme-and-appearance.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 96bdb00e5..585e969d8 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -65,7 +65,7 @@ case "$OSTYPE" in test-ls-args ls -G && alias ls='ls -G' # Only use GNU ls if installed and there are user defaults for $LS_COLORS, # as the default coloring scheme is not very pretty - zstyle -T ':omz:lib:theme-and-appearance' gnu-ls \ + zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \ && test-ls-args gls --color \ && alias ls='gls --color=tty' ;; -- cgit v1.2.3-70-g09d2 From aaf83d37aa1cc5ed2cb96dd29328502003a70848 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 9 May 2023 12:10:05 +0200 Subject: docs(theme-and-appearance): reflect properly dcff7a7 changes --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 650fb00ea..2249b49dd 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi - [Manual Installation](#manual-installation) - [Installation Problems](#installation-problems) - [Custom Plugins and Themes](#custom-plugins-and-themes) - - [Disable GNU ls in macOS and freeBSD systems](#disable-gnu-ls) + - [Enable GNU ls in macOS and freeBSD systems](#enable-gnu-ls) - [Skip aliases](#skip-aliases) - [Getting Updates](#getting-updates) - [Updates verbosity](#updates-verbosity) @@ -279,18 +279,20 @@ If you have many functions that go well together, you can put them as a `XYZ.plu If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`. -### Disable GNU ls in macOS and freeBSD systems +### Enable GNU ls in macOS and freeBSD systems - + -The default behaviour in Oh My Zsh is to use GNU `ls` even in macOS and freeBSD systems if it's installed (as -`gls` command) when enabling colorized `ls` in `lib/theme-and-appearance.zsh`. If you want to disable this -behaviour you can use zstyle-based config before sourcing `oh-my-zsh.sh`: +The default behaviour in Oh My Zsh is to use BSD `ls` in macOS and freeBSD systems. If GNU `ls` is installed +(as `gls` command), you can choose to use it instead. To do it, you can use zstyle-based config before +sourcing `oh-my-zsh.sh`: ```zsh zstyle ':omz:lib:theme-and-appearance' gnu-ls no ``` +_Note: this is not compatible with `DISABLE_LS_COLORS=true`_ + ### Skip aliases -- cgit v1.2.3-70-g09d2 From aab3bfff9f27a261dcd4cd4a2082a2ce3fff8c59 Mon Sep 17 00:00:00 2001 From: roodkcab Date: Tue, 9 May 2023 18:27:22 +0800 Subject: fix(robbyrussell) multiline command editing (#11681) Co-authored-by: chenshuoshi Closes #11680 --- themes/robbyrussell.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/robbyrussell.zsh-theme b/themes/robbyrussell.zsh-theme index 2fd5f2cdc..173e6d579 100644 --- a/themes/robbyrussell.zsh-theme +++ b/themes/robbyrussell.zsh-theme @@ -1,5 +1,5 @@ -PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )" -PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' +PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ ) %{$fg[cyan]%}%c%{$reset_color%}" +PROMPT+=' $(git_prompt_info)' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " -- cgit v1.2.3-70-g09d2 From f01eea76da194fef6005f53a281b6f5a998db126 Mon Sep 17 00:00:00 2001 From: ZYX Date: Fri, 12 May 2023 02:42:30 -0700 Subject: fix(aws): use the correct variable to assert region is defined (#11691) --- plugins/aws/aws.plugin.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index b2415b737..c946515be 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -224,12 +224,12 @@ function aws_prompt_info() { local _aws_to_show local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}" - if [[ -n $AWS_PROFILE ]];then + if [[ -n "$AWS_PROFILE" ]];then _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX=""}" fi - if [[ -n $AWS_REGION ]]; then - [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=" "}" + if [[ -n "$region" ]]; then + [[ -n "$_aws_to_show" ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=" "}" _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX=""}" fi -- cgit v1.2.3-70-g09d2 From 7a030f6bd6c15259052c7007020cf3ecf8a3f299 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 15 May 2023 09:27:31 -0400 Subject: docs(pyenv): warn about pyenv init (#11692) --- plugins/pyenv/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/pyenv/README.md b/plugins/pyenv/README.md index b9ee937b7..f1ca3d288 100644 --- a/plugins/pyenv/README.md +++ b/plugins/pyenv/README.md @@ -10,6 +10,14 @@ To use it, add `pyenv` to the plugins array in your zshrc file: plugins=(... pyenv) ``` +If you receive a `Found pyenv, but it is badly configured.` error on startup, you may need to ensure that `pyenv` is initialized before the oh-my-zsh pyenv plugin is loaded. This can be achived by adding the following earlier in the `.zshrc` file than the `plugins=(...)` line: + +```zsh +export PYENV_ROOT="$HOME/.pyenv" +export PATH="$PYENV_ROOT/bin:$PATH" +eval "$(pyenv init --path)" +``` + ## Settings - `ZSH_PYENV_QUIET`: if set to `true`, the plugin will not print any messages if it -- cgit v1.2.3-70-g09d2 From bfeeda1491b5366aa5798a86cf6f3621536b171c Mon Sep 17 00:00:00 2001 From: Craig Furman Date: Sun, 21 May 2023 11:47:38 +0100 Subject: docs(theme-and-appearance): fix gnu-ls snippet (#11701) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2249b49dd..a30595581 100644 --- a/README.md +++ b/README.md @@ -288,7 +288,7 @@ The default behaviour in Oh My Zsh is to use BSD `ls` in macOS and freeBSD syste sourcing `oh-my-zsh.sh`: ```zsh -zstyle ':omz:lib:theme-and-appearance' gnu-ls no +zstyle ':omz:lib:theme-and-appearance' gnu-ls yes ``` _Note: this is not compatible with `DISABLE_LS_COLORS=true`_ -- cgit v1.2.3-70-g09d2 From 3a01d7df82157a5f3aef01eab9a940e4cba2283a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 21 May 2023 19:58:26 +0200 Subject: fix(extract): fix extract dir naming conflicts Fixes #11642 --- plugins/extract/extract.plugin.zsh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index 34c080653..ee1d38b3f 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -27,12 +27,20 @@ EOF fi local success=0 - local extract_dir="${1:t:r}" local file="$1" full_path="${1:A}" + local extract_dir="${1:t:r}" + + # If there's a file or directory with the same name as the archive + # add a random string to the end of the extract directory + if [[ -e "$extract_dir" ]]; then + local rnd="${(L)"${$(( [##36]$RANDOM*$RANDOM ))}":1:5}" + extract_dir="${extract_dir}-${rnd}" + fi # Create an extraction directory based on the file name command mkdir -p "$extract_dir" builtin cd -q "$extract_dir" + echo "extract: extracting to $extract_dir" >&2 case "${file:l}" in (*.tar.gz|*.tgz) @@ -107,11 +115,13 @@ EOF if [[ "${content[1]:t}" == "$extract_dir" ]]; then # =(:) gives /tmp/zsh, with :t it gives zsh local tmp_dir==(:); tmp_dir="${tmp_dir:t}" - command mv -f "${content[1]}" "$tmp_dir" \ + command mv "${content[1]}" "$tmp_dir" \ && command rmdir "$extract_dir" \ - && command mv -f "$tmp_dir" "$extract_dir" - else - command mv -f "${content[1]}" . \ + && command mv "$tmp_dir" "$extract_dir" + # Otherwise, if the extracted folder name already exists in the current + # directory (because of a previous file / folder), keep the extract_dir + elif [[ ! -e "${content[1]:t}" ]]; then + command mv "${content[1]}" . \ && command rmdir "$extract_dir" fi elif [[ ${#content} -eq 0 ]]; then -- cgit v1.2.3-70-g09d2 From b06663df23b2910a6e542dc114dc7adc2cdce22f Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 21 May 2023 20:14:32 +0200 Subject: feat(extract): add support for `.zlib` and `.exe` files (#11085) Fixes #11085 --- plugins/extract/README.md | 3 +++ plugins/extract/extract.plugin.zsh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/extract/README.md b/plugins/extract/README.md index ac4a8e197..c8d98b229 100644 --- a/plugins/extract/README.md +++ b/plugins/extract/README.md @@ -25,6 +25,7 @@ plugins=(... extract) | `cpio` | Cpio archive | | `deb` | Debian package | | `ear` | Enterprise Application aRchive | +| `exe` | Windows executable file | | `gz` | Gzip file | | `ipa` | iOS app package | | `ipsw` | iOS firmware file | @@ -52,9 +53,11 @@ plugins=(... extract) | `txz` | Tarball with lzma2 compression | | `tzst` | Tarball with zstd compression | | `war` | Web Application archive (Java-based) | +| `whl` | Python wheel file | | `xpi` | Mozilla XPI module file | | `xz` | LZMA2 archive | | `zip` | Zip archive | +| `zlib` | zlib archive | | `zst` | Zstandard file (zstd) | | `zpaq` | Zpaq file | diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index ee1d38b3f..b7a823c9f 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -83,9 +83,10 @@ EOF builtin cd -q ../data; extract ../data.tar.* builtin cd -q ..; command rm *.tar.* debian-binary ;; (*.zst) unzstd "$full_path" ;; - (*.cab) cabextract "$full_path" ;; + (*.cab|*.exe) cabextract "$full_path" ;; (*.cpio|*.obscpio) cpio -idmvF "$full_path" ;; (*.zpaq) zpaq x "$full_path" ;; + (*.zlib) zlib-flate -uncompress < "$full_path" > "${file:r}" ;; (*) echo "extract: '$file' cannot be extracted" >&2 success=1 ;; -- cgit v1.2.3-70-g09d2 From 444e715766c4a8b267dba82f3f0f562584d61adc Mon Sep 17 00:00:00 2001 From: rogarb <69053978+rogarb@users.noreply.github.com> Date: Mon, 22 May 2023 10:49:10 +0000 Subject: feat(bureau): ignore hidden git repos (#11707) The git_prompt_info() function in lib/git.zsh ignores git repos which contains a specific config key, allowing to effectively "hide" them from the prompt. Unfortunately, the bureau theme doesn't use the library function to build its prompt. This commit modifies the specific prompt generation function in the bureau theme in order to achieve the same behaviour. --- themes/bureau.zsh-theme | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 698aa2ff8..9943a0c8c 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -67,6 +67,12 @@ bureau_git_status() { } bureau_git_prompt() { + # ignore non git folders and hidden repos (adapted from lib/git.zsh) + if ! command git rev-parse --git-dir &> /dev/null \ + || [[ "$(command git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then + return + fi + # check git information local gitinfo=$(bureau_git_info) if [[ -z "$gitinfo" ]]; then -- cgit v1.2.3-70-g09d2 From 902b79e635fedf4a12542d2ed8bd29665d3d281c Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 23 May 2023 08:43:47 +0200 Subject: fix(functions): use `command` env Closes #11709 --- lib/functions.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/functions.zsh b/lib/functions.zsh index 1d85ea38a..a252d0a33 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -5,7 +5,7 @@ function zsh_stats() { } function uninstall_oh_my_zsh() { - env ZSH="$ZSH" sh "$ZSH/tools/uninstall.sh" + command env ZSH="$ZSH" sh "$ZSH/tools/uninstall.sh" } function upgrade_oh_my_zsh() { -- cgit v1.2.3-70-g09d2 From 1bbe4d8d2431b5ac06d7402b570431884786db58 Mon Sep 17 00:00:00 2001 From: Felipe Francisco Date: Tue, 23 May 2023 03:46:46 -0300 Subject: feat(half-life): add virtualenv prompt (#11708) --- themes/half-life.zsh-theme | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/themes/half-life.zsh-theme b/themes/half-life.zsh-theme index c4d785126..2ad84ac83 100644 --- a/themes/half-life.zsh-theme +++ b/themes/half-life.zsh-theme @@ -89,5 +89,9 @@ ZSH_THEME_RUBY_PROMPT_PREFIX="with%F{red} " ZSH_THEME_RUBY_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_RVM_PROMPT_OPTIONS="v g" +# virtualenv prompt settings +ZSH_THEME_VIRTUALENV_PREFIX=" with%F{red} " +ZSH_THEME_VIRTUALENV_SUFFIX="%{$reset_color%}" + setopt prompt_subst -PROMPT="${purple}%n%{$reset_color%} in ${limegreen}%~%{$reset_color%}\$(ruby_prompt_info)\$vcs_info_msg_0_${orange} λ%{$reset_color%} " +PROMPT="${purple}%n%{$reset_color%} in ${limegreen}%~%{$reset_color%}\$(virtualenv_prompt_info)\$(ruby_prompt_info)\$vcs_info_msg_0_${orange} λ%{$reset_color%} " -- cgit v1.2.3-70-g09d2 From ec369bb38e873fa2e8954bc45bc192fdb0051313 Mon Sep 17 00:00:00 2001 From: rogarb <69053978+rogarb@users.noreply.github.com> Date: Wed, 24 May 2023 12:32:26 +0000 Subject: fix(bureau): properly display git stash info (#11711) --- themes/bureau.zsh-theme | 1 + 1 file changed, 1 insertion(+) diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 9943a0c8c..e87a594cd 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -15,6 +15,7 @@ ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}" ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}" ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_STASHED="(%{$fg_bold[blue]%}✹%{$reset_color%})" bureau_git_info () { local ref -- cgit v1.2.3-70-g09d2 From 5901f30b44fc5a3055e6b801d3d71af6d2359ee8 Mon Sep 17 00:00:00 2001 From: WH-2099 Date: Thu, 25 May 2023 18:43:01 +0800 Subject: feat(archlinux): optimize `paclist` and `pacdisowned` (#11398) Co-authored-by: ratijas --- plugins/archlinux/README.md | 1 + plugins/archlinux/archlinux.plugin.zsh | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/archlinux/README.md b/plugins/archlinux/README.md index fd772c61a..5e015dbaa 100644 --- a/plugins/archlinux/README.md +++ b/plugins/archlinux/README.md @@ -181,3 +181,4 @@ whether the package manager is installed, checked in the following order: - Ybalrid (Arthur Brainville) - ybalrid@ybalrid.info - Jeff M. Hubbard - jeffmhubbard@gmail.com - K. Harishankar(harishnkr) - hari2menon1234@gmail.com +- WH-2099 - wh2099@outlook.com \ No newline at end of file diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index da170f488..796ff7adf 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -25,27 +25,28 @@ alias pacown='pacman -Qo' alias pacupd="sudo pacman -Sy" function paclist() { - # Based on https://bbs.archlinux.org/viewtopic.php?id=93683 - pacman -Qqe | \ - xargs -I '{}' \ - expac "${bold_color}% 20n ${fg_no_bold[white]}%d${reset_color}" '{}' + local pkgs=$(LC_ALL=C pacman -Qqe) + for pkg in ${(f)pkgs}; do + pacman -Qs --color=auto "^${pkg}\$" || break + done } function pacdisowned() { - local tmp db fs - tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$ - db=$tmp/db - fs=$tmp/fs + local tmp_dir db fs + tmp_dir=$(mktemp --directory) + db=$tmp_dir/db + fs=$tmp_dir/fs - mkdir "$tmp" - trap 'rm -rf "$tmp"' EXIT + trap "rm -rf $tmp_dir" EXIT pacman -Qlq | sort -u > "$db" - find /bin /etc /lib /sbin /usr ! -name lost+found \ + find /etc /usr ! -name lost+found \ \( -type d -printf '%p/\n' -o -print \) | sort > "$fs" comm -23 "$fs" "$db" + + rm -rf $tmp_dir } alias pacmanallkeys='sudo pacman-key --refresh-keys' -- cgit v1.2.3-70-g09d2 From fb4213c34ff8ec83cbe6251f432fdac383378562 Mon Sep 17 00:00:00 2001 From: Tom D Date: Fri, 26 May 2023 09:43:17 +0200 Subject: perf(git): improve `gunwip` alias (#11714) --- plugins/git/README.md | 2 +- plugins/git/git.plugin.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index f87d3fbca..2742aa539 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -186,7 +186,7 @@ plugins=(... git) | gtv | git tag \| sort -V | | gtl | gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl | | gunignore | git update-index --no-assume-unchanged | -| gunwip | git log --max-count=1 \| grep -q -c "\-\-wip\-\-" && git reset HEAD~1 | +| gunwip | git rev-list --max-count=1 --format="%s" HEAD \| grep -q "\-\-wip\-\-" && git reset HEAD~1 | | gup | git pull --rebase | | gupv | git pull --rebase --verbose | | gupa | git pull --rebase --autostash | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 3c8d53c8c..4be865f6a 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -312,7 +312,7 @@ alias gtv='git tag | sort -V' alias gtl='gtl(){ git tag --sort=-v:refname -n --list "${1}*" }; noglob gtl' alias gunignore='git update-index --no-assume-unchanged' -alias gunwip='git log --max-count=1 | grep -q -c "\--wip--" && git reset HEAD~1' +alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1' alias gup='git pull --rebase' alias gupv='git pull --rebase --verbose' alias gupa='git pull --rebase --autostash' -- cgit v1.2.3-70-g09d2 From 00241073105643874531e1826b7df6d2cb3cadfb Mon Sep 17 00:00:00 2001 From: William Snyders Date: Wed, 31 May 2023 14:59:41 -0700 Subject: fix(gcloud): update AUR default location (#11718) --- plugins/gcloud/gcloud.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/gcloud/gcloud.plugin.zsh b/plugins/gcloud/gcloud.plugin.zsh index 30f1dba8f..9c26aea10 100644 --- a/plugins/gcloud/gcloud.plugin.zsh +++ b/plugins/gcloud/gcloud.plugin.zsh @@ -14,6 +14,7 @@ if [[ -z "${CLOUDSDK_HOME}" ]]; then "/usr/lib/google-cloud-sdk" "/usr/lib64/google-cloud-sdk" "/opt/google-cloud-sdk" + "/opt/google-cloud-cli" "/opt/local/libexec/google-cloud-sdk" ) -- cgit v1.2.3-70-g09d2 From 6101106916147b1716ff2d5de4a53260e7607bae Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Fri, 2 Jun 2023 21:37:48 +0200 Subject: feat(install): deploy installer to install.ohmyz.sh (#11722) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- .github/workflows/installer.yml | 55 +++++++++++++++++++++++++++++++ .github/workflows/installer/.gitignore | 1 + .github/workflows/installer/.vercelignore | 2 ++ .github/workflows/installer/vercel.json | 14 ++++++++ .github/workflows/main.yml | 2 -- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/installer.yml create mode 100644 .github/workflows/installer/.gitignore create mode 100644 .github/workflows/installer/.vercelignore create mode 100644 .github/workflows/installer/vercel.json diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml new file mode 100644 index 000000000..ac88d10b0 --- /dev/null +++ b/.github/workflows/installer.yml @@ -0,0 +1,55 @@ +name: Test and Deploy installer +on: + workflow_dispatch: {} + push: + paths: + - tools/install.sh + - .github/workflows/installer + - .github/workflows/installer.yml + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: false + +permissions: + contents: read # to checkout + +jobs: + test: + name: Test installer + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + steps: + - name: Set up git repository + uses: actions/checkout@v3 + - name: Install zsh + if: runner.os == 'Linux' + run: sudo apt-get update; sudo apt-get install zsh + - name: Test installer + run: sh ./tools/install.sh + + deploy: + name: Deploy installer in install.ohmyz.sh + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + environment: vercel + needs: + - test + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Vercel CLI + run: npm install -g vercel + - name: Setup project and deploy + env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + run: | + cp tools/install.sh .github/workflows/installer/install.sh + cd .github/workflows/installer + vc link --yes -t ${{ secrets.VERCEL_TOKEN }} + vc deploy --prod -t ${{ secrets.VERCEL_TOKEN }} diff --git a/.github/workflows/installer/.gitignore b/.github/workflows/installer/.gitignore new file mode 100644 index 000000000..f66fce310 --- /dev/null +++ b/.github/workflows/installer/.gitignore @@ -0,0 +1 @@ +install.sh diff --git a/.github/workflows/installer/.vercelignore b/.github/workflows/installer/.vercelignore new file mode 100644 index 000000000..41b233364 --- /dev/null +++ b/.github/workflows/installer/.vercelignore @@ -0,0 +1,2 @@ +/* +!/install.sh diff --git a/.github/workflows/installer/vercel.json b/.github/workflows/installer/vercel.json new file mode 100644 index 000000000..8c5aec5e0 --- /dev/null +++ b/.github/workflows/installer/vercel.json @@ -0,0 +1,14 @@ +{ + "headers": [ + { + "source": "/((?!favicon.ico).*)", + "headers": [{ "key": "Content-Type", "value": "text/plain" }] + } + ], + "rewrites": [ + { + "source": "/((?!favicon.ico|install.sh).*)", + "destination": "/install.sh" + } + ] +} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8ee2df3d8..57403629c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,8 +31,6 @@ jobs: - name: Install zsh if: runner.os == 'Linux' run: sudo apt-get update; sudo apt-get install zsh - - name: Test installer - run: sh ./tools/install.sh - name: Check syntax run: | for file in ./oh-my-zsh.sh \ -- cgit v1.2.3-70-g09d2 From 62ab5406dd89848bb26e8c6e648eb7d860e9dce5 Mon Sep 17 00:00:00 2001 From: Lawrence Shah Date: Mon, 5 Jun 2023 01:20:32 -0700 Subject: docs(custom): update comments in example files (#11727) --- custom/example.zsh | 18 ++++++++++-------- custom/plugins/example/example.plugin.zsh | 1 + custom/themes/example.zsh-theme | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/custom/example.zsh b/custom/example.zsh index c505a9673..21a8d8be7 100644 --- a/custom/example.zsh +++ b/custom/example.zsh @@ -1,10 +1,12 @@ -# You can put files here to add functionality separated per file, which -# will be ignored by git. -# Files on the custom/ directory will be automatically loaded by the init -# script, in alphabetical order. - -# For example: add yourself some shortcuts to projects you often work on. -# +# Put files in this folder to add your own custom functionality. +# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization +# +# Files in the custom/ directory will be: +# - loaded automatically by the init script, in alphabetical order +# - loaded last, after all built-ins in the lib/ directory, to override them +# - ignored by git by default +# +# Example: add custom/shortcuts.zsh for shortcuts to your local projects +# # brainstormr=~/Projects/development/planetargon/brainstormr # cd $brainstormr -# diff --git a/custom/plugins/example/example.plugin.zsh b/custom/plugins/example/example.plugin.zsh index 406f27445..83611fe3f 100644 --- a/custom/plugins/example/example.plugin.zsh +++ b/custom/plugins/example/example.plugin.zsh @@ -1,2 +1,3 @@ # Add your own custom plugins in the custom/plugins directory. Plugins placed # here will override ones with the same name in the main plugins directory. +# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-plugins diff --git a/custom/themes/example.zsh-theme b/custom/themes/example.zsh-theme index ef8f1c630..494d029e8 100644 --- a/custom/themes/example.zsh-theme +++ b/custom/themes/example.zsh-theme @@ -1,4 +1,6 @@ # Put your custom themes in this folder. +# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes +# # Example: PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% " -- cgit v1.2.3-70-g09d2 From b36c90d9abd2fd2ffe53d19b11e47077dfdb38a8 Mon Sep 17 00:00:00 2001 From: Diego Costa R <62116423+diegocostares@users.noreply.github.com> Date: Mon, 5 Jun 2023 04:25:17 -0400 Subject: feat(autoenv): macOS compatibility, add more dirs (#11724) Co-authored-by: Carlo Sala --- plugins/autoenv/autoenv.plugin.zsh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/autoenv/autoenv.plugin.zsh b/plugins/autoenv/autoenv.plugin.zsh index 229a8a834..cbf7cefbb 100644 --- a/plugins/autoenv/autoenv.plugin.zsh +++ b/plugins/autoenv/autoenv.plugin.zsh @@ -17,9 +17,13 @@ if ! type autoenv_init >/dev/null; then /usr/local/bin /usr/share/autoenv-git ~/Library/Python/bin + .venv/bin + venv/bin + env/bin + .env/bin ) for d ( $install_locations ); do - if [[ -e $d/activate.sh ]]; then + if [[ -e $d/activate || -e $d/activate.sh ]]; then autoenv_dir=$d break fi @@ -29,13 +33,13 @@ if ! type autoenv_init >/dev/null; then # Look for Homebrew path as a last resort if [[ -z "$autoenv_dir" ]] && (( $+commands[brew] )); then d=$(brew --prefix)/opt/autoenv - if [[ -e $d/activate.sh ]]; then + if [[ -e $d/activate || -e $d/activate.sh ]]; then autoenv_dir=$d fi fi # Complain if autoenv is not installed - if [[ -z $autoenv_dir ]]; then + if [[ -z $autoenv_dir ]]; then cat <&2 -------- AUTOENV --------- Could not locate autoenv installation. @@ -46,7 +50,11 @@ END return 1 fi # Load autoenv - source $autoenv_dir/activate.sh + if [[ -e $autoenv_dir/activate ]]; + source $autoenv_dir/activate + else + source $autoenv_dir/activate.sh + fi fi } [[ $? != 0 ]] && return $? -- cgit v1.2.3-70-g09d2 From d1c64bfda30ad56bac09f11c920b93b94dab7f9f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 5 Jun 2023 10:26:36 +0200 Subject: fix(autoenv): typo --- plugins/autoenv/autoenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/autoenv/autoenv.plugin.zsh b/plugins/autoenv/autoenv.plugin.zsh index cbf7cefbb..2f84f0acf 100644 --- a/plugins/autoenv/autoenv.plugin.zsh +++ b/plugins/autoenv/autoenv.plugin.zsh @@ -50,7 +50,7 @@ END return 1 fi # Load autoenv - if [[ -e $autoenv_dir/activate ]]; + if [[ -e $autoenv_dir/activate ]]; then source $autoenv_dir/activate else source $autoenv_dir/activate.sh -- cgit v1.2.3-70-g09d2 From 115cee17015e4b5665e16dc4fd15c53e06a22f9a Mon Sep 17 00:00:00 2001 From: Ihor Date: Mon, 5 Jun 2023 10:38:54 +0200 Subject: feat(git): add `gunwipall` function (#11725) Co-authored-by: Carlo Sala --- plugins/git/README.md | 1 + plugins/git/git.plugin.zsh | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index 2742aa539..bf4b19f39 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -254,6 +254,7 @@ These features allow to pause a branch development and switch to another one (_" | work_in_progress | Echoes a warning if the current branch is a wip | | gwip | Commit wip branch | | gunwip | Uncommit wip branch | +| gunwipall | Uncommit `--wip--` commits recursively | ### Deprecated functions diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 4be865f6a..192124301 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -27,6 +27,20 @@ function work_in_progress() { command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" } +# Same as `gunwip` but recursive +# "Unwips" all recent `--wip--` commits in loop until there is no left +function gunwipall() { + while true; do + commit_message=$(git rev-list --max-count=1 --format="%s" HEAD) + if [[ $commit_message =~ "--wip--" ]]; then + git reset "HEAD~1" + (( $? )) && return 1 + else + break + fi + done +} + # Check if main exists and use instead of master function git_main_branch() { command git rev-parse --git-dir &>/dev/null || return -- cgit v1.2.3-70-g09d2 From 46c70406dd0b26bbd61210873ad6c86d9e8ee5da Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 7 Jun 2023 18:43:47 +0200 Subject: feat(nvm): add `npx` to lazy trigger list Closes #11740 --- plugins/nvm/README.md | 2 +- plugins/nvm/nvm.plugin.zsh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index d3fd980be..6830c14d0 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -26,7 +26,7 @@ These settings should go in your zshrc file, before Oh My Zsh is sourced: #### Lazy startup This option will help you to defer nvm's load until you use it to speed-up your zsh startup. This will source -nvm script only when using it, and will create a function for `node`, `npm`, `pnpm`, `yarn`, and the +nvm script only when using it, and will create a function for `node`, `npm`, `npx`, `pnpm`, `yarn`, and the command(s) specified by `lazy-cmd` option, so when you call either of them, nvm will be loaded and run with default version. To enable it, you can add this snippet to your zshrc, before Oh My Zsh is sourced: diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 20697d67d..31d275415 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -43,8 +43,8 @@ if zstyle -t ':omz:plugins:nvm' lazy; then # Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd eval " - function nvm node npm pnpm yarn $nvm_lazy_cmd { - unfunction nvm node npm pnpm yarn $nvm_lazy_cmd + function nvm node npm npx pnpm yarn $nvm_lazy_cmd { + unfunction nvm node npm npx pnpm yarn $nvm_lazy_cmd # Load nvm if it exists in \$NVM_DIR [[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\" \"\$0\" \"\$@\" -- cgit v1.2.3-70-g09d2 From 50c678687e73d1433f278b7bb7f168e8fa817670 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 8 Jun 2023 18:47:05 +0200 Subject: fix(termsupport): fix pwd report for Konsole (#11730) The Konsole terminal shows an error if the host is provided in the OSC 7 sequence. Fixes #11730 --- lib/termsupport.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index cf8f08741..145982705 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -150,8 +150,11 @@ function omz_termsupport_cwd { URL_HOST="$(omz_urlencode -P $HOST)" || return 1 URL_PATH="$(omz_urlencode -P $PWD)" || return 1 + # Konsole errors if the HOST is provided + [[ -z "$KONSOLE_VERSION" ]] || URL_HOST="" + # common control sequence (OSC 7) to set current host and path - printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" + printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}" } # Use a precmd hook instead of a chpwd hook to avoid contaminating output -- cgit v1.2.3-70-g09d2 From cb8b677488c7a20278917af58dfccd72cd40e1b1 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 11 Jun 2023 17:02:48 +0200 Subject: fix(termsupport): don't report current working directory in SSH sessions (#11703) --- lib/termsupport.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 145982705..6d969503d 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -121,8 +121,8 @@ fi # # As of May 2021 mlterm, PuTTY, rxvt, screen, termux & xterm simply ignore the unknown OSC. -# Don't define the function if we're inside Emacs -if [[ -n "$INSIDE_EMACS" ]]; then +# Don't define the function if we're inside Emacs or in an SSH session (#11696) +if [[ -n "$INSIDE_EMACS" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then return fi -- cgit v1.2.3-70-g09d2 From 14f0f2971f42952e2eb78fdc2535538e98323b2b Mon Sep 17 00:00:00 2001 From: Oleg Voronkovich Date: Thu, 15 Jun 2023 12:01:02 +0300 Subject: feat(brew): autoconfigure completions (#11152) --- plugins/brew/README.md | 2 ++ plugins/brew/brew.plugin.zsh | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/plugins/brew/README.md b/plugins/brew/README.md index 412daae63..4730194bc 100644 --- a/plugins/brew/README.md +++ b/plugins/brew/README.md @@ -33,6 +33,8 @@ defined for convenience. ## Completion +This plugin configures paths with Homebrew's completion functions automatically, so you don't need to do it manually. See: https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh. + With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the brew installation, so we no longer ship it with the brew plugin; now it only has brew aliases. If you find that brew completion no longer works, make sure you have your Homebrew diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh index f6abe0875..b52664a39 100644 --- a/plugins/brew/brew.plugin.zsh +++ b/plugins/brew/brew.plugin.zsh @@ -25,6 +25,10 @@ if [[ -z "$HOMEBREW_PREFIX" ]]; then export HOMEBREW_PREFIX="$(brew --prefix)" fi +if [[ -d "$HOMEBREW_PREFIX/share/zsh/site-functions" ]]; then + fpath+=("$HOMEBREW_PREFIX/share/zsh/site-functions") +fi + alias bcubc='brew upgrade --cask && brew cleanup' alias bcubo='brew update && brew outdated --cask' alias bcubc='brew upgrade --cask && brew cleanup' -- cgit v1.2.3-70-g09d2 From b1b3a020ecb1b4b322efbf8e08ad7fb55e2e687a Mon Sep 17 00:00:00 2001 From: Josh Powell Date: Thu, 15 Jun 2023 05:03:45 -0400 Subject: feat(rails): add some aliases (#11739) --- plugins/rails/README.md | 5 ++++- plugins/rails/rails.plugin.zsh | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/rails/README.md b/plugins/rails/README.md index b2425aabc..c0c37ff3d 100644 --- a/plugins/rails/README.md +++ b/plugins/rails/README.md @@ -40,7 +40,10 @@ plugins=(... rails) | `rn` | `rails notes` | Search for notes (`FIXME`, `TODO`) in code comments | | `rp` | `rails plugin` | Run a Rails plugin command | | `rr` | `rails routes` | List all defined routes | -| `rrg` | `rails routes \| grep` | List and filter the defined routes | +| `rrc` | `rails routes --controller` | List and filter routes mapped to specific controller | +| `rre` | `rails routes --expanded` | List all defined routes in expanded table mode | +| `rrg` | `rails routes --grep` | List and filter the defined routes | +| `rru` | `rails routes --unused` | List unused routes | | `rs` | `rails server` | Launch a web server | | `rsb` | `rails server --bind` | Launch a web server binding it to a specific IP | | `rsd` | `rails server --debugger` | Launch a web server with debugger | diff --git a/plugins/rails/rails.plugin.zsh b/plugins/rails/rails.plugin.zsh index 015dc9ecb..75dd9b0c6 100644 --- a/plugins/rails/rails.plugin.zsh +++ b/plugins/rails/rails.plugin.zsh @@ -68,7 +68,10 @@ alias rmd='rails middleware' alias rn='rails notes' alias rp='rails plugin' alias rr='rails routes' -alias rrg='rails routes | grep' +alias rrc='rails routes --controller' +alias rre='rails routes --expanded' +alias rrg='rails routes --grep' +alias rru='rails routes --unused' alias rs='rails server' alias rsb='rails server --bind' alias rsd='rails server --debugger' -- cgit v1.2.3-70-g09d2 From 68f3ebb4de11aa2013ccc5252d4415840e0d7342 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 15 Jun 2023 11:16:25 +0200 Subject: feat(docker): generate completion function Closes #10825 Closes #10912 Closes #11751 --- plugins/docker/_docker | 3123 -------------------------------------- plugins/docker/docker.plugin.zsh | 10 + 2 files changed, 10 insertions(+), 3123 deletions(-) delete mode 100644 plugins/docker/_docker diff --git a/plugins/docker/_docker b/plugins/docker/_docker deleted file mode 100644 index e6a12d774..000000000 --- a/plugins/docker/_docker +++ /dev/null @@ -1,3123 +0,0 @@ -#compdef docker dockerd -# -# zsh completion for docker (http://docker.com) -# -# version: 0.3.0 -# github: https://github.com/felixr/docker-zsh-completion -# -# contributors: -# - Felix Riedel -# - Steve Durrheimer -# - Vincent Bernat -# - Rohan Verma -# -# license: -# -# Copyright (c) 2013, Felix Riedel -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -# Short-option stacking can be enabled with: -# zstyle ':completion:*:*:docker:*' option-stacking yes -# zstyle ':completion:*:*:docker-*:*' option-stacking yes -__docker_arguments() { - if zstyle -t ":completion:${curcontext}:" option-stacking; then - print -- -s - fi -} - -__docker_get_containers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local kind type line s - declare -a running stopped lines args names - - kind=$1; shift - type=$1; shift - [[ $kind = (stopped|all) ]] && args=($args -a) - - lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line - lines=(${lines[2,-1]}) - - # Container ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - # Names: we only display the one without slash. All other names - # are generated and may clutter the completion. However, with - # Swarm, all names may be prefixed by the swarm node name. - if [[ $type = (names|all) ]]; then - for line in $lines; do - names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) - # First step: find a common prefix and strip it (swarm node case) - (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} - # Second step: only keep the first name without a / - s=${${names:#*/*}[1]} - # If no name, well give up. - (( $#s != 0 )) || continue - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 - [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 - return ret -} - -__docker_complete_stopped_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers stopped all "$@" -} - -__docker_complete_running_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers running all "$@" -} - -__docker_complete_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all all "$@" -} - -__docker_complete_containers_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all ids "$@" -} - -__docker_complete_containers_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all names "$@" -} - -__docker_complete_info_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - emulate -L zsh - setopt extendedglob - local -a plugins - plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) - _describe -t plugins "$1 plugins" plugins && ret=0 - return ret -} - -__docker_complete_images() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a images - images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) - _describe -t docker-images "images" images && ret=0 - __docker_complete_repositories_with_tags && ret=0 - return ret -} - -__docker_complete_repositories() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos - repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) - repos=(${repos#}) - _describe -t docker-repos "repositories" repos && ret=0 - return ret -} - -__docker_complete_repositories_with_tags() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos onlyrepos matched - declare m - repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) - repos=(${${repos%:::}#}) - # Check if we have a prefix-match for the current prefix. - onlyrepos=(${repos%::*}) - for m in $onlyrepos; do - [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { - # Yes, complete with tags - repos=(${${repos/:::/:}/:/\\:}) - _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 - return ret - } - done - # No, only complete repositories - onlyrepos=(${${repos%:::*}/:/\\:}) - _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 - - return ret -} - -__docker_search() { - [[ $PREFIX = -* ]] && return 1 - local cache_policy - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - local searchterm cachename - searchterm="${words[$CURRENT]%/}" - cachename=_docker-search-$searchterm - - local expl - local -a result - if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ - && ! _retrieve_cache ${cachename#_}; then - _message "Searching for ${searchterm}..." - result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) - _store_cache ${cachename#_} result - fi - _wanted dockersearch expl 'available images' compadd -a result -} - -__docker_get_log_options() { - [[ $PREFIX = -* ]] && return 1 - - integer ret=1 - local log_driver=${opt_args[--log-driver]:-"all"} - local -a common_options common_options2 awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options - - common_options=("max-buffer-size" "mode") - common_options2=("env" "env-regex" "labels") - awslogs_options=($common_options "awslogs-create-group" "awslogs-datetime-format" "awslogs-group" "awslogs-multiline-pattern" "awslogs-region" "awslogs-stream" "tag") - fluentd_options=($common_options $common_options2 "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "fluentd-sub-second-precision" "tag") - gcplogs_options=($common_options $common_options2 "gcp-log-cmd" "gcp-meta-id" "gcp-meta-name" "gcp-meta-zone" "gcp-project") - gelf_options=($common_options $common_options2 "gelf-address" "gelf-compression-level" "gelf-compression-type" "tag") - journald_options=($common_options $common_options2 "tag") - json_file_options=($common_options $common_options2 "max-file" "max-size") - logentries_options=($common_options $common_options2 "logentries-token" "tag") - syslog_options=($common_options $common_options2 "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") - splunk_options=($common_options $common_options2 "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") - - [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 - [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 - [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 - [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 - [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 - [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 - [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 - [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 - [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 - - return ret -} - -__docker_complete_log_drivers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) - _describe -t log-drivers "log drivers" drivers && ret=0 - return ret -} - -__docker_complete_log_options() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (syslog-format) - local opts=('rfc3164' 'rfc5424' 'rfc5424micro') - _describe -t syslog-format-opts "syslog format options" opts && ret=0 - ;; - (mode) - local opts=('blocking' 'non-blocking') - _describe -t mode-opts "mode options" opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - __docker_get_log_options -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_detach_keys() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - compset -P "*," - keys=(${:-{a-z}}) - ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) - _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 - _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 -} - -__docker_complete_pid() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local -a opts vopts - - opts=('host') - vopts=('container') - - if compset -P '*:'; then - case "${${words[-1]%:*}#*=}" in - (container) - __docker_complete_running_containers && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 - _describe -t pid-opts "PID Options" opts && ret=0 - fi - - return ret -} - -__docker_complete_runtimes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - emulate -L zsh - setopt extendedglob - local -a runtimes_opts - runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) - _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 -} - -__docker_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (ancestor) - __docker_complete_images && ret=0 - ;; - (before|since) - __docker_complete_containers && ret=0 - ;; - (health) - health_opts=('healthy' 'none' 'starting' 'unhealthy') - _describe -t health-filter-opts "health filter options" health_opts && ret=0 - ;; - (id) - __docker_complete_containers_ids && ret=0 - ;; - (is-task) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - (name) - __docker_complete_containers_names && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (status) - status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') - _describe -t status-filter-opts "status filter options" status_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('ancestor' 'before' 'exited' 'expose' 'health' 'id' 'label' 'name' 'network' 'publish' 'since' 'status' 'volume') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_search_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('is-automated' 'is-official' 'stars') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (is-automated|is-official) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_images_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('before' 'dangling' 'label' 'reference' 'since') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (before|reference|since) - __docker_complete_images && ret=0 - ;; - (dangling) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_events_filter() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a opts - - opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'scope' 'type' 'volume') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (container) - __docker_complete_containers && ret=0 - ;; - (daemon) - emulate -L zsh - setopt extendedglob - local -a daemon_opts - daemon_opts=( - ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} - ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} - ) - _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 - ;; - (event) - local -a event_opts - event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disable' 'disconnect' 'enable' 'exec_create' 'exec_detach' - 'exec_start' 'export' 'health_status' 'import' 'install' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'remove' 'rename' 'resize' - 'restart' 'save' 'start' 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') - _describe -t event-filter-opts "event filter options" event_opts && ret=0 - ;; - (image) - __docker_complete_images && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (scope) - local -a scope_opts - scope_opts=('local' 'swarm') - _describe -t scope-filter-opts "scope filter options" scope_opts && ret=0 - ;; - (type) - local -a type_opts - type_opts=('container' 'daemon' 'image' 'network' 'volume') - _describe -t type-filter-opts "type filter options" type_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_prune_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a opts - - opts=('until') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -# BO checkpoint - -__docker_checkpoint_commands() { - local -a _docker_checkpoint_subcommands - _docker_checkpoint_subcommands=( - "create:Create a checkpoint from a running container" - "ls:List checkpoints for a container" - "rm:Remove a checkpoint" - ) - _describe -t docker-checkpoint-commands "docker checkpoint command" _docker_checkpoint_subcommands -} - -__docker_checkpoint_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ - "($help)--leave-running[Leave the container running after checkpoint]" \ - "($help -)1:container:__docker_complete_running_containers" \ - "($help -)2:checkpoint: " && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ - "($help -)1:container:__docker_complete_containers" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ - "($help -)1:container:__docker_complete_containers" \ - "($help -)2:checkpoint: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_checkpoint_commands" && ret=0 - ;; - esac - - return ret -} - -# EO checkpoint - -# BO container - -__docker_container_commands() { - local -a _docker_container_subcommands - _docker_container_subcommands=( - "attach:Attach to a running container" - "commit:Create a new image from a container's changes" - "cp:Copy files/folders between a container and the local filesystem" - "create:Create a new container" - "diff:Inspect changes on a container's filesystem" - "exec:Execute a command in a running container" - "export:Export a container's filesystem as a tar archive" - "inspect:Display detailed information on one or more containers" - "kill:Kill one or more running containers" - "logs:Fetch the logs of a container" - "ls:List containers" - "pause:Pause all processes within one or more containers" - "port:List port mappings or a specific mapping for the container" - "prune:Remove all stopped containers" - "rename:Rename a container" - "restart:Restart one or more containers" - "rm:Remove one or more containers" - "run:Create and run a new container from an image" - "start:Start one or more stopped containers" - "stats:Display a live stream of container(s) resource usage statistics" - "stop:Stop one or more running containers" - "top:Display the running processes of a container" - "unpause:Unpause all processes within one or more containers" - "update:Update configuration of one or more containers" - "wait:Block until one or more containers stop, then print their exit codes" - ) - _describe -t docker-container-commands "docker container command" _docker_container_subcommands -} - -__docker_container_subcommand() { - local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update - local expl help="--help" - integer ret=1 - - opts_attach_exec_run_start=( - "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" - ) - opts_create_run=( - "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" - "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " - "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " - "($help)*--cap-add=[Add Linux capabilities]:capability: " - "($help)*--cap-drop=[Drop Linux capabilities]:capability: " - "($help)--cgroupns=[Cgroup namespace mode to use]:cgroup namespace mode: " - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " - "($help)--cidfile=[Write the container ID to the file]:CID file:_files" - "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " - "($help)*--device=[Add a host device to the container]:device:_files" - "($help)*--device-cgroup-rule=[Add a rule to the cgroup allowed devices list]:device:cgroup: " - "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " - "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " - "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " - "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " - "($help)--disable-content-trust[Skip image verification]" - "($help)*--dns=[Custom DNS servers]:DNS server: " - "($help)*--dns-option=[Custom DNS options]:DNS option: " - "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " - "($help)*--domainname=[Container NIS domain name]:domainname:_hosts" - "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " - "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" - "($help)*--expose=[Expose a port from the container without publishing it]: " - "($help)*--gpus=[GPU devices to add to the container ('all' to pass all GPUs)]:device: " - "($help)*--group-add=[Set one or more supplementary user groups for the container]:group:_groups" - "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" - "($help)--init[Run an init inside the container that forwards signals and reaps processes]" - "($help)--ip=[IPv4 address]:IPv4: " - "($help)--ip6=[IPv6 address]:IPv6: " - "($help)--ipc=[IPC namespace to use]:IPC namespace: " - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" - "($help)*--link=[Add link to another container]:link:->link" - "($help)*--link-local-ip=[Container IPv4/IPv6 link-local addresses]:IPv4/IPv6: " - "($help)*"{-l=,--label=}"[Container metadata]:label: " - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" - "($help)--mac-address=[Container MAC address]:MAC address: " - "($help)*--mount=[Attach a filesystem mount to the container]:mount: " - "($help)--name=[Container name]:name: " - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" - "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " - "($help)--oom-kill-disable[Disable OOM Killer]" - "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" - "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" - "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" - "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" - "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" - "($help)--privileged[Give extended privileges to this container]" - "($help -q --quiet)"{-q,--quiet}"[Suppress the pull output]" - "($help)--read-only[Mount the container's root filesystem as read only]" - "($help)*--security-opt=[Security options]:security option: " - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " - "($help)--stop-signal=[Signal to kill a container]:signal:_signals" - "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " - "($help)*--sysctl=-[sysctl options]:sysctl: " - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)*--ulimit=[ulimit options]:ulimit: " - "($help)--userns=[Container user namespace]:user namespace:(host)" - "($help)--tmpfs[mount tmpfs]" - "($help)*-v[Bind mount a volume]:volume: " - "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" - "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - opts_create_run_update=( - "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " - "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " - "($help)--memory-reservation=[Memory soft limit]:Memory limit: " - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " - "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" - "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" - ) - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help)--no-stdin[Do not attach stdin]" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help -):containers:__docker_complete_running_containers" && ret=0 - ;; - (commit) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --author)"{-a=,--author=}"[Author]:author: " \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ - "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ - "($help -):container:__docker_complete_containers" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (cp) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ - "($help -)1:container:->container" \ - "($help -)2:hostpath:_files" && ret=0 - case $state in - (container) - if compset -P "*:"; then - _files && ret=0 - else - __docker_complete_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (diff) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (exec) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ - "($help)--privileged[Give extended Linux capabilities to the command]" \ - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" \ - "($help -):containers:__docker_complete_running_containers" \ - "($help -)*::command:->anycommand" && ret=0 - case $state in - (anycommand) - shift 1 words - (( CURRENT-- )) - _normal && ret=0 - ;; - esac - ;; - (export) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (kill) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (logs) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--details[Show extra details provided to logs]" \ - "($help -f --follow)"{-f,--follow}"[Follow log output]" \ - "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ - "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ - "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers]" \ - "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ - "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show container IDs]" \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 - ;; - (pause|unpause) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (port) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)2:port:_ports" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rename) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):old name:__docker_complete_containers" \ - "($help -):new name: " && ret=0 - ;; - (restart) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (rm) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ - "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ - "($help -)*:containers:->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then - __docker_complete_containers && ret=0 - else - __docker_complete_stopped_containers && ret=0 - fi - ;; - esac - ;; - (run) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)--health-cmd=[Command to run to check health]:command: " \ - "($help)--health-interval=[Time between running the check]:time: " \ - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ - "($help)--rm[Remove intermediate containers when it exits]" \ - "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - (storage-opt) - if compset -P "*="; then - _message "value" && ret=0 - else - opts=('size') - _describe -t filter-opts "storage options" opts -qS "=" && ret=0 - fi - ;; - esac - ;; - (start) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ - "($help -i --interactive)"{-i,--interactive}"[Attach container's stdin]" \ - "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 - ;; - (stats) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help)--no-stream[Disable streaming stats and only pull the first result]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (stop) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (top) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)*:: :->ps-arguments" && ret=0 - case $state in - (ps-arguments) - _ps && ret=0 - ;; - esac - ;; - (update) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run_update \ - "($help -)*: :->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then - __docker_complete_stopped_containers && ret=0 - else - __docker_complete_containers && ret=0 - fi - ;; - esac - ;; - (wait) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO container - -# BO image - -__docker_image_commands() { - local -a _docker_image_subcommands - _docker_image_subcommands=( - "build:Build an image from a Dockerfile" - "history:Show the history of an image" - "import:Import the contents from a tarball to create a filesystem image" - "inspect:Display detailed information on one or more images" - "load:Load an image from a tar archive or STDIN" - "ls:List images" - "prune:Remove unused images" - "pull:Download an image from a registry" - "push:Upload an image to a registry" - "rm:Remove one or more images" - "save:Save one or more images to a tar archive (streamed to STDOUT by default)" - "tag:Tag an image into a repository" - ) - _describe -t docker-image-commands "docker image command" _docker_image_subcommands -} - -__docker_image_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (build) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " \ - "($help)*--build-arg=[Build-time variables]:=: " \ - "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ - "($help)--compress[Compress the build context using gzip]" \ - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ - "($help)--force-rm[Always remove intermediate containers]" \ - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ - "($help)*--label=[Set metadata for an image]:label=value: " \ - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ - "($help)--no-cache[Do not use cache when building the image]" \ - "($help)--pull[Attempt to pull a newer version of the image]" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ - "($help)--rm[Remove intermediate containers after a successful build]" \ - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ - "($help)--squash[Squash newly built layers into a single new layer]" \ - "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ - "($help)--target=[Set the target build stage to build.]" \ - "($help)*--ulimit=[ulimit options]:ulimit: " \ - "($help)--userns=[Container user namespace]:user namespace:(host)" \ - "($help -):path or URL:_directories" && ret=0 - ;; - (history) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (import) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ - "($help -):URL:(- http:// file://)" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)*:images:__docker_complete_images" && ret=0 - ;; - (load) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 - ;; - (ls|list) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all images]" \ - "($help)--digests[Show digests]" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_images_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ - "($help -): :__docker_complete_repositories" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (pull) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -):name:__docker_search" && ret=0 - ;; - (push) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all-tags)"{-a,--all-tags}"[Push all tags of an image to the repository]" \ - "($help)--disable-content-trust[Skip image signing]" \ - "($help -): :__docker_complete_images" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help)--no-prune[Do not delete untagged parents]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (save) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (tag) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):source:__docker_complete_images"\ - "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO image - -# BO network - -__docker_network_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (driver) - __docker_complete_info_plugins Network && ret=0 - ;; - (id) - __docker_complete_networks_ids && ret=0 - ;; - (name) - __docker_complete_networks_names && ret=0 - ;; - (scope) - opts=('global' 'local' 'swarm') - _describe -t scope-filter-opts "Scope filter options" opts && ret=0 - ;; - (type) - opts=('builtin' 'custom') - _describe -t type-filter-opts "Type filter options" opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('driver' 'id' 'label' 'name' 'scope' 'type') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_get_networks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines networks - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Network ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - _describe -t networks-list "networks" networks "$@" && ret=0 - return ret -} - -__docker_complete_networks() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks all "$@" -} - -__docker_complete_networks_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks ids "$@" -} - -__docker_complete_networks_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks names "$@" -} - -__docker_network_commands() { - local -a _docker_network_subcommands - _docker_network_subcommands=( - "connect:Connect a container to a network" - "create:Creates a new network with a name specified by the user" - "disconnect:Disconnects a container from a network" - "inspect:Displays detailed information on a network" - "ls:Lists all the networks created by the user" - "prune:Remove all unused networks" - "rm:Deletes one or more networks" - ) - _describe -t docker-network-commands "docker network command" _docker_network_subcommands -} - -__docker_network_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (connect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ - "($help)--ip=[IPv4 address]:IPv4: " \ - "($help)--ip6=[IPv6 address]:IPv6: " \ - "($help)*--link=[Add a link to another container]:link:->link" \ - "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)--attachable[Enable manual container attachment]" \ - "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ - "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ - "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ - "($help)--internal[Restricts external access to the network]" \ - "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ - "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ - "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help)*--label=[Set metadata on a network]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ - "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ - "($help -)1:Network Name: " && ret=0 - ;; - (disconnect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--verbose[Show detailed information]" \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--no-trunc[Do not truncate the output]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_network_complete_ls_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display network IDs]" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO network - -# BO node - -__docker_node_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_nodes_ids && ret=0 - ;; - (membership) - membership_opts=('accepted' 'pending' 'rejected') - _describe -t membership-opts "membership options" membership_opts && ret=0 - ;; - (name) - __docker_complete_nodes_names && ret=0 - ;; - (role) - role_opts=('manager' 'worker') - _describe -t role-opts "role options" role_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'membership' 'name' 'node.label' 'role') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_node_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running' 'shutdown') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_nodes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines nodes args - - type=$1; shift - filter=$1; shift - [[ $filter != "none" ]] && args=("-f $filter") - - lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Node ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - nodes=($nodes $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[HOSTNAME]},${end[HOSTNAME]}]%% ##}" - nodes=($nodes $s) - done - fi - - _describe -t nodes-list "nodes" nodes "$@" && ret=0 - return ret -} - -__docker_complete_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all none "$@" -} - -__docker_complete_nodes_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes ids none "$@" -} - -__docker_complete_nodes_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes names none "$@" -} - -__docker_complete_pending_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "membership=pending" "$@" -} - -__docker_complete_manager_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=manager" "$@" -} - -__docker_complete_worker_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=worker" "$@" -} - -__docker_node_commands() { - local -a _docker_node_subcommands - _docker_node_subcommands=( - "demote:Demote a node as manager in the swarm" - "inspect:Display detailed information on one or more nodes" - "ls:List nodes in the swarm" - "promote:Promote a node as manager in the swarm" - "rm:Remove one or more nodes from the swarm" - "ps:List tasks running on one or more nodes, defaults to current node" - "update:Update a node" - ) - _describe -t docker-node-commands "docker node command" _docker_node_subcommands -} - -__docker_node_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ - "($help -)*:node:__docker_complete_pending_nodes" && ret=0 - ;; - (demote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_manager_nodes" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ls_filters" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (promote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_worker_nodes" && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all instances]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ps_filters" \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ - "($help)*--label-add=[Add or update a node label]:key=value: " \ - "($help)*--label-rm=[Remove a node label if exists]:label: " \ - "($help)--role=[Role of the node]:role:(manager worker)" \ - "($help -)1:node:__docker_complete_nodes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 - ;; - esac - - return ret -} - -# EO node - -# BO plugin - -__docker_plugin_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (capability) - opts=('authz' 'ipamdriver' 'logdriver' 'metricscollector' 'networkdriver' 'volumedriver') - _describe -t capability-opts "capability options" opts && ret=0 - ;; - (enabled) - opts=('false' 'true') - _describe -t enabled-opts "enabled options" opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('capability' 'enabled') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines plugins args - - filter=$1; shift - [[ $filter != "none" ]] && args=("-f $filter") - - lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls $args)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Name - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" - plugins=($plugins $s) - done - - _describe -t plugins-list "plugins" plugins "$@" && ret=0 - return ret -} - -__docker_complete_plugins() { - [[ $PREFIX = -* ]] && return 1 - __docker_plugins none "$@" -} - -__docker_complete_enabled_plugins() { - [[ $PREFIX = -* ]] && return 1 - __docker_plugins enabled=true "$@" -} - -__docker_complete_disabled_plugins() { - [[ $PREFIX = -* ]] && return 1 - __docker_plugins enabled=false "$@" -} - -__docker_plugin_commands() { - local -a _docker_plugin_subcommands - _docker_plugin_subcommands=( - "disable:Disable a plugin" - "enable:Enable a plugin" - "inspect:Return low-level information about a plugin" - "install:Install a plugin" - "ls:List plugins" - "push:Push a plugin" - "rm:Remove a plugin" - "set:Change settings for a plugin" - "upgrade:Upgrade an existing plugin" - ) - _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands -} - -__docker_plugin_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (disable) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the disable of an active plugin]" \ - "($help -)1:plugin:__docker_complete_enabled_plugins" && ret=0 - ;; - (enable) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--timeout=[HTTP client timeout (in seconds)]:timeout: " \ - "($help -)1:plugin:__docker_complete_disabled_plugins" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ - "($help -)*:plugin:__docker_complete_plugins" && ret=0 - ;; - (install) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--alias=[Local name for plugin]:alias: " \ - "($help)--disable[Do not enable the plugin on install]" \ - "($help)--disable-content-trust[Skip image verification (default true)]" \ - "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help -)*:key=value: " && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_plugin_complete_ls_filters" \ - "($help --format)--format=[Format the output using the given Go template]:template: " \ - "($help)--no-trunc[Don't truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (push) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--disable-content-trust[Skip image verification (default true)]" \ - "($help -)1:plugin:__docker_complete_plugins" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the removal of an active plugin]" \ - "($help -)*:plugin:__docker_complete_plugins" && ret=0 - ;; - (set) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help -)*:key=value: " && ret=0 - ;; - (upgrade) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--disable-content-trust[Skip image verification (default true)]" \ - "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ - "($help)--skip-remote-check[Do not check if specified remote plugin matches existing plugin image]" \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help -):remote: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 - ;; - esac - - return ret -} - -# EO plugin - -# BO secret - -__docker_secrets() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines secrets - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - secrets=($secrets $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - secrets=($secrets $s) - done - fi - - _describe -t secrets-list "secrets" secrets "$@" && ret=0 - return ret -} - -__docker_complete_secrets() { - [[ $PREFIX = -* ]] && return 1 - __docker_secrets all "$@" -} - -__docker_secret_commands() { - local -a _docker_secret_subcommands - _docker_secret_subcommands=( - "create:Create a secret using stdin as content" - "inspect:Display detailed information on one or more secrets" - "ls:List secrets" - "rm:Remove one or more secrets" - ) - _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands -} - -__docker_secret_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)*"{-l=,--label=}"[Secret labels]:label: " \ - "($help -):secret: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 - ;; - esac - - return ret -} - -# EO secret - -# BO service - -__docker_service_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_services_ids && ret=0 - ;; - (mode) - opts=('global' 'replicated') - _describe -t mode-opts "mode options" opts && ret=0 - ;; - (name) - __docker_complete_services_names && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'mode' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_service_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running' 'shutdown') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_service_complete_placement_pref() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (spread) - opts=('engine.labels' 'node.labels') - _describe -t spread-opts "spread options" opts -qS "." && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('spread') - _describe -t pref-opts "placement pref options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_services() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines services - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - _describe -t services-list "services" services "$@" && ret=0 - return ret -} - -__docker_complete_services() { - [[ $PREFIX = -* ]] && return 1 - __docker_services all "$@" -} - -__docker_complete_services_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_services ids "$@" -} - -__docker_complete_services_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_services names "$@" -} - -__docker_service_commands() { - local -a _docker_service_subcommands - _docker_service_subcommands=( - "create:Create a new service" - "inspect:Display detailed information on one or more services" - "logs:Fetch the logs of a service or task" - "ls:List services" - "rm:Remove one or more services" - "rollback:Revert changes to a service's configuration" - "scale:Scale one or multiple replicated services" - "ps:List the tasks of a service" - "update:Update a service" - ) - _describe -t docker-service-commands "docker service command" _docker_service_subcommands -} - -__docker_service_subcommand() { - local -a _command_args opts_help opts_create_update - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - opts_create_update=( - "($help)*--cap-add=[Add Linux capabilities]:capability: " - "($help)*--cap-drop=[Drop Linux capabilities]:capability: " - "($help)*--constraint=[Placement constraints]:constraint: " - "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" - "($help)*"{-e=,--env=}"[Set environment variables]:env: " - "($help)--health-cmd=[Command to run to check health]:command: " - "($help)--health-interval=[Time between running the check]:time: " - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " - "($help)--hostname=[Service container hostname]:hostname: " \ - "($help)--isolation=[Service container isolation mode]:isolation:(default process hyperv)" \ - "($help)*--label=[Service labels]:label: " - "($help)--limit-cpu=[Limit CPUs]:value: " - "($help)--limit-memory=[Limit Memory]:value: " - "($help)--limit-pids[Limit maximum number of processes (default 0 = unlimited)]" - "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" - "($help)*--mount=[Attach a filesystem mount to the service]:mount: " - "($help)*--network=[Network attachments]:network: " - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" - "($help)--read-only[Mount the container's root filesystem as read only]" - "($help)--replicas=[Number of tasks]:replicas: " - "($help)--reserve-cpu=[Reserve CPUs]:value: " - "($help)--reserve-memory=[Reserve Memory]:value: " - "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" - "($help)--restart-delay=[Delay between restart attempts]:delay: " - "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " - "($help)--restart-window=[Window used to evaluate the restart policy]:duration: " - "($help)--rollback-delay=[Delay between task rollbacks]:duration: " - "($help)--rollback-failure-action=[Action on rollback failure]:action:(continue pause)" - "($help)--rollback-max-failure-ratio=[Failure rate to tolerate during a rollback]:failure rate: " - "($help)--rollback-monitor=[Duration after each task rollback to monitor for failure]:duration: " - "($help)--rollback-parallelism=[Maximum number of tasks rolled back simultaneously]:number: " - "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" - "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " - "($help)--stop-signal=[Signal to stop the container]:signal:_signals" - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" - "($help)--update-delay=[Delay between updates]:delay: " - "($help)--update-failure-action=[Action on update failure]:mode:(continue pause rollback)" - "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " - "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " - "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)--with-registry-auth[Send registry authentication details to swarm agents]" - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)*--container-label=[Container labels]:label: " \ - "($help)*--dns=[Set custom DNS servers]:DNS: " \ - "($help)*--dns-option=[Set DNS options]:DNS option: " \ - "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ - "($help)*--group=[Set one or more supplementary user groups for the container]:group: _groups " \ - "($help)--mode=[Service Mode]:mode:(global replicated)" \ - "($help)--name=[Service name]:name: " \ - "($help)*--placement-pref=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ - "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (logs) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --follow)"{-f,--follow}"[Follow log output]" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-task-ids[Do not include task IDs]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help)--since=[Show logs since timestamp]:timestamp: " \ - "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ - "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_service_complete_ls_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (rollback) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress progress output]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (scale) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ - "($help -)*:service:->values" && ret=0 - case $state in - (values) - if compset -P '*='; then - _message 'replicas' && ret=0 - else - __docker_complete_services -qS "=" - fi - ;; - esac - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_service_complete_ps_filters" \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)--arg=[Service command args]:arguments: _normal" \ - "($help)*--container-label-add=[Add or update container labels]:label: " \ - "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ - "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ - "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ - "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ - "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ - "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ - "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ - "($help)--force[Force update]" \ - "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ - "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ - "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ - "($help)*--placement-pref-add=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ - "($help)*--placement-pref-rm=[Remove a placement preference]:pref:__docker_service_complete_placement_pref" \ - "($help)*--publish-add=[Add or update a port]:port: " \ - "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ - "($help)--rollback[Rollback to previous specification]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 - ;; - esac - - return ret -} - -# EO service - -# BO stack - -__docker_stack_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running' 'shutdown') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stack_complete_services_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stacks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines stacks - - lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service NAME - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - stacks=($stacks $s) - done - - _describe -t stacks-list "stacks" stacks "$@" && ret=0 - return ret -} - -__docker_complete_stacks() { - [[ $PREFIX = -* ]] && return 1 - __docker_stacks "$@" -} - -__docker_stack_commands() { - local -a _docker_stack_subcommands - _docker_stack_subcommands=( - "deploy:Deploy a new stack or update an existing stack" - "ls:List stacks" - "ps:List the tasks in the stack" - "rm:Remove the stack" - "services:List the services in the stack" - ) - _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands -} - -__docker_stack_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (deploy|up) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file, or '-' to read from stdin]:compose file:_files -g \"*.(yml|yaml)\"" \ - "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all tasks]" \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (rm|remove|down) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (services) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 - ;; - esac - - return ret -} - -# EO stack - -# BO swarm - -__docker_swarm_commands() { - local -a _docker_swarm_subcommands - _docker_swarm_subcommands=( - "init:Initialize a swarm" - "join:Join a swarm as a node and/or manager" - "join-token:Manage join tokens" - "leave:Leave a swarm" - "unlock:Unlock swarm" - "unlock-key:Manage the unlock key" - "update:Update the swarm" - ) - _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands -} - -__docker_swarm_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (init) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--advertise-addr=[Advertised address]:ip\:port: " \ - "($help)--data-path-addr=[Data path IP or interface]:ip " \ - "($help)--data-path-port=[Data Path Port]:port " \ - "($help)--default-addr-pool=[Default address pool]" \ - "($help)--default-addr-pool-mask-length=[Default address pool subnet mask length]" \ - "($help)--autolock[Enable manager autolocking]" \ - "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ - "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ - "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--force-new-cluster[Force create a new cluster from current state]" \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (join) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)--advertise-addr=[Advertised address]:ip\:port: " \ - "($help)--data-path-addr=[Data path IP or interface]:ip " \ - "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--token=[Token for entry into the swarm]:secret: " \ - "($help -):host\:port: " && ret=0 - ;; - (join-token) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ - "($help)--rotate[Rotate join token]" \ - "($help -):role:(manager worker)" && ret=0 - ;; - (leave) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 - ;; - (unlock) - _arguments $(__docker_arguments) \ - $opts_help && ret=0 - ;; - (unlock-key) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ - "($help)--rotate[Rotate unlock token]" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--autolock[Enable manager autolocking]" \ - "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ - "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO swarm - -# BO system - -__docker_system_commands() { - local -a _docker_system_subcommands - _docker_system_subcommands=( - "df:Show docker filesystem usage" - "events:Get real time events from the server" - "info:Display system-wide information" - "prune:Remove unused data" - ) - _describe -t docker-system-commands "docker system command" _docker_system_subcommands -} - -__docker_system_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (df) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 - ;; - (events) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ - "($help)--since=[Events created since this timestamp]:timestamp: " \ - "($help)--until=[Events created until this timestamp]:timestamp: " \ - "($help)--format=[Format the output using the given go template]:template: " && ret=0 - ;; - (info) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" \ - "($help)--volumes=[Remove all unused volumes]" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO system - -# BO volume - -__docker_volume_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (dangling) - dangling_opts=('true' 'false') - _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 - ;; - (driver) - __docker_complete_info_plugins Volume && ret=0 - ;; - (name) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('dangling' 'driver' 'label' 'name') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_volumes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a lines volumes - - lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Names - local line s - for line in $lines; do - s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - volumes=($volumes $s) - done - - _describe -t volumes-list "volumes" volumes && ret=0 - return ret -} - -__docker_volume_commands() { - local -a _docker_volume_subcommands - _docker_volume_subcommands=( - "create:Create a volume" - "inspect:Display detailed information on one or more volumes" - "ls:List volumes" - "prune:Remove all unused volumes" - "rm:Remove one or more volumes" - ) - _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands -} - -__docker_volume_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ - "($help)*--label=[Set metadata for a volume]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ - "($help -)1:Volume name: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)1:volume:__docker_complete_volumes" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_volume_complete_ls_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ - "($help -):volume:__docker_complete_volumes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO volume - -# BO context - -__docker_complete_contexts() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a contexts - - contexts=(${(f)${:-"$(_call_program commands docker $docker_options context ls -q)"$'\n'}}) - - _describe -t context-list "context" contexts && ret=0 - return ret -} - -__docker_context_commands() { - local -a _docker_context_subcommands - _docker_context_subcommands=( - "create:Create new context" - "inspect:Display detailed information on one or more contexts" - "list:List available contexts" - "rm:Remove one or more contexts" - "show:Print the current context" - "update:Update a context" - "use:Set the default context" - ) - _describe -t docker-context-commands "docker context command" _docker_context_subcommands -} - -__docker_context_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--description=[Description of the context]:description:" \ - "($help)--docker=[Set the docker endpoint]:docker:" \ - "($help)--from=[Create context from a named context]:from:__docker_complete_contexts" \ - "($help -):name: " && ret=0 - ;; - (use) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:context:__docker_complete_contexts" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:context:__docker_complete_contexts" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:context:__docker_complete_contexts" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--description=[Description of the context]:description:" \ - "($help)--docker=[Set the docker endpoint]:docker:" \ - "($help -):name:" && ret=0 - ;; - esac - - return ret -} - -# EO context - -__docker_caching_policy() { - oldp=( "$1"(Nmh+1) ) # 1 hour - (( $#oldp )) -} - -__docker_commands() { - local cache_policy - integer force_invalidation=0 - - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - if ( (( ! ${+_docker_hide_legacy_commands} )) || _cache_invalid docker_hide_legacy_commands ) \ - && ! _retrieve_cache docker_hide_legacy_commands; - then - _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" - _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands - fi - - if [[ "${_docker_hide_legacy_commands}" != "${DOCKER_HIDE_LEGACY_COMMANDS}" ]]; then - force_invalidation=1 - _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" - _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands - fi - - if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands ) \ - && ! _retrieve_cache docker_subcommands || [[ ${force_invalidation} -eq 1 ]]; - then - local -a lines - lines=(${(f)"$(_call_program commands docker 2>&1)"}) - _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/\*# ##/:}) - _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') - (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands - fi - _describe -t docker-commands "docker command" _docker_subcommands -} - -__docker_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) - __docker_container_subcommand && ret=0 - ;; - (build|history|import|load|pull|push|save|tag) - __docker_image_subcommand && ret=0 - ;; - (checkpoint) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_checkpoint_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_checkpoint_subcommand && ret=0 - ;; - esac - ;; - (container) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_container_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_container_subcommand && ret=0 - ;; - esac - ;; - (context) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_context_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_context_subcommand && ret=0 - ;; - esac - ;; - (daemon) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ - "($help)*--allow-nondistributable-artifacts=[Push nondistributable artifacts to specified registries]:registry: " \ - "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ - "($help)*--authorization-plugin=[Authorization plugins to load]" \ - "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ - "($help)--bip=[Network bridge IP]:IP address: " \ - "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ - "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ - "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ - "($help)--containerd-namespace=[Containerd namespace to use]:containerd namespace:" \ - "($help)--containerd-plugins-namespace=[Containerd namespace to use for plugins]:containerd namespace:" \ - "($help)--data-root=[Root directory of persisted Docker data]:path:_directories" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ - "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ - "($help)--default-shm-size=[Default shm size for containers]:size:" \ - "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ - "($help)*--dns=[DNS server to use]:DNS: " \ - "($help)*--dns-opt=[DNS options to use]:DNS option: " \ - "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ - "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ - "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ - "($help)--experimental[Enable experimental features]" \ - "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ - "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ - "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help)--icc[Enable inter-container communication]" \ - "($help)--init[Run an init inside containers to forward signals and reap processes]" \ - "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ - "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ - "($help)--ip=[Default IP when binding container ports]" \ - "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ - "($help)--ip-masq[Enable IP masquerading]" \ - "($help)--iptables[Enable addition of iptables rules]" \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)*--label=[Key=value labels]:label: " \ - "($help)--live-restore[Enable live restore of docker when containers are still running]" \ - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ - "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ - "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \ - "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \ - "($help)--max-download-attempts[Set the max download attempts for each pull]" \ - "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ - "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ - "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ - "($help)--raw-logs[Full timestamps without ANSI coloring]" \ - "($help)*--registry-mirror=[Preferred registry mirror]:registry mirror: " \ - "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ - "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \ - "($help)--selinux-enabled[Enable selinux support]" \ - "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ - "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" \ - "($help)--validate[Validate daemon configuration and exit]" && ret=0 - - case $state in - (users-groups) - if compset -P '*:'; then - _groups && ret=0 - else - _describe -t userns-default "default Docker user management" '(default)' && ret=0 - _users && ret=0 - fi - ;; - esac - ;; - (events|info) - __docker_system_subcommand && ret=0 - ;; - (image) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_image_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_image_subcommand && ret=0 - ;; - esac - ;; - (images) - words[1]='ls' - __docker_image_subcommand && ret=0 - ;; - (inspect) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ - "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ - "($help -)*: :->values" && ret=0 - - case $state in - (values) - if [[ ${words[(r)--type=container]} == --type=container ]]; then - __docker_complete_containers && ret=0 - elif [[ ${words[(r)--type=image]} == --type=image ]]; then - __docker_complete_images && ret=0 - elif [[ ${words[(r)--type=network]} == --type=network ]]; then - __docker_complete_networks && ret=0 - elif [[ ${words[(r)--type=node]} == --type=node ]]; then - __docker_complete_nodes && ret=0 - elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then - __docker_complete_plugins && ret=0 - elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then - __docker_complete_secrets && ret=0 - elif [[ ${words[(r)--type=service]} == --type=service ]]; then - __docker_complete_services && ret=0 - elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then - __docker_complete_volumes && ret=0 - else - __docker_complete_containers - __docker_complete_images - __docker_complete_networks - __docker_complete_nodes - __docker_complete_plugins - __docker_complete_secrets - __docker_complete_services - __docker_complete_volumes && ret=0 - fi - ;; - esac - ;; - (login) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -p --password)"{-p=,--password=}"[Password]:password: " \ - "($help)--password-stdin[Read password from stdin]" \ - "($help -u --username)"{-u=,--username=}"[Username]:username: " \ - "($help -)1:server: " && ret=0 - ;; - (logout) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -)1:server: " && ret=0 - ;; - (network) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_network_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_network_subcommand && ret=0 - ;; - esac - ;; - (node) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_node_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_node_subcommand && ret=0 - ;; - esac - ;; - (plugin) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_plugin_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_plugin_subcommand && ret=0 - ;; - esac - ;; - (ps) - words[1]='ls' - __docker_container_subcommand && ret=0 - ;; - (rmi) - words[1]='rm' - __docker_image_subcommand && ret=0 - ;; - (search) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_search_filters" \ - "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -):term: " && ret=0 - ;; - (secret) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_secret_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_secret_subcommand && ret=0 - ;; - esac - ;; - (service) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_service_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_service_subcommand && ret=0 - ;; - esac - ;; - (stack) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_stack_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_stack_subcommand && ret=0 - ;; - esac - ;; - (swarm) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_swarm_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_swarm_subcommand && ret=0 - ;; - esac - ;; - (system) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_system_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_system_subcommand && ret=0 - ;; - esac - ;; - (version) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (volume) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_volume_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_volume_subcommand && ret=0 - ;; - esac - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 - ;; - esac - - return ret -} - -_docker() { - # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. - # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. - if [[ $service != docker ]]; then - _call_function - _$service - return - fi - - local curcontext="$curcontext" state line help="-h --help" - integer ret=1 - typeset -A opt_args - - _arguments $(__docker_arguments) -C \ - "(: -)"{-h,--help}"[Print usage]" \ - "($help)--config[Location of client config files]:path:_directories" \ - "($help -c --context)"{-c=,--context=}"[Execute the command in a docker context]:context:__docker_complete_contexts" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help -v --version)"{-v,--version}"[Print version information and quit]" \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - local host=${opt_args[-H]}${opt_args[--host]} - local config=${opt_args[--config]} - local context=${opt_args[-c]}${opt_args[--context]} - local docker_options="${host:+--host $host} ${config:+--config $config} ${context:+--context $context} " - - case $state in - (command) - __docker_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-$words[1]: - __docker_subcommand && ret=0 - ;; - esac - - return ret -} - -_dockerd() { - integer ret=1 - words[1]='daemon' - __docker_subcommand && ret=0 - return ret -} - -_docker "$@" - -# Local Variables: -# mode: Shell-Script -# sh-indentation: 4 -# indent-tabs-mode: nil -# sh-basic-offset: 4 -# End: -# vim: ft=zsh sw=4 ts=4 et diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index 8684a9785..06a191a10 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -1,3 +1,13 @@ +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `docker`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then + typeset -g -A _comps + autoload -Uz _docker + _comps[docker]=_docker +fi + +docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" &| + alias dbl='docker build' alias dcin='docker container inspect' alias dcls='docker container ls' -- cgit v1.2.3-70-g09d2 From 6bffaab2904d4bb37edad90e00b6f6e842d3811d Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 15 Jun 2023 20:06:56 +0200 Subject: fix(docker): only generate completion for docker >23 (#11754) --- plugins/docker/docker.plugin.zsh | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index 06a191a10..e8aad9230 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -1,13 +1,3 @@ -# If the completion file doesn't exist yet, we need to autoload it and -# bind it to `docker`. Otherwise, compinit will have already done that. -if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then - typeset -g -A _comps - autoload -Uz _docker - _comps[docker]=_docker -fi - -docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" &| - alias dbl='docker build' alias dcin='docker container inspect' alias dcls='docker container ls' @@ -41,3 +31,22 @@ alias dvls='docker volume ls' alias dvprune='docker volume prune' alias dxc='docker container exec' alias dxcit='docker container exec -it' + +if (( ! $+commands[docker] )); then + return +fi + +{ + # `docker completion` is only available from 23.0.0 on + local _docker_version=$(docker version --format '{{.Client.Version}}' 2>/dev/null) + if is-at-least 23.0.0 $_docker_version; then + # If the completion file doesn't exist yet, we need to autoload it and + # bind it to `docker`. Otherwise, compinit will have already done that. + if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then + typeset -g -A _comps + autoload -Uz _docker + _comps[docker]=_docker + fi + docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" + fi +} &| -- cgit v1.2.3-70-g09d2 From 42b86327ed875ee182f8fc394b90ae9328a5ac00 Mon Sep 17 00:00:00 2001 From: rfigueroa <41128440+rfigueroa@users.noreply.github.com> Date: Fri, 16 Jun 2023 02:52:12 -0500 Subject: fix(mvn)!: rename `mvnd` to `mvndp` alias (#11756) BREAKING CHANGE: Rename alias to prevent conflicts with Apache Maven Daemon. --- plugins/mvn/README.md | 2 +- plugins/mvn/mvn.plugin.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mvn/README.md b/plugins/mvn/README.md index 815dfd57c..4181fedc5 100644 --- a/plugins/mvn/README.md +++ b/plugins/mvn/README.md @@ -33,7 +33,7 @@ if it's found, or the mvn command otherwise. | `mvnct` | `mvn clean test` | | `mvncv` | `mvn clean verify` | | `mvncvst` | `mvn clean verify -DskipTests` | -| `mvnd` | `mvn deploy` | +| `mvndp` | `mvn deploy` | | `mvndocs` | `mvn dependency:resolve -Dclassifier=javadoc` | | `mvndt` | `mvn dependency:tree` | | `mvne` | `mvn eclipse:eclipse` | diff --git a/plugins/mvn/mvn.plugin.zsh b/plugins/mvn/mvn.plugin.zsh index da51f74df..a569a87fa 100644 --- a/plugins/mvn/mvn.plugin.zsh +++ b/plugins/mvn/mvn.plugin.zsh @@ -62,7 +62,7 @@ alias mvncp='mvn clean package' alias mvnct='mvn clean test' alias mvncv='mvn clean verify' alias mvncvst='mvn clean verify -DskipTests' -alias mvnd='mvn deploy' +alias mvndp='mvn deploy' alias mvndocs='mvn dependency:resolve -Dclassifier=javadoc' alias mvndt='mvn dependency:tree' alias mvne='mvn eclipse:eclipse' -- cgit v1.2.3-70-g09d2 From f5cb9a6c978693c9570206f4267ba2589bef1b4c Mon Sep 17 00:00:00 2001 From: Ihor Date: Sat, 17 Jun 2023 13:28:55 +0200 Subject: fix(git): `gunwipall` now only resets once (#11758) Closes #11750 Co-authored-by: Carlo Sala --- plugins/git/README.md | 2 +- plugins/git/git.plugin.zsh | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index bf4b19f39..05cba8586 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -254,7 +254,7 @@ These features allow to pause a branch development and switch to another one (_" | work_in_progress | Echoes a warning if the current branch is a wip | | gwip | Commit wip branch | | gunwip | Uncommit wip branch | -| gunwipall | Uncommit `--wip--` commits recursively | +| gunwipall | Uncommit all recent `--wip--` commits | ### Deprecated functions diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 192124301..66877df4f 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -27,18 +27,14 @@ function work_in_progress() { command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" } -# Same as `gunwip` but recursive -# "Unwips" all recent `--wip--` commits in loop until there is no left +# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one function gunwipall() { - while true; do - commit_message=$(git rev-list --max-count=1 --format="%s" HEAD) - if [[ $commit_message =~ "--wip--" ]]; then - git reset "HEAD~1" - (( $? )) && return 1 - else - break - fi - done + local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H) + + # Check if a commit without "--wip--" was found and it's not the same as HEAD + if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then + git reset $_commit || return 1 + fi } # Check if main exists and use instead of master -- cgit v1.2.3-70-g09d2 From c0e811c90df387eca4223c7d4dbb3f2d32a684c7 Mon Sep 17 00:00:00 2001 From: WH-2099 Date: Mon, 19 Jun 2023 18:32:37 +0800 Subject: perf(archlinux): improve `paclist` performance (#11764) --- plugins/archlinux/archlinux.plugin.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index 796ff7adf..fca6548c0 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -25,10 +25,7 @@ alias pacown='pacman -Qo' alias pacupd="sudo pacman -Sy" function paclist() { - local pkgs=$(LC_ALL=C pacman -Qqe) - for pkg in ${(f)pkgs}; do - pacman -Qs --color=auto "^${pkg}\$" || break - done + pacman -Qqe | xargs -I{} -P0 --no-run-if-empty pacman -Qs --color=auto "^{}\$" } function pacdisowned() { -- cgit v1.2.3-70-g09d2 From 8ace453f37acf0568bdb2e40920edb7598ad873a Mon Sep 17 00:00:00 2001 From: kang Date: Tue, 20 Jun 2023 08:49:56 +0200 Subject: feat(git-extras): update completion (2023-06-19 3a258cb) Closes #11712 --- plugins/git-extras/git-extras.plugin.zsh | 176 +++++++++---------------------- 1 file changed, 48 insertions(+), 128 deletions(-) diff --git a/plugins/git-extras/git-extras.plugin.zsh b/plugins/git-extras/git-extras.plugin.zsh index 6b96e12af..f5fd387d1 100644 --- a/plugins/git-extras/git-extras.plugin.zsh +++ b/plugins/git-extras/git-extras.plugin.zsh @@ -80,22 +80,10 @@ __gitex_specific_branch_names() { _wanted branch-names expl branch-name compadd - $branch_names } -__gitex_chore_branch_names() { - __gitex_specific_branch_names 'chore' -} - __gitex_feature_branch_names() { __gitex_specific_branch_names 'feature' } -__gitex_refactor_branch_names() { - __gitex_specific_branch_names 'refactor' -} - -__gitex_bug_branch_names() { - __gitex_specific_branch_names 'bug' -} - __gitex_submodule_names() { local expl declare -a submodule_names @@ -114,88 +102,29 @@ __gitex_author_names() { } # subcommands +# new subcommand should be added in alphabetical order _git-authors() { _arguments -C \ '(--list -l)'{--list,-l}'[show authors]' \ '--no-email[without email]' \ } -_git-bug() { - local curcontext=$curcontext state line ret=1 - declare -A opt_args - - _arguments -C \ - ': :->command' \ - '*:: :->option-or-argument' && ret=0 - - case $state in - (command) - declare -a commands - commands=( - 'finish:merge bug into the current branch' - ) - _describe -t commands command commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*}-$line[1]: - case $line[1] in - (finish) - _arguments -C \ - ':branch-name:__gitex_bug_branch_names' - ;; - -r|--remote ) - _arguments -C \ - ':remote-name:__gitex_remote_names' - ;; - esac - return 0 - esac - - _arguments \ - '(--remote -r)'{--remote,-r}'[setup remote tracking branch]' -} - - _git-changelog() { _arguments \ '(-l --list)'{-l,--list}'[list commits]' \ } -_git-chore() { - local curcontext=$curcontext state line ret=1 - declare -A opt_args - - _arguments -C \ - ': :->command' \ - '*:: :->option-or-argument' && ret=0 - - case $state in - (command) - declare -a commands - commands=( - 'finish:merge and delete the chore branch' - ) - _describe -t commands command commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*}-$line[1]: - case $line[1] in - (finish) - _arguments -C \ - ':branch-name:__gitex_chore_branch_names' - ;; - -r|--remote ) - _arguments -C \ - ':remote-name:__gitex_remote_names' - ;; - esac - return 0 - esac - +_git-clear() { _arguments \ - '(--remote -r)'{--remote,-r}'[setup remote tracking branch]' + '(-f --force)'{-f,--force}'[force clear]' \ + '(-h --help)'{-h,--help}'[help message]' \ } +_git-coauthor() { + _arguments \ + ':co-author[co-author to add]' \ + ':co-author-email[email address of co-author to add]' +} _git-contrib() { _arguments \ @@ -235,6 +164,11 @@ _git-delete-branch() { ':branch-name:__gitex_branch_names' } +_git-delete-squashed-branches() { + _arguments \ + ':branch-name:__gitex_branch_names' +} + _git-delete-submodule() { _arguments \ @@ -298,6 +232,7 @@ _git-feature() { case $line[1] in (finish) _arguments -C \ + '--squash[Use squash merge]' \ ':branch-name:__gitex_feature_branch_names' ;; -r|--remote ) @@ -327,20 +262,17 @@ _git-guilt() { } _git-ignore() { - _arguments -C \ + _arguments -C \ '(--local -l)'{--local,-l}'[show local gitignore]' \ '(--global -g)'{--global,-g}'[show global gitignore]' \ '(--private -p)'{--private,-p}'[show repo gitignore]' } -_git-ignore() { - _arguments -C \ - '(--append -a)'{--append,-a}'[append .gitignore]' \ - '(--replace -r)'{--replace,-r}'[replace .gitignore]' \ - '(--list-in-table -l)'{--list-in-table,-l}'[print available types in table format]' \ - '(--list-alphabetically -L)'{--list-alphabetically,-L}'[print available types in alphabetical order]' \ - '(--search -s)'{--search,-s}'[search word in available types]' +_git-info() { + _arguments -C \ + '(--color -c)'{--color,-c}'[use color for information titles]' \ + '--no-config[do not show list all variables set in config file, along with their values]' } @@ -357,50 +289,27 @@ _git-missing() { ':second-branch-name:__gitex_branch_names' } - -_git-refactor() { - local curcontext=$curcontext state line ret=1 - declare -A opt_args - +_git-release() { _arguments -C \ - ': :->command' \ - '*:: :->option-or-argument' && ret=0 - - case $state in - (command) - declare -a commands - commands=( - 'finish:merge refactor into the current branch' - ) - _describe -t commands command commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*}-$line[1]: - case $line[1] in - (finish) - _arguments -C \ - ':branch-name:__gitex_refactor_branch_names' - ;; - -r|--remote ) - _arguments -C \ - ':remote-name:__gitex_remote_names' - ;; - esac - return 0 - esac - - _arguments \ - '(--remote -r)'{--remote,-r}'[setup remote tracking branch]' + '-c[Generates/populates the changelog with all commit message since the last tag.]' \ + '-r[The "remote" repository that is destination of a push operation.]' \ + '-m[use the custom commit information instead of the default message.]' \ + '-s[Create a signed and annotated tag.]' \ + '-u[Create a tag, annotated and signed with the given key.]' \ + '--semver[If the latest tag in your repo matches the semver format requirement, you could increase part of it as the new release tag.]' \ + '--prefix[Add a prefix string to semver to allow more complex tags.]' \ + '--no-empty-commit[Avoid creating empty commit if nothing could be committed.]' \ + '--[The arguments listed after "--" separator will be passed to pre/post-release hook.]' } - _git-squash() { + _arguments '--squash-msg[commit with the squashed commit messages]' _arguments \ ':branch-name:__gitex_branch_names' } _git-stamp() { - _arguments -C \ + _arguments -C \ '(--replace -r)'{--replace,-r}'[replace stamps with same id]' } @@ -413,17 +322,19 @@ _git-standup() { '-g[Display GPG signed info]' \ '-h[Display help message]' \ '-L[Enable the inclusion of symbolic links]' \ - '-m[The depth of recursive directory search]' + '-m[The depth of recursive directory search]' \ + '-B[Display the commits in branch groups]' } _git-summary() { _arguments '--line[summarize with lines rather than commits]' + _arguments '--dedup-by-email[remove duplicate users by the email address]' + _arguments '--no-merges[exclude merge commits]' __gitex_commits } - _git-undo(){ - _arguments -C \ + _arguments -C \ '(--soft -s)'{--soft,-s}'[only rolls back the commit but changes remain un-staged]' \ '(--hard -h)'{--hard,-h}'[wipes your commit(s)]' } @@ -432,21 +343,26 @@ zstyle -g existing_user_commands ':completion:*:*:git:*' user-commands zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \ alias:'define, search and show aliases' \ + abort:'abort current revert, merge, rebase, or cherry-pick process' \ archive-file:'export the current head of the git repository to an archive' \ authors:'generate authors report' \ - back:'undo and stage latest commits' \ + browse:'open repo website in browser' \ + browse-ci:'open repo CI page in browser' \ bug:'create bug branch' \ bulk:'run bulk commands' \ + brv:'list branches sorted by their last commit date'\ changelog:'generate a changelog report' \ chore:'create chore branch' \ clear-soft:'soft clean up a repository' \ clear:'rigorously clean up a repository' \ + coauthor:'add a co-author to the last commit' \ commits-since:'show commit logs since some date' \ contrib:'show user contributions' \ count:'show commit count' \ create-branch:'create branches' \ delete-branch:'delete branches' \ delete-merged-branches:'delete merged branches' \ + delete-squashed-branches:'delete squashed branches' \ delete-submodule:'delete submodules' \ delete-tag:'delete tags' \ delta:'lists changed files' \ @@ -465,11 +381,13 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \ local-commits:'list local commits' \ lock:'lock a file excluded from version control' \ locked:'ls files that have been locked' \ + magic:'commits everything with a generated message' \ merge-into:'merge one branch into another' \ merge-repo:'merge two repo histories' \ missing:'show commits missing from another branch' \ mr:'checks out a merge request locally' \ obliterate:'rewrite past commits to remove some files' \ + paste:'send patches to pastebin sites' \ pr:'checks out a pull request locally' \ psykorebase:'rebase a branch with a merge commit' \ pull-request:'create pull request to GitHub project' \ @@ -479,6 +397,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \ release:'commit, tag and push changes to the repository' \ rename-branch:'rename a branch' \ rename-tag:'rename a tag' \ + rename-remote:'rename a remote' \ repl:'git read-eval-print-loop' \ reset-file:'reset one file' \ root:'show path of root' \ @@ -495,4 +414,5 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \ sync:'sync local branch with remote branch' \ touch:'touch and add file to the index' \ undo:'remove latest commits' \ - unlock:'unlock a file excluded from version control' + unlock:'unlock a file excluded from version control' \ + utimes:'change files modification time to their last commit date' -- cgit v1.2.3-70-g09d2 From 4ba17232dae591f67b8e474fb013d2cb6555696e Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 20 Jun 2023 08:54:35 +0200 Subject: feat(nvm)!: remove soft-deprecated code BREAKING CHANGE: $NVM_LAZY, $NVM_LAZY_CMD, AND $NVM_AUTOLOAD cannot be used anymore to tweak nvm plugin. Use zstyle-based configurations instead. --- plugins/nvm/nvm.plugin.zsh | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 31d275415..943678f7a 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -16,29 +16,6 @@ fi # Note: nvm is a function so we need to use `which` which nvm &>/dev/null && return -# TODO: 2022-11-11: Remove soft-deprecate options -if (( ${+NVM_LAZY} + ${+NVM_LAZY_CMD} + ${+NVM_AUTOLOAD} )); then - # Get list of NVM_* variable settings defined - local -a used_vars - used_vars=(${(o)parameters[(I)NVM_(AUTOLOAD|LAZY|LAZY_CMD)]}) - # Nicely print the list in the style `var1, var2 and var3` - echo "${fg[yellow]}[nvm plugin] Variable-style settings are deprecated. Instead of ${(j:, :)used_vars[1,-2]}${used_vars[-2]+ and }${used_vars[-1]}, use:\n" - if (( $+NVM_AUTOLOAD )); then - echo " zstyle ':omz:plugins:nvm' autoload yes" - zstyle ':omz:plugins:nvm' autoload yes - fi - if (( $+NVM_LAZY )); then - echo " zstyle ':omz:plugins:nvm' lazy yes" - zstyle ':omz:plugins:nvm' lazy yes - fi - if (( $+NVM_LAZY_CMD )); then - echo " zstyle ':omz:plugins:nvm' lazy-cmd $NVM_LAZY_CMD" - zstyle ':omz:plugins:nvm' lazy-cmd $NVM_LAZY_CMD - fi - echo "$reset_color" - unset used_vars NVM_AUTOLOAD NVM_LAZY NVM_LAZY_CMD -fi - if zstyle -t ':omz:plugins:nvm' lazy; then # Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd -- cgit v1.2.3-70-g09d2 From b5be2d39e2d2a598f7bba26d0bae2cce8c7d3d64 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 20 Jun 2023 09:36:11 +0200 Subject: fix(nvm): disable lazy-loading if autoload is set Closes #11748 --- plugins/nvm/README.md | 3 +++ plugins/nvm/nvm.plugin.zsh | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index 6830c14d0..eee3bf717 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -43,6 +43,9 @@ zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ... #### `.nvmrc` autoload +Note: _this option cannot be used at the same time as `lazy`. `autoload` will override it and load `nvm` at +startup._ + If set, 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. This can be done, similar as previous options, adding: diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 943678f7a..484ef2964 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -16,7 +16,18 @@ fi # Note: nvm is a function so we need to use `which` which nvm &>/dev/null && return -if zstyle -t ':omz:plugins:nvm' lazy; then +if [[ -z "$NVM_DIR" ]]; then + echo "[oh-my-zsh] nvm installation cannot be found" + echo "[oh-my-zsh] set NVM_DIR to your installation" + return +fi +if [[ ! -f "$NVM_DIR/nvm.sh" ]]; then + echo "[oh-my-zsh] nvm.sh does not exist in $NVM_DIR" + return +fi + +if zstyle -t ':omz:plugins:nvm' lazy && \ + ! zstyle -t ':omz:plugins:nvm' autoload; then # Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd eval " @@ -28,11 +39,8 @@ if zstyle -t ':omz:plugins:nvm' lazy; then } " unset nvm_lazy_cmd -elif [[ -f "$NVM_DIR/nvm.sh" ]]; then - # Load nvm if it exists in $NVM_DIR - source "$NVM_DIR/nvm.sh" else - return + source "$NVM_DIR/nvm.sh" fi # Autoload nvm when finding a .nvmrc file in the current directory -- cgit v1.2.3-70-g09d2 From 8a6fc5c16d49368dc8f9ddd965a9e25ef652e129 Mon Sep 17 00:00:00 2001 From: Haltarys <45515869+Haltarys@users.noreply.github.com> Date: Tue, 20 Jun 2023 22:27:14 +0200 Subject: fix(docker): use `command docker` (#11766) --- plugins/docker/docker.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index e8aad9230..434b1fc60 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -38,7 +38,7 @@ fi { # `docker completion` is only available from 23.0.0 on - local _docker_version=$(docker version --format '{{.Client.Version}}' 2>/dev/null) + local _docker_version=$(command docker version --format '{{.Client.Version}}' 2>/dev/null) if is-at-least 23.0.0 $_docker_version; then # If the completion file doesn't exist yet, we need to autoload it and # bind it to `docker`. Otherwise, compinit will have already done that. @@ -47,6 +47,6 @@ fi autoload -Uz _docker _comps[docker]=_docker fi - docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" + command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" fi } &| -- cgit v1.2.3-70-g09d2 From 22e710b4e4c8934706ef5047506b3b7594af9138 Mon Sep 17 00:00:00 2001 From: Gustavo Perdomo Date: Mon, 26 Jun 2023 04:35:38 -0400 Subject: fix(gcloud): add support for `brew` installations (#11772) --- plugins/gcloud/gcloud.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/gcloud/gcloud.plugin.zsh b/plugins/gcloud/gcloud.plugin.zsh index 9c26aea10..5c57302d3 100644 --- a/plugins/gcloud/gcloud.plugin.zsh +++ b/plugins/gcloud/gcloud.plugin.zsh @@ -6,6 +6,7 @@ if [[ -z "${CLOUDSDK_HOME}" ]]; then search_locations=( "$HOME/google-cloud-sdk" + "/usr/local/share/google-cloud-sdk" "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk" "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk" "/usr/share/google-cloud-sdk" -- cgit v1.2.3-70-g09d2 From d5f1f50ad2d62363785464d5b6eef1a009243d7a Mon Sep 17 00:00:00 2001 From: Richard Mitchell Date: Mon, 26 Jun 2023 04:48:17 -0400 Subject: docs(git-extras): clarify readme (#11776) --- plugins/git-extras/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git-extras/README.md b/plugins/git-extras/README.md index 2adc9d477..7eb53fcfd 100644 --- a/plugins/git-extras/README.md +++ b/plugins/git-extras/README.md @@ -1,6 +1,6 @@ # git-extras -This plugin provides completion definitions for some of the commands defined by [git-extras](https://github.com/tj/git-extras). +This plugin provides completion definitions for some of the commands defined by [git-extras](https://github.com/tj/git-extras), which must already be installed. To use it, add `git-extras` to the plugins array in your zshrc file: -- cgit v1.2.3-70-g09d2 From 8cbe98469d9862d37d43ca4229dc8e915ec377a9 Mon Sep 17 00:00:00 2001 From: Devraj Mehta Date: Mon, 26 Jun 2023 13:05:22 -0400 Subject: fix(git): remove color codes from some aliases (#11770) --- plugins/git/README.md | 4 ++-- plugins/git/git.plugin.zsh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 05cba8586..d18531955 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -26,8 +26,8 @@ plugins=(... git) | gbda | git branch --no-color --merged \| grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| xargs git branch --delete 2>/dev/null | | gbD | git branch --delete --force | | gbg | git branch -vv | grep ": gone\]" | -| gbgd | local res=$(git branch -vv | grep ": gone\]" | awk '{print $1}') && [[ $res ]] && echo $res | xargs git branch -d | -| gbgD | local res=$(git branch -vv | grep ": gone\]" | awk '{print $1}') && [[ $res ]] && echo $res | xargs git branch -D | +| gbgd | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d | +| gbgD | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D | | gbl | git blame -b -w | | gbnm | git branch --no-merged | | gbr | git branch --remote | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 66877df4f..d04edea5e 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -84,8 +84,8 @@ alias gbd='git branch --delete' alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null' alias gbD='git branch --delete --force' alias gbg='git branch -vv | grep ": gone\]"' -alias gbgd='local res=$(gbg | awk '"'"'{print $1}'"'"') && [[ $res ]] && echo $res | xargs git branch -d' -alias gbgD='local res=$(gbg | awk '"'"'{print $1}'"'"') && [[ $res ]] && echo $res | xargs git branch -D' +alias gbgd='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' +alias gbgD='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' alias gbl='git blame -b -w' alias gbnm='git branch --no-merged' alias gbr='git branch --remote' -- cgit v1.2.3-70-g09d2 From 723af07a566cbadc26e61f69c44a1a67ed1ba0c8 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 29 Jun 2023 13:25:05 +0200 Subject: fix(docker): add static completion script --- plugins/docker/_docker | 3126 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3126 insertions(+) create mode 100644 plugins/docker/_docker diff --git a/plugins/docker/_docker b/plugins/docker/_docker new file mode 100644 index 000000000..466b09d94 --- /dev/null +++ b/plugins/docker/_docker @@ -0,0 +1,3126 @@ +#compdef docker dockerd +# +# zsh completion for docker (http://docker.com) +# +# version: 0.3.0 +# github: https://github.com/felixr/docker-zsh-completion +# +# contributors: +# - Felix Riedel +# - Steve Durrheimer +# - Vincent Bernat +# - Rohan Verma +# +# license: +# +# Copyright (c) 2013, Felix Riedel +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# Short-option stacking can be enabled with: +# zstyle ':completion:*:*:docker:*' option-stacking yes +# zstyle ':completion:*:*:docker-*:*' option-stacking yes +__docker_arguments() { + if zstyle -t ":completion:${curcontext}:" option-stacking; then + print -- -s + fi +} + +__docker_get_containers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local kind type line s + declare -a running stopped lines args names + + kind=$1; shift + type=$1; shift + [[ $kind = (stopped|all) ]] && args=($args -a) + + lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line + lines=(${lines[2,-1]}) + + # Container ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + + # Names: we only display the one without slash. All other names + # are generated and may clutter the completion. However, with + # Swarm, all names may be prefixed by the swarm node name. + if [[ $type = (names|all) ]]; then + for line in $lines; do + names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) + # First step: find a common prefix and strip it (swarm node case) + (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} + # Second step: only keep the first name without a / + s=${${names:#*/*}[1]} + # If no name, well give up. + (( $#s != 0 )) || continue + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + + [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 + [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 + return ret +} + +__docker_complete_stopped_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers stopped all "$@" +} + +__docker_complete_running_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers running all "$@" +} + +__docker_complete_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all all "$@" +} + +__docker_complete_containers_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all ids "$@" +} + +__docker_complete_containers_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all names "$@" +} + +__docker_complete_info_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + emulate -L zsh + setopt extendedglob + local -a plugins + plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) + _describe -t plugins "$1 plugins" plugins && ret=0 + return ret +} + +__docker_complete_images() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a images + images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) + _describe -t docker-images "images" images && ret=0 + __docker_complete_repositories_with_tags && ret=0 + return ret +} + +__docker_complete_repositories() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a repos + repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) + repos=(${repos#}) + _describe -t docker-repos "repositories" repos && ret=0 + return ret +} + +__docker_complete_repositories_with_tags() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a repos onlyrepos matched + declare m + repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) + repos=(${${repos%:::}#}) + # Check if we have a prefix-match for the current prefix. + onlyrepos=(${repos%::*}) + for m in $onlyrepos; do + [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { + # Yes, complete with tags + repos=(${${repos/:::/:}/:/\\:}) + _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 + return ret + } + done + # No, only complete repositories + onlyrepos=(${${repos%:::*}/:/\\:}) + _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 + + return ret +} + +__docker_search() { + [[ $PREFIX = -* ]] && return 1 + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + local searchterm cachename + searchterm="${words[$CURRENT]%/}" + cachename=_docker-search-$searchterm + + local expl + local -a result + if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ + && ! _retrieve_cache ${cachename#_}; then + _message "Searching for ${searchterm}..." + result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) + _store_cache ${cachename#_} result + fi + _wanted dockersearch expl 'available images' compadd -a result +} + +__docker_get_log_options() { + [[ $PREFIX = -* ]] && return 1 + + integer ret=1 + local log_driver=${opt_args[--log-driver]:-"all"} + local -a common_options common_options2 awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options + + common_options=("max-buffer-size" "mode") + common_options2=("env" "env-regex" "labels") + awslogs_options=($common_options "awslogs-create-group" "awslogs-datetime-format" "awslogs-group" "awslogs-multiline-pattern" "awslogs-region" "awslogs-stream" "tag") + fluentd_options=($common_options $common_options2 "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "fluentd-sub-second-precision" "tag") + gcplogs_options=($common_options $common_options2 "gcp-log-cmd" "gcp-meta-id" "gcp-meta-name" "gcp-meta-zone" "gcp-project") + gelf_options=($common_options $common_options2 "gelf-address" "gelf-compression-level" "gelf-compression-type" "tag") + journald_options=($common_options $common_options2 "tag") + json_file_options=($common_options $common_options2 "max-file" "max-size") + logentries_options=($common_options $common_options2 "logentries-token" "tag") + syslog_options=($common_options $common_options2 "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") + splunk_options=($common_options $common_options2 "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") + + [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 + [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 + [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 + [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 + [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 + [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 + [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 + [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 + [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 + + return ret +} + +__docker_complete_log_drivers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) + _describe -t log-drivers "log drivers" drivers && ret=0 + return ret +} + +__docker_complete_log_options() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (syslog-format) + local opts=('rfc3164' 'rfc5424' 'rfc5424micro') + _describe -t syslog-format-opts "syslog format options" opts && ret=0 + ;; + (mode) + local opts=('blocking' 'non-blocking') + _describe -t mode-opts "mode options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + __docker_get_log_options -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_detach_keys() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + compset -P "*," + keys=(${:-{a-z}}) + ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) + _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 + _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 +} + +__docker_complete_pid() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local -a opts vopts + + opts=('host') + vopts=('container') + + if compset -P '*:'; then + case "${${words[-1]%:*}#*=}" in + (container) + __docker_complete_running_containers && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 + _describe -t pid-opts "PID Options" opts && ret=0 + fi + + return ret +} + +__docker_complete_runtimes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + emulate -L zsh + setopt extendedglob + local -a runtimes_opts + runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) + _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 +} + +__docker_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (ancestor) + __docker_complete_images && ret=0 + ;; + (before|since) + __docker_complete_containers && ret=0 + ;; + (health) + health_opts=('healthy' 'none' 'starting' 'unhealthy') + _describe -t health-filter-opts "health filter options" health_opts && ret=0 + ;; + (id) + __docker_complete_containers_ids && ret=0 + ;; + (is-task) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + (name) + __docker_complete_containers_names && ret=0 + ;; + (network) + __docker_complete_networks && ret=0 + ;; + (status) + status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') + _describe -t status-filter-opts "status filter options" status_opts && ret=0 + ;; + (volume) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('ancestor' 'before' 'exited' 'expose' 'health' 'id' 'label' 'name' 'network' 'publish' 'since' 'status' 'volume') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_search_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('is-automated' 'is-official' 'stars') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (is-automated|is-official) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_images_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('before' 'dangling' 'label' 'reference' 'since') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (before|reference|since) + __docker_complete_images && ret=0 + ;; + (dangling) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_events_filter() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a opts + + opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'scope' 'type' 'volume') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (container) + __docker_complete_containers && ret=0 + ;; + (daemon) + emulate -L zsh + setopt extendedglob + local -a daemon_opts + daemon_opts=( + ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} + ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} + ) + _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 + ;; + (event) + local -a event_opts + event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disable' 'disconnect' 'enable' 'exec_create' 'exec_detach' + 'exec_start' 'export' 'health_status' 'import' 'install' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'remove' 'rename' 'resize' + 'restart' 'save' 'start' 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') + _describe -t event-filter-opts "event filter options" event_opts && ret=0 + ;; + (image) + __docker_complete_images && ret=0 + ;; + (network) + __docker_complete_networks && ret=0 + ;; + (scope) + local -a scope_opts + scope_opts=('local' 'swarm') + _describe -t scope-filter-opts "scope filter options" scope_opts && ret=0 + ;; + (type) + local -a type_opts + type_opts=('container' 'daemon' 'image' 'network' 'volume') + _describe -t type-filter-opts "type filter options" type_opts && ret=0 + ;; + (volume) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_prune_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a opts + + opts=('until') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +# BO checkpoint + +__docker_checkpoint_commands() { + local -a _docker_checkpoint_subcommands + _docker_checkpoint_subcommands=( + "create:Create a checkpoint from a running container" + "ls:List checkpoints for a container" + "rm:Remove a checkpoint" + ) + _describe -t docker-checkpoint-commands "docker checkpoint command" _docker_checkpoint_subcommands +} + +__docker_checkpoint_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help)--leave-running[Leave the container running after checkpoint]" \ + "($help -)1:container:__docker_complete_running_containers" \ + "($help -)2:checkpoint: " && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help -)1:container:__docker_complete_containers" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help -)1:container:__docker_complete_containers" \ + "($help -)2:checkpoint: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_checkpoint_commands" && ret=0 + ;; + esac + + return ret +} + +# EO checkpoint + +# BO container + +__docker_container_commands() { + local -a _docker_container_subcommands + _docker_container_subcommands=( + "attach:Attach to a running container" + "commit:Create a new image from a container's changes" + "cp:Copy files/folders between a container and the local filesystem" + "create:Create a new container" + "diff:Inspect changes on a container's filesystem" + "exec:Execute a command in a running container" + "export:Export a container's filesystem as a tar archive" + "inspect:Display detailed information on one or more containers" + "kill:Kill one or more running containers" + "logs:Fetch the logs of a container" + "ls:List containers" + "pause:Pause all processes within one or more containers" + "port:List port mappings or a specific mapping for the container" + "prune:Remove all stopped containers" + "rename:Rename a container" + "restart:Restart one or more containers" + "rm:Remove one or more containers" + "run:Create and run a new container from an image" + "start:Start one or more stopped containers" + "stats:Display a live stream of container(s) resource usage statistics" + "stop:Stop one or more running containers" + "top:Display the running processes of a container" + "unpause:Unpause all processes within one or more containers" + "update:Update configuration of one or more containers" + "wait:Block until one or more containers stop, then print their exit codes" + ) + _describe -t docker-container-commands "docker container command" _docker_container_subcommands +} + +__docker_container_subcommand() { + local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update + local expl help="--help" + integer ret=1 + + opts_attach_exec_run_start=( + "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" + ) + opts_create_run=( + "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" + "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " + "($help)*--annotation=[Add an annotation to the container (passed through to the OCI runtime)]:annotations: " + "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " + "($help)--cgroupns=[Cgroup namespace mode to use]:cgroup namespace mode: " + "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " + "($help)--cidfile=[Write the container ID to the file]:CID file:_files" + "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " + "($help)*--device=[Add a host device to the container]:device:_files" + "($help)*--device-cgroup-rule=[Add a rule to the cgroup allowed devices list]:device:cgroup: " + "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " + "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " + "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " + "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " + "($help)--disable-content-trust[Skip image verification]" + "($help)*--dns=[Custom DNS servers]:DNS server: " + "($help)*--dns-option=[Custom DNS options]:DNS option: " + "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " + "($help)*--domainname=[Container NIS domain name]:domainname:_hosts" + "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " + "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" + "($help)*--expose=[Expose a port from the container without publishing it]: " + "($help)*--gpus=[GPU devices to add to the container ('all' to pass all GPUs)]:device: " + "($help)*--group-add=[Set one or more supplementary user groups for the container]:group:_groups" + "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" + "($help)--init[Run an init inside the container that forwards signals and reaps processes]" + "($help)--ip=[IPv4 address]:IPv4: " + "($help)--ip6=[IPv6 address]:IPv6: " + "($help)--ipc=[IPC namespace to use]:IPC namespace: " + "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" + "($help)*--link=[Add link to another container]:link:->link" + "($help)*--link-local-ip=[Container IPv4/IPv6 link-local addresses]:IPv4/IPv6: " + "($help)*"{-l=,--label=}"[Container metadata]:label: " + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" + "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" + "($help)--mac-address=[Container MAC address]:MAC address: " + "($help)*--mount=[Attach a filesystem mount to the container]:mount: " + "($help)--name=[Container name]:name: " + "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" + "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " + "($help)--oom-kill-disable[Disable OOM Killer]" + "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" + "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" + "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" + "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" + "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" + "($help)--privileged[Give extended privileges to this container]" + "($help -q --quiet)"{-q,--quiet}"[Suppress the pull output]" + "($help)--read-only[Mount the container's root filesystem as read only]" + "($help)*--security-opt=[Security options]:security option: " + "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " + "($help)--stop-signal=[Signal to kill a container]:signal:_signals" + "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " + "($help)*--sysctl=-[sysctl options]:sysctl: " + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)*--ulimit=[ulimit options]:ulimit: " + "($help)--userns=[Container user namespace]:user namespace:(host)" + "($help)--tmpfs[mount tmpfs]" + "($help)*-v[Bind mount a volume]:volume:_directories -W / -P '/' -S '\:' -r '/ '" + "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" + "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + opts_create_run_update=( + "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" + "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" + "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " + "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " + "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " + "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " + "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " + "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " + "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " + "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " + "($help)--memory-reservation=[Memory soft limit]:Memory limit: " + "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " + "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" + "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" + ) + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (attach) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help)--no-stdin[Do not attach stdin]" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help -):containers:__docker_complete_running_containers" && ret=0 + ;; + (commit) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --author)"{-a=,--author=}"[Author]:author: " \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ + "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ + "($help -):container:__docker_complete_containers" \ + "($help -): :__docker_complete_repositories_with_tags" && ret=0 + ;; + (cp) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ + "($help -)1:container:->container" \ + "($help -)2:hostpath:_files" && ret=0 + case $state in + (container) + if compset -P "*:"; then + _files && ret=0 + else + __docker_complete_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run \ + $opts_create_run_update \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (diff) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (exec) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ + "($help)--privileged[Give extended Linux capabilities to the command]" \ + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" \ + "($help -):containers:__docker_complete_running_containers" \ + "($help -)*::command:->anycommand" && ret=0 + case $state in + (anycommand) + shift 1 words + (( CURRENT-- )) + _normal && ret=0 + ;; + esac + ;; + (export) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -s --size)"{-s,--size}"[Display total file sizes]" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (kill) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (logs) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--details[Show extra details provided to logs]" \ + "($help -f --follow)"{-f,--follow}"[Follow log output]" \ + "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ + "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers]" \ + "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ + "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show container IDs]" \ + "($help -s --size)"{-s,--size}"[Display total file sizes]" \ + "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 + ;; + (pause|unpause) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (port) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_complete_running_containers" \ + "($help -)2:port:_ports" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rename) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):old name:__docker_complete_containers" \ + "($help -):new name: " && ret=0 + ;; + (restart) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (rm) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ + "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ + "($help -)*:containers:->values" && ret=0 + case $state in + (values) + if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then + __docker_complete_containers && ret=0 + else + __docker_complete_stopped_containers && ret=0 + fi + ;; + esac + ;; + (run) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run \ + $opts_create_run_update \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help)--health-cmd=[Command to run to check health]:command: " \ + "($help)--health-interval=[Time between running the check]:time: " \ + "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ + "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ + "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ + "($help)--rm[Remove intermediate containers when it exits]" \ + "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + (storage-opt) + if compset -P "*="; then + _message "value" && ret=0 + else + opts=('size') + _describe -t filter-opts "storage options" opts -qS "=" && ret=0 + fi + ;; + esac + ;; + (start) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ + "($help -i --interactive)"{-i,--interactive}"[Attach container's stdin]" \ + "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 + ;; + (stats) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-stream[Disable streaming stats and only pull the first result]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (stop) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (top) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_complete_running_containers" \ + "($help -)*:: :->ps-arguments" && ret=0 + case $state in + (ps-arguments) + _ps && ret=0 + ;; + esac + ;; + (update) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run_update \ + "($help -)*: :->values" && ret=0 + case $state in + (values) + if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then + __docker_complete_stopped_containers && ret=0 + else + __docker_complete_containers && ret=0 + fi + ;; + esac + ;; + (wait) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 + ;; + esac + + return ret +} + +# EO container + +# BO image + +__docker_image_commands() { + local -a _docker_image_subcommands + _docker_image_subcommands=( + "build:Build an image from a Dockerfile" + "history:Show the history of an image" + "import:Import the contents from a tarball to create a filesystem image" + "inspect:Display detailed information on one or more images" + "load:Load an image from a tar archive or STDIN" + "ls:List images" + "prune:Remove unused images" + "pull:Download an image from a registry" + "push:Upload an image to a registry" + "rm:Remove one or more images" + "save:Save one or more images to a tar archive (streamed to STDOUT by default)" + "tag:Tag an image into a repository" + ) + _describe -t docker-image-commands "docker image command" _docker_image_subcommands +} + +__docker_image_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (build) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " \ + "($help)*--build-arg=[Build-time variables]:=: " \ + "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ + "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ + "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ + "($help)--compress[Compress the build context using gzip]" \ + "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ + "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ + "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ + "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ + "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ + "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ + "($help)--disable-content-trust[Skip image verification]" \ + "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ + "($help)--force-rm[Always remove intermediate containers]" \ + "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ + "($help)*--label=[Set metadata for an image]:label=value: " \ + "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ + "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ + "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ + "($help)--no-cache[Do not use cache when building the image]" \ + "($help)--pull[Attempt to pull a newer version of the image]" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ + "($help)--rm[Remove intermediate containers after a successful build]" \ + "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ + "($help)--squash[Squash newly built layers into a single new layer]" \ + "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ + "($help)--target=[Set the target build stage to build.]" \ + "($help)*--ulimit=[ulimit options]:ulimit: " \ + "($help)--userns=[Container user namespace]:user namespace:(host)" \ + "($help -):path or URL:_directories" && ret=0 + ;; + (history) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (import) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ + "($help -):URL:(- http:// file://)" \ + "($help -): :__docker_complete_repositories_with_tags" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)*:images:__docker_complete_images" && ret=0 + ;; + (load) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 + ;; + (ls|list) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all images]" \ + "($help)--digests[Show digests]" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_images_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ + "($help -): :__docker_complete_repositories" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (pull) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ + "($help)--disable-content-trust[Skip image verification]" \ + "($help -):name:__docker_search" && ret=0 + ;; + (push) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all-tags)"{-a,--all-tags}"[Push all tags of an image to the repository]" \ + "($help)--disable-content-trust[Skip image signing]" \ + "($help -): :__docker_complete_images" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help)--no-prune[Do not delete untagged parents]" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (save) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (tag) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):source:__docker_complete_images"\ + "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 + ;; + esac + + return ret +} + +# EO image + +# BO network + +__docker_network_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (driver) + __docker_complete_info_plugins Network && ret=0 + ;; + (id) + __docker_complete_networks_ids && ret=0 + ;; + (name) + __docker_complete_networks_names && ret=0 + ;; + (scope) + opts=('global' 'local' 'swarm') + _describe -t scope-filter-opts "Scope filter options" opts && ret=0 + ;; + (type) + opts=('builtin' 'custom') + _describe -t type-filter-opts "Type filter options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('driver' 'id' 'label' 'name' 'scope' 'type') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_get_networks() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines networks + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Network ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" + networks=($networks $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" + networks=($networks $s) + done + fi + + _describe -t networks-list "networks" networks "$@" && ret=0 + return ret +} + +__docker_complete_networks() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks all "$@" +} + +__docker_complete_networks_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks ids "$@" +} + +__docker_complete_networks_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks names "$@" +} + +__docker_network_commands() { + local -a _docker_network_subcommands + _docker_network_subcommands=( + "connect:Connect a container to a network" + "create:Creates a new network with a name specified by the user" + "disconnect:Disconnects a container from a network" + "inspect:Displays detailed information on a network" + "ls:Lists all the networks created by the user" + "prune:Remove all unused networks" + "rm:Deletes one or more networks" + ) + _describe -t docker-network-commands "docker network command" _docker_network_subcommands +} + +__docker_network_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (connect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ + "($help)--ip=[IPv4 address]:IPv4: " \ + "($help)--ip6=[IPv6 address]:IPv6: " \ + "($help)*--link=[Add a link to another container]:link:->link" \ + "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ + "($help -)1:network:__docker_complete_networks" \ + "($help -)2:containers:__docker_complete_containers" && ret=0 + + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)--attachable[Enable manual container attachment]" \ + "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ + "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ + "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ + "($help)--internal[Restricts external access to the network]" \ + "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ + "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ + "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help)*--label=[Set metadata on a network]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ + "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ + "($help -)1:Network Name: " && ret=0 + ;; + (disconnect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:network:__docker_complete_networks" \ + "($help -)2:containers:__docker_complete_containers" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--verbose[Show detailed information]" \ + "($help -)*:network:__docker_complete_networks" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--no-trunc[Do not truncate the output]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_network_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display network IDs]" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:network:__docker_complete_networks" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret +} + +# EO network + +# BO node + +__docker_node_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_nodes_ids && ret=0 + ;; + (membership) + membership_opts=('accepted' 'pending' 'rejected') + _describe -t membership-opts "membership options" membership_opts && ret=0 + ;; + (name) + __docker_complete_nodes_names && ret=0 + ;; + (role) + role_opts=('manager' 'worker') + _describe -t role-opts "role options" role_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'membership' 'name' 'node.label' 'role') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_node_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_nodes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines nodes args + + type=$1; shift + filter=$1; shift + [[ $filter != "none" ]] && args=("-f $filter") + + lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Node ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + nodes=($nodes $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[HOSTNAME]},${end[HOSTNAME]}]%% ##}" + nodes=($nodes $s) + done + fi + + _describe -t nodes-list "nodes" nodes "$@" && ret=0 + return ret +} + +__docker_complete_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all none "$@" +} + +__docker_complete_nodes_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes ids none "$@" +} + +__docker_complete_nodes_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes names none "$@" +} + +__docker_complete_pending_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "membership=pending" "$@" +} + +__docker_complete_manager_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=manager" "$@" +} + +__docker_complete_worker_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=worker" "$@" +} + +__docker_node_commands() { + local -a _docker_node_subcommands + _docker_node_subcommands=( + "demote:Demote a node as manager in the swarm" + "inspect:Display detailed information on one or more nodes" + "ls:List nodes in the swarm" + "promote:Promote a node as manager in the swarm" + "rm:Remove one or more nodes from the swarm" + "ps:List tasks running on one or more nodes, defaults to current node" + "update:Update a node" + ) + _describe -t docker-node-commands "docker node command" _docker_node_subcommands +} + +__docker_node_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ + "($help -)*:node:__docker_complete_pending_nodes" && ret=0 + ;; + (demote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_manager_nodes" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:node:__docker_complete_nodes" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ls_filters" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (promote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_worker_nodes" && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all instances]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ + "($help -)*:node:__docker_complete_nodes" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ + "($help)*--label-add=[Add or update a node label]:key=value: " \ + "($help)*--label-rm=[Remove a node label if exists]:label: " \ + "($help)--role=[Role of the node]:role:(manager worker)" \ + "($help -)1:node:__docker_complete_nodes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 + ;; + esac + + return ret +} + +# EO node + +# BO plugin + +__docker_plugin_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (capability) + opts=('authz' 'ipamdriver' 'logdriver' 'metricscollector' 'networkdriver' 'volumedriver') + _describe -t capability-opts "capability options" opts && ret=0 + ;; + (enabled) + opts=('false' 'true') + _describe -t enabled-opts "enabled options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('capability' 'enabled') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines plugins args + + filter=$1; shift + [[ $filter != "none" ]] && args=("-f $filter") + + lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls $args)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Name + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" + plugins=($plugins $s) + done + + _describe -t plugins-list "plugins" plugins "$@" && ret=0 + return ret +} + +__docker_complete_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins none "$@" +} + +__docker_complete_enabled_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins enabled=true "$@" +} + +__docker_complete_disabled_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins enabled=false "$@" +} + +__docker_plugin_commands() { + local -a _docker_plugin_subcommands + _docker_plugin_subcommands=( + "disable:Disable a plugin" + "enable:Enable a plugin" + "inspect:Return low-level information about a plugin" + "install:Install a plugin" + "ls:List plugins" + "push:Push a plugin" + "rm:Remove a plugin" + "set:Change settings for a plugin" + "upgrade:Upgrade an existing plugin" + ) + _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands +} + +__docker_plugin_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (disable) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the disable of an active plugin]" \ + "($help -)1:plugin:__docker_complete_enabled_plugins" && ret=0 + ;; + (enable) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--timeout=[HTTP client timeout (in seconds)]:timeout: " \ + "($help -)1:plugin:__docker_complete_disabled_plugins" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ + "($help -)*:plugin:__docker_complete_plugins" && ret=0 + ;; + (install) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--alias=[Local name for plugin]:alias: " \ + "($help)--disable[Do not enable the plugin on install]" \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -)*:key=value: " && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_plugin_complete_ls_filters" \ + "($help --format)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-trunc[Don't truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (push) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help -)1:plugin:__docker_complete_plugins" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the removal of an active plugin]" \ + "($help -)*:plugin:__docker_complete_plugins" && ret=0 + ;; + (set) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -)*:key=value: " && ret=0 + ;; + (upgrade) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ + "($help)--skip-remote-check[Do not check if specified remote plugin matches existing plugin image]" \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -):remote: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 + ;; + esac + + return ret +} + +# EO plugin + +# BO secret + +__docker_secrets() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines secrets + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + secrets=($secrets $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + secrets=($secrets $s) + done + fi + + _describe -t secrets-list "secrets" secrets "$@" && ret=0 + return ret +} + +__docker_complete_secrets() { + [[ $PREFIX = -* ]] && return 1 + __docker_secrets all "$@" +} + +__docker_secret_commands() { + local -a _docker_secret_subcommands + _docker_secret_subcommands=( + "create:Create a secret using stdin as content" + "inspect:Display detailed information on one or more secrets" + "ls:List secrets" + "rm:Remove one or more secrets" + ) + _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands +} + +__docker_secret_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)*"{-l=,--label=}"[Secret labels]:label: " \ + "($help -):secret: " && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ + "($help -)*:secret:__docker_complete_secrets" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:secret:__docker_complete_secrets" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 + ;; + esac + + return ret +} + +# EO secret + +# BO service + +__docker_service_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_services_ids && ret=0 + ;; + (mode) + opts=('global' 'replicated') + _describe -t mode-opts "mode options" opts && ret=0 + ;; + (name) + __docker_complete_services_names && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'mode' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_service_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_service_complete_placement_pref() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (spread) + opts=('engine.labels' 'node.labels') + _describe -t spread-opts "spread options" opts -qS "." && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('spread') + _describe -t pref-opts "placement pref options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_services() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines services + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Service ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + _describe -t services-list "services" services "$@" && ret=0 + return ret +} + +__docker_complete_services() { + [[ $PREFIX = -* ]] && return 1 + __docker_services all "$@" +} + +__docker_complete_services_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_services ids "$@" +} + +__docker_complete_services_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_services names "$@" +} + +__docker_service_commands() { + local -a _docker_service_subcommands + _docker_service_subcommands=( + "create:Create a new service" + "inspect:Display detailed information on one or more services" + "logs:Fetch the logs of a service or task" + "ls:List services" + "rm:Remove one or more services" + "rollback:Revert changes to a service's configuration" + "scale:Scale one or multiple replicated services" + "ps:List the tasks of a service" + "update:Update a service" + ) + _describe -t docker-service-commands "docker service command" _docker_service_subcommands +} + +__docker_service_subcommand() { + local -a _command_args opts_help opts_create_update + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + opts_create_update=( + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " + "($help)*--constraint=[Placement constraints]:constraint: " + "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" + "($help)*"{-e=,--env=}"[Set environment variables]:env: " + "($help)--health-cmd=[Command to run to check health]:command: " + "($help)--health-interval=[Time between running the check]:time: " + "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" + "($help)--health-timeout=[Maximum time to allow one check to run]:time: " + "($help)--hostname=[Service container hostname]:hostname: " \ + "($help)--isolation=[Service container isolation mode]:isolation:(default process hyperv)" \ + "($help)*--label=[Service labels]:label: " + "($help)--limit-cpu=[Limit CPUs]:value: " + "($help)--limit-memory=[Limit Memory]:value: " + "($help)--limit-pids[Limit maximum number of processes (default 0 = unlimited)]" + "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" + "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" + "($help)*--mount=[Attach a filesystem mount to the service]:mount: " + "($help)*--network=[Network attachments]:network: " + "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" + "($help)--read-only[Mount the container's root filesystem as read only]" + "($help)--replicas=[Number of tasks]:replicas: " + "($help)--reserve-cpu=[Reserve CPUs]:value: " + "($help)--reserve-memory=[Reserve Memory]:value: " + "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" + "($help)--restart-delay=[Delay between restart attempts]:delay: " + "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " + "($help)--restart-window=[Window used to evaluate the restart policy]:duration: " + "($help)--rollback-delay=[Delay between task rollbacks]:duration: " + "($help)--rollback-failure-action=[Action on rollback failure]:action:(continue pause)" + "($help)--rollback-max-failure-ratio=[Failure rate to tolerate during a rollback]:failure rate: " + "($help)--rollback-monitor=[Duration after each task rollback to monitor for failure]:duration: " + "($help)--rollback-parallelism=[Maximum number of tasks rolled back simultaneously]:number: " + "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" + "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " + "($help)--stop-signal=[Signal to stop the container]:signal:_signals" + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" + "($help)--update-delay=[Delay between updates]:delay: " + "($help)--update-failure-action=[Action on update failure]:mode:(continue pause rollback)" + "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " + "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " + "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)--with-registry-auth[Send registry authentication details to swarm agents]" + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)*--container-label=[Container labels]:label: " \ + "($help)*--dns=[Set custom DNS servers]:DNS: " \ + "($help)*--dns-option=[Set DNS options]:DNS option: " \ + "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ + "($help)*--group=[Set one or more supplementary user groups for the container]:group: _groups " \ + "($help)--mode=[Service Mode]:mode:(global replicated)" \ + "($help)--name=[Service name]:name: " \ + "($help)*--placement-pref=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (logs) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --follow)"{-f,--follow}"[Follow log output]" \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-task-ids[Do not include task IDs]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help)--since=[Show logs since timestamp]:timestamp: " \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ + "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ + "($help -)1:service:__docker_complete_services" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_service_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (rollback) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress progress output]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (scale) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ + "($help -)*:service:->values" && ret=0 + case $state in + (values) + if compset -P '*='; then + _message 'replicas' && ret=0 + else + __docker_complete_services -qS "=" + fi + ;; + esac + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_service_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)--arg=[Service command args]:arguments: _normal" \ + "($help)*--container-label-add=[Add or update container labels]:label: " \ + "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ + "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ + "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ + "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ + "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ + "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ + "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ + "($help)--force[Force update]" \ + "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ + "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ + "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ + "($help)*--placement-pref-add=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*--placement-pref-rm=[Remove a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*--publish-add=[Add or update a port]:port: " \ + "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ + "($help)--rollback[Rollback to previous specification]" \ + "($help -)1:service:__docker_complete_services" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 + ;; + esac + + return ret +} + +# EO service + +# BO stack + +__docker_stack_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_stack_complete_services_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_stacks() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines stacks + + lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Service NAME + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + stacks=($stacks $s) + done + + _describe -t stacks-list "stacks" stacks "$@" && ret=0 + return ret +} + +__docker_complete_stacks() { + [[ $PREFIX = -* ]] && return 1 + __docker_stacks "$@" +} + +__docker_stack_commands() { + local -a _docker_stack_subcommands + _docker_stack_subcommands=( + "deploy:Deploy a new stack or update an existing stack" + "ls:List stacks" + "ps:List the tasks in the stack" + "rm:Remove the stack" + "services:List the services in the stack" + ) + _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands +} + +__docker_stack_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (deploy|up) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file, or '-' to read from stdin]:compose file:_files -g \"*.(yml|yaml)\"" \ + "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all tasks]" \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (rm|remove|down) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (services) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 + ;; + esac + + return ret +} + +# EO stack + +# BO swarm + +__docker_swarm_commands() { + local -a _docker_swarm_subcommands + _docker_swarm_subcommands=( + "init:Initialize a swarm" + "join:Join a swarm as a node and/or manager" + "join-token:Manage join tokens" + "leave:Leave a swarm" + "unlock:Unlock swarm" + "unlock-key:Manage the unlock key" + "update:Update the swarm" + ) + _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands +} + +__docker_swarm_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (init) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--advertise-addr=[Advertised address]:ip\:port: " \ + "($help)--data-path-addr=[Data path IP or interface]:ip " \ + "($help)--data-path-port=[Data Path Port]:port " \ + "($help)--default-addr-pool=[Default address pool]" \ + "($help)--default-addr-pool-mask-length=[Default address pool subnet mask length]" \ + "($help)--autolock[Enable manager autolocking]" \ + "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ + "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ + "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ + "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ + "($help)--force-new-cluster[Force create a new cluster from current state]" \ + "($help)--listen-addr=[Listen address]:ip\:port: " \ + "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ + "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ + "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 + ;; + (join) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)--advertise-addr=[Advertised address]:ip\:port: " \ + "($help)--data-path-addr=[Data path IP or interface]:ip " \ + "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ + "($help)--listen-addr=[Listen address]:ip\:port: " \ + "($help)--token=[Token for entry into the swarm]:secret: " \ + "($help -):host\:port: " && ret=0 + ;; + (join-token) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ + "($help)--rotate[Rotate join token]" \ + "($help -):role:(manager worker)" && ret=0 + ;; + (leave) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 + ;; + (unlock) + _arguments $(__docker_arguments) \ + $opts_help && ret=0 + ;; + (unlock-key) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ + "($help)--rotate[Rotate unlock token]" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--autolock[Enable manager autolocking]" \ + "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ + "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ + "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ + "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ + "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ + "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret +} + +# EO swarm + +# BO system + +__docker_system_commands() { + local -a _docker_system_subcommands + _docker_system_subcommands=( + "df:Show docker filesystem usage" + "events:Get real time events from the server" + "info:Display system-wide information" + "prune:Remove unused data" + ) + _describe -t docker-system-commands "docker system command" _docker_system_subcommands +} + +__docker_system_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (df) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 + ;; + (events) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ + "($help)--since=[Events created since this timestamp]:timestamp: " \ + "($help)--until=[Events created until this timestamp]:timestamp: " \ + "($help)--format=[Format the output using the given go template]:template: " && ret=0 + ;; + (info) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" \ + "($help)--volumes=[Remove all unused volumes]" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 + ;; + esac + + return ret +} + +# EO system + +# BO volume + +__docker_volume_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (dangling) + dangling_opts=('true' 'false') + _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 + ;; + (driver) + __docker_complete_info_plugins Volume && ret=0 + ;; + (name) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('dangling' 'driver' 'label' 'name') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_volumes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a lines volumes + + lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Names + local line s + for line in $lines; do + s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + volumes=($volumes $s) + done + + _describe -t volumes-list "volumes" volumes && ret=0 + return ret +} + +__docker_volume_commands() { + local -a _docker_volume_subcommands + _docker_volume_subcommands=( + "create:Create a volume" + "inspect:Display detailed information on one or more volumes" + "ls:List volumes" + "prune:Remove all unused volumes" + "rm:Remove one or more volumes" + ) + _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands +} + +__docker_volume_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ + "($help)*--label=[Set metadata for a volume]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ + "($help -)1:Volume name: " && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)1:volume:__docker_complete_volumes" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_volume_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused local volumes, not just anonymous ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ + "($help -):volume:__docker_complete_volumes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 + ;; + esac + + return ret +} + +# EO volume + +# BO context + +__docker_complete_contexts() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a contexts + + contexts=(${(f)${:-"$(_call_program commands docker $docker_options context ls -q)"$'\n'}}) + + _describe -t context-list "context" contexts && ret=0 + return ret +} + +__docker_context_commands() { + local -a _docker_context_subcommands + _docker_context_subcommands=( + "create:Create new context" + "inspect:Display detailed information on one or more contexts" + "list:List available contexts" + "rm:Remove one or more contexts" + "show:Print the current context" + "update:Update a context" + "use:Set the default context" + ) + _describe -t docker-context-commands "docker context command" _docker_context_subcommands +} + +__docker_context_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--description=[Description of the context]:description:" \ + "($help)--docker=[Set the docker endpoint]:docker:" \ + "($help)--from=[Create context from a named context]:from:__docker_complete_contexts" \ + "($help -):name: " && ret=0 + ;; + (use) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--description=[Description of the context]:description:" \ + "($help)--docker=[Set the docker endpoint]:docker:" \ + "($help -):name:" && ret=0 + ;; + esac + + return ret +} + +# EO context + +__docker_caching_policy() { + oldp=( "$1"(Nmh+1) ) # 1 hour + (( $#oldp )) +} + +__docker_commands() { + local cache_policy + integer force_invalidation=0 + + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + if ( (( ! ${+_docker_hide_legacy_commands} )) || _cache_invalid docker_hide_legacy_commands ) \ + && ! _retrieve_cache docker_hide_legacy_commands; + then + _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" + _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands + fi + + if [[ "${_docker_hide_legacy_commands}" != "${DOCKER_HIDE_LEGACY_COMMANDS}" ]]; then + force_invalidation=1 + _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" + _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands + fi + + if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands ) \ + && ! _retrieve_cache docker_subcommands || [[ ${force_invalidation} -eq 1 ]]; + then + local -a lines + lines=(${(f)"$(_call_program commands docker 2>&1)"}) + _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/\*# ##/:}) + _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') + (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands + fi + _describe -t docker-commands "docker command" _docker_subcommands +} + +__docker_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) + __docker_container_subcommand && ret=0 + ;; + (build|history|import|load|pull|push|save|tag) + __docker_image_subcommand && ret=0 + ;; + (checkpoint) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_checkpoint_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_checkpoint_subcommand && ret=0 + ;; + esac + ;; + (container) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_container_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_container_subcommand && ret=0 + ;; + esac + ;; + (context) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_context_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_context_subcommand && ret=0 + ;; + esac + ;; + (daemon) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ + "($help)*--allow-nondistributable-artifacts=[Push nondistributable artifacts to specified registries]:registry: " \ + "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ + "($help)*--authorization-plugin=[Authorization plugins to load]" \ + "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ + "($help)--bip=[Network bridge IP]:IP address: " \ + "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ + "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ + "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ + "($help)--containerd-namespace=[Containerd namespace to use]:containerd namespace:" \ + "($help)--containerd-plugins-namespace=[Containerd namespace to use for plugins]:containerd namespace:" \ + "($help)--data-root=[Root directory of persisted Docker data]:path:_directories" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ + "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ + "($help)--default-shm-size=[Default shm size for containers]:size:" \ + "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ + "($help)*--dns=[DNS server to use]:DNS: " \ + "($help)*--dns-opt=[DNS options to use]:DNS option: " \ + "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ + "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ + "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ + "($help)--experimental[Enable experimental features]" \ + "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ + "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ + "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help)--icc[Enable inter-container communication]" \ + "($help)--init[Run an init inside containers to forward signals and reap processes]" \ + "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ + "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ + "($help)--ip=[Default IP when binding container ports]" \ + "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ + "($help)--ip-masq[Enable IP masquerading]" \ + "($help)--iptables[Enable addition of iptables rules]" \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)*--label=[Key=value labels]:label: " \ + "($help)--live-restore[Enable live restore of docker when containers are still running]" \ + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ + "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ + "($help)--max-concurrent-downloads[Set the max concurrent downloads]" \ + "($help)--max-concurrent-uploads[Set the max concurrent uploads]" \ + "($help)--max-download-attempts[Set the max download attempts for each pull]" \ + "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ + "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ + "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ + "($help)--raw-logs[Full timestamps without ANSI coloring]" \ + "($help)*--registry-mirror=[Preferred registry mirror]:registry mirror: " \ + "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ + "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(btrfs devicemapper overlay2 vfs zfs)" \ + "($help)--selinux-enabled[Enable selinux support]" \ + "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ + "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ + "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" \ + "($help)--validate[Validate daemon configuration and exit]" && ret=0 + + case $state in + (users-groups) + if compset -P '*:'; then + _groups && ret=0 + else + _describe -t userns-default "default Docker user management" '(default)' && ret=0 + _users && ret=0 + fi + ;; + esac + ;; + (events|info) + __docker_system_subcommand && ret=0 + ;; + (image) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_image_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_image_subcommand && ret=0 + ;; + esac + ;; + (images) + words[1]='ls' + __docker_image_subcommand && ret=0 + ;; + (inspect) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ + "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ + "($help -)*: :->values" && ret=0 + + case $state in + (values) + if [[ ${words[(r)--type=container]} == --type=container ]]; then + __docker_complete_containers && ret=0 + elif [[ ${words[(r)--type=image]} == --type=image ]]; then + __docker_complete_images && ret=0 + elif [[ ${words[(r)--type=network]} == --type=network ]]; then + __docker_complete_networks && ret=0 + elif [[ ${words[(r)--type=node]} == --type=node ]]; then + __docker_complete_nodes && ret=0 + elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then + __docker_complete_plugins && ret=0 + elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then + __docker_complete_secrets && ret=0 + elif [[ ${words[(r)--type=service]} == --type=service ]]; then + __docker_complete_services && ret=0 + elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then + __docker_complete_volumes && ret=0 + else + __docker_complete_containers + __docker_complete_images + __docker_complete_networks + __docker_complete_nodes + __docker_complete_plugins + __docker_complete_secrets + __docker_complete_services + __docker_complete_volumes && ret=0 + fi + ;; + esac + ;; + (login) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -p --password)"{-p=,--password=}"[Password]:password: " \ + "($help)--password-stdin[Read password from stdin]" \ + "($help -u --username)"{-u=,--username=}"[Username]:username: " \ + "($help -)1:server: " && ret=0 + ;; + (logout) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -)1:server: " && ret=0 + ;; + (network) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_network_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_network_subcommand && ret=0 + ;; + esac + ;; + (node) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_node_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_node_subcommand && ret=0 + ;; + esac + ;; + (plugin) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_plugin_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_plugin_subcommand && ret=0 + ;; + esac + ;; + (ps) + words[1]='ls' + __docker_container_subcommand && ret=0 + ;; + (rmi) + words[1]='rm' + __docker_image_subcommand && ret=0 + ;; + (search) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_search_filters" \ + "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -):term: " && ret=0 + ;; + (secret) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_secret_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_secret_subcommand && ret=0 + ;; + esac + ;; + (service) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_service_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_service_subcommand && ret=0 + ;; + esac + ;; + (stack) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_stack_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_stack_subcommand && ret=0 + ;; + esac + ;; + (swarm) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_swarm_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_swarm_subcommand && ret=0 + ;; + esac + ;; + (system) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_system_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_system_subcommand && ret=0 + ;; + esac + ;; + (version) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 + ;; + (volume) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_volume_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_volume_subcommand && ret=0 + ;; + esac + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 + ;; + esac + + return ret +} + +_docker() { + # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. + # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. + if [[ $service != docker ]]; then + _call_function - _$service + return + fi + + local curcontext="$curcontext" state line help="-h --help" + integer ret=1 + typeset -A opt_args + + _arguments $(__docker_arguments) -C \ + "(: -)"{-h,--help}"[Print usage]" \ + "($help)--config[Location of client config files]:path:_directories" \ + "($help -c --context)"{-c=,--context=}"[Execute the command in a docker context]:context:__docker_complete_contexts" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ + "($help -v --version)"{-v,--version}"[Print version information and quit]" \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + local host=${opt_args[-H]}${opt_args[--host]} + local config=${opt_args[--config]} + local context=${opt_args[-c]}${opt_args[--context]} + local docker_options="${host:+--host $host} ${config:+--config $config} ${context:+--context $context} " + + case $state in + (command) + __docker_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-$words[1]: + __docker_subcommand && ret=0 + ;; + esac + + return ret +} + +_dockerd() { + integer ret=1 + words[1]='daemon' + __docker_subcommand && ret=0 + return ret +} + +_docker "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 4 +# indent-tabs-mode: nil +# sh-basic-offset: 4 +# End: +# vim: ft=zsh sw=4 ts=4 et -- cgit v1.2.3-70-g09d2 From 73c4764e78947864c6f067df3bec4cff02866eb2 Mon Sep 17 00:00:00 2001 From: Andrei Polushin Date: Thu, 29 Jun 2023 13:25:41 +0200 Subject: fix(docker): use `docker --version` instead of `docker version` `docker version` subcommand is able to return both docker client and docker daemon information. To get a daemon version, it connects to a possibly remote daemon. If the remote daemon is not accessible, the client waits for some time, until it gets interrupted by timeout. As a result we can have a docker client running in background. When zsh session is rather short, a terminal application (iTerm2) starts asking if that background docker process should be stopped. On the other hand, to get a docker client version only, we can use `docker --version` instead. It does not connect to a daemon. Closes #11780 --- plugins/docker/docker.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index 434b1fc60..3abce6466 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -37,8 +37,10 @@ if (( ! $+commands[docker] )); then fi { + # docker version returns `Docker version 24.0.2, build cb74dfcd85` + # with `s:,:` remove the comma after the version, and select third word of it + local _docker_version=${${(s:,:z)"$(command docker --version)"}[3]} # `docker completion` is only available from 23.0.0 on - local _docker_version=$(command docker version --format '{{.Client.Version}}' 2>/dev/null) if is-at-least 23.0.0 $_docker_version; then # If the completion file doesn't exist yet, we need to autoload it and # bind it to `docker`. Otherwise, compinit will have already done that. -- cgit v1.2.3-70-g09d2 From 54779e5250f362ebd1cf6a7094657f2c894958c3 Mon Sep 17 00:00:00 2001 From: Matthias Heyman Date: Thu, 29 Jun 2023 13:29:14 +0200 Subject: fix(jira): support identifiers delimited with a hyphen (#11782) Co-authored-by: Matthias Heyman --- plugins/jira/jira.plugin.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index e789fce92..b6ee9f100 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -80,7 +80,13 @@ function jira() { issue_arg=${issue_arg##*/} # Strip suffixes starting with _ issue_arg=(${(s:_:)issue_arg}) - issue_arg=${issue_arg[1]} + # If there is only one part, it means that there is a different delimiter. Try with - + if [[ ${#issue_arg[@]} = 1 && ${issue_arg} == *-* ]]; then + issue_arg=(${(s:-:)issue_arg}) + issue_arg="${issue_arg[1]}-${issue_arg[2]}" + else + issue_arg=${issue_arg[1]} + fi if [[ "${issue_arg:l}" = ${jira_prefix:l}* ]]; then issue="${issue_arg}" else -- cgit v1.2.3-70-g09d2 From fe4b5659863c388786986d70fa6d1bb66b00afb6 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Fri, 30 Jun 2023 11:41:44 +0200 Subject: fix(docker): only load old completion if docker <23 --- plugins/docker/_docker | 3126 ------------------------------------ plugins/docker/completions/_docker | 3126 ++++++++++++++++++++++++++++++++++++ plugins/docker/docker.plugin.zsh | 7 + 3 files changed, 3133 insertions(+), 3126 deletions(-) delete mode 100644 plugins/docker/_docker create mode 100644 plugins/docker/completions/_docker diff --git a/plugins/docker/_docker b/plugins/docker/_docker deleted file mode 100644 index 466b09d94..000000000 --- a/plugins/docker/_docker +++ /dev/null @@ -1,3126 +0,0 @@ -#compdef docker dockerd -# -# zsh completion for docker (http://docker.com) -# -# version: 0.3.0 -# github: https://github.com/felixr/docker-zsh-completion -# -# contributors: -# - Felix Riedel -# - Steve Durrheimer -# - Vincent Bernat -# - Rohan Verma -# -# license: -# -# Copyright (c) 2013, Felix Riedel -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -# Short-option stacking can be enabled with: -# zstyle ':completion:*:*:docker:*' option-stacking yes -# zstyle ':completion:*:*:docker-*:*' option-stacking yes -__docker_arguments() { - if zstyle -t ":completion:${curcontext}:" option-stacking; then - print -- -s - fi -} - -__docker_get_containers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local kind type line s - declare -a running stopped lines args names - - kind=$1; shift - type=$1; shift - [[ $kind = (stopped|all) ]] && args=($args -a) - - lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line - lines=(${lines[2,-1]}) - - # Container ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - # Names: we only display the one without slash. All other names - # are generated and may clutter the completion. However, with - # Swarm, all names may be prefixed by the swarm node name. - if [[ $type = (names|all) ]]; then - for line in $lines; do - names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) - # First step: find a common prefix and strip it (swarm node case) - (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} - # Second step: only keep the first name without a / - s=${${names:#*/*}[1]} - # If no name, well give up. - (( $#s != 0 )) || continue - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 - [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 - return ret -} - -__docker_complete_stopped_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers stopped all "$@" -} - -__docker_complete_running_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers running all "$@" -} - -__docker_complete_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all all "$@" -} - -__docker_complete_containers_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all ids "$@" -} - -__docker_complete_containers_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all names "$@" -} - -__docker_complete_info_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - emulate -L zsh - setopt extendedglob - local -a plugins - plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) - _describe -t plugins "$1 plugins" plugins && ret=0 - return ret -} - -__docker_complete_images() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a images - images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) - _describe -t docker-images "images" images && ret=0 - __docker_complete_repositories_with_tags && ret=0 - return ret -} - -__docker_complete_repositories() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos - repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) - repos=(${repos#}) - _describe -t docker-repos "repositories" repos && ret=0 - return ret -} - -__docker_complete_repositories_with_tags() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos onlyrepos matched - declare m - repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) - repos=(${${repos%:::}#}) - # Check if we have a prefix-match for the current prefix. - onlyrepos=(${repos%::*}) - for m in $onlyrepos; do - [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { - # Yes, complete with tags - repos=(${${repos/:::/:}/:/\\:}) - _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 - return ret - } - done - # No, only complete repositories - onlyrepos=(${${repos%:::*}/:/\\:}) - _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 - - return ret -} - -__docker_search() { - [[ $PREFIX = -* ]] && return 1 - local cache_policy - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - local searchterm cachename - searchterm="${words[$CURRENT]%/}" - cachename=_docker-search-$searchterm - - local expl - local -a result - if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ - && ! _retrieve_cache ${cachename#_}; then - _message "Searching for ${searchterm}..." - result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) - _store_cache ${cachename#_} result - fi - _wanted dockersearch expl 'available images' compadd -a result -} - -__docker_get_log_options() { - [[ $PREFIX = -* ]] && return 1 - - integer ret=1 - local log_driver=${opt_args[--log-driver]:-"all"} - local -a common_options common_options2 awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options - - common_options=("max-buffer-size" "mode") - common_options2=("env" "env-regex" "labels") - awslogs_options=($common_options "awslogs-create-group" "awslogs-datetime-format" "awslogs-group" "awslogs-multiline-pattern" "awslogs-region" "awslogs-stream" "tag") - fluentd_options=($common_options $common_options2 "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "fluentd-sub-second-precision" "tag") - gcplogs_options=($common_options $common_options2 "gcp-log-cmd" "gcp-meta-id" "gcp-meta-name" "gcp-meta-zone" "gcp-project") - gelf_options=($common_options $common_options2 "gelf-address" "gelf-compression-level" "gelf-compression-type" "tag") - journald_options=($common_options $common_options2 "tag") - json_file_options=($common_options $common_options2 "max-file" "max-size") - logentries_options=($common_options $common_options2 "logentries-token" "tag") - syslog_options=($common_options $common_options2 "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") - splunk_options=($common_options $common_options2 "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") - - [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 - [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 - [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 - [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 - [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 - [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 - [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 - [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 - [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 - - return ret -} - -__docker_complete_log_drivers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) - _describe -t log-drivers "log drivers" drivers && ret=0 - return ret -} - -__docker_complete_log_options() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (syslog-format) - local opts=('rfc3164' 'rfc5424' 'rfc5424micro') - _describe -t syslog-format-opts "syslog format options" opts && ret=0 - ;; - (mode) - local opts=('blocking' 'non-blocking') - _describe -t mode-opts "mode options" opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - __docker_get_log_options -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_detach_keys() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - compset -P "*," - keys=(${:-{a-z}}) - ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) - _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 - _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 -} - -__docker_complete_pid() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local -a opts vopts - - opts=('host') - vopts=('container') - - if compset -P '*:'; then - case "${${words[-1]%:*}#*=}" in - (container) - __docker_complete_running_containers && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 - _describe -t pid-opts "PID Options" opts && ret=0 - fi - - return ret -} - -__docker_complete_runtimes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - emulate -L zsh - setopt extendedglob - local -a runtimes_opts - runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) - _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 -} - -__docker_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (ancestor) - __docker_complete_images && ret=0 - ;; - (before|since) - __docker_complete_containers && ret=0 - ;; - (health) - health_opts=('healthy' 'none' 'starting' 'unhealthy') - _describe -t health-filter-opts "health filter options" health_opts && ret=0 - ;; - (id) - __docker_complete_containers_ids && ret=0 - ;; - (is-task) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - (name) - __docker_complete_containers_names && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (status) - status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') - _describe -t status-filter-opts "status filter options" status_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('ancestor' 'before' 'exited' 'expose' 'health' 'id' 'label' 'name' 'network' 'publish' 'since' 'status' 'volume') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_search_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('is-automated' 'is-official' 'stars') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (is-automated|is-official) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_images_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('before' 'dangling' 'label' 'reference' 'since') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (before|reference|since) - __docker_complete_images && ret=0 - ;; - (dangling) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_events_filter() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a opts - - opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'scope' 'type' 'volume') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (container) - __docker_complete_containers && ret=0 - ;; - (daemon) - emulate -L zsh - setopt extendedglob - local -a daemon_opts - daemon_opts=( - ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} - ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} - ) - _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 - ;; - (event) - local -a event_opts - event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disable' 'disconnect' 'enable' 'exec_create' 'exec_detach' - 'exec_start' 'export' 'health_status' 'import' 'install' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'remove' 'rename' 'resize' - 'restart' 'save' 'start' 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') - _describe -t event-filter-opts "event filter options" event_opts && ret=0 - ;; - (image) - __docker_complete_images && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (scope) - local -a scope_opts - scope_opts=('local' 'swarm') - _describe -t scope-filter-opts "scope filter options" scope_opts && ret=0 - ;; - (type) - local -a type_opts - type_opts=('container' 'daemon' 'image' 'network' 'volume') - _describe -t type-filter-opts "type filter options" type_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_prune_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a opts - - opts=('until') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -# BO checkpoint - -__docker_checkpoint_commands() { - local -a _docker_checkpoint_subcommands - _docker_checkpoint_subcommands=( - "create:Create a checkpoint from a running container" - "ls:List checkpoints for a container" - "rm:Remove a checkpoint" - ) - _describe -t docker-checkpoint-commands "docker checkpoint command" _docker_checkpoint_subcommands -} - -__docker_checkpoint_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ - "($help)--leave-running[Leave the container running after checkpoint]" \ - "($help -)1:container:__docker_complete_running_containers" \ - "($help -)2:checkpoint: " && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ - "($help -)1:container:__docker_complete_containers" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ - "($help -)1:container:__docker_complete_containers" \ - "($help -)2:checkpoint: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_checkpoint_commands" && ret=0 - ;; - esac - - return ret -} - -# EO checkpoint - -# BO container - -__docker_container_commands() { - local -a _docker_container_subcommands - _docker_container_subcommands=( - "attach:Attach to a running container" - "commit:Create a new image from a container's changes" - "cp:Copy files/folders between a container and the local filesystem" - "create:Create a new container" - "diff:Inspect changes on a container's filesystem" - "exec:Execute a command in a running container" - "export:Export a container's filesystem as a tar archive" - "inspect:Display detailed information on one or more containers" - "kill:Kill one or more running containers" - "logs:Fetch the logs of a container" - "ls:List containers" - "pause:Pause all processes within one or more containers" - "port:List port mappings or a specific mapping for the container" - "prune:Remove all stopped containers" - "rename:Rename a container" - "restart:Restart one or more containers" - "rm:Remove one or more containers" - "run:Create and run a new container from an image" - "start:Start one or more stopped containers" - "stats:Display a live stream of container(s) resource usage statistics" - "stop:Stop one or more running containers" - "top:Display the running processes of a container" - "unpause:Unpause all processes within one or more containers" - "update:Update configuration of one or more containers" - "wait:Block until one or more containers stop, then print their exit codes" - ) - _describe -t docker-container-commands "docker container command" _docker_container_subcommands -} - -__docker_container_subcommand() { - local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update - local expl help="--help" - integer ret=1 - - opts_attach_exec_run_start=( - "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" - ) - opts_create_run=( - "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" - "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " - "($help)*--annotation=[Add an annotation to the container (passed through to the OCI runtime)]:annotations: " - "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " - "($help)*--cap-add=[Add Linux capabilities]:capability: " - "($help)*--cap-drop=[Drop Linux capabilities]:capability: " - "($help)--cgroupns=[Cgroup namespace mode to use]:cgroup namespace mode: " - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " - "($help)--cidfile=[Write the container ID to the file]:CID file:_files" - "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " - "($help)*--device=[Add a host device to the container]:device:_files" - "($help)*--device-cgroup-rule=[Add a rule to the cgroup allowed devices list]:device:cgroup: " - "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " - "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " - "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " - "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " - "($help)--disable-content-trust[Skip image verification]" - "($help)*--dns=[Custom DNS servers]:DNS server: " - "($help)*--dns-option=[Custom DNS options]:DNS option: " - "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " - "($help)*--domainname=[Container NIS domain name]:domainname:_hosts" - "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " - "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" - "($help)*--expose=[Expose a port from the container without publishing it]: " - "($help)*--gpus=[GPU devices to add to the container ('all' to pass all GPUs)]:device: " - "($help)*--group-add=[Set one or more supplementary user groups for the container]:group:_groups" - "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" - "($help)--init[Run an init inside the container that forwards signals and reaps processes]" - "($help)--ip=[IPv4 address]:IPv4: " - "($help)--ip6=[IPv6 address]:IPv6: " - "($help)--ipc=[IPC namespace to use]:IPC namespace: " - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" - "($help)*--link=[Add link to another container]:link:->link" - "($help)*--link-local-ip=[Container IPv4/IPv6 link-local addresses]:IPv4/IPv6: " - "($help)*"{-l=,--label=}"[Container metadata]:label: " - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" - "($help)--mac-address=[Container MAC address]:MAC address: " - "($help)*--mount=[Attach a filesystem mount to the container]:mount: " - "($help)--name=[Container name]:name: " - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" - "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " - "($help)--oom-kill-disable[Disable OOM Killer]" - "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" - "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" - "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" - "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" - "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" - "($help)--privileged[Give extended privileges to this container]" - "($help -q --quiet)"{-q,--quiet}"[Suppress the pull output]" - "($help)--read-only[Mount the container's root filesystem as read only]" - "($help)*--security-opt=[Security options]:security option: " - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " - "($help)--stop-signal=[Signal to kill a container]:signal:_signals" - "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " - "($help)*--sysctl=-[sysctl options]:sysctl: " - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)*--ulimit=[ulimit options]:ulimit: " - "($help)--userns=[Container user namespace]:user namespace:(host)" - "($help)--tmpfs[mount tmpfs]" - "($help)*-v[Bind mount a volume]:volume:_directories -W / -P '/' -S '\:' -r '/ '" - "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" - "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - opts_create_run_update=( - "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " - "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " - "($help)--memory-reservation=[Memory soft limit]:Memory limit: " - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " - "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" - "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" - ) - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help)--no-stdin[Do not attach stdin]" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help -):containers:__docker_complete_running_containers" && ret=0 - ;; - (commit) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --author)"{-a=,--author=}"[Author]:author: " \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ - "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ - "($help -):container:__docker_complete_containers" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (cp) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ - "($help -)1:container:->container" \ - "($help -)2:hostpath:_files" && ret=0 - case $state in - (container) - if compset -P "*:"; then - _files && ret=0 - else - __docker_complete_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (diff) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (exec) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ - "($help)--privileged[Give extended Linux capabilities to the command]" \ - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" \ - "($help -):containers:__docker_complete_running_containers" \ - "($help -)*::command:->anycommand" && ret=0 - case $state in - (anycommand) - shift 1 words - (( CURRENT-- )) - _normal && ret=0 - ;; - esac - ;; - (export) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (kill) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (logs) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--details[Show extra details provided to logs]" \ - "($help -f --follow)"{-f,--follow}"[Follow log output]" \ - "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ - "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ - "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers]" \ - "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ - "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show container IDs]" \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 - ;; - (pause|unpause) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (port) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)2:port:_ports" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rename) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):old name:__docker_complete_containers" \ - "($help -):new name: " && ret=0 - ;; - (restart) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (rm) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ - "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ - "($help -)*:containers:->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then - __docker_complete_containers && ret=0 - else - __docker_complete_stopped_containers && ret=0 - fi - ;; - esac - ;; - (run) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)--health-cmd=[Command to run to check health]:command: " \ - "($help)--health-interval=[Time between running the check]:time: " \ - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ - "($help)--rm[Remove intermediate containers when it exits]" \ - "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - (storage-opt) - if compset -P "*="; then - _message "value" && ret=0 - else - opts=('size') - _describe -t filter-opts "storage options" opts -qS "=" && ret=0 - fi - ;; - esac - ;; - (start) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ - "($help -i --interactive)"{-i,--interactive}"[Attach container's stdin]" \ - "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 - ;; - (stats) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help)--no-stream[Disable streaming stats and only pull the first result]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (stop) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (top) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)*:: :->ps-arguments" && ret=0 - case $state in - (ps-arguments) - _ps && ret=0 - ;; - esac - ;; - (update) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run_update \ - "($help -)*: :->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then - __docker_complete_stopped_containers && ret=0 - else - __docker_complete_containers && ret=0 - fi - ;; - esac - ;; - (wait) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO container - -# BO image - -__docker_image_commands() { - local -a _docker_image_subcommands - _docker_image_subcommands=( - "build:Build an image from a Dockerfile" - "history:Show the history of an image" - "import:Import the contents from a tarball to create a filesystem image" - "inspect:Display detailed information on one or more images" - "load:Load an image from a tar archive or STDIN" - "ls:List images" - "prune:Remove unused images" - "pull:Download an image from a registry" - "push:Upload an image to a registry" - "rm:Remove one or more images" - "save:Save one or more images to a tar archive (streamed to STDOUT by default)" - "tag:Tag an image into a repository" - ) - _describe -t docker-image-commands "docker image command" _docker_image_subcommands -} - -__docker_image_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (build) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " \ - "($help)*--build-arg=[Build-time variables]:=: " \ - "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ - "($help)--compress[Compress the build context using gzip]" \ - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ - "($help)--force-rm[Always remove intermediate containers]" \ - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ - "($help)*--label=[Set metadata for an image]:label=value: " \ - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ - "($help)--no-cache[Do not use cache when building the image]" \ - "($help)--pull[Attempt to pull a newer version of the image]" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ - "($help)--rm[Remove intermediate containers after a successful build]" \ - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ - "($help)--squash[Squash newly built layers into a single new layer]" \ - "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ - "($help)--target=[Set the target build stage to build.]" \ - "($help)*--ulimit=[ulimit options]:ulimit: " \ - "($help)--userns=[Container user namespace]:user namespace:(host)" \ - "($help -):path or URL:_directories" && ret=0 - ;; - (history) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (import) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ - "($help -):URL:(- http:// file://)" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)*:images:__docker_complete_images" && ret=0 - ;; - (load) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 - ;; - (ls|list) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all images]" \ - "($help)--digests[Show digests]" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_images_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ - "($help -): :__docker_complete_repositories" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (pull) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -):name:__docker_search" && ret=0 - ;; - (push) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all-tags)"{-a,--all-tags}"[Push all tags of an image to the repository]" \ - "($help)--disable-content-trust[Skip image signing]" \ - "($help -): :__docker_complete_images" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help)--no-prune[Do not delete untagged parents]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (save) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (tag) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):source:__docker_complete_images"\ - "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO image - -# BO network - -__docker_network_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (driver) - __docker_complete_info_plugins Network && ret=0 - ;; - (id) - __docker_complete_networks_ids && ret=0 - ;; - (name) - __docker_complete_networks_names && ret=0 - ;; - (scope) - opts=('global' 'local' 'swarm') - _describe -t scope-filter-opts "Scope filter options" opts && ret=0 - ;; - (type) - opts=('builtin' 'custom') - _describe -t type-filter-opts "Type filter options" opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('driver' 'id' 'label' 'name' 'scope' 'type') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_get_networks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines networks - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Network ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - _describe -t networks-list "networks" networks "$@" && ret=0 - return ret -} - -__docker_complete_networks() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks all "$@" -} - -__docker_complete_networks_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks ids "$@" -} - -__docker_complete_networks_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks names "$@" -} - -__docker_network_commands() { - local -a _docker_network_subcommands - _docker_network_subcommands=( - "connect:Connect a container to a network" - "create:Creates a new network with a name specified by the user" - "disconnect:Disconnects a container from a network" - "inspect:Displays detailed information on a network" - "ls:Lists all the networks created by the user" - "prune:Remove all unused networks" - "rm:Deletes one or more networks" - ) - _describe -t docker-network-commands "docker network command" _docker_network_subcommands -} - -__docker_network_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (connect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ - "($help)--ip=[IPv4 address]:IPv4: " \ - "($help)--ip6=[IPv6 address]:IPv6: " \ - "($help)*--link=[Add a link to another container]:link:->link" \ - "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)--attachable[Enable manual container attachment]" \ - "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ - "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ - "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ - "($help)--internal[Restricts external access to the network]" \ - "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ - "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ - "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help)*--label=[Set metadata on a network]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ - "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ - "($help -)1:Network Name: " && ret=0 - ;; - (disconnect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--verbose[Show detailed information]" \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--no-trunc[Do not truncate the output]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_network_complete_ls_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display network IDs]" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO network - -# BO node - -__docker_node_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_nodes_ids && ret=0 - ;; - (membership) - membership_opts=('accepted' 'pending' 'rejected') - _describe -t membership-opts "membership options" membership_opts && ret=0 - ;; - (name) - __docker_complete_nodes_names && ret=0 - ;; - (role) - role_opts=('manager' 'worker') - _describe -t role-opts "role options" role_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'membership' 'name' 'node.label' 'role') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_node_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running' 'shutdown') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_nodes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines nodes args - - type=$1; shift - filter=$1; shift - [[ $filter != "none" ]] && args=("-f $filter") - - lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Node ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - nodes=($nodes $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[HOSTNAME]},${end[HOSTNAME]}]%% ##}" - nodes=($nodes $s) - done - fi - - _describe -t nodes-list "nodes" nodes "$@" && ret=0 - return ret -} - -__docker_complete_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all none "$@" -} - -__docker_complete_nodes_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes ids none "$@" -} - -__docker_complete_nodes_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes names none "$@" -} - -__docker_complete_pending_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "membership=pending" "$@" -} - -__docker_complete_manager_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=manager" "$@" -} - -__docker_complete_worker_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=worker" "$@" -} - -__docker_node_commands() { - local -a _docker_node_subcommands - _docker_node_subcommands=( - "demote:Demote a node as manager in the swarm" - "inspect:Display detailed information on one or more nodes" - "ls:List nodes in the swarm" - "promote:Promote a node as manager in the swarm" - "rm:Remove one or more nodes from the swarm" - "ps:List tasks running on one or more nodes, defaults to current node" - "update:Update a node" - ) - _describe -t docker-node-commands "docker node command" _docker_node_subcommands -} - -__docker_node_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ - "($help -)*:node:__docker_complete_pending_nodes" && ret=0 - ;; - (demote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_manager_nodes" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ls_filters" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (promote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_worker_nodes" && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all instances]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ps_filters" \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ - "($help)*--label-add=[Add or update a node label]:key=value: " \ - "($help)*--label-rm=[Remove a node label if exists]:label: " \ - "($help)--role=[Role of the node]:role:(manager worker)" \ - "($help -)1:node:__docker_complete_nodes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 - ;; - esac - - return ret -} - -# EO node - -# BO plugin - -__docker_plugin_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (capability) - opts=('authz' 'ipamdriver' 'logdriver' 'metricscollector' 'networkdriver' 'volumedriver') - _describe -t capability-opts "capability options" opts && ret=0 - ;; - (enabled) - opts=('false' 'true') - _describe -t enabled-opts "enabled options" opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('capability' 'enabled') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines plugins args - - filter=$1; shift - [[ $filter != "none" ]] && args=("-f $filter") - - lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls $args)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Name - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" - plugins=($plugins $s) - done - - _describe -t plugins-list "plugins" plugins "$@" && ret=0 - return ret -} - -__docker_complete_plugins() { - [[ $PREFIX = -* ]] && return 1 - __docker_plugins none "$@" -} - -__docker_complete_enabled_plugins() { - [[ $PREFIX = -* ]] && return 1 - __docker_plugins enabled=true "$@" -} - -__docker_complete_disabled_plugins() { - [[ $PREFIX = -* ]] && return 1 - __docker_plugins enabled=false "$@" -} - -__docker_plugin_commands() { - local -a _docker_plugin_subcommands - _docker_plugin_subcommands=( - "disable:Disable a plugin" - "enable:Enable a plugin" - "inspect:Return low-level information about a plugin" - "install:Install a plugin" - "ls:List plugins" - "push:Push a plugin" - "rm:Remove a plugin" - "set:Change settings for a plugin" - "upgrade:Upgrade an existing plugin" - ) - _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands -} - -__docker_plugin_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (disable) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the disable of an active plugin]" \ - "($help -)1:plugin:__docker_complete_enabled_plugins" && ret=0 - ;; - (enable) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--timeout=[HTTP client timeout (in seconds)]:timeout: " \ - "($help -)1:plugin:__docker_complete_disabled_plugins" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ - "($help -)*:plugin:__docker_complete_plugins" && ret=0 - ;; - (install) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--alias=[Local name for plugin]:alias: " \ - "($help)--disable[Do not enable the plugin on install]" \ - "($help)--disable-content-trust[Skip image verification (default true)]" \ - "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help -)*:key=value: " && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_plugin_complete_ls_filters" \ - "($help --format)--format=[Format the output using the given Go template]:template: " \ - "($help)--no-trunc[Don't truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (push) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--disable-content-trust[Skip image verification (default true)]" \ - "($help -)1:plugin:__docker_complete_plugins" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the removal of an active plugin]" \ - "($help -)*:plugin:__docker_complete_plugins" && ret=0 - ;; - (set) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help -)*:key=value: " && ret=0 - ;; - (upgrade) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--disable-content-trust[Skip image verification (default true)]" \ - "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ - "($help)--skip-remote-check[Do not check if specified remote plugin matches existing plugin image]" \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help -):remote: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 - ;; - esac - - return ret -} - -# EO plugin - -# BO secret - -__docker_secrets() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines secrets - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - secrets=($secrets $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - secrets=($secrets $s) - done - fi - - _describe -t secrets-list "secrets" secrets "$@" && ret=0 - return ret -} - -__docker_complete_secrets() { - [[ $PREFIX = -* ]] && return 1 - __docker_secrets all "$@" -} - -__docker_secret_commands() { - local -a _docker_secret_subcommands - _docker_secret_subcommands=( - "create:Create a secret using stdin as content" - "inspect:Display detailed information on one or more secrets" - "ls:List secrets" - "rm:Remove one or more secrets" - ) - _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands -} - -__docker_secret_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)*"{-l=,--label=}"[Secret labels]:label: " \ - "($help -):secret: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 - ;; - esac - - return ret -} - -# EO secret - -# BO service - -__docker_service_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_services_ids && ret=0 - ;; - (mode) - opts=('global' 'replicated') - _describe -t mode-opts "mode options" opts && ret=0 - ;; - (name) - __docker_complete_services_names && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'mode' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_service_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running' 'shutdown') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_service_complete_placement_pref() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (spread) - opts=('engine.labels' 'node.labels') - _describe -t spread-opts "spread options" opts -qS "." && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('spread') - _describe -t pref-opts "placement pref options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_services() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines services - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - _describe -t services-list "services" services "$@" && ret=0 - return ret -} - -__docker_complete_services() { - [[ $PREFIX = -* ]] && return 1 - __docker_services all "$@" -} - -__docker_complete_services_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_services ids "$@" -} - -__docker_complete_services_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_services names "$@" -} - -__docker_service_commands() { - local -a _docker_service_subcommands - _docker_service_subcommands=( - "create:Create a new service" - "inspect:Display detailed information on one or more services" - "logs:Fetch the logs of a service or task" - "ls:List services" - "rm:Remove one or more services" - "rollback:Revert changes to a service's configuration" - "scale:Scale one or multiple replicated services" - "ps:List the tasks of a service" - "update:Update a service" - ) - _describe -t docker-service-commands "docker service command" _docker_service_subcommands -} - -__docker_service_subcommand() { - local -a _command_args opts_help opts_create_update - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - opts_create_update=( - "($help)*--cap-add=[Add Linux capabilities]:capability: " - "($help)*--cap-drop=[Drop Linux capabilities]:capability: " - "($help)*--constraint=[Placement constraints]:constraint: " - "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" - "($help)*"{-e=,--env=}"[Set environment variables]:env: " - "($help)--health-cmd=[Command to run to check health]:command: " - "($help)--health-interval=[Time between running the check]:time: " - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " - "($help)--hostname=[Service container hostname]:hostname: " \ - "($help)--isolation=[Service container isolation mode]:isolation:(default process hyperv)" \ - "($help)*--label=[Service labels]:label: " - "($help)--limit-cpu=[Limit CPUs]:value: " - "($help)--limit-memory=[Limit Memory]:value: " - "($help)--limit-pids[Limit maximum number of processes (default 0 = unlimited)]" - "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" - "($help)*--mount=[Attach a filesystem mount to the service]:mount: " - "($help)*--network=[Network attachments]:network: " - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" - "($help)--read-only[Mount the container's root filesystem as read only]" - "($help)--replicas=[Number of tasks]:replicas: " - "($help)--reserve-cpu=[Reserve CPUs]:value: " - "($help)--reserve-memory=[Reserve Memory]:value: " - "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" - "($help)--restart-delay=[Delay between restart attempts]:delay: " - "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " - "($help)--restart-window=[Window used to evaluate the restart policy]:duration: " - "($help)--rollback-delay=[Delay between task rollbacks]:duration: " - "($help)--rollback-failure-action=[Action on rollback failure]:action:(continue pause)" - "($help)--rollback-max-failure-ratio=[Failure rate to tolerate during a rollback]:failure rate: " - "($help)--rollback-monitor=[Duration after each task rollback to monitor for failure]:duration: " - "($help)--rollback-parallelism=[Maximum number of tasks rolled back simultaneously]:number: " - "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" - "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " - "($help)--stop-signal=[Signal to stop the container]:signal:_signals" - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" - "($help)--update-delay=[Delay between updates]:delay: " - "($help)--update-failure-action=[Action on update failure]:mode:(continue pause rollback)" - "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " - "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " - "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)--with-registry-auth[Send registry authentication details to swarm agents]" - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)*--container-label=[Container labels]:label: " \ - "($help)*--dns=[Set custom DNS servers]:DNS: " \ - "($help)*--dns-option=[Set DNS options]:DNS option: " \ - "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ - "($help)*--group=[Set one or more supplementary user groups for the container]:group: _groups " \ - "($help)--mode=[Service Mode]:mode:(global replicated)" \ - "($help)--name=[Service name]:name: " \ - "($help)*--placement-pref=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ - "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (logs) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --follow)"{-f,--follow}"[Follow log output]" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-task-ids[Do not include task IDs]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help)--since=[Show logs since timestamp]:timestamp: " \ - "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ - "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_service_complete_ls_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (rollback) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress progress output]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (scale) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ - "($help -)*:service:->values" && ret=0 - case $state in - (values) - if compset -P '*='; then - _message 'replicas' && ret=0 - else - __docker_complete_services -qS "=" - fi - ;; - esac - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_service_complete_ps_filters" \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)--arg=[Service command args]:arguments: _normal" \ - "($help)*--container-label-add=[Add or update container labels]:label: " \ - "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ - "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ - "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ - "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ - "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ - "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ - "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ - "($help)--force[Force update]" \ - "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ - "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ - "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ - "($help)*--placement-pref-add=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ - "($help)*--placement-pref-rm=[Remove a placement preference]:pref:__docker_service_complete_placement_pref" \ - "($help)*--publish-add=[Add or update a port]:port: " \ - "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ - "($help)--rollback[Rollback to previous specification]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 - ;; - esac - - return ret -} - -# EO service - -# BO stack - -__docker_stack_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running' 'shutdown') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stack_complete_services_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stacks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines stacks - - lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service NAME - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - stacks=($stacks $s) - done - - _describe -t stacks-list "stacks" stacks "$@" && ret=0 - return ret -} - -__docker_complete_stacks() { - [[ $PREFIX = -* ]] && return 1 - __docker_stacks "$@" -} - -__docker_stack_commands() { - local -a _docker_stack_subcommands - _docker_stack_subcommands=( - "deploy:Deploy a new stack or update an existing stack" - "ls:List stacks" - "ps:List the tasks in the stack" - "rm:Remove the stack" - "services:List the services in the stack" - ) - _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands -} - -__docker_stack_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (deploy|up) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file, or '-' to read from stdin]:compose file:_files -g \"*.(yml|yaml)\"" \ - "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all tasks]" \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ - "($help)--format=[Format the output using the given go template]:template: " \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (rm|remove|down) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (services) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 - ;; - esac - - return ret -} - -# EO stack - -# BO swarm - -__docker_swarm_commands() { - local -a _docker_swarm_subcommands - _docker_swarm_subcommands=( - "init:Initialize a swarm" - "join:Join a swarm as a node and/or manager" - "join-token:Manage join tokens" - "leave:Leave a swarm" - "unlock:Unlock swarm" - "unlock-key:Manage the unlock key" - "update:Update the swarm" - ) - _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands -} - -__docker_swarm_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (init) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--advertise-addr=[Advertised address]:ip\:port: " \ - "($help)--data-path-addr=[Data path IP or interface]:ip " \ - "($help)--data-path-port=[Data Path Port]:port " \ - "($help)--default-addr-pool=[Default address pool]" \ - "($help)--default-addr-pool-mask-length=[Default address pool subnet mask length]" \ - "($help)--autolock[Enable manager autolocking]" \ - "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ - "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ - "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--force-new-cluster[Force create a new cluster from current state]" \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (join) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)--advertise-addr=[Advertised address]:ip\:port: " \ - "($help)--data-path-addr=[Data path IP or interface]:ip " \ - "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--token=[Token for entry into the swarm]:secret: " \ - "($help -):host\:port: " && ret=0 - ;; - (join-token) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ - "($help)--rotate[Rotate join token]" \ - "($help -):role:(manager worker)" && ret=0 - ;; - (leave) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 - ;; - (unlock) - _arguments $(__docker_arguments) \ - $opts_help && ret=0 - ;; - (unlock-key) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ - "($help)--rotate[Rotate unlock token]" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--autolock[Enable manager autolocking]" \ - "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ - "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO swarm - -# BO system - -__docker_system_commands() { - local -a _docker_system_subcommands - _docker_system_subcommands=( - "df:Show docker filesystem usage" - "events:Get real time events from the server" - "info:Display system-wide information" - "prune:Remove unused data" - ) - _describe -t docker-system-commands "docker system command" _docker_system_subcommands -} - -__docker_system_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (df) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 - ;; - (events) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ - "($help)--since=[Events created since this timestamp]:timestamp: " \ - "($help)--until=[Events created until this timestamp]:timestamp: " \ - "($help)--format=[Format the output using the given go template]:template: " && ret=0 - ;; - (info) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" \ - "($help)--volumes=[Remove all unused volumes]" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO system - -# BO volume - -__docker_volume_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (dangling) - dangling_opts=('true' 'false') - _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 - ;; - (driver) - __docker_complete_info_plugins Volume && ret=0 - ;; - (name) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('dangling' 'driver' 'label' 'name') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_volumes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a lines volumes - - lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Names - local line s - for line in $lines; do - s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - volumes=($volumes $s) - done - - _describe -t volumes-list "volumes" volumes && ret=0 - return ret -} - -__docker_volume_commands() { - local -a _docker_volume_subcommands - _docker_volume_subcommands=( - "create:Create a volume" - "inspect:Display detailed information on one or more volumes" - "ls:List volumes" - "prune:Remove all unused volumes" - "rm:Remove one or more volumes" - ) - _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands -} - -__docker_volume_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ - "($help)*--label=[Set metadata for a volume]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ - "($help -)1:Volume name: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)1:volume:__docker_complete_volumes" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_volume_complete_ls_filters" \ - "($help)--format=[Format the output using the given Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused local volumes, not just anonymous ones]" \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ - "($help -):volume:__docker_complete_volumes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO volume - -# BO context - -__docker_complete_contexts() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a contexts - - contexts=(${(f)${:-"$(_call_program commands docker $docker_options context ls -q)"$'\n'}}) - - _describe -t context-list "context" contexts && ret=0 - return ret -} - -__docker_context_commands() { - local -a _docker_context_subcommands - _docker_context_subcommands=( - "create:Create new context" - "inspect:Display detailed information on one or more contexts" - "list:List available contexts" - "rm:Remove one or more contexts" - "show:Print the current context" - "update:Update a context" - "use:Set the default context" - ) - _describe -t docker-context-commands "docker context command" _docker_context_subcommands -} - -__docker_context_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--description=[Description of the context]:description:" \ - "($help)--docker=[Set the docker endpoint]:docker:" \ - "($help)--from=[Create context from a named context]:from:__docker_complete_contexts" \ - "($help -):name: " && ret=0 - ;; - (use) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:context:__docker_complete_contexts" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:context:__docker_complete_contexts" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:context:__docker_complete_contexts" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--description=[Description of the context]:description:" \ - "($help)--docker=[Set the docker endpoint]:docker:" \ - "($help -):name:" && ret=0 - ;; - esac - - return ret -} - -# EO context - -__docker_caching_policy() { - oldp=( "$1"(Nmh+1) ) # 1 hour - (( $#oldp )) -} - -__docker_commands() { - local cache_policy - integer force_invalidation=0 - - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - if ( (( ! ${+_docker_hide_legacy_commands} )) || _cache_invalid docker_hide_legacy_commands ) \ - && ! _retrieve_cache docker_hide_legacy_commands; - then - _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" - _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands - fi - - if [[ "${_docker_hide_legacy_commands}" != "${DOCKER_HIDE_LEGACY_COMMANDS}" ]]; then - force_invalidation=1 - _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" - _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands - fi - - if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands ) \ - && ! _retrieve_cache docker_subcommands || [[ ${force_invalidation} -eq 1 ]]; - then - local -a lines - lines=(${(f)"$(_call_program commands docker 2>&1)"}) - _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/\*# ##/:}) - _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') - (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands - fi - _describe -t docker-commands "docker command" _docker_subcommands -} - -__docker_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) - __docker_container_subcommand && ret=0 - ;; - (build|history|import|load|pull|push|save|tag) - __docker_image_subcommand && ret=0 - ;; - (checkpoint) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_checkpoint_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_checkpoint_subcommand && ret=0 - ;; - esac - ;; - (container) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_container_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_container_subcommand && ret=0 - ;; - esac - ;; - (context) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_context_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_context_subcommand && ret=0 - ;; - esac - ;; - (daemon) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ - "($help)*--allow-nondistributable-artifacts=[Push nondistributable artifacts to specified registries]:registry: " \ - "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ - "($help)*--authorization-plugin=[Authorization plugins to load]" \ - "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ - "($help)--bip=[Network bridge IP]:IP address: " \ - "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ - "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ - "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ - "($help)--containerd-namespace=[Containerd namespace to use]:containerd namespace:" \ - "($help)--containerd-plugins-namespace=[Containerd namespace to use for plugins]:containerd namespace:" \ - "($help)--data-root=[Root directory of persisted Docker data]:path:_directories" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ - "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ - "($help)--default-shm-size=[Default shm size for containers]:size:" \ - "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ - "($help)*--dns=[DNS server to use]:DNS: " \ - "($help)*--dns-opt=[DNS options to use]:DNS option: " \ - "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ - "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ - "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ - "($help)--experimental[Enable experimental features]" \ - "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ - "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ - "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help)--icc[Enable inter-container communication]" \ - "($help)--init[Run an init inside containers to forward signals and reap processes]" \ - "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ - "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ - "($help)--ip=[Default IP when binding container ports]" \ - "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ - "($help)--ip-masq[Enable IP masquerading]" \ - "($help)--iptables[Enable addition of iptables rules]" \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)*--label=[Key=value labels]:label: " \ - "($help)--live-restore[Enable live restore of docker when containers are still running]" \ - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ - "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ - "($help)--max-concurrent-downloads[Set the max concurrent downloads]" \ - "($help)--max-concurrent-uploads[Set the max concurrent uploads]" \ - "($help)--max-download-attempts[Set the max download attempts for each pull]" \ - "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ - "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ - "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ - "($help)--raw-logs[Full timestamps without ANSI coloring]" \ - "($help)*--registry-mirror=[Preferred registry mirror]:registry mirror: " \ - "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ - "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(btrfs devicemapper overlay2 vfs zfs)" \ - "($help)--selinux-enabled[Enable selinux support]" \ - "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ - "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" \ - "($help)--validate[Validate daemon configuration and exit]" && ret=0 - - case $state in - (users-groups) - if compset -P '*:'; then - _groups && ret=0 - else - _describe -t userns-default "default Docker user management" '(default)' && ret=0 - _users && ret=0 - fi - ;; - esac - ;; - (events|info) - __docker_system_subcommand && ret=0 - ;; - (image) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_image_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_image_subcommand && ret=0 - ;; - esac - ;; - (images) - words[1]='ls' - __docker_image_subcommand && ret=0 - ;; - (inspect) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ - "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ - "($help -)*: :->values" && ret=0 - - case $state in - (values) - if [[ ${words[(r)--type=container]} == --type=container ]]; then - __docker_complete_containers && ret=0 - elif [[ ${words[(r)--type=image]} == --type=image ]]; then - __docker_complete_images && ret=0 - elif [[ ${words[(r)--type=network]} == --type=network ]]; then - __docker_complete_networks && ret=0 - elif [[ ${words[(r)--type=node]} == --type=node ]]; then - __docker_complete_nodes && ret=0 - elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then - __docker_complete_plugins && ret=0 - elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then - __docker_complete_secrets && ret=0 - elif [[ ${words[(r)--type=service]} == --type=service ]]; then - __docker_complete_services && ret=0 - elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then - __docker_complete_volumes && ret=0 - else - __docker_complete_containers - __docker_complete_images - __docker_complete_networks - __docker_complete_nodes - __docker_complete_plugins - __docker_complete_secrets - __docker_complete_services - __docker_complete_volumes && ret=0 - fi - ;; - esac - ;; - (login) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -p --password)"{-p=,--password=}"[Password]:password: " \ - "($help)--password-stdin[Read password from stdin]" \ - "($help -u --username)"{-u=,--username=}"[Username]:username: " \ - "($help -)1:server: " && ret=0 - ;; - (logout) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -)1:server: " && ret=0 - ;; - (network) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_network_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_network_subcommand && ret=0 - ;; - esac - ;; - (node) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_node_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_node_subcommand && ret=0 - ;; - esac - ;; - (plugin) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_plugin_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_plugin_subcommand && ret=0 - ;; - esac - ;; - (ps) - words[1]='ls' - __docker_container_subcommand && ret=0 - ;; - (rmi) - words[1]='rm' - __docker_image_subcommand && ret=0 - ;; - (search) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_search_filters" \ - "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -):term: " && ret=0 - ;; - (secret) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_secret_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_secret_subcommand && ret=0 - ;; - esac - ;; - (service) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_service_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_service_subcommand && ret=0 - ;; - esac - ;; - (stack) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_stack_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_stack_subcommand && ret=0 - ;; - esac - ;; - (swarm) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_swarm_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_swarm_subcommand && ret=0 - ;; - esac - ;; - (system) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_system_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_system_subcommand && ret=0 - ;; - esac - ;; - (version) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (volume) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_volume_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_volume_subcommand && ret=0 - ;; - esac - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 - ;; - esac - - return ret -} - -_docker() { - # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. - # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. - if [[ $service != docker ]]; then - _call_function - _$service - return - fi - - local curcontext="$curcontext" state line help="-h --help" - integer ret=1 - typeset -A opt_args - - _arguments $(__docker_arguments) -C \ - "(: -)"{-h,--help}"[Print usage]" \ - "($help)--config[Location of client config files]:path:_directories" \ - "($help -c --context)"{-c=,--context=}"[Execute the command in a docker context]:context:__docker_complete_contexts" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help -v --version)"{-v,--version}"[Print version information and quit]" \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - local host=${opt_args[-H]}${opt_args[--host]} - local config=${opt_args[--config]} - local context=${opt_args[-c]}${opt_args[--context]} - local docker_options="${host:+--host $host} ${config:+--config $config} ${context:+--context $context} " - - case $state in - (command) - __docker_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-$words[1]: - __docker_subcommand && ret=0 - ;; - esac - - return ret -} - -_dockerd() { - integer ret=1 - words[1]='daemon' - __docker_subcommand && ret=0 - return ret -} - -_docker "$@" - -# Local Variables: -# mode: Shell-Script -# sh-indentation: 4 -# indent-tabs-mode: nil -# sh-basic-offset: 4 -# End: -# vim: ft=zsh sw=4 ts=4 et diff --git a/plugins/docker/completions/_docker b/plugins/docker/completions/_docker new file mode 100644 index 000000000..466b09d94 --- /dev/null +++ b/plugins/docker/completions/_docker @@ -0,0 +1,3126 @@ +#compdef docker dockerd +# +# zsh completion for docker (http://docker.com) +# +# version: 0.3.0 +# github: https://github.com/felixr/docker-zsh-completion +# +# contributors: +# - Felix Riedel +# - Steve Durrheimer +# - Vincent Bernat +# - Rohan Verma +# +# license: +# +# Copyright (c) 2013, Felix Riedel +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# Short-option stacking can be enabled with: +# zstyle ':completion:*:*:docker:*' option-stacking yes +# zstyle ':completion:*:*:docker-*:*' option-stacking yes +__docker_arguments() { + if zstyle -t ":completion:${curcontext}:" option-stacking; then + print -- -s + fi +} + +__docker_get_containers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local kind type line s + declare -a running stopped lines args names + + kind=$1; shift + type=$1; shift + [[ $kind = (stopped|all) ]] && args=($args -a) + + lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line + lines=(${lines[2,-1]}) + + # Container ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + + # Names: we only display the one without slash. All other names + # are generated and may clutter the completion. However, with + # Swarm, all names may be prefixed by the swarm node name. + if [[ $type = (names|all) ]]; then + for line in $lines; do + names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) + # First step: find a common prefix and strip it (swarm node case) + (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} + # Second step: only keep the first name without a / + s=${${names:#*/*}[1]} + # If no name, well give up. + (( $#s != 0 )) || continue + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + + [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 + [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 + return ret +} + +__docker_complete_stopped_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers stopped all "$@" +} + +__docker_complete_running_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers running all "$@" +} + +__docker_complete_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all all "$@" +} + +__docker_complete_containers_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all ids "$@" +} + +__docker_complete_containers_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all names "$@" +} + +__docker_complete_info_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + emulate -L zsh + setopt extendedglob + local -a plugins + plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) + _describe -t plugins "$1 plugins" plugins && ret=0 + return ret +} + +__docker_complete_images() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a images + images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) + _describe -t docker-images "images" images && ret=0 + __docker_complete_repositories_with_tags && ret=0 + return ret +} + +__docker_complete_repositories() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a repos + repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) + repos=(${repos#}) + _describe -t docker-repos "repositories" repos && ret=0 + return ret +} + +__docker_complete_repositories_with_tags() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a repos onlyrepos matched + declare m + repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) + repos=(${${repos%:::}#}) + # Check if we have a prefix-match for the current prefix. + onlyrepos=(${repos%::*}) + for m in $onlyrepos; do + [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { + # Yes, complete with tags + repos=(${${repos/:::/:}/:/\\:}) + _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 + return ret + } + done + # No, only complete repositories + onlyrepos=(${${repos%:::*}/:/\\:}) + _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 + + return ret +} + +__docker_search() { + [[ $PREFIX = -* ]] && return 1 + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + local searchterm cachename + searchterm="${words[$CURRENT]%/}" + cachename=_docker-search-$searchterm + + local expl + local -a result + if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ + && ! _retrieve_cache ${cachename#_}; then + _message "Searching for ${searchterm}..." + result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) + _store_cache ${cachename#_} result + fi + _wanted dockersearch expl 'available images' compadd -a result +} + +__docker_get_log_options() { + [[ $PREFIX = -* ]] && return 1 + + integer ret=1 + local log_driver=${opt_args[--log-driver]:-"all"} + local -a common_options common_options2 awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options + + common_options=("max-buffer-size" "mode") + common_options2=("env" "env-regex" "labels") + awslogs_options=($common_options "awslogs-create-group" "awslogs-datetime-format" "awslogs-group" "awslogs-multiline-pattern" "awslogs-region" "awslogs-stream" "tag") + fluentd_options=($common_options $common_options2 "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "fluentd-sub-second-precision" "tag") + gcplogs_options=($common_options $common_options2 "gcp-log-cmd" "gcp-meta-id" "gcp-meta-name" "gcp-meta-zone" "gcp-project") + gelf_options=($common_options $common_options2 "gelf-address" "gelf-compression-level" "gelf-compression-type" "tag") + journald_options=($common_options $common_options2 "tag") + json_file_options=($common_options $common_options2 "max-file" "max-size") + logentries_options=($common_options $common_options2 "logentries-token" "tag") + syslog_options=($common_options $common_options2 "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") + splunk_options=($common_options $common_options2 "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") + + [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 + [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 + [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 + [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 + [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 + [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 + [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 + [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 + [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 + + return ret +} + +__docker_complete_log_drivers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) + _describe -t log-drivers "log drivers" drivers && ret=0 + return ret +} + +__docker_complete_log_options() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (syslog-format) + local opts=('rfc3164' 'rfc5424' 'rfc5424micro') + _describe -t syslog-format-opts "syslog format options" opts && ret=0 + ;; + (mode) + local opts=('blocking' 'non-blocking') + _describe -t mode-opts "mode options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + __docker_get_log_options -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_detach_keys() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + compset -P "*," + keys=(${:-{a-z}}) + ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) + _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 + _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 +} + +__docker_complete_pid() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local -a opts vopts + + opts=('host') + vopts=('container') + + if compset -P '*:'; then + case "${${words[-1]%:*}#*=}" in + (container) + __docker_complete_running_containers && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 + _describe -t pid-opts "PID Options" opts && ret=0 + fi + + return ret +} + +__docker_complete_runtimes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + emulate -L zsh + setopt extendedglob + local -a runtimes_opts + runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) + _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 +} + +__docker_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (ancestor) + __docker_complete_images && ret=0 + ;; + (before|since) + __docker_complete_containers && ret=0 + ;; + (health) + health_opts=('healthy' 'none' 'starting' 'unhealthy') + _describe -t health-filter-opts "health filter options" health_opts && ret=0 + ;; + (id) + __docker_complete_containers_ids && ret=0 + ;; + (is-task) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + (name) + __docker_complete_containers_names && ret=0 + ;; + (network) + __docker_complete_networks && ret=0 + ;; + (status) + status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') + _describe -t status-filter-opts "status filter options" status_opts && ret=0 + ;; + (volume) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('ancestor' 'before' 'exited' 'expose' 'health' 'id' 'label' 'name' 'network' 'publish' 'since' 'status' 'volume') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_search_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('is-automated' 'is-official' 'stars') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (is-automated|is-official) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_images_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('before' 'dangling' 'label' 'reference' 'since') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (before|reference|since) + __docker_complete_images && ret=0 + ;; + (dangling) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_events_filter() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a opts + + opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'scope' 'type' 'volume') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (container) + __docker_complete_containers && ret=0 + ;; + (daemon) + emulate -L zsh + setopt extendedglob + local -a daemon_opts + daemon_opts=( + ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} + ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} + ) + _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 + ;; + (event) + local -a event_opts + event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disable' 'disconnect' 'enable' 'exec_create' 'exec_detach' + 'exec_start' 'export' 'health_status' 'import' 'install' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'remove' 'rename' 'resize' + 'restart' 'save' 'start' 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') + _describe -t event-filter-opts "event filter options" event_opts && ret=0 + ;; + (image) + __docker_complete_images && ret=0 + ;; + (network) + __docker_complete_networks && ret=0 + ;; + (scope) + local -a scope_opts + scope_opts=('local' 'swarm') + _describe -t scope-filter-opts "scope filter options" scope_opts && ret=0 + ;; + (type) + local -a type_opts + type_opts=('container' 'daemon' 'image' 'network' 'volume') + _describe -t type-filter-opts "type filter options" type_opts && ret=0 + ;; + (volume) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_prune_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a opts + + opts=('until') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +# BO checkpoint + +__docker_checkpoint_commands() { + local -a _docker_checkpoint_subcommands + _docker_checkpoint_subcommands=( + "create:Create a checkpoint from a running container" + "ls:List checkpoints for a container" + "rm:Remove a checkpoint" + ) + _describe -t docker-checkpoint-commands "docker checkpoint command" _docker_checkpoint_subcommands +} + +__docker_checkpoint_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help)--leave-running[Leave the container running after checkpoint]" \ + "($help -)1:container:__docker_complete_running_containers" \ + "($help -)2:checkpoint: " && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help -)1:container:__docker_complete_containers" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help -)1:container:__docker_complete_containers" \ + "($help -)2:checkpoint: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_checkpoint_commands" && ret=0 + ;; + esac + + return ret +} + +# EO checkpoint + +# BO container + +__docker_container_commands() { + local -a _docker_container_subcommands + _docker_container_subcommands=( + "attach:Attach to a running container" + "commit:Create a new image from a container's changes" + "cp:Copy files/folders between a container and the local filesystem" + "create:Create a new container" + "diff:Inspect changes on a container's filesystem" + "exec:Execute a command in a running container" + "export:Export a container's filesystem as a tar archive" + "inspect:Display detailed information on one or more containers" + "kill:Kill one or more running containers" + "logs:Fetch the logs of a container" + "ls:List containers" + "pause:Pause all processes within one or more containers" + "port:List port mappings or a specific mapping for the container" + "prune:Remove all stopped containers" + "rename:Rename a container" + "restart:Restart one or more containers" + "rm:Remove one or more containers" + "run:Create and run a new container from an image" + "start:Start one or more stopped containers" + "stats:Display a live stream of container(s) resource usage statistics" + "stop:Stop one or more running containers" + "top:Display the running processes of a container" + "unpause:Unpause all processes within one or more containers" + "update:Update configuration of one or more containers" + "wait:Block until one or more containers stop, then print their exit codes" + ) + _describe -t docker-container-commands "docker container command" _docker_container_subcommands +} + +__docker_container_subcommand() { + local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update + local expl help="--help" + integer ret=1 + + opts_attach_exec_run_start=( + "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" + ) + opts_create_run=( + "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" + "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " + "($help)*--annotation=[Add an annotation to the container (passed through to the OCI runtime)]:annotations: " + "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " + "($help)--cgroupns=[Cgroup namespace mode to use]:cgroup namespace mode: " + "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " + "($help)--cidfile=[Write the container ID to the file]:CID file:_files" + "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " + "($help)*--device=[Add a host device to the container]:device:_files" + "($help)*--device-cgroup-rule=[Add a rule to the cgroup allowed devices list]:device:cgroup: " + "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " + "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " + "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " + "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " + "($help)--disable-content-trust[Skip image verification]" + "($help)*--dns=[Custom DNS servers]:DNS server: " + "($help)*--dns-option=[Custom DNS options]:DNS option: " + "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " + "($help)*--domainname=[Container NIS domain name]:domainname:_hosts" + "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " + "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" + "($help)*--expose=[Expose a port from the container without publishing it]: " + "($help)*--gpus=[GPU devices to add to the container ('all' to pass all GPUs)]:device: " + "($help)*--group-add=[Set one or more supplementary user groups for the container]:group:_groups" + "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" + "($help)--init[Run an init inside the container that forwards signals and reaps processes]" + "($help)--ip=[IPv4 address]:IPv4: " + "($help)--ip6=[IPv6 address]:IPv6: " + "($help)--ipc=[IPC namespace to use]:IPC namespace: " + "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" + "($help)*--link=[Add link to another container]:link:->link" + "($help)*--link-local-ip=[Container IPv4/IPv6 link-local addresses]:IPv4/IPv6: " + "($help)*"{-l=,--label=}"[Container metadata]:label: " + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" + "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" + "($help)--mac-address=[Container MAC address]:MAC address: " + "($help)*--mount=[Attach a filesystem mount to the container]:mount: " + "($help)--name=[Container name]:name: " + "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" + "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " + "($help)--oom-kill-disable[Disable OOM Killer]" + "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" + "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" + "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" + "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" + "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" + "($help)--privileged[Give extended privileges to this container]" + "($help -q --quiet)"{-q,--quiet}"[Suppress the pull output]" + "($help)--read-only[Mount the container's root filesystem as read only]" + "($help)*--security-opt=[Security options]:security option: " + "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " + "($help)--stop-signal=[Signal to kill a container]:signal:_signals" + "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " + "($help)*--sysctl=-[sysctl options]:sysctl: " + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)*--ulimit=[ulimit options]:ulimit: " + "($help)--userns=[Container user namespace]:user namespace:(host)" + "($help)--tmpfs[mount tmpfs]" + "($help)*-v[Bind mount a volume]:volume:_directories -W / -P '/' -S '\:' -r '/ '" + "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" + "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + opts_create_run_update=( + "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" + "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" + "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " + "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " + "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " + "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " + "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " + "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " + "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " + "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " + "($help)--memory-reservation=[Memory soft limit]:Memory limit: " + "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " + "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" + "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" + ) + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (attach) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help)--no-stdin[Do not attach stdin]" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help -):containers:__docker_complete_running_containers" && ret=0 + ;; + (commit) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --author)"{-a=,--author=}"[Author]:author: " \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ + "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ + "($help -):container:__docker_complete_containers" \ + "($help -): :__docker_complete_repositories_with_tags" && ret=0 + ;; + (cp) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ + "($help -)1:container:->container" \ + "($help -)2:hostpath:_files" && ret=0 + case $state in + (container) + if compset -P "*:"; then + _files && ret=0 + else + __docker_complete_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run \ + $opts_create_run_update \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (diff) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (exec) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ + "($help)--privileged[Give extended Linux capabilities to the command]" \ + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" \ + "($help -):containers:__docker_complete_running_containers" \ + "($help -)*::command:->anycommand" && ret=0 + case $state in + (anycommand) + shift 1 words + (( CURRENT-- )) + _normal && ret=0 + ;; + esac + ;; + (export) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -s --size)"{-s,--size}"[Display total file sizes]" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (kill) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (logs) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--details[Show extra details provided to logs]" \ + "($help -f --follow)"{-f,--follow}"[Follow log output]" \ + "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ + "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers]" \ + "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ + "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show container IDs]" \ + "($help -s --size)"{-s,--size}"[Display total file sizes]" \ + "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 + ;; + (pause|unpause) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (port) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_complete_running_containers" \ + "($help -)2:port:_ports" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rename) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):old name:__docker_complete_containers" \ + "($help -):new name: " && ret=0 + ;; + (restart) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (rm) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ + "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ + "($help -)*:containers:->values" && ret=0 + case $state in + (values) + if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then + __docker_complete_containers && ret=0 + else + __docker_complete_stopped_containers && ret=0 + fi + ;; + esac + ;; + (run) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run \ + $opts_create_run_update \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help)--health-cmd=[Command to run to check health]:command: " \ + "($help)--health-interval=[Time between running the check]:time: " \ + "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ + "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ + "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ + "($help)--rm[Remove intermediate containers when it exits]" \ + "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + (storage-opt) + if compset -P "*="; then + _message "value" && ret=0 + else + opts=('size') + _describe -t filter-opts "storage options" opts -qS "=" && ret=0 + fi + ;; + esac + ;; + (start) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ + "($help -i --interactive)"{-i,--interactive}"[Attach container's stdin]" \ + "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 + ;; + (stats) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-stream[Disable streaming stats and only pull the first result]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (stop) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (top) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_complete_running_containers" \ + "($help -)*:: :->ps-arguments" && ret=0 + case $state in + (ps-arguments) + _ps && ret=0 + ;; + esac + ;; + (update) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run_update \ + "($help -)*: :->values" && ret=0 + case $state in + (values) + if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then + __docker_complete_stopped_containers && ret=0 + else + __docker_complete_containers && ret=0 + fi + ;; + esac + ;; + (wait) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 + ;; + esac + + return ret +} + +# EO container + +# BO image + +__docker_image_commands() { + local -a _docker_image_subcommands + _docker_image_subcommands=( + "build:Build an image from a Dockerfile" + "history:Show the history of an image" + "import:Import the contents from a tarball to create a filesystem image" + "inspect:Display detailed information on one or more images" + "load:Load an image from a tar archive or STDIN" + "ls:List images" + "prune:Remove unused images" + "pull:Download an image from a registry" + "push:Upload an image to a registry" + "rm:Remove one or more images" + "save:Save one or more images to a tar archive (streamed to STDOUT by default)" + "tag:Tag an image into a repository" + ) + _describe -t docker-image-commands "docker image command" _docker_image_subcommands +} + +__docker_image_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (build) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " \ + "($help)*--build-arg=[Build-time variables]:=: " \ + "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ + "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ + "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ + "($help)--compress[Compress the build context using gzip]" \ + "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ + "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ + "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ + "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ + "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ + "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ + "($help)--disable-content-trust[Skip image verification]" \ + "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ + "($help)--force-rm[Always remove intermediate containers]" \ + "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ + "($help)*--label=[Set metadata for an image]:label=value: " \ + "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ + "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ + "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ + "($help)--no-cache[Do not use cache when building the image]" \ + "($help)--pull[Attempt to pull a newer version of the image]" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ + "($help)--rm[Remove intermediate containers after a successful build]" \ + "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ + "($help)--squash[Squash newly built layers into a single new layer]" \ + "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ + "($help)--target=[Set the target build stage to build.]" \ + "($help)*--ulimit=[ulimit options]:ulimit: " \ + "($help)--userns=[Container user namespace]:user namespace:(host)" \ + "($help -):path or URL:_directories" && ret=0 + ;; + (history) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (import) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ + "($help -):URL:(- http:// file://)" \ + "($help -): :__docker_complete_repositories_with_tags" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)*:images:__docker_complete_images" && ret=0 + ;; + (load) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 + ;; + (ls|list) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all images]" \ + "($help)--digests[Show digests]" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_images_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ + "($help -): :__docker_complete_repositories" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (pull) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ + "($help)--disable-content-trust[Skip image verification]" \ + "($help -):name:__docker_search" && ret=0 + ;; + (push) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all-tags)"{-a,--all-tags}"[Push all tags of an image to the repository]" \ + "($help)--disable-content-trust[Skip image signing]" \ + "($help -): :__docker_complete_images" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help)--no-prune[Do not delete untagged parents]" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (save) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (tag) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):source:__docker_complete_images"\ + "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 + ;; + esac + + return ret +} + +# EO image + +# BO network + +__docker_network_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (driver) + __docker_complete_info_plugins Network && ret=0 + ;; + (id) + __docker_complete_networks_ids && ret=0 + ;; + (name) + __docker_complete_networks_names && ret=0 + ;; + (scope) + opts=('global' 'local' 'swarm') + _describe -t scope-filter-opts "Scope filter options" opts && ret=0 + ;; + (type) + opts=('builtin' 'custom') + _describe -t type-filter-opts "Type filter options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('driver' 'id' 'label' 'name' 'scope' 'type') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_get_networks() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines networks + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Network ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" + networks=($networks $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" + networks=($networks $s) + done + fi + + _describe -t networks-list "networks" networks "$@" && ret=0 + return ret +} + +__docker_complete_networks() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks all "$@" +} + +__docker_complete_networks_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks ids "$@" +} + +__docker_complete_networks_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks names "$@" +} + +__docker_network_commands() { + local -a _docker_network_subcommands + _docker_network_subcommands=( + "connect:Connect a container to a network" + "create:Creates a new network with a name specified by the user" + "disconnect:Disconnects a container from a network" + "inspect:Displays detailed information on a network" + "ls:Lists all the networks created by the user" + "prune:Remove all unused networks" + "rm:Deletes one or more networks" + ) + _describe -t docker-network-commands "docker network command" _docker_network_subcommands +} + +__docker_network_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (connect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ + "($help)--ip=[IPv4 address]:IPv4: " \ + "($help)--ip6=[IPv6 address]:IPv6: " \ + "($help)*--link=[Add a link to another container]:link:->link" \ + "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ + "($help -)1:network:__docker_complete_networks" \ + "($help -)2:containers:__docker_complete_containers" && ret=0 + + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)--attachable[Enable manual container attachment]" \ + "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ + "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ + "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ + "($help)--internal[Restricts external access to the network]" \ + "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ + "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ + "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help)*--label=[Set metadata on a network]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ + "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ + "($help -)1:Network Name: " && ret=0 + ;; + (disconnect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:network:__docker_complete_networks" \ + "($help -)2:containers:__docker_complete_containers" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--verbose[Show detailed information]" \ + "($help -)*:network:__docker_complete_networks" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--no-trunc[Do not truncate the output]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_network_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display network IDs]" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:network:__docker_complete_networks" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret +} + +# EO network + +# BO node + +__docker_node_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_nodes_ids && ret=0 + ;; + (membership) + membership_opts=('accepted' 'pending' 'rejected') + _describe -t membership-opts "membership options" membership_opts && ret=0 + ;; + (name) + __docker_complete_nodes_names && ret=0 + ;; + (role) + role_opts=('manager' 'worker') + _describe -t role-opts "role options" role_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'membership' 'name' 'node.label' 'role') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_node_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_nodes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines nodes args + + type=$1; shift + filter=$1; shift + [[ $filter != "none" ]] && args=("-f $filter") + + lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Node ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + nodes=($nodes $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[HOSTNAME]},${end[HOSTNAME]}]%% ##}" + nodes=($nodes $s) + done + fi + + _describe -t nodes-list "nodes" nodes "$@" && ret=0 + return ret +} + +__docker_complete_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all none "$@" +} + +__docker_complete_nodes_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes ids none "$@" +} + +__docker_complete_nodes_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes names none "$@" +} + +__docker_complete_pending_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "membership=pending" "$@" +} + +__docker_complete_manager_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=manager" "$@" +} + +__docker_complete_worker_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=worker" "$@" +} + +__docker_node_commands() { + local -a _docker_node_subcommands + _docker_node_subcommands=( + "demote:Demote a node as manager in the swarm" + "inspect:Display detailed information on one or more nodes" + "ls:List nodes in the swarm" + "promote:Promote a node as manager in the swarm" + "rm:Remove one or more nodes from the swarm" + "ps:List tasks running on one or more nodes, defaults to current node" + "update:Update a node" + ) + _describe -t docker-node-commands "docker node command" _docker_node_subcommands +} + +__docker_node_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ + "($help -)*:node:__docker_complete_pending_nodes" && ret=0 + ;; + (demote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_manager_nodes" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:node:__docker_complete_nodes" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ls_filters" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (promote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_worker_nodes" && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all instances]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ + "($help -)*:node:__docker_complete_nodes" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ + "($help)*--label-add=[Add or update a node label]:key=value: " \ + "($help)*--label-rm=[Remove a node label if exists]:label: " \ + "($help)--role=[Role of the node]:role:(manager worker)" \ + "($help -)1:node:__docker_complete_nodes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 + ;; + esac + + return ret +} + +# EO node + +# BO plugin + +__docker_plugin_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (capability) + opts=('authz' 'ipamdriver' 'logdriver' 'metricscollector' 'networkdriver' 'volumedriver') + _describe -t capability-opts "capability options" opts && ret=0 + ;; + (enabled) + opts=('false' 'true') + _describe -t enabled-opts "enabled options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('capability' 'enabled') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines plugins args + + filter=$1; shift + [[ $filter != "none" ]] && args=("-f $filter") + + lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls $args)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Name + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" + plugins=($plugins $s) + done + + _describe -t plugins-list "plugins" plugins "$@" && ret=0 + return ret +} + +__docker_complete_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins none "$@" +} + +__docker_complete_enabled_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins enabled=true "$@" +} + +__docker_complete_disabled_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins enabled=false "$@" +} + +__docker_plugin_commands() { + local -a _docker_plugin_subcommands + _docker_plugin_subcommands=( + "disable:Disable a plugin" + "enable:Enable a plugin" + "inspect:Return low-level information about a plugin" + "install:Install a plugin" + "ls:List plugins" + "push:Push a plugin" + "rm:Remove a plugin" + "set:Change settings for a plugin" + "upgrade:Upgrade an existing plugin" + ) + _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands +} + +__docker_plugin_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (disable) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the disable of an active plugin]" \ + "($help -)1:plugin:__docker_complete_enabled_plugins" && ret=0 + ;; + (enable) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--timeout=[HTTP client timeout (in seconds)]:timeout: " \ + "($help -)1:plugin:__docker_complete_disabled_plugins" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ + "($help -)*:plugin:__docker_complete_plugins" && ret=0 + ;; + (install) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--alias=[Local name for plugin]:alias: " \ + "($help)--disable[Do not enable the plugin on install]" \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -)*:key=value: " && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_plugin_complete_ls_filters" \ + "($help --format)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-trunc[Don't truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (push) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help -)1:plugin:__docker_complete_plugins" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the removal of an active plugin]" \ + "($help -)*:plugin:__docker_complete_plugins" && ret=0 + ;; + (set) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -)*:key=value: " && ret=0 + ;; + (upgrade) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ + "($help)--skip-remote-check[Do not check if specified remote plugin matches existing plugin image]" \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -):remote: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 + ;; + esac + + return ret +} + +# EO plugin + +# BO secret + +__docker_secrets() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines secrets + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + secrets=($secrets $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + secrets=($secrets $s) + done + fi + + _describe -t secrets-list "secrets" secrets "$@" && ret=0 + return ret +} + +__docker_complete_secrets() { + [[ $PREFIX = -* ]] && return 1 + __docker_secrets all "$@" +} + +__docker_secret_commands() { + local -a _docker_secret_subcommands + _docker_secret_subcommands=( + "create:Create a secret using stdin as content" + "inspect:Display detailed information on one or more secrets" + "ls:List secrets" + "rm:Remove one or more secrets" + ) + _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands +} + +__docker_secret_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)*"{-l=,--label=}"[Secret labels]:label: " \ + "($help -):secret: " && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ + "($help -)*:secret:__docker_complete_secrets" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:secret:__docker_complete_secrets" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 + ;; + esac + + return ret +} + +# EO secret + +# BO service + +__docker_service_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_services_ids && ret=0 + ;; + (mode) + opts=('global' 'replicated') + _describe -t mode-opts "mode options" opts && ret=0 + ;; + (name) + __docker_complete_services_names && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'mode' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_service_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_service_complete_placement_pref() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (spread) + opts=('engine.labels' 'node.labels') + _describe -t spread-opts "spread options" opts -qS "." && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('spread') + _describe -t pref-opts "placement pref options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_services() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines services + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Service ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + _describe -t services-list "services" services "$@" && ret=0 + return ret +} + +__docker_complete_services() { + [[ $PREFIX = -* ]] && return 1 + __docker_services all "$@" +} + +__docker_complete_services_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_services ids "$@" +} + +__docker_complete_services_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_services names "$@" +} + +__docker_service_commands() { + local -a _docker_service_subcommands + _docker_service_subcommands=( + "create:Create a new service" + "inspect:Display detailed information on one or more services" + "logs:Fetch the logs of a service or task" + "ls:List services" + "rm:Remove one or more services" + "rollback:Revert changes to a service's configuration" + "scale:Scale one or multiple replicated services" + "ps:List the tasks of a service" + "update:Update a service" + ) + _describe -t docker-service-commands "docker service command" _docker_service_subcommands +} + +__docker_service_subcommand() { + local -a _command_args opts_help opts_create_update + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + opts_create_update=( + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " + "($help)*--constraint=[Placement constraints]:constraint: " + "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" + "($help)*"{-e=,--env=}"[Set environment variables]:env: " + "($help)--health-cmd=[Command to run to check health]:command: " + "($help)--health-interval=[Time between running the check]:time: " + "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" + "($help)--health-timeout=[Maximum time to allow one check to run]:time: " + "($help)--hostname=[Service container hostname]:hostname: " \ + "($help)--isolation=[Service container isolation mode]:isolation:(default process hyperv)" \ + "($help)*--label=[Service labels]:label: " + "($help)--limit-cpu=[Limit CPUs]:value: " + "($help)--limit-memory=[Limit Memory]:value: " + "($help)--limit-pids[Limit maximum number of processes (default 0 = unlimited)]" + "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" + "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" + "($help)*--mount=[Attach a filesystem mount to the service]:mount: " + "($help)*--network=[Network attachments]:network: " + "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" + "($help)--read-only[Mount the container's root filesystem as read only]" + "($help)--replicas=[Number of tasks]:replicas: " + "($help)--reserve-cpu=[Reserve CPUs]:value: " + "($help)--reserve-memory=[Reserve Memory]:value: " + "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" + "($help)--restart-delay=[Delay between restart attempts]:delay: " + "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " + "($help)--restart-window=[Window used to evaluate the restart policy]:duration: " + "($help)--rollback-delay=[Delay between task rollbacks]:duration: " + "($help)--rollback-failure-action=[Action on rollback failure]:action:(continue pause)" + "($help)--rollback-max-failure-ratio=[Failure rate to tolerate during a rollback]:failure rate: " + "($help)--rollback-monitor=[Duration after each task rollback to monitor for failure]:duration: " + "($help)--rollback-parallelism=[Maximum number of tasks rolled back simultaneously]:number: " + "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" + "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " + "($help)--stop-signal=[Signal to stop the container]:signal:_signals" + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" + "($help)--update-delay=[Delay between updates]:delay: " + "($help)--update-failure-action=[Action on update failure]:mode:(continue pause rollback)" + "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " + "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " + "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)--with-registry-auth[Send registry authentication details to swarm agents]" + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)*--container-label=[Container labels]:label: " \ + "($help)*--dns=[Set custom DNS servers]:DNS: " \ + "($help)*--dns-option=[Set DNS options]:DNS option: " \ + "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ + "($help)*--group=[Set one or more supplementary user groups for the container]:group: _groups " \ + "($help)--mode=[Service Mode]:mode:(global replicated)" \ + "($help)--name=[Service name]:name: " \ + "($help)*--placement-pref=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (logs) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --follow)"{-f,--follow}"[Follow log output]" \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-task-ids[Do not include task IDs]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help)--since=[Show logs since timestamp]:timestamp: " \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ + "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ + "($help -)1:service:__docker_complete_services" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_service_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (rollback) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress progress output]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (scale) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ + "($help -)*:service:->values" && ret=0 + case $state in + (values) + if compset -P '*='; then + _message 'replicas' && ret=0 + else + __docker_complete_services -qS "=" + fi + ;; + esac + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_service_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)--arg=[Service command args]:arguments: _normal" \ + "($help)*--container-label-add=[Add or update container labels]:label: " \ + "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ + "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ + "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ + "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ + "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ + "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ + "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ + "($help)--force[Force update]" \ + "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ + "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ + "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ + "($help)*--placement-pref-add=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*--placement-pref-rm=[Remove a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*--publish-add=[Add or update a port]:port: " \ + "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ + "($help)--rollback[Rollback to previous specification]" \ + "($help -)1:service:__docker_complete_services" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 + ;; + esac + + return ret +} + +# EO service + +# BO stack + +__docker_stack_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_stack_complete_services_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_stacks() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines stacks + + lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Service NAME + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + stacks=($stacks $s) + done + + _describe -t stacks-list "stacks" stacks "$@" && ret=0 + return ret +} + +__docker_complete_stacks() { + [[ $PREFIX = -* ]] && return 1 + __docker_stacks "$@" +} + +__docker_stack_commands() { + local -a _docker_stack_subcommands + _docker_stack_subcommands=( + "deploy:Deploy a new stack or update an existing stack" + "ls:List stacks" + "ps:List the tasks in the stack" + "rm:Remove the stack" + "services:List the services in the stack" + ) + _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands +} + +__docker_stack_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (deploy|up) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file, or '-' to read from stdin]:compose file:_files -g \"*.(yml|yaml)\"" \ + "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all tasks]" \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (rm|remove|down) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (services) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 + ;; + esac + + return ret +} + +# EO stack + +# BO swarm + +__docker_swarm_commands() { + local -a _docker_swarm_subcommands + _docker_swarm_subcommands=( + "init:Initialize a swarm" + "join:Join a swarm as a node and/or manager" + "join-token:Manage join tokens" + "leave:Leave a swarm" + "unlock:Unlock swarm" + "unlock-key:Manage the unlock key" + "update:Update the swarm" + ) + _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands +} + +__docker_swarm_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (init) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--advertise-addr=[Advertised address]:ip\:port: " \ + "($help)--data-path-addr=[Data path IP or interface]:ip " \ + "($help)--data-path-port=[Data Path Port]:port " \ + "($help)--default-addr-pool=[Default address pool]" \ + "($help)--default-addr-pool-mask-length=[Default address pool subnet mask length]" \ + "($help)--autolock[Enable manager autolocking]" \ + "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ + "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ + "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ + "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ + "($help)--force-new-cluster[Force create a new cluster from current state]" \ + "($help)--listen-addr=[Listen address]:ip\:port: " \ + "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ + "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ + "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 + ;; + (join) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)--advertise-addr=[Advertised address]:ip\:port: " \ + "($help)--data-path-addr=[Data path IP or interface]:ip " \ + "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ + "($help)--listen-addr=[Listen address]:ip\:port: " \ + "($help)--token=[Token for entry into the swarm]:secret: " \ + "($help -):host\:port: " && ret=0 + ;; + (join-token) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ + "($help)--rotate[Rotate join token]" \ + "($help -):role:(manager worker)" && ret=0 + ;; + (leave) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 + ;; + (unlock) + _arguments $(__docker_arguments) \ + $opts_help && ret=0 + ;; + (unlock-key) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ + "($help)--rotate[Rotate unlock token]" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--autolock[Enable manager autolocking]" \ + "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ + "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ + "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ + "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ + "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ + "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret +} + +# EO swarm + +# BO system + +__docker_system_commands() { + local -a _docker_system_subcommands + _docker_system_subcommands=( + "df:Show docker filesystem usage" + "events:Get real time events from the server" + "info:Display system-wide information" + "prune:Remove unused data" + ) + _describe -t docker-system-commands "docker system command" _docker_system_subcommands +} + +__docker_system_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (df) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 + ;; + (events) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ + "($help)--since=[Events created since this timestamp]:timestamp: " \ + "($help)--until=[Events created until this timestamp]:timestamp: " \ + "($help)--format=[Format the output using the given go template]:template: " && ret=0 + ;; + (info) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" \ + "($help)--volumes=[Remove all unused volumes]" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 + ;; + esac + + return ret +} + +# EO system + +# BO volume + +__docker_volume_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (dangling) + dangling_opts=('true' 'false') + _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 + ;; + (driver) + __docker_complete_info_plugins Volume && ret=0 + ;; + (name) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('dangling' 'driver' 'label' 'name') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_volumes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a lines volumes + + lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Names + local line s + for line in $lines; do + s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + volumes=($volumes $s) + done + + _describe -t volumes-list "volumes" volumes && ret=0 + return ret +} + +__docker_volume_commands() { + local -a _docker_volume_subcommands + _docker_volume_subcommands=( + "create:Create a volume" + "inspect:Display detailed information on one or more volumes" + "ls:List volumes" + "prune:Remove all unused volumes" + "rm:Remove one or more volumes" + ) + _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands +} + +__docker_volume_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ + "($help)*--label=[Set metadata for a volume]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ + "($help -)1:Volume name: " && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)1:volume:__docker_complete_volumes" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_volume_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused local volumes, not just anonymous ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ + "($help -):volume:__docker_complete_volumes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 + ;; + esac + + return ret +} + +# EO volume + +# BO context + +__docker_complete_contexts() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a contexts + + contexts=(${(f)${:-"$(_call_program commands docker $docker_options context ls -q)"$'\n'}}) + + _describe -t context-list "context" contexts && ret=0 + return ret +} + +__docker_context_commands() { + local -a _docker_context_subcommands + _docker_context_subcommands=( + "create:Create new context" + "inspect:Display detailed information on one or more contexts" + "list:List available contexts" + "rm:Remove one or more contexts" + "show:Print the current context" + "update:Update a context" + "use:Set the default context" + ) + _describe -t docker-context-commands "docker context command" _docker_context_subcommands +} + +__docker_context_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--description=[Description of the context]:description:" \ + "($help)--docker=[Set the docker endpoint]:docker:" \ + "($help)--from=[Create context from a named context]:from:__docker_complete_contexts" \ + "($help -):name: " && ret=0 + ;; + (use) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--description=[Description of the context]:description:" \ + "($help)--docker=[Set the docker endpoint]:docker:" \ + "($help -):name:" && ret=0 + ;; + esac + + return ret +} + +# EO context + +__docker_caching_policy() { + oldp=( "$1"(Nmh+1) ) # 1 hour + (( $#oldp )) +} + +__docker_commands() { + local cache_policy + integer force_invalidation=0 + + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + if ( (( ! ${+_docker_hide_legacy_commands} )) || _cache_invalid docker_hide_legacy_commands ) \ + && ! _retrieve_cache docker_hide_legacy_commands; + then + _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" + _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands + fi + + if [[ "${_docker_hide_legacy_commands}" != "${DOCKER_HIDE_LEGACY_COMMANDS}" ]]; then + force_invalidation=1 + _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" + _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands + fi + + if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands ) \ + && ! _retrieve_cache docker_subcommands || [[ ${force_invalidation} -eq 1 ]]; + then + local -a lines + lines=(${(f)"$(_call_program commands docker 2>&1)"}) + _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/\*# ##/:}) + _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') + (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands + fi + _describe -t docker-commands "docker command" _docker_subcommands +} + +__docker_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) + __docker_container_subcommand && ret=0 + ;; + (build|history|import|load|pull|push|save|tag) + __docker_image_subcommand && ret=0 + ;; + (checkpoint) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_checkpoint_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_checkpoint_subcommand && ret=0 + ;; + esac + ;; + (container) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_container_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_container_subcommand && ret=0 + ;; + esac + ;; + (context) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_context_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_context_subcommand && ret=0 + ;; + esac + ;; + (daemon) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ + "($help)*--allow-nondistributable-artifacts=[Push nondistributable artifacts to specified registries]:registry: " \ + "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ + "($help)*--authorization-plugin=[Authorization plugins to load]" \ + "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ + "($help)--bip=[Network bridge IP]:IP address: " \ + "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ + "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ + "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ + "($help)--containerd-namespace=[Containerd namespace to use]:containerd namespace:" \ + "($help)--containerd-plugins-namespace=[Containerd namespace to use for plugins]:containerd namespace:" \ + "($help)--data-root=[Root directory of persisted Docker data]:path:_directories" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ + "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ + "($help)--default-shm-size=[Default shm size for containers]:size:" \ + "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ + "($help)*--dns=[DNS server to use]:DNS: " \ + "($help)*--dns-opt=[DNS options to use]:DNS option: " \ + "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ + "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ + "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ + "($help)--experimental[Enable experimental features]" \ + "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ + "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ + "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help)--icc[Enable inter-container communication]" \ + "($help)--init[Run an init inside containers to forward signals and reap processes]" \ + "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ + "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ + "($help)--ip=[Default IP when binding container ports]" \ + "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ + "($help)--ip-masq[Enable IP masquerading]" \ + "($help)--iptables[Enable addition of iptables rules]" \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)*--label=[Key=value labels]:label: " \ + "($help)--live-restore[Enable live restore of docker when containers are still running]" \ + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ + "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ + "($help)--max-concurrent-downloads[Set the max concurrent downloads]" \ + "($help)--max-concurrent-uploads[Set the max concurrent uploads]" \ + "($help)--max-download-attempts[Set the max download attempts for each pull]" \ + "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ + "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ + "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ + "($help)--raw-logs[Full timestamps without ANSI coloring]" \ + "($help)*--registry-mirror=[Preferred registry mirror]:registry mirror: " \ + "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ + "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(btrfs devicemapper overlay2 vfs zfs)" \ + "($help)--selinux-enabled[Enable selinux support]" \ + "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ + "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ + "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" \ + "($help)--validate[Validate daemon configuration and exit]" && ret=0 + + case $state in + (users-groups) + if compset -P '*:'; then + _groups && ret=0 + else + _describe -t userns-default "default Docker user management" '(default)' && ret=0 + _users && ret=0 + fi + ;; + esac + ;; + (events|info) + __docker_system_subcommand && ret=0 + ;; + (image) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_image_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_image_subcommand && ret=0 + ;; + esac + ;; + (images) + words[1]='ls' + __docker_image_subcommand && ret=0 + ;; + (inspect) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ + "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ + "($help -)*: :->values" && ret=0 + + case $state in + (values) + if [[ ${words[(r)--type=container]} == --type=container ]]; then + __docker_complete_containers && ret=0 + elif [[ ${words[(r)--type=image]} == --type=image ]]; then + __docker_complete_images && ret=0 + elif [[ ${words[(r)--type=network]} == --type=network ]]; then + __docker_complete_networks && ret=0 + elif [[ ${words[(r)--type=node]} == --type=node ]]; then + __docker_complete_nodes && ret=0 + elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then + __docker_complete_plugins && ret=0 + elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then + __docker_complete_secrets && ret=0 + elif [[ ${words[(r)--type=service]} == --type=service ]]; then + __docker_complete_services && ret=0 + elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then + __docker_complete_volumes && ret=0 + else + __docker_complete_containers + __docker_complete_images + __docker_complete_networks + __docker_complete_nodes + __docker_complete_plugins + __docker_complete_secrets + __docker_complete_services + __docker_complete_volumes && ret=0 + fi + ;; + esac + ;; + (login) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -p --password)"{-p=,--password=}"[Password]:password: " \ + "($help)--password-stdin[Read password from stdin]" \ + "($help -u --username)"{-u=,--username=}"[Username]:username: " \ + "($help -)1:server: " && ret=0 + ;; + (logout) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -)1:server: " && ret=0 + ;; + (network) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_network_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_network_subcommand && ret=0 + ;; + esac + ;; + (node) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_node_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_node_subcommand && ret=0 + ;; + esac + ;; + (plugin) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_plugin_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_plugin_subcommand && ret=0 + ;; + esac + ;; + (ps) + words[1]='ls' + __docker_container_subcommand && ret=0 + ;; + (rmi) + words[1]='rm' + __docker_image_subcommand && ret=0 + ;; + (search) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_search_filters" \ + "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -):term: " && ret=0 + ;; + (secret) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_secret_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_secret_subcommand && ret=0 + ;; + esac + ;; + (service) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_service_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_service_subcommand && ret=0 + ;; + esac + ;; + (stack) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_stack_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_stack_subcommand && ret=0 + ;; + esac + ;; + (swarm) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_swarm_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_swarm_subcommand && ret=0 + ;; + esac + ;; + (system) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_system_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_system_subcommand && ret=0 + ;; + esac + ;; + (version) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 + ;; + (volume) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_volume_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_volume_subcommand && ret=0 + ;; + esac + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 + ;; + esac + + return ret +} + +_docker() { + # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. + # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. + if [[ $service != docker ]]; then + _call_function - _$service + return + fi + + local curcontext="$curcontext" state line help="-h --help" + integer ret=1 + typeset -A opt_args + + _arguments $(__docker_arguments) -C \ + "(: -)"{-h,--help}"[Print usage]" \ + "($help)--config[Location of client config files]:path:_directories" \ + "($help -c --context)"{-c=,--context=}"[Execute the command in a docker context]:context:__docker_complete_contexts" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ + "($help -v --version)"{-v,--version}"[Print version information and quit]" \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + local host=${opt_args[-H]}${opt_args[--host]} + local config=${opt_args[--config]} + local context=${opt_args[-c]}${opt_args[--context]} + local docker_options="${host:+--host $host} ${config:+--config $config} ${context:+--context $context} " + + case $state in + (command) + __docker_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-$words[1]: + __docker_subcommand && ret=0 + ;; + esac + + return ret +} + +_dockerd() { + integer ret=1 + words[1]='daemon' + __docker_subcommand && ret=0 + return ret +} + +_docker "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 4 +# indent-tabs-mode: nil +# sh-basic-offset: 4 +# End: +# vim: ft=zsh sw=4 ts=4 et diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index 3abce6466..7777048a3 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -36,6 +36,11 @@ if (( ! $+commands[docker] )); then return fi +# Standarized $0 handling +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" + { # docker version returns `Docker version 24.0.2, build cb74dfcd85` # with `s:,:` remove the comma after the version, and select third word of it @@ -50,5 +55,7 @@ fi _comps[docker]=_docker fi command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" + else + command cp "${0:h}/completions/_docker" "$ZSH_CACHE_DIR/completions/_docker" fi } &| -- cgit v1.2.3-70-g09d2 From 8bdb5c959c9a5c74d3b59c05a3a0bca5e602c3cd Mon Sep 17 00:00:00 2001 From: Jarrett Lusso Date: Sat, 15 Jul 2023 16:10:48 -0400 Subject: docs(nvm): clarify autoload setup (#11797) --- plugins/nvm/README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index eee3bf717..b5ef221d3 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -52,12 +52,7 @@ version to load. This can be done, similar as previous options, adding: ```zsh zstyle ':omz:plugins:nvm' autoload yes -``` - -To remove the output generated by NVM when autoloading, you can set the following option: - -```zsh -zstyle ':omz:plugins:nvm' silent-autoload yes +zstyle ':omz:plugins:nvm' silent-autoload yes # optionally remove the output generated by NVM when autoloading ``` Note: _this will not remove regular `nvm` output_ -- cgit v1.2.3-70-g09d2 From b3427f0de6cf7a2ea8387366c44257663e72555c Mon Sep 17 00:00:00 2001 From: majick <125657+majick@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:28:33 +0200 Subject: fix(ubuntu)!: rename `acse` alias to `acs` Closes #11799 This commit reverses 5bfdd0356b46dc711a8f0866eeb9b717c033d5b2 BREAKING CHANGE: reverting alias rename from `acs` to `acse`. --- plugins/debian/README.md | 2 +- plugins/debian/debian.plugin.zsh | 2 +- plugins/ubuntu/README.md | 2 +- plugins/ubuntu/ubuntu.plugin.zsh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/debian/README.md b/plugins/debian/README.md index c1ebe1c50..1db534f13 100644 --- a/plugins/debian/README.md +++ b/plugins/debian/README.md @@ -21,7 +21,7 @@ Set `$apt_pref` and `$apt_upgr` to whatever command you want (before sourcing Oh | ------ | ---------------------------------------------------------------------- | ---------------------------------------------------------- | | `age` | `apt-get` | Command line tool for handling packages | | `api` | `aptitude` | Same functionality as `apt-get`, provides extra options | -| `acse` | `apt-cache search` | Command line tool for searching apt software package cache | +| `acs` | `apt-cache search` | Command line tool for searching apt software package cache | | `aps` | `aptitude search` | Searches installed packages using aptitude | | `as` | `aptitude -F '* %p -> %d \n(%v/%V)' --no-gui --disable-columns search` | Print searched packages using a custom format | | `afs` | `apt-file search --regexp` | Search file in packages | diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index bab1ae1c6..5ef4cfb67 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -26,7 +26,7 @@ alias age='apt-get' alias api='aptitude' # Some self-explanatory aliases -alias acse="apt-cache search" +alias acs="apt-cache search" alias aps='aptitude search' alias as="aptitude -F '* %p -> %d \n(%v/%V)' --no-gui --disable-columns search" diff --git a/plugins/ubuntu/README.md b/plugins/ubuntu/README.md index 2401c102b..20f5c65ee 100644 --- a/plugins/ubuntu/README.md +++ b/plugins/ubuntu/README.md @@ -15,7 +15,7 @@ Commands that use `$APT` will use `apt` if installed or defer to `apt-get` other | Alias | Command | Description | |---------|--------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| | age | `sudo $APT` | Run apt-get with sudo | -| acse | `apt-cache search` | Search the apt-cache with the specified criteria | +| acs | `apt-cache search` | Search the apt-cache with the specified criteria | | acsp | `apt-cache showpkg` | Shows information about the listed packages | | acp | `apt-cache policy` | Display the package source priorities | | afs | `apt-file search --regexp` | Perform a regular expression apt-file search | diff --git a/plugins/ubuntu/ubuntu.plugin.zsh b/plugins/ubuntu/ubuntu.plugin.zsh index 4d35da2ac..7b765a406 100644 --- a/plugins/ubuntu/ubuntu.plugin.zsh +++ b/plugins/ubuntu/ubuntu.plugin.zsh @@ -1,6 +1,6 @@ (( $+commands[apt] )) && APT=apt || APT=apt-get -alias acse='apt-cache search' +alias acs='apt-cache search' alias afs='apt-file search --regexp' -- cgit v1.2.3-70-g09d2 From 33fbbdbb0d46e87d76bbef94ac07ceff2cd0b47e Mon Sep 17 00:00:00 2001 From: majick <125657+majick@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:28:55 +0200 Subject: fix(aliases)!: rename `acs` to `als` BREAKING CHANGE: rename main function from `acs` to `als` to avoid conflicts with `ubuntu` and `debian` plugins and improve semantics. --- plugins/aliases/README.md | 10 +++++----- plugins/aliases/aliases.plugin.zsh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/aliases/README.md b/plugins/aliases/README.md index 6a2da3d74..419554095 100644 --- a/plugins/aliases/README.md +++ b/plugins/aliases/README.md @@ -15,14 +15,14 @@ Requirements: Python needs to be installed. ## Usage -- `acs`: show all aliases by group +- `als`: show all aliases by group -- `acs -h/--help`: print help mesage +- `als -h/--help`: print help mesage -- `acs `: filter and highlight aliases by `` +- `als `: filter and highlight aliases by `` -- `acs -g /--group `: show only aliases for group ``. Multiple uses of the flag show all groups +- `als -g /--group `: show only aliases for group ``. Multiple uses of the flag show all groups -- `acs --groups`: show only group names +- `als --groups`: show only group names ![screenshot](https://cloud.githubusercontent.com/assets/3602957/11581913/cb54fb8a-9a82-11e5-846b-5a67f67ad9ad.png) diff --git a/plugins/aliases/aliases.plugin.zsh b/plugins/aliases/aliases.plugin.zsh index 9864de957..7f1ba83b8 100644 --- a/plugins/aliases/aliases.plugin.zsh +++ b/plugins/aliases/aliases.plugin.zsh @@ -4,7 +4,7 @@ 0="${${(M)0:#/*}:-$PWD/$0}" eval ' - function acs(){ + function als(){ (( $+commands[python3] )) || { echo "[error] No python executable detected" return -- cgit v1.2.3-70-g09d2 From 7cf00a0b5cf0f25c16fc7902f78dff480e03fe3d Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 19 Jul 2023 14:46:35 +0200 Subject: fix(nvm): remove nvm not found verbose message --- plugins/nvm/nvm.plugin.zsh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 484ef2964..1badbeab5 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -16,13 +16,7 @@ fi # Note: nvm is a function so we need to use `which` which nvm &>/dev/null && return -if [[ -z "$NVM_DIR" ]]; then - echo "[oh-my-zsh] nvm installation cannot be found" - echo "[oh-my-zsh] set NVM_DIR to your installation" - return -fi -if [[ ! -f "$NVM_DIR/nvm.sh" ]]; then - echo "[oh-my-zsh] nvm.sh does not exist in $NVM_DIR" +if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then return fi -- cgit v1.2.3-70-g09d2 From c4392a4da31efee36f29a62d3951d5c0fcd7d4e6 Mon Sep 17 00:00:00 2001 From: Jokeoo <30483934+SunJun8@users.noreply.github.com> Date: Wed, 19 Jul 2023 21:03:38 +0800 Subject: feat(tig): add two new aliases (#11090) --- plugins/tig/tig.plugin.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/tig/tig.plugin.zsh b/plugins/tig/tig.plugin.zsh index 7e0c530ac..5b7d2550a 100644 --- a/plugins/tig/tig.plugin.zsh +++ b/plugins/tig/tig.plugin.zsh @@ -1,3 +1,5 @@ alias tis='tig status' alias til='tig log' alias tib='tig blame -C' +alias tif='tig reflog' +alias tia='tig --all' -- cgit v1.2.3-70-g09d2 From 7d5e12500a2ba0b575ffafcbb516568973528730 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 20 Jul 2023 10:43:56 +0200 Subject: feat(docker): add `legacy-completion` option --- plugins/docker/README.md | 11 ++++++++++- plugins/docker/docker.plugin.zsh | 27 ++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/plugins/docker/README.md b/plugins/docker/README.md index 512b5d17c..0ab2e41fb 100644 --- a/plugins/docker/README.md +++ b/plugins/docker/README.md @@ -30,6 +30,15 @@ file**, but be aware of the side effects: > zstyle ':completion:*:*:docker-*:*' option-stacking yes > ``` +### Use old-style completion + +If the current completion does not work well for you, you can enable legacy completion instead with the +following setting. See https://github.com/ohmyzsh/ohmyzsh/issues/11789 for more information. + +```zsh +zstyle ':omz:plugins:docker' legacy-completion yes +``` + ## Aliases | Alias | Command | Description | @@ -58,7 +67,7 @@ file**, but be aware of the side effects: | drm | `docker container rm` | Remove the specified container(s) | | drm! | `docker container rm -f` | Force the removal of a running container (uses SIGKILL) | | dst | `docker container start` | Start one or more stopped containers | -| drs | `docker container restart` | Restart one or more containers +| drs | `docker container restart` | Restart one or more containers | | dsta | `docker stop $(docker ps -q)` | Stop all running containers | | dstp | `docker container stop` | Stop one or more running containers | | dtop | `docker top` | Display the running processes of a container | diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index 7777048a3..7e657f2df 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -41,21 +41,22 @@ fi 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" 0="${${(M)0:#/*}:-$PWD/$0}" +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `docker`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then + typeset -g -A _comps + autoload -Uz _docker + _comps[docker]=_docker +fi + { + # `docker completion` is only available from 23.0.0 on # docker version returns `Docker version 24.0.2, build cb74dfcd85` # with `s:,:` remove the comma after the version, and select third word of it - local _docker_version=${${(s:,:z)"$(command docker --version)"}[3]} - # `docker completion` is only available from 23.0.0 on - if is-at-least 23.0.0 $_docker_version; then - # If the completion file doesn't exist yet, we need to autoload it and - # bind it to `docker`. Otherwise, compinit will have already done that. - if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then - typeset -g -A _comps - autoload -Uz _docker - _comps[docker]=_docker - fi - command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" - else - command cp "${0:h}/completions/_docker" "$ZSH_CACHE_DIR/completions/_docker" + if zstyle -t ':omz:plugins:docker' legacy-completion || \ + ! is-at-least 23.0.0 ${${(s:,:z)"$(command docker --version)"}[3]}; then + command cp "${0:h}/completions/_docker" "$ZSH_CACHE_DIR/completions/_docker" + else + command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" fi } &| -- cgit v1.2.3-70-g09d2 From b9354c5e9c29bd2d5b53731847855d25381c157c Mon Sep 17 00:00:00 2001 From: Zou Yang Date: Mon, 24 Jul 2023 01:44:30 +0800 Subject: fix(michelebologna): use blue instead of white (#11810) --- themes/michelebologna.zsh-theme | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/themes/michelebologna.zsh-theme b/themes/michelebologna.zsh-theme index bb86d68db..b13b2caf1 100644 --- a/themes/michelebologna.zsh-theme +++ b/themes/michelebologna.zsh-theme @@ -29,14 +29,13 @@ local cyan="%{$fg_bold[cyan]%}" local yellow="%{$fg_bold[yellow]%}" local blue="%{$fg_bold[blue]%}" local magenta="%{$fg_bold[magenta]%}" -local white="%{$fg_bold[white]%}" local reset="%{$reset_color%}" local -a color_array -color_array=($green $red $cyan $yellow $blue $magenta $white) +color_array=($green $red $cyan $yellow $blue $magenta) -local username_color=$white -local hostname_color=$color_array[$[((#HOST))%7+1]] # choose hostname color based on first character +local username_color=$blue +local hostname_color=$color_array[$[((#HOST))%6+1]] # choose hostname color based on first character local current_dir_color=$blue local username="%n" @@ -66,10 +65,10 @@ function michelebologna_git_prompt { local out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status) [[ -n $out ]] || return printf " %s(%s%s%s)%s" \ - "%{$fg_bold[white]%}" \ + "%{$fg_bold[blue]%}" \ "%{$fg_bold[green]%}" \ "$out" \ - "%{$fg_bold[white]%}" \ + "%{$fg_bold[blue]%}" \ "%{$reset_color%}" } -- cgit v1.2.3-70-g09d2 From 338b9a615a276240deaf4b6a26bb3abda204fe3f Mon Sep 17 00:00:00 2001 From: cohml <62400541+cohml@users.noreply.github.com> Date: Sun, 23 Jul 2023 16:02:17 -0400 Subject: fix(per-directory-history): ^G also in vi mode (#11808) Co-authored-by: Chris Hamill --- plugins/per-directory-history/per-directory-history.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/per-directory-history/per-directory-history.zsh b/plugins/per-directory-history/per-directory-history.zsh index 7cd673cdb..acbd64757 100644 --- a/plugins/per-directory-history/per-directory-history.zsh +++ b/plugins/per-directory-history/per-directory-history.zsh @@ -81,6 +81,7 @@ function per-directory-history-toggle-history() { autoload per-directory-history-toggle-history zle -N per-directory-history-toggle-history bindkey $PER_DIRECTORY_HISTORY_TOGGLE per-directory-history-toggle-history +bindkey -M vicmd $PER_DIRECTORY_HISTORY_TOGGLE per-directory-history-toggle-history #------------------------------------------------------------------------------- # implementation details -- cgit v1.2.3-70-g09d2 From 6925c44af4bf909a1e023aaa7243e1752db2439a Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 25 Jul 2023 01:22:33 +0200 Subject: fix(aliases): rename acs to als in script help Closes #11812 --- plugins/aliases/cheatsheet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aliases/cheatsheet.py b/plugins/aliases/cheatsheet.py index f742fba9e..61bf5f956 100644 --- a/plugins/aliases/cheatsheet.py +++ b/plugins/aliases/cheatsheet.py @@ -57,7 +57,7 @@ def pretty_print(cheatsheet, wfilter, group_list=None, groups_only=False): pretty_print_group(key, [ alias for alias in aliases if alias[0].find(wfilter)>-1 or alias[1].find(wfilter)>-1], wfilter) if __name__ == '__main__': - parser = argparse.ArgumentParser(description="Pretty print aliases.", prog="acs") + parser = argparse.ArgumentParser(description="Pretty print aliases.", prog="als") parser.add_argument('filter', nargs="*", metavar="", help="search aliases matching keywords") parser.add_argument('-g', '--group', dest="group_list", action='append', help="only print aliases in given groups") parser.add_argument('--groups', dest='groups_only', action='store_true', help="only print alias groups") -- cgit v1.2.3-70-g09d2 From e564793939a086fc4c46628b193a38997ea4ecb3 Mon Sep 17 00:00:00 2001 From: naturedamends <120284608+naturedamends@users.noreply.github.com> Date: Tue, 25 Jul 2023 09:25:07 +0100 Subject: feat(fino-time): add conda environment (#11785) --- themes/fino-time.zsh-theme | 1 + 1 file changed, 1 insertion(+) diff --git a/themes/fino-time.zsh-theme b/themes/fino-time.zsh-theme index c7e2d965e..3f9360ac5 100644 --- a/themes/fino-time.zsh-theme +++ b/themes/fino-time.zsh-theme @@ -12,6 +12,7 @@ # Also borrowing from http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/ function virtualenv_info { + [ $CONDA_DEFAULT_ENV ] && echo "($CONDA_DEFAULT_ENV) " [ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' } -- cgit v1.2.3-70-g09d2 From 4188b22aea3356a02768505103e42a96d18547a3 Mon Sep 17 00:00:00 2001 From: jabunovoty Date: Tue, 25 Jul 2023 10:31:24 +0200 Subject: feat(agnoster): add git tag to prompt (#8417) Co-authored-by: Jakub Novotny --- themes/agnoster.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index 88854eccd..aa274a5bb 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -109,7 +109,9 @@ prompt_git() { if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then repo_path=$(git rev-parse --git-dir 2>/dev/null) dirty=$(parse_git_dirty) - ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)" + ref=$(git symbolic-ref HEAD 2> /dev/null) || \ + ref="◈ $(git describe --exact-match --tags HEAD 2> /dev/null)" || \ + ref="➦ $(git rev-parse --short HEAD 2> /dev/null)" if [[ -n $dirty ]]; then prompt_segment yellow black else -- cgit v1.2.3-70-g09d2 From 7d2aedf199d1e27b6bea8ab33212043b055b3715 Mon Sep 17 00:00:00 2001 From: David LJ Date: Wed, 9 Aug 2023 18:27:39 +0200 Subject: chore(gitignore): use new API endpoint from TopTal (#11835) --- plugins/gitignore/README.md | 2 +- plugins/gitignore/gitignore.plugin.zsh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/gitignore/README.md b/plugins/gitignore/README.md index 753dd31fd..23c7887cf 100644 --- a/plugins/gitignore/README.md +++ b/plugins/gitignore/README.md @@ -1,6 +1,6 @@ # gitignore -This plugin enables you the use of [gitignore.io](https://www.gitignore.io/) from the command line. You need an active internet connection. +This plugin enables you the use of [gitignore.io](https://www.toptal.com/developers/gitignore) from the command line. You need an active internet connection. To use it, add `gitignore` to the plugins array in your zshrc file: diff --git a/plugins/gitignore/gitignore.plugin.zsh b/plugins/gitignore/gitignore.plugin.zsh index a687f5cce..3271d61a9 100644 --- a/plugins/gitignore/gitignore.plugin.zsh +++ b/plugins/gitignore/gitignore.plugin.zsh @@ -1,7 +1,7 @@ -function gi() { curl -fLw '\n' https://www.gitignore.io/api/"${(j:,:)@}" } +function gi() { curl -fLw '\n' https://www.toptal.com/developers/gitignore/api/"${(j:,:)@}" } _gitignoreio_get_command_list() { - curl -sfL https://www.gitignore.io/api/list | tr "," "\n" + curl -sfL https://www.toptal.com/developers/gitignore/api/list | tr "," "\n" } _gitignoreio () { -- cgit v1.2.3-70-g09d2 From fd219a94ab585fa699a0e842335a9f33dcbb613b Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 10 Aug 2023 15:39:40 +0200 Subject: docs(aliases): replace screenshot Closes #11837 Closes #11822 --- plugins/aliases/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aliases/README.md b/plugins/aliases/README.md index 419554095..53b68ea01 100644 --- a/plugins/aliases/README.md +++ b/plugins/aliases/README.md @@ -25,4 +25,4 @@ Requirements: Python needs to be installed. - `als --groups`: show only group names - ![screenshot](https://cloud.githubusercontent.com/assets/3602957/11581913/cb54fb8a-9a82-11e5-846b-5a67f67ad9ad.png) + ![screenshot](https://github.com/ohmyzsh/ohmyzsh/assets/66907184/5bfa00ea-5fc3-4e97-8b22-2f74f6b948c7) -- cgit v1.2.3-70-g09d2 From b81915d3293cc4657cec64202b9fd991b96b4ba2 Mon Sep 17 00:00:00 2001 From: Jin Cheol <76617139+bik1111@users.noreply.github.com> Date: Wed, 16 Aug 2023 20:46:28 +0900 Subject: feat(terraform): add terraform version prompt (#11845) --- plugins/terraform/README.md | 13 ++++++++----- plugins/terraform/terraform.plugin.zsh | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/terraform/README.md b/plugins/terraform/README.md index c19f2ad1c..fc9a9f005 100644 --- a/plugins/terraform/README.md +++ b/plugins/terraform/README.md @@ -1,7 +1,7 @@ # Terraform plugin -Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently. -It adds completion for `terraform`, as well as aliases and a prompt function. +Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently. It adds +completion for `terraform`, as well as aliases and a prompt function. To use it, add `terraform` to the plugins array of your `~/.zshrc` file: @@ -11,7 +11,7 @@ plugins=(... terraform) ## Requirements -* [Terraform](https://terraform.io/) +- [Terraform](https://terraform.io/) ## Aliases @@ -29,11 +29,12 @@ plugins=(... terraform) ## Prompt function -You can add the current Terraform workspace in your prompt by adding `$(tf_prompt_info)` -to your `PROMPT` or `RPROMPT` variable. +You can add the current Terraform workspace in your prompt by adding `$(tf_prompt_info)`, +`$(tf_version_prompt_info)` to your `PROMPT` or `RPROMPT` variable. ```sh RPROMPT='$(tf_prompt_info)' +RPROMPT='$(tf_version_prompt_info)' ``` You can also specify the PREFIX and SUFFIX for the workspace with the following variables: @@ -41,4 +42,6 @@ You can also specify the PREFIX and SUFFIX for the workspace with the following ```sh ZSH_THEME_TF_PROMPT_PREFIX="%{$fg[white]%}" ZSH_THEME_TF_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_TF_VERSION_PROMPT_PREFIX="%{$fg[white]%}" +ZSH_THEME_TF_VERSION_PROMPT_SUFFIX="%{$reset_color%}" ``` diff --git a/plugins/terraform/terraform.plugin.zsh b/plugins/terraform/terraform.plugin.zsh index 7006f204b..ccca54684 100644 --- a/plugins/terraform/terraform.plugin.zsh +++ b/plugins/terraform/terraform.plugin.zsh @@ -8,6 +8,13 @@ function tf_prompt_info() { echo "${ZSH_THEME_TF_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TF_PROMPT_SUFFIX-]}" } +function tf_version_prompt_info() { + local terraform_version + terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2) + echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}" +} + + alias tf='terraform' alias tfa='terraform apply' alias tfc='terraform console' -- cgit v1.2.3-70-g09d2 From 6bc4c80c7db072a0d2d265eb3589bbe52e0d2737 Mon Sep 17 00:00:00 2001 From: Ahmed Wael <73046395+ahmedwael216@users.noreply.github.com> Date: Mon, 21 Aug 2023 19:07:28 +0300 Subject: fix(colored-man-pages): add env GROFF_NO_SGR=1 (#11831) --- plugins/colored-man-pages/colored-man-pages.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/colored-man-pages/colored-man-pages.plugin.zsh b/plugins/colored-man-pages/colored-man-pages.plugin.zsh index 981992d88..57facbb5c 100644 --- a/plugins/colored-man-pages/colored-man-pages.plugin.zsh +++ b/plugins/colored-man-pages/colored-man-pages.plugin.zsh @@ -36,6 +36,7 @@ function colored() { # Prefer `less` whenever available, since we specifically configured # environment for it. environment+=( PAGER="${commands[less]:-$PAGER}" ) + environment+=( GROFF_NO_SGR=1 ) # See ./nroff script. if [[ "$OSTYPE" = solaris* ]]; then -- cgit v1.2.3-70-g09d2 From dfe2f04de7e839ae0a9757c37a26b9d8710aa372 Mon Sep 17 00:00:00 2001 From: LuckyWindsck Date: Tue, 22 Aug 2023 01:09:02 +0900 Subject: refactor(init): rename variable (#11851) --- oh-my-zsh.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index a577c1f41..40f13f37e 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -187,12 +187,12 @@ _omz_source() { fi } -# Load all of the config files in ~/oh-my-zsh that end in .zsh +# Load all of the lib files in ~/oh-my-zsh/lib that end in .zsh # TIP: Add files you don't want in git to .gitignore -for config_file ("$ZSH"/lib/*.zsh); do - _omz_source "lib/${config_file:t}" +for lib_file ("$ZSH"/lib/*.zsh); do + _omz_source "lib/${lib_file:t}" done -unset custom_config_file +unset lib_file # Load all of the plugins that were defined in ~/.zshrc for plugin ($plugins); do -- cgit v1.2.3-70-g09d2 From 3f477e5da5ee42356f103d2c5cdd478d23bf9f03 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 23 Aug 2023 13:25:33 +0200 Subject: fix(extract): extraction to directory for single-file .gz (#11852) --- plugins/extract/extract.plugin.zsh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index b7a823c9f..513950f33 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -64,7 +64,7 @@ EOF (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;; (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;; (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;; - (*.gz) (( $+commands[pigz] )) && pigz -dk "$full_path" || gunzip -k "$full_path" ;; + (*.gz) (( $+commands[pigz] )) && pigz -cdk "$full_path" > "${file:t:r}" || gunzip -ck "$full_path" > "${file:t:r}" ;; (*.bz2) bunzip2 "$full_path" ;; (*.xz) unxz "$full_path" ;; (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;; @@ -106,19 +106,19 @@ EOF # - Y2: at most give 2 files local -a content content=("${extract_dir}"/*(DNY2)) - if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then - # The extracted folder (${content[1]}) may have the same name as $extract_dir + if [[ ${#content} -eq 1 && -e "${content[1]}" ]]; then + # The extracted file/folder (${content[1]}) may have the same name as $extract_dir # If so, we need to rename it to avoid conflicts in a 3-step process # - # 1. Move and rename the extracted folder to a temporary random name + # 1. Move and rename the extracted file/folder to a temporary random name # 2. Delete the empty folder - # 3. Rename the extracted folder to the original name + # 3. Rename the extracted file/folder to the original name if [[ "${content[1]:t}" == "$extract_dir" ]]; then # =(:) gives /tmp/zsh, with :t it gives zsh - local tmp_dir==(:); tmp_dir="${tmp_dir:t}" - command mv "${content[1]}" "$tmp_dir" \ + local tmp_name==(:); tmp_name="${tmp_name:t}" + command mv "${content[1]}" "$tmp_name" \ && command rmdir "$extract_dir" \ - && command mv "$tmp_dir" "$extract_dir" + && command mv "$tmp_name" "$extract_dir" # Otherwise, if the extracted folder name already exists in the current # directory (because of a previous file / folder), keep the extract_dir elif [[ ! -e "${content[1]:t}" ]]; then -- cgit v1.2.3-70-g09d2 From 33c0de7add12b050b94fd6f2f988e9b5547d172c Mon Sep 17 00:00:00 2001 From: Miguel Hargreaves Pimenta Date: Wed, 23 Aug 2023 12:38:32 +0100 Subject: refactor(git): sort git aliases alphabetically (#9743) --- plugins/git/README.md | 419 ++++++++++++++++++++++--------------------- plugins/git/git.plugin.zsh | 434 ++++++++++++++++++++++----------------------- 2 files changed, 427 insertions(+), 426 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index d18531955..0b757c481 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -10,213 +10,214 @@ plugins=(... git) ## Aliases -| Alias | Command | -| :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| g | git | -| ga | git add | -| gaa | git add --all | -| gapa | git add --patch | -| gau | git add --update | -| gav | git add --verbose | -| gap | git apply | -| gapt | git apply --3way | -| gb | git branch | -| gba | git branch --all | -| gbd | git branch --delete | -| gbda | git branch --no-color --merged \| grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| xargs git branch --delete 2>/dev/null | -| gbD | git branch --delete --force | -| gbg | git branch -vv | grep ": gone\]" | -| gbgd | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d | -| gbgD | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D | -| gbl | git blame -b -w | -| gbnm | git branch --no-merged | -| gbr | git branch --remote | -| gbs | git bisect | -| gbsb | git bisect bad | -| gbsg | git bisect good | -| gbsr | git bisect reset | -| gbss | git bisect start | -| gc | git commit --verbose | -| gc! | git commit --verbose --amend | -| gcn! | git commit --verbose --no-edit --amend | -| gca | git commit --verbose --all | -| gca! | git commit --verbose --all --amend | -| gcan! | git commit --verbose --all --no-edit --amend | -| gcans! | git commit --verbose --all --signoff --no-edit --amend | -| gcam | git commit --all --message | -| gcas | git commit --all --signoff | -| gcasm | git commit --all --signoff --message | -| gcsm | git commit --signoff --message | -| gcb | git checkout -b | -| gcf | git config --list | -| gcl | git clone --recurse-submodules | -| gccd | git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)" | -| gclean | git clean --interactive -d | -| gpristine | git reset --hard && git clean -dffx | -| gcm | git checkout $(git_main_branch) | -| gcd | git checkout $(git_develop_branch) | -| gcmsg | git commit --message | -| gco | git checkout | -| gcor | git checkout --recurse-submodules | -| gcount | git shortlog --summary -n | -| gcp | git cherry-pick | -| gcpa | git cherry-pick --abort | -| gcpc | git cherry-pick --continue | -| gcs | git commit -S | -| gcss | git commit -S -s | -| gcssm | git commit -S -s -m | -| gd | git diff | -| gdca | git diff --cached | -| gdcw | git diff --cached --word-diff | -| gdct | git describe --tags $(git rev-list --tags --max-count=1) | -| gds | git diff --staged | -| gdt | git diff-tree --no-commit-id --name-only -r | -| gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock" | -| gdup | git diff @{upstream} | -| gdv | git diff -w $@ \| view - | -| gdw | git diff --word-diff | -| gf | git fetch | -| gfa | git fetch --all --prune | -| gfg | git ls-files \| grep | -| gfo | git fetch origin | -| gg | git gui citool | -| gga | git gui citool --amend | -| ggf | git push --force origin $(current_branch) | -| ggfl | git push --force-with-lease origin $(current_branch) | -| ggl | git pull origin $(current_branch) | -| ggp | git push origin $(current_branch) | -| ggpnp | ggl && ggp | -| ggpull | git pull origin "$(git_current_branch)" | -| ggpur | ggu | -| ggpush | git push origin "$(git_current_branch)" | -| ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | -| ggu | git pull --rebase origin $(current_branch) | -| gpsup | git push --set-upstream origin $(git_current_branch) | -| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30) | -| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30) | -| ghh | git help | -| gignore | git update-index --assume-unchanged | -| gignored | git ls-files -v \| grep "^[[:lower:]]" | -| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk | -| gk | gitk --all --branches &! | -| gke | gitk --all $(git log --walk-reflogs --pretty=%h) &! | -| gl | git pull | -| glg | git log --stat | -| glgp | git log --stat --patch | -| glgg | git log --graph | -| glgga | git log --graph --decorate --all | -| glgm | git log --graph --max-count=10 | -| glo | git log --oneline --decorate | -| glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' | -| glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat | -| glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | -| glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short | -| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all | -| glog | git log --oneline --decorate --graph | -| gloga | git log --oneline --decorate --graph --all | -| glp | git log --pretty=\ | -| gm | git merge | -| gms | git merge --squash | -| gmom | git merge origin/$(git_main_branch) | -| gmtl | git mergetool --no-prompt | -| gmtlvim | git mergetool --no-prompt --tool=vimdiff | -| gmum | git merge upstream/$(git_main_branch) | -| gma | git merge --abort | -| gp | git push | -| gpd | git push --dry-run | -| gpf | git push --force-with-lease --force-if-includes (git version >= 2.30) | -| gpf | git push --force-with-lease (git version < 2.30) | -| gpf! | git push --force | -| gpoat | git push origin --all && git push origin --tags | -| gpod | git push origin --delete | -| gpr | git pull --rebase | -| gpu | git push upstream | -| gpv | git push --verbose | -| gr | git remote | -| gra | git remote add | -| grb | git rebase | -| grba | git rebase --abort | -| grbc | git rebase --continue | -| grbd | git rebase $(git_develop_branch) | -| grbi | git rebase --interactive | -| grbm | git rebase $(git_main_branch) | -| grbom | git rebase origin/$(git_main_branch) | -| grbo | git rebase --onto | -| grbs | git rebase --skip | -| grev | git revert | -| grh | git reset | -| grhh | git reset --hard | -| groh | git reset origin/$(git_current_branch) --hard | -| grm | git rm | -| grmc | git rm --cached | -| grmv | git remote rename | -| grrm | git remote remove | -| grs | git restore | -| grset | git remote set-url | -| grss | git restore --source | -| grst | git restore --staged | -| grt | cd "$(git rev-parse --show-toplevel \|\| echo .)" | -| gru | git reset -- | -| grup | git remote update | -| grv | git remote --verbose | -| gsb | git status --short -b | -| gsd | git svn dcommit | -| gsh | git show | -| gsi | git submodule init | -| gsps | git show --pretty=short --show-signature | -| gsr | git svn rebase | -| gss | git status --short | -| gst | git status | -| gsta | git stash push (git version >= 2.13) | -| gsta | git stash save (git version < 2.13) | -| gstaa | git stash apply | -| gstc | git stash clear | -| gstd | git stash drop | -| gstl | git stash list | -| gstp | git stash pop | -| gsts | git stash show --text | -| gstu | git stash --include-untracked | -| gstall | git stash --all | -| gsu | git submodule update | -| gsw | git switch | -| gswc | git switch -c | -| gswm | git switch $(git_main_branch) | -| gswd | git switch $(git_develop_branch) | -| gts | git tag -s | -| gtv | git tag \| sort -V | -| gtl | gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl | -| gunignore | git update-index --no-assume-unchanged | -| gunwip | git rev-list --max-count=1 --format="%s" HEAD \| grep -q "\-\-wip\-\-" && git reset HEAD~1 | -| gup | git pull --rebase | -| gupv | git pull --rebase --verbose | -| gupa | git pull --rebase --autostash | -| gupav | git pull --rebase --autostash --verbose | -| gupom | git pull --rebase origin $(git_main_branch) | -| gupomi | git pull --rebase=interactive origin $(git_main_branch) | -| glum | git pull upstream $(git_main_branch) | -| gluc | git pull upstream $(git_current_branch) | -| gwch | git whatchanged -p --abbrev-commit --pretty=medium | -| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]" | -| gam | git am | -| gamc | git am --continue | -| gams | git am --skip | -| gama | git am --abort | -| gamscp | git am --show-current-patch | -| gwt | git worktree | -| gwtls | git worktree list | -| gwtmv | git worktree move | -| gwtrm | git worktree remove | +| Alias | Command | +| :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| grt | cd "$(git rev-parse --show-toplevel || echo .)" | +| ggpnp | ggl && ggp | +| ggpur | ggu | +| g | git | +| ga | git add | +| gaa | git add --all | +| gapa | git add --patch | +| gau | git add --update | +| gav | git add --verbose | +| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]" | +| gam | git am | +| gama | git am --abort | +| gamc | git am --continue | +| gamscp | git am --show-current-patch | +| gams | git am --skip | +| gap | git apply | +| gapt | git apply --3way | +| gbs | git bisect | +| gbsb | git bisect bad | +| gbsg | git bisect good | +| gbsr | git bisect reset | +| gbss | git bisect start | +| gbl | git blame -b -w | +| gb | git branch | +| gba | git branch --all | +| gbd | git branch --delete | +| gbD | git branch --delete --force | +| gbda | git branch --no-color --merged | grep -vE "^([+]|\s($(git_main_branch)|$(git_develop_branch))\s\*$)" | xargs git branch --delete 2>/dev/null | +| gbgd | git branch --no-color -vv | +| gbgD | git branch --no-color -vv | +| gbnm | git branch --no-merged | +| gbr | git branch --remote | +| ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | +| gbg | git branch -vv | +| gco | git checkout | +| gcor | git checkout --recurse-submodules | +| gcb | git checkout -b | +| gcd | git checkout $(git_develop_branch) | +| gcm | git checkout $(git_main_branch) | +| gcp | git cherry-pick | +| gcpa | git cherry-pick --abort | +| gcpc | git cherry-pick --continue | +| gclean | git clean --interactive -d | +| gcl | git clone --recurse-submodules | +| gccd | git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)" | +| gcam | git commit --all --message | +| gcas | git commit --all --signoff | +| gcasm | git commit --all --signoff --message | +| gcmsg | git commit --message | +| gcsm | git commit --signoff --message | +| gc | git commit --verbose | +| gca | git commit --verbose --all | +| gca! | git commit --verbose --all --amend | +| gcan! | git commit --verbose --all --no-edit --amend | +| gcans! | git commit --verbose --all --signoff --no-edit --amend | +| gc! | git commit --verbose --amend | +| gcn! | git commit --verbose --no-edit --amend | +| gcs | git commit -S | +| gcss | git commit -S -s | +| gcssm | git commit -S -s -m | +| gcf | git config --list | +| gdct | git describe --tags $(git rev-list --tags --max-count=1) | +| gd | git diff | +| gdca | git diff --cached | +| gdcw | git diff --cached --word-diff | +| gds | git diff --staged | +| gdw | git diff --word-diff | +| gdv | git diff -w $@ | view - | +| gdup | git diff @{upstream} | +| gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock" | +| gdt | git diff-tree --no-commit-id --name-only -r | +| gf | git fetch | +| gfa | git fetch --all --prune | +| gfo | git fetch origin | +| gg | git gui citool | +| gga | git gui citool --amend | +| ghh | git help | +| glgg | git log --graph | +| glgga | git log --graph --decorate --all | +| glgm | git log --graph --max-count=10 | +| glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | +| glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short | +| glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' | +| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all | +| glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat | +| glo | git log --oneline --decorate | +| glog | git log --oneline --decorate --graph | +| gloga | git log --oneline --decorate --graph --all | +| glp | git log --pretty=\ | +| glg | git log --stat | +| glgp | git log --stat --patch | +| gignored | git ls-files -v | grep "^[[:lower:]]" | +| gfg | git ls-files | grep | +| gm | git merge | +| gma | git merge --abort | +| gms | git merge --squash | +| gmom | git merge origin/$(git_main_branch) | +| gmum | git merge upstream/$(git_main_branch) | +| gmtl | git mergetool --no-prompt | +| gmtlvim | git mergetool --no-prompt --tool=vimdiff | +| gl | git pull | +| gpr | git pull --rebase | +| gup | git pull --rebase | +| gupa | git pull --rebase --autostash | +| gupav | git pull --rebase --autostash --verbose | +| gupv | git pull --rebase --verbose | +| ggu | git pull --rebase origin $(current_branch) | +| gupom | git pull --rebase origin $(git_main_branch) | +| gupomi | git pull --rebase=interactive origin $(git_main_branch) | +| ggpull | git pull origin "$(git_current_branch)" | +| ggl | git pull origin $(current_branch) | +| gluc | git pull upstream $(git_current_branch) | +| glum | git pull upstream $(git_main_branch) | +| gp | git push | +| gpd | git push --dry-run | +| gpf! | git push --force | +| ggf | git push --force origin $(current_branch) | +| gpf | git push --force-with-lease --force-if-includes (git version >= 2.30) | +| gpf | git push --force-with-lease (git version < 2.30) | +| ggfl | git push --force-with-lease origin $(current_branch) | +| gpsup | git push --set-upstream origin $(git_current_branch) | +| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30) | +| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30) | +| gpv | git push --verbose | +| gpoat | git push origin --all && git push origin --tags | +| gpod | git push origin --delete | +| ggpush | git push origin "$(git_current_branch)" | +| ggp | git push origin $(current_branch) | +| gpu | git push upstream | +| grb | git rebase | +| grba | git rebase --abort | +| grbc | git rebase --continue | +| grbi | git rebase --interactive | +| grbo | git rebase --onto | +| grbs | git rebase --skip | +| grbd | git rebase $(git_develop_branch) | +| grbm | git rebase $(git_main_branch) | +| grbom | git rebase origin/$(git_main_branch) | +| gr | git remote | +| grv | git remote --verbose | +| gra | git remote add | +| grrm | git remote remove | +| grmv | git remote rename | +| grset | git remote set-url | +| grup | git remote update | +| grh | git reset | +| gru | git reset -- | +| grhh | git reset --hard | +| gpristine | git reset --hard && git clean -dffx | +| groh | git reset origin/$(git_current_branch) --hard | +| grs | git restore | +| grss | git restore --source | +| grst | git restore --staged | +| gunwip | git rev-list --max-count=1 --format="%s" HEAD | grep -q "--wip--" && git reset HEAD~1 | +| grev | git revert | +| grm | git rm | +| grmc | git rm --cached | +| gcount | git shortlog --summary -n | +| gsh | git show | +| gsps | git show --pretty=short --show-signature | +| gstall | git stash --all | +| gstu | git stash --include-untracked | +| gstaa | git stash apply | +| gstc | git stash clear | +| gstd | git stash drop | +| gstl | git stash list | +| gstp | git stash pop | +| gsta | git stash push (git version >= 2.13) | +| gsta | git stash save (git version < 2.13) | +| gsts | git stash show --text | +| gst | git status | +| gss | git status --short | +| gsb | git status --short -b | +| gsi | git submodule init | +| gsu | git submodule update | +| gsd | git svn dcommit | +| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk | +| gsr | git svn rebase | +| gsw | git switch | +| gswc | git switch -c | +| gswd | git switch $(git_develop_branch) | +| gswm | git switch $(git_main_branch) | +| gts | git tag -s | +| gtv | git tag | sort -V | +| gignore | git update-index --assume-unchanged | +| gunignore | git update-index --no-assume-unchanged | +| gwch | git whatchanged -p --abbrev-commit --pretty=medium | +| gwt | git worktree | +| gwtls | git worktree list | +| gwtmv | git worktree move | +| gwtrm | git worktree remove | +| gk | gitk --all --branches &! | +| gke | gitk --all $(git log --walk-reflogs --pretty=%h) &! | +| gtl | gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl | ### Main branch preference -Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin favors using -a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive term `main`. This means -that any aliases and functions that previously used `master`, will use `main` if that branch exists. We do this via the -function `git_main_branch`. +Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin +favors using a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive +term `main`. This means that any aliases and functions that previously used `master`, will use `main` if that +branch exists. We do this via the function `git_main_branch`. ### Deprecated aliases -These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support. +These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, +receive further support. | Alias | Command | Modification | | :----- | :----------------------------------------------------- | :----------------------------------------------------- | @@ -238,23 +239,27 @@ These are aliases that have been removed, renamed, or otherwise modified in a wa | Command | Description | | :--------------------- | :------------------------------------------------------------------------------------------------------- | -| `grename ` | Rename `old` branch to `new`, including in origin remote | | current_branch | Return the name of the current branch | -| git_current_user_name | Returns the `user.name` config value | -| git_current_user_email | Returns the `user.email` config value | -| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise | +| git_current_user_email | Returns the `user.email` config value (lives in lib/git.zsh) | +| git_current_user_name | Returns the `user.name` config value (lives in lib/git.zsh) | | git_develop_branch | Returns the name of the develop branch: `dev`, `devel`, `development` if they exist, `develop` otherwise | +| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise | +| grename \ \ | Rename `old` branch to `new`, including in origin remote | ### Work in Progress (WIP) -These features allow to pause a branch development and switch to another one (_"Work in Progress"_, or wip). When you want to go back to work, just unwip it. +These features allow to pause a branch development and switch to another one (_"Work in Progress"_, or wip). +When you want to go back to work, just unwip it. | Command | Description | | :--------------- | :---------------------------------------------- | -| work_in_progress | Echoes a warning if the current branch is a wip | | gwip | Commit wip branch | | gunwip | Uncommit wip branch | | gunwipall | Uncommit all recent `--wip--` commits | +| work_in_progress | Echoes a warning if the current branch is a wip | + +Note that `gwip` and `gunwip` are effectivly alias, but are also documented here to group all related WIP +features. ### Deprecated functions diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index d04edea5e..b321ce7b0 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -3,7 +3,9 @@ autoload -Uz is-at-least git_version="${${(As: :)$(git version 2>/dev/null)}[3]}" # -# Functions +# Functions Current +# (sorted alphabetically by function name) +# (order should follow README) # # The name of the current branch @@ -14,27 +16,17 @@ function current_branch() { git_current_branch } -# Pretty log messages -function _git_log_prettily(){ - if ! [ -z $1 ]; then - git log --pretty=$1 - fi -} -compdef _git _git_log_prettily=git-log - -# Warn if the current branch is a WIP -function work_in_progress() { - command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" -} - -# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one -function gunwipall() { - local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H) - - # Check if a commit without "--wip--" was found and it's not the same as HEAD - if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then - git reset $_commit || return 1 - fi +# Check for develop and similarly named branches +function git_develop_branch() { + command git rev-parse --git-dir &>/dev/null || return + local branch + for branch in dev devel development; do + if command git show-ref -q --verify refs/heads/$branch; then + echo $branch + return + fi + done + echo develop } # Check if main exists and use instead of master @@ -50,64 +42,101 @@ function git_main_branch() { echo master } -# Check for develop and similarly named branches -function git_develop_branch() { - command git rev-parse --git-dir &>/dev/null || return - local branch - for branch in dev devel development; do - if command git show-ref -q --verify refs/heads/$branch; then - echo $branch - return - fi - done - echo develop +function grename() { + if [[ -z "$1" || -z "$2" ]]; then + echo "Usage: $0 old_branch new_branch" + return 1 + fi + + # Rename branch locally + git branch -m "$1" "$2" + # Rename branch in origin remote + if git push origin :"$1"; then + git push --set-upstream origin "$2" + fi +} + +# +# Functions Work in Progress (WIP) +# (sorted alphabetically by function name) +# (order should follow README) +# + +# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one +function gunwipall() { + local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H) + + # Check if a commit without "--wip--" was found and it's not the same as HEAD + if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then + git reset $_commit || return 1 + fi +} + +# Warn if the current branch is a WIP +function work_in_progress() { + command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" } # # Aliases -# (sorted alphabetically) +# (sorted alphabetically by command) +# (order should follow README) +# (in some cases force the alisas order to match README, like for example gke and gk) # -alias g='git' +alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' +function ggpnp() { + if [[ "$#" == 0 ]]; then + ggl && ggp + else + ggl "${*}" && ggp "${*}" + fi +} +compdef _git ggpnp=git-checkout + +alias ggpur='ggu' +alias g='git' alias ga='git add' alias gaa='git add --all' alias gapa='git add --patch' alias gau='git add --update' alias gav='git add --verbose' +alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"' +alias gam='git am' +alias gama='git am --abort' +alias gamc='git am --continue' +alias gamscp='git am --show-current-patch' +alias gams='git am --skip' alias gap='git apply' alias gapt='git apply --3way' - +alias gbs='git bisect' +alias gbsb='git bisect bad' +alias gbsg='git bisect good' +alias gbsr='git bisect reset' +alias gbss='git bisect start' +alias gbl='git blame -b -w' alias gb='git branch' alias gba='git branch --all' alias gbd='git branch --delete' -alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null' alias gbD='git branch --delete --force' -alias gbg='git branch -vv | grep ": gone\]"' +alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null' alias gbgd='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' alias gbgD='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' -alias gbl='git blame -b -w' alias gbnm='git branch --no-merged' alias gbr='git branch --remote' -alias gbs='git bisect' -alias gbsb='git bisect bad' -alias gbsg='git bisect good' -alias gbsr='git bisect reset' -alias gbss='git bisect start' - -alias gc='git commit --verbose' -alias gc!='git commit --verbose --amend' -alias gcn!='git commit --verbose --no-edit --amend' -alias gca='git commit --verbose --all' -alias gca!='git commit --verbose --all --amend' -alias gcan!='git commit --verbose --all --no-edit --amend' -alias gcans!='git commit --verbose --all --signoff --no-edit --amend' -alias gcam='git commit --all --message' -alias gcsm='git commit --signoff --message' -alias gcas='git commit --all --signoff' -alias gcasm='git commit --all --signoff --message' +alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' +alias gbg='git branch -vv | grep ": gone\]"' +alias gco='git checkout' +alias gcor='git checkout --recurse-submodules' alias gcb='git checkout -b' -alias gcf='git config --list' +alias gcd='git checkout $(git_develop_branch)' +alias gcm='git checkout $(git_main_branch)' +alias gcp='git cherry-pick' +alias gcpa='git cherry-pick --abort' +alias gcpc='git cherry-pick --continue' +alias gclean='git clean --interactive -d' +alias gcl='git clone --recurse-submodules' function gccd() { command git clone --recurse-submodules "$@" @@ -115,61 +144,97 @@ function gccd() { } compdef _git gccd=git-clone -alias gcl='git clone --recurse-submodules' -alias gclean='git clean --interactive -d' -alias gpristine='git reset --hard && git clean --force -dfx' -alias gcm='git checkout $(git_main_branch)' -alias gcd='git checkout $(git_develop_branch)' -alias gcmsg='git commit --message' -alias gco='git checkout' -alias gcor='git checkout --recurse-submodules' -alias gcount='git shortlog --summary --numbered' -alias gcp='git cherry-pick' -alias gcpa='git cherry-pick --abort' -alias gcpc='git cherry-pick --continue' +alias gcam='git commit --all --message' +alias gcas='git commit --all --signoff' +alias gcasm='git commit --all --signoff --message' alias gcs='git commit --gpg-sign' alias gcss='git commit --gpg-sign --signoff' alias gcssm='git commit --gpg-sign --signoff --message' - +alias gcmsg='git commit --message' +alias gcsm='git commit --signoff --message' +alias gc='git commit --verbose' +alias gca='git commit --verbose --all' +alias gca!='git commit --verbose --all --amend' +alias gcan!='git commit --verbose --all --no-edit --amend' +alias gcans!='git commit --verbose --all --signoff --no-edit --amend' +alias gc!='git commit --verbose --amend' +alias gcn!='git commit --verbose --no-edit --amend' +alias gcf='git config --list' +alias gdct='git describe --tags $(git rev-list --tags --max-count=1)' alias gd='git diff' alias gdca='git diff --cached' alias gdcw='git diff --cached --word-diff' -alias gdct='git describe --tags $(git rev-list --tags --max-count=1)' alias gds='git diff --staged' -alias gdt='git diff-tree --no-commit-id --name-only -r' -alias gdup='git diff @{upstream}' alias gdw='git diff --word-diff' +function gdv() { git diff -w "$@" | view - } +compdef _git gdv=git-diff + +alias gdup='git diff @{upstream}' + function gdnolock() { git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock" } compdef _git gdnolock=git-diff -function gdv() { git diff -w "$@" | view - } -compdef _git gdv=git-diff - +alias gdt='git diff-tree --no-commit-id --name-only -r' alias gf='git fetch' # --jobs= was added in git 2.8 is-at-least 2.8 "$git_version" \ && alias gfa='git fetch --all --prune --jobs=10' \ || alias gfa='git fetch --all --prune' alias gfo='git fetch origin' - -alias gfg='git ls-files | grep' - alias gg='git gui citool' alias gga='git gui citool --amend' +alias ghh='git help' +alias glgg='git log --graph' +alias glgga='git log --graph --decorate --all' +alias glgm='git log --graph --max-count=10' +alias glods='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset" --date=short' +alias glod='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset"' +alias glola='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all' +alias glols='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat' +alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"' +alias glo='git log --oneline --decorate' +alias glog='git log --oneline --decorate --graph' +alias gloga='git log --oneline --decorate --graph --all' -function ggf() { - [[ "$#" != 1 ]] && local b="$(git_current_branch)" - git push --force origin "${b:=$1}" +# Pretty log messages +function _git_log_prettily(){ + if ! [ -z $1 ]; then + git log --pretty=$1 + fi } -compdef _git ggf=git-checkout -function ggfl() { +compdef _git _git_log_prettily=git-log + +alias glp='_git_log_prettily' +alias glg='git log --stat' +alias glgp='git log --stat --patch' +alias gignored='git ls-files -v | grep "^[[:lower:]]"' +alias gfg='git ls-files | grep' +alias gm='git merge' +alias gma='git merge --abort' +alias gms="git merge --squash" +alias gmom='git merge origin/$(git_main_branch)' +alias gmum='git merge upstream/$(git_main_branch)' +alias gmtl='git mergetool --no-prompt' +alias gmtlvim='git mergetool --no-prompt --tool=vimdiff' +alias gl='git pull' +alias gpr='git pull --rebase' +alias gup='git pull --rebase' +alias gupa='git pull --rebase --autostash' +alias gupav='git pull --rebase --autostash --verbose' +alias gupv='git pull --rebase --verbose' + +function ggu() { [[ "$#" != 1 ]] && local b="$(git_current_branch)" - git push --force-with-lease origin "${b:=$1}" + git pull --rebase origin "${b:=$1}" } -compdef _git ggfl=git-checkout +compdef _git ggu=git-checkout + +alias gupom='git pull --rebase origin $(git_main_branch)' +alias gupomi='git pull --rebase=interactive origin $(git_main_branch)' +alias ggpull='git pull origin "$(git_current_branch)"' function ggl() { if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then @@ -181,184 +246,115 @@ function ggl() { } compdef _git ggl=git-checkout -function ggp() { - if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then - git push origin "${*}" - else - [[ "$#" == 0 ]] && local b="$(git_current_branch)" - git push origin "${b:=$1}" - fi -} -compdef _git ggp=git-checkout +alias gluc='git pull upstream $(git_current_branch)' +alias glum='git pull upstream $(git_main_branch)' +alias gp='git push' +alias gpd='git push --dry-run' -function ggpnp() { - if [[ "$#" == 0 ]]; then - ggl && ggp - else - ggl "${*}" && ggp "${*}" - fi +function ggf() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force origin "${b:=$1}" } -compdef _git ggpnp=git-checkout +compdef _git ggf=git-checkout -function ggu() { +alias gpf!='git push --force' +is-at-least 2.30 "$git_version" \ + && alias gpf='git push --force-with-lease --force-if-includes' \ + || alias gpf='git push --force-with-lease' + +function ggfl() { [[ "$#" != 1 ]] && local b="$(git_current_branch)" - git pull --rebase origin "${b:=$1}" + git push --force-with-lease origin "${b:=$1}" } -compdef _git ggu=git-checkout - -alias ggpur='ggu' -alias ggpull='git pull origin "$(git_current_branch)"' -alias ggpush='git push origin "$(git_current_branch)"' +compdef _git ggfl=git-checkout -alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' alias gpsup='git push --set-upstream origin $(git_current_branch)' is-at-least 2.30 "$git_version" \ && alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes' \ || alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease' - -alias ghh='git help' - -alias gignore='git update-index --assume-unchanged' -alias gignored='git ls-files -v | grep "^[[:lower:]]"' -alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk' - -alias gk='\gitk --all --branches &!' -alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!' - -alias gl='git pull' -alias glg='git log --stat' -alias glgp='git log --stat --patch' -alias glgg='git log --graph' -alias glgga='git log --graph --decorate --all' -alias glgm='git log --graph --max-count=10' -alias glo='git log --oneline --decorate' -alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'" -alias glols="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat" -alias glod="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'" -alias glods="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short" -alias glola="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all" -alias glog='git log --oneline --decorate --graph' -alias gloga='git log --oneline --decorate --graph --all' -alias glp="_git_log_prettily" - -alias gm='git merge' -alias gmom='git merge origin/$(git_main_branch)' -alias gmtl='git mergetool --no-prompt' -alias gmtlvim='git mergetool --no-prompt --tool=vimdiff' -alias gmum='git merge upstream/$(git_main_branch)' -alias gma='git merge --abort' -alias gms="git merge --squash" - -alias gp='git push' -alias gpd='git push --dry-run' -is-at-least 2.30 "$git_version" \ - && alias gpf='git push --force-with-lease --force-if-includes' \ - || alias gpf='git push --force-with-lease' -alias gpf!='git push --force' +alias gpv='git push --verbose' alias gpoat='git push origin --all && git push origin --tags' alias gpod='git push origin --delete' -alias gpr='git pull --rebase' -alias gpu='git push upstream' -alias gpv='git push --verbose' +alias ggpush='git push origin "$(git_current_branch)"' -alias gr='git remote' -alias gra='git remote add' +function ggp() { + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git push origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git push origin "${b:=$1}" + fi +} +compdef _git ggp=git-checkout + +alias gpu='git push upstream' alias grb='git rebase' alias grba='git rebase --abort' alias grbc='git rebase --continue' -alias grbd='git rebase $(git_develop_branch)' alias grbi='git rebase --interactive' -alias grbm='git rebase $(git_main_branch)' -alias grbom='git rebase origin/$(git_main_branch)' alias grbo='git rebase --onto' alias grbs='git rebase --skip' -alias grev='git revert' +alias grbd='git rebase $(git_develop_branch)' +alias grbm='git rebase $(git_main_branch)' +alias grbom='git rebase origin/$(git_main_branch)' +alias gr='git remote' +alias grv='git remote --verbose' +alias gra='git remote add' +alias grrm='git remote remove' +alias grmv='git remote rename' +alias grset='git remote set-url' +alias grup='git remote update' alias grh='git reset' +alias gru='git reset --' alias grhh='git reset --hard' +alias gpristine='git reset --hard && git clean --force -dfx' alias groh='git reset origin/$(git_current_branch) --hard' -alias grm='git rm' -alias grmc='git rm --cached' -alias grmv='git remote rename' -alias grrm='git remote remove' alias grs='git restore' -alias grset='git remote set-url' alias grss='git restore --source' alias grst='git restore --staged' -alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' -alias gru='git reset --' -alias grup='git remote update' -alias grv='git remote --verbose' - -alias gsb='git status --short --branch' -alias gsd='git svn dcommit' +alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1' +alias grev='git revert' +alias grm='git rm' +alias grmc='git rm --cached' +alias gcount='git shortlog --summary --numbered' alias gsh='git show' -alias gsi='git submodule init' alias gsps='git show --pretty=short --show-signature' -alias gsr='git svn rebase' -alias gss='git status --short' -alias gst='git status' - -# use the default stash push on git 2.13 and newer -is-at-least 2.13 "$git_version" \ - && alias gsta='git stash push' \ - || alias gsta='git stash save' - +alias gstall='git stash --all' alias gstaa='git stash apply' alias gstc='git stash clear' alias gstd='git stash drop' alias gstl='git stash list' alias gstp='git stash pop' +# use the default stash push on git 2.13 and newer +is-at-least 2.13 "$git_version" \ + && alias gsta='git stash push' \ + || alias gsta='git stash save' alias gsts='git stash show --text' -alias gstu='gsta --include-untracked' -alias gstall='git stash --all' +alias gst='git status' +alias gss='git status --short' +alias gsb='git status --short --branch' +alias gsi='git submodule init' alias gsu='git submodule update' +alias gsd='git svn dcommit' +alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk' +alias gsr='git svn rebase' alias gsw='git switch' alias gswc='git switch --create' -alias gswm='git switch $(git_main_branch)' alias gswd='git switch $(git_develop_branch)' - +alias gswm='git switch $(git_main_branch)' alias gts='git tag --sign' alias gtv='git tag | sort -V' -alias gtl='gtl(){ git tag --sort=-v:refname -n --list "${1}*" }; noglob gtl' - +alias gignore='git update-index --assume-unchanged' alias gunignore='git update-index --no-assume-unchanged' -alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1' -alias gup='git pull --rebase' -alias gupv='git pull --rebase --verbose' -alias gupa='git pull --rebase --autostash' -alias gupav='git pull --rebase --autostash --verbose' -alias gupom='git pull --rebase origin $(git_main_branch)' -alias gupomi='git pull --rebase=interactive origin $(git_main_branch)' -alias glum='git pull upstream $(git_main_branch)' -alias gluc='git pull upstream $(git_current_branch)' - alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' -alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"' - alias gwt='git worktree' alias gwta='git worktree add' alias gwtls='git worktree list' alias gwtmv='git worktree move' alias gwtrm='git worktree remove' - -alias gam='git am' -alias gamc='git am --continue' -alias gams='git am --skip' -alias gama='git am --abort' -alias gamscp='git am --show-current-patch' - -function grename() { - if [[ -z "$1" || -z "$2" ]]; then - echo "Usage: $0 old_branch new_branch" - return 1 - fi - - # Rename branch locally - git branch -m "$1" "$2" - # Rename branch in origin remote - if git push origin :"$1"; then - git push --set-upstream origin "$2" - fi -} +alias gstu='gsta --include-untracked' +alias gtl='gtl(){ git tag --sort=-v:refname -n --list "${1}*" }; noglob gtl' +alias gk='\gitk --all --branches &!' +alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!' unset git_version -- cgit v1.2.3-70-g09d2 From c92af18c36c84cef0c785e1ae9cabc49a61a5c3a Mon Sep 17 00:00:00 2001 From: Zhang Visper Date: Thu, 24 Aug 2023 17:37:38 +0800 Subject: fix(git): some aliases under non-english LANG (#11855) --- plugins/git/README.md | 6 +++--- plugins/git/git.plugin.zsh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 0b757c481..c3e6dd27d 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -40,12 +40,12 @@ plugins=(... git) | gbd | git branch --delete | | gbD | git branch --delete --force | | gbda | git branch --no-color --merged | grep -vE "^([+]|\s($(git_main_branch)|$(git_develop_branch))\s\*$)" | xargs git branch --delete 2>/dev/null | -| gbgd | git branch --no-color -vv | -| gbgD | git branch --no-color -vv | +| gbgd | LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d | +| gbgD | LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D | | gbnm | git branch --no-merged | | gbr | git branch --remote | | ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | -| gbg | git branch -vv | +| gbg | LANG=C git branch -vv | grep ": gone\]" | | gco | git checkout | | gcor | git checkout --recurse-submodules | | gcb | git checkout -b | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index b321ce7b0..8886aac6d 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -121,12 +121,12 @@ alias gba='git branch --all' alias gbd='git branch --delete' alias gbD='git branch --delete --force' alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null' -alias gbgd='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' -alias gbgD='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' +alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' +alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' alias gbnm='git branch --no-merged' alias gbr='git branch --remote' alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' -alias gbg='git branch -vv | grep ": gone\]"' +alias gbg='LANG=C git branch -vv | grep ": gone\]"' alias gco='git checkout' alias gcor='git checkout --recurse-submodules' alias gcb='git checkout -b' -- cgit v1.2.3-70-g09d2 From 13a8e3d98aeeb4f5f0b98f92ace540067e58ba92 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Fri, 25 Aug 2023 00:12:59 +0900 Subject: feat(alias-finder): add cheaper option and apply zstyle options (#11773) --- plugins/alias-finder/.zunit.yml | 9 +++ plugins/alias-finder/README.md | 55 +++++-------- plugins/alias-finder/alias-finder.plugin.zsh | 79 +++++++++++-------- plugins/alias-finder/tests/_output/.gitkeep | 0 plugins/alias-finder/tests/_support/.gitkeep | 0 plugins/alias-finder/tests/_support/bootstrap | 2 + plugins/alias-finder/tests/test_run.sh | 107 ++++++++++++++++++++++++++ 7 files changed, 186 insertions(+), 66 deletions(-) create mode 100644 plugins/alias-finder/.zunit.yml create mode 100644 plugins/alias-finder/tests/_output/.gitkeep create mode 100644 plugins/alias-finder/tests/_support/.gitkeep create mode 100644 plugins/alias-finder/tests/_support/bootstrap create mode 100644 plugins/alias-finder/tests/test_run.sh diff --git a/plugins/alias-finder/.zunit.yml b/plugins/alias-finder/.zunit.yml new file mode 100644 index 000000000..ae65f8ef2 --- /dev/null +++ b/plugins/alias-finder/.zunit.yml @@ -0,0 +1,9 @@ +tap: false +directories: + tests: tests + output: tests/_output + support: tests/_support +time_limit: 0 +fail_fast: false +allow_risky: false +verbose: true diff --git a/plugins/alias-finder/README.md b/plugins/alias-finder/README.md index 409f4b653..6c87c723a 100644 --- a/plugins/alias-finder/README.md +++ b/plugins/alias-finder/README.md @@ -2,45 +2,32 @@ This plugin searches the defined aliases and outputs any that match the command inputted. This makes learning new aliases easier. +## Usage + To use it, add `alias-finder` to the `plugins` array of your zshrc file: ``` plugins=(... alias-finder) ``` -## Usage -To see if there is an alias defined for the command, pass it as an argument to `alias-finder`. This can also run automatically before each command you input - add `ZSH_ALIAS_FINDER_AUTOMATIC=true` to your zshrc if you want this. +To enable it for every single command, set zstyle in your `~/.zshrc`. -## Options +```zsh +# ~/.zshrc -- Use `--longer` or `-l` to allow the aliases to be longer than the input (match aliases if they contain the input). -- Use `--exact` or `-e` to avoid matching aliases that are shorter than the input. - -## Examples -``` -$ alias-finder "git pull" -gl='git pull' -g=git -``` -``` -$ alias-finder "web_search google oh my zsh" -google='web_search google' -``` -``` -$ alias-finder "git commit -v" -gc="git commit -v" -g=git -``` -``` -$ alias-finder -e "git commit -v" -gc='git commit -v' -``` -``` -$ alias-finder -l "git commit -v" -gc='git commit -v' -'gc!'='git commit -v --amend' -gca='git commit -v -a' -'gca!'='git commit -v -a --amend' -'gcan!'='git commit -v -a --no-edit --amend' -'gcans!'='git commit -v -a -s --no-edit --amend' -'gcn!'='git commit -v --no-edit --amend' +zstyle ':omz:plugins:alias-finder' autoload yes # disabled by default +zstyle ':omz:plugins:alias-finder' longer yes # disabled by default +zstyle ':omz:plugins:alias-finder' exact yes # disabled by default +zstyle ':omz:plugins:alias-finder' cheaper yes # disabled by default ``` + +As you can see, options are also available with zstyle. + +### Options + +> In order to clarify, let's say `alias a=abc` has source 'abc' and destination 'a'. + +- Use `--longer` or `-l` to include aliases where the source is longer than the input (in other words, the source could contain the whole input). +- Use `--exact` or `-e` to avoid aliases where the source is shorter than the input (in other words, the source must be the same with the input). +- Use `--cheaper` or `-c` to avoid aliases where the destination is longer than the input (in other words, the destination must be the shorter than the input). + + diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index caee9b5a3..5fdfbc835 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -1,44 +1,59 @@ alias-finder() { - local cmd="" exact="" longer="" wordStart="" wordEnd="" multiWordEnd="" - for i in $@; do - case $i in + local cmd=" " exact="" longer="" cheaper="" wordEnd="'{0,1}$" finder="" filter="" + + # build command and options + for c in "$@"; do + case $c in + # TODO: Remove backward compatibility (other than zstyle form) + # set options if exist -e|--exact) exact=true;; -l|--longer) longer=true;; - *) - if [[ -z $cmd ]]; then - cmd=$i - else - cmd="$cmd $i" - fi - ;; + -c|--cheaper) cheaper=true;; + # concatenate cmd + *) cmd="$cmd$c " ;; esac done - cmd=$(sed 's/[].\|$(){}?+*^[]/\\&/g' <<< $cmd) # adds escaping for grep - if (( $(wc -l <<< $cmd) == 1 )); then - while [[ $cmd != "" ]]; do - if [[ $longer = true ]]; then - wordStart="'{0,1}" - else - wordEnd="$" - multiWordEnd="'$" - fi - if [[ $cmd == *" "* ]]; then - local finder="'$cmd$multiWordEnd" - else - local finder=$wordStart$cmd$wordEnd - fi - alias | grep -E "=$finder" - if [[ $exact = true || $longer = true ]]; then - break - else - cmd=$(sed -E 's/ {0,1}[^ ]*$//' <<< $cmd) # removes last word - fi - done + + zstyle -t ':omz:plugins:alias-finder' longer && longer=true + zstyle -t ':omz:plugins:alias-finder' exact && exact=true + zstyle -t ':omz:plugins:alias-finder' cheaper && cheaper=true + + # format cmd for grep + ## - replace newlines with spaces + ## - trim both ends + ## - replace multiple spaces with one space + ## - add escaping character to special characters + cmd=$(echo -n "$cmd" | tr '\n' ' ' | xargs | tr -s '[:space:]' | sed 's/[].\|$(){}?+*^[]/\\&/g') + + if [[ $longer == true ]]; then + wordEnd="" # remove wordEnd to find longer aliases fi + + # find with alias and grep, removing last word each time until no more words + while [[ $cmd != "" ]]; do + finder="'{0,1}$cmd$wordEnd" + + # make filter to find only shorter results than current cmd + if [[ $cheaper == true ]]; then + cmdLen=$(echo -n "$cmd" | wc -c) + filter="^'{0,1}.{0,$((cmdLen - 1))}=" + fi + + alias | grep -E "$filter" | grep -E "=$finder" + + if [[ $exact == true ]]; then + break # because exact case is only one + elif [[ $longer = true ]]; then + break # because above grep command already found every longer aliases during first cycle + fi + + cmd=$(sed -E 's/ {0,}[^ ]*$//' <<< "$cmd") # remove last word + done } preexec_alias-finder() { - if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then + # TODO: Remove backward compatibility (other than zstyle form) + zstyle -t ':omz:plugins:alias-finder' autoload && alias-finder $1 || if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then alias-finder $1 fi } diff --git a/plugins/alias-finder/tests/_output/.gitkeep b/plugins/alias-finder/tests/_output/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/alias-finder/tests/_support/.gitkeep b/plugins/alias-finder/tests/_support/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/alias-finder/tests/_support/bootstrap b/plugins/alias-finder/tests/_support/bootstrap new file mode 100644 index 000000000..01076611e --- /dev/null +++ b/plugins/alias-finder/tests/_support/bootstrap @@ -0,0 +1,2 @@ +#!/usr/bin/env zsh +# Write your bootstrap code here diff --git a/plugins/alias-finder/tests/test_run.sh b/plugins/alias-finder/tests/test_run.sh new file mode 100644 index 000000000..6b7abebb6 --- /dev/null +++ b/plugins/alias-finder/tests/test_run.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env zunit + +@setup { + load ../alias-finder.plugin.zsh + + set_git_aliases() { + unalias -a # all + alias g="git" + alias gc="git commit" + alias gcv="git commit -v" + alias gcvs="git commit -v -S" + } +} + +@test 'find aliases that contain input' { + set_git_aliases + + run alias-finder "git" + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "g=git" +} + +@test 'find aliases that contain input with whitespaces at ends' { + set_git_aliases + + run alias-finder " git " + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "g=git" +} + +@test 'find aliases that contain multiple words' { + set_git_aliases + + run alias-finder "git commit -v" + + assert "${#lines[@]}" equals 3 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "gc='git commit'" + assert "${lines[3]}" same_as "g=git" +} + +@test 'find alias that is the same with input when --exact option is set' { + set_git_aliases + + run alias-finder -e "git" + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "g=git" +} + +@test 'find alias that is the same with multiple words input when --exact option is set' { + set_git_aliases + + run alias-finder -e "git commit -v" + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "gcv='git commit -v'" +} + +@test 'find alias that is the same with or longer than input when --longer option is set' { + set_git_aliases + + run alias-finder -l "git" + + assert "${#lines[@]}" equals 4 + assert "${lines[1]}" same_as "g=git" + assert "${lines[2]}" same_as "gc='git commit'" + assert "${lines[3]}" same_as "gcv='git commit -v'" + assert "${lines[4]}" same_as "gcvs='git commit -v -S'" +} + +@test 'find alias that is the same with or longer than multiple words input when --longer option is set' { + set_git_aliases + + run alias-finder -l "git commit -v" + + assert "${#lines[@]}" equals 2 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "gcvs='git commit -v -S'" +} + +@test 'find aliases including expensive (longer) than input' { + set_git_aliases + alias expensiveCommands="git commit" + + run alias-finder "git commit -v" + + assert "${#lines[@]}" equals 4 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "expensiveCommands='git commit'" + assert "${lines[3]}" same_as "gc='git commit'" + assert "${lines[4]}" same_as "g=git" +} + +@test 'find aliases excluding expensive (longer) than input when --cheap option is set' { + set_git_aliases + alias expensiveCommands="git commit" + + run alias-finder -c "git commit -v" + + assert "${#lines[@]}" equals 3 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "gc='git commit'" + assert "${lines[3]}" same_as "g=git" +} -- cgit v1.2.3-70-g09d2 From 03a0d5bbaedc732436b5c67b166cde954817cc2f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 24 Aug 2023 17:20:24 +0200 Subject: fix(clipboard): load clipboard on usage Closes #8827 --- lib/clipboard.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh index 2f3b6bcad..4b37abc9b 100644 --- a/lib/clipboard.zsh +++ b/lib/clipboard.zsh @@ -100,8 +100,8 @@ function detect-clipboard() { fi } -# Detect at startup. A non-zero exit here indicates that the dummy clipboards were set, -# which is not really an error. If the user calls them, they will attempt to redetect -# (for example, perhaps the user has now installed xclip) and then either print an error -# or proceed successfully. -detect-clipboard || true +function clipcopy clippaste { + unfunction clipcopy clippaste + detect-clipboard || true # let one retry + "$0" "$@" +} -- cgit v1.2.3-70-g09d2 From 000be72dd0c2f668cd94b36c69e45dec7b06a23e Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 29 Aug 2023 10:27:36 +0200 Subject: fix(updater): disable `nounset` to avoid warnings (#11856) --- tools/upgrade.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 34ff3f027..f7a263d66 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -1,4 +1,5 @@ #!/usr/bin/env zsh +set +u # disable nounset local ret=0 # exit code -- cgit v1.2.3-70-g09d2 From bf774211916c8a9d57b2b56c7846cd0b3d91baab Mon Sep 17 00:00:00 2001 From: Tomás Hernández Date: Tue, 29 Aug 2023 04:29:15 -0400 Subject: feat(bun): add plugin (#11859) --- plugins/bun/README.md | 20 ++++++++++++++++++++ plugins/bun/bun.plugin.zsh | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 plugins/bun/README.md create mode 100644 plugins/bun/bun.plugin.zsh diff --git a/plugins/bun/README.md b/plugins/bun/README.md new file mode 100644 index 000000000..5a312370f --- /dev/null +++ b/plugins/bun/README.md @@ -0,0 +1,20 @@ +# Bun Plugin + +This plugin sets up completion for [Bun](https://bun.sh). + +To use it, add `bun` to the plugins array in your zshrc file: + +```zsh +plugins=(... bun) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and is automatically updated when the +plugin is loaded, which is usually when you start up a new terminal emulator. + +The cache is stored at: + +- `$ZSH_CACHE_DIR/completions/_bun_` completions script diff --git a/plugins/bun/bun.plugin.zsh b/plugins/bun/bun.plugin.zsh new file mode 100644 index 000000000..9924faa84 --- /dev/null +++ b/plugins/bun/bun.plugin.zsh @@ -0,0 +1,14 @@ +# If Bun is not found, don't do the rest of the script +if (( ! $+commands[bun] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `bun`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_bun" ]]; then + typeset -g -A _comps + autoload -Uz _bun + _comps[bun]=_bun +fi + +bun completions >| "$ZSH_CACHE_DIR/completions/_bun" &| -- cgit v1.2.3-70-g09d2 From 2ef7c73cc884163367279e4b586136e3335b1c53 Mon Sep 17 00:00:00 2001 From: t-aswath <119417646+t-aswath@users.noreply.github.com> Date: Wed, 30 Aug 2023 21:38:09 +0530 Subject: feat(web-search): add `youtube` alias (#11865) --- plugins/web-search/web-search.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index ec176dd68..fc87a3495 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -25,6 +25,7 @@ function web_search() { archive "https://web.archive.org/web/*/" scholar "https://scholar.google.com/scholar?q=" ask "https://www.ask.com/web?q=" + youtube "https://www.youtube.com/results?search_query=" ) # check whether the search engine is supported @@ -66,11 +67,12 @@ alias wolframalpha='web_search wolframalpha' alias archive='web_search archive' alias scholar='web_search scholar' alias ask='web_search ask' +alias youtube='web_search youtube' #add your own !bang searches here alias wiki='web_search duckduckgo \!w' alias news='web_search duckduckgo \!n' -alias youtube='web_search duckduckgo \!yt' +#alias youtube='web_search duckduckgo \!yt' alias map='web_search duckduckgo \!m' alias image='web_search duckduckgo \!i' alias ducky='web_search duckduckgo \!' -- cgit v1.2.3-70-g09d2 From ccce2e1cfdf5b9680f691a402e288d9cf6ce272a Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 31 Aug 2023 15:35:33 -0600 Subject: fix(termsupport): match all `foot`-like terminfo (#11868) --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 6d969503d..a800e651f 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -17,7 +17,7 @@ function title { : ${2=$1} case "$TERM" in - cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot|contour*) + cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot*|contour*) print -Pn "\e]2;${2:q}\a" # set window name print -Pn "\e]1;${1:q}\a" # set tab name ;; -- cgit v1.2.3-70-g09d2 From 0dc40e88a3f5bbe2607d958b5f0bf79e9df0c118 Mon Sep 17 00:00:00 2001 From: not pua <140790944+im-notpua@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:46:59 +0000 Subject: feat(battery): add support for OpenBSD (#11872) --- plugins/battery/battery.plugin.zsh | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index db5eeb93a..1d3d529a3 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -13,6 +13,10 @@ # Author: Avneet Singh (kalsi-avneet) # # Modified to add support for Android # ########################################### +# Author: Not Pua (im-notpua) # +# Modified to add support for OpenBSD # +########################################### + if [[ "$OSTYPE" = darwin* ]]; then function battery_is_charging() { @@ -139,6 +143,46 @@ elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} ) echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } +elif [[ "$OSTYPE" = openbsd* ]]; then + function battery_is_charging() { + [[ $(apm -b) -eq 3 ]] + } + function battery_pct() { + apm -l + } + function battery_pct_remaining() { + if ! battery_is_charging; then + battery_pct + else + echo "External Power" + fi + } + function battery_time_remaining() { + local remaining_time + remaining_time=$(apm -m) + if [[ $remaining_time -ge 0 ]]; then + ((hour = $remaining_time / 60 )) + ((minute = $remaining_time % 60 )) + printf %02d:%02d $hour $minute + fi + } + function battery_pct_prompt() { + local battery_pct color + battery_pct=$(battery_pct_remaining) + if battery_is_charging; then + echo "∞" + else + if [[ $battery_pct -gt 50 ]]; then + color='green' + elif [[ $battery_pct -gt 20 ]]; then + color='yellow' + else + color='red' + fi + echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" + fi + } + elif [[ "$OSTYPE" = linux* ]]; then function battery_is_charging() { if (( $+commands[acpitool] )); then -- cgit v1.2.3-70-g09d2 From 1f56f2bdc455f2167c10fdbeca10934f5f0cbd99 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Sun, 3 Sep 2023 23:08:19 +0800 Subject: fix(extract): remove extraction file extension for tar (#11873) --- plugins/extract/extract.plugin.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index 513950f33..88d8b0740 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -30,6 +30,11 @@ EOF local file="$1" full_path="${1:A}" local extract_dir="${1:t:r}" + # Remove the .tar extension if the file name is .tar.* + if [[ $extract_dir =~ '\.tar$' ]]; then + extract_dir="${extract_dir:r}" + fi + # If there's a file or directory with the same name as the archive # add a random string to the end of the extract directory if [[ -e "$extract_dir" ]]; then -- cgit v1.2.3-70-g09d2 From 2b1303a728afc285cc13a6710de128a050500f1e Mon Sep 17 00:00:00 2001 From: n0tr00t <106423923+0x020B@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:38:32 +0000 Subject: feat(tmux): allow all standard config files (#11103) Closes #11803 Co-authored-by: n0tr00t <106423923+n0tr00teuorg@users.noreply.github.com> --- plugins/tmux/README.md | 26 +++++++++++++------------- plugins/tmux/tmux.plugin.zsh | 9 +++++++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 7348f77c9..0f8473daf 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -28,16 +28,16 @@ The plugin also supports the following: ## Configuration Variables -| Variable | Description | -| ----------------------------------- | ----------------------------------------------------------------------------- | -| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | -| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | -| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | -| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | -| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | -| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | -| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) | -| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` | -| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`) | -| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | -| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | +| Variable | Description | +| ----------------------------------- | ------------------------------------------------------------------------------------------- | +| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | +| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | +| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | +| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | +| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | +| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | +| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) | +| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` | +| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | +| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | +| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 311c2e6a9..680f72598 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -26,12 +26,17 @@ fi # systems without the proper terminfo : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} # Set the configuration path -: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +if [[ -e $HOME/.tmux.conf ]]; then + : ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +elif [[ -e ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf ]]; then + : ${ZSH_TMUX_CONFIG:=${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf} +else + : ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +fi # Set -u option to support unicode : ${ZSH_TMUX_UNICODE:=false} # ALIASES - alias ta='tmux attach -t' alias tad='tmux attach -d -t' alias ts='tmux new-session -s' -- cgit v1.2.3-70-g09d2 From f694d5ecc9aa45f4c394d2e15bf2bfde96eeeda6 Mon Sep 17 00:00:00 2001 From: Peter Puškár <93598525+puskarpeter@users.noreply.github.com> Date: Mon, 4 Sep 2023 19:17:28 +0200 Subject: feat(qodana): add completion plugin (#11813) --- plugins/qodana/README.md | 20 ++++++++++++++++++++ plugins/qodana/qodana.plugin.zsh | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 plugins/qodana/README.md create mode 100644 plugins/qodana/qodana.plugin.zsh diff --git a/plugins/qodana/README.md b/plugins/qodana/README.md new file mode 100644 index 000000000..0b68bdecf --- /dev/null +++ b/plugins/qodana/README.md @@ -0,0 +1,20 @@ +# JetBrains Qodana CLI plugin + +This plugin adds completion for the [JetBrains Qodana CLI](https://github.com/JetBrains/qodana-cli). + +To use it, add `qodana` to the plugins array in your zshrc file: + +```zsh +plugins=(... qodana) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and is automatically updated when the +plugin is loaded, which is usually when you start up a new terminal emulator. + +The cache is stored at: + +- `$ZSH_CACHE_DIR/completions/_qodana` completions script diff --git a/plugins/qodana/qodana.plugin.zsh b/plugins/qodana/qodana.plugin.zsh new file mode 100644 index 000000000..2b92a8051 --- /dev/null +++ b/plugins/qodana/qodana.plugin.zsh @@ -0,0 +1,14 @@ +# Autocompletion for the JetBrains Qodana CLI (qodana). +if (( ! $+commands[qodana] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `qodana`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_qodana" ]]; then + typeset -g -A _comps + autoload -Uz _qodana + _comps[qodana]=_qodana +fi + +qodana completion zsh >| "$ZSH_CACHE_DIR/completions/_qodana" &| -- cgit v1.2.3-70-g09d2 From 1abc1d998a71efd50af30210e26bee462496e442 Mon Sep 17 00:00:00 2001 From: Oscar Lee-Vermeren Date: Mon, 4 Sep 2023 13:21:27 -0400 Subject: feat(git-commit): create plugin (#9646) Co-authored-by: K. Akatsuki --- plugins/git-commit/README.md | 36 ++++++++++++++++++++++++++++++++ plugins/git-commit/git-commit.plugin.zsh | 23 ++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 plugins/git-commit/README.md create mode 100644 plugins/git-commit/git-commit.plugin.zsh diff --git a/plugins/git-commit/README.md b/plugins/git-commit/README.md new file mode 100644 index 000000000..dc10d8ad5 --- /dev/null +++ b/plugins/git-commit/README.md @@ -0,0 +1,36 @@ +# git-commit plugin + +The git-commit plugin adds several [git aliases](https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-alias) for [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) messages. + +To use it, add `git-commit` to the plugins array in your zshrc file: + +```zsh +plugins=(... git-commit) +``` + +## Syntax + +```zshrc +git [(-s, --scope) ""] "" +``` + +> ⚠️ Single/Double quotes around the scope and message are required + +Where `type` is one of the following: + +- `build` +- `chore` +- `ci` +- `docs` +- `feat` +- `fix` +- `perf` +- `refactor` +- `revert` +- `style` +- `test` + +## Examples + +`git style "remove trailing whitespace"` -> `git commit -m "style: remove trailing whitespace"` +`git fix -s "router" "correct redirect link"` -> `git commit -m "fix(router): correct redirect link"` diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh new file mode 100644 index 000000000..70d541f21 --- /dev/null +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -0,0 +1,23 @@ +_register() { + if ! git config --global --get-all alias.$1 &>/dev/null; then + git config --global alias.$1 '!a() { if [[ "$1" == "-s" || "$1" == "--scope" ]]; then git commit -m "'$1'(${2}): ${@:3}"; else git commit -m "'$1': ${@}"; fi }; a' + fi +} + +aliases=( + 'build' + 'chore' + 'ci' + 'docs' + 'feat' + 'fix' + 'perf' + 'refactor' + 'revert' + 'style' + 'test' +) + +for alias in "${aliases[@]}"; do + _register $alias +done \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 30f0d591881713c4efd1482511943abca5103927 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 4 Sep 2023 19:32:38 +0200 Subject: fix(init): exit gracefully if on non-zsh emulation mode (#11874) Fixes #11686 --- oh-my-zsh.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 40f13f37e..137ca3b6f 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -1,14 +1,14 @@ +# ANSI formatting function (\033[m) +# 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow +omz_f() { + [ $# -gt 0 ] || return + IFS=";" printf "\033[%sm" $* +} +# If stdout is not a terminal ignore all formatting +[ -t 1 ] || omz_f() { :; } + # Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here) [ -n "$ZSH_VERSION" ] || { - # ANSI formatting function (\033[m) - # 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow - omz_f() { - [ $# -gt 0 ] || return - IFS=";" printf "\033[%sm" $* - } - # If stdout is not a terminal ignore all formatting - [ -t 1 ] || omz_f() { :; } - omz_ptree() { # Get process tree of the current process pid=$$; pids="$pid" @@ -38,6 +38,15 @@ return 1 } +# Check if in emulation mode, if so early return +# https://github.com/ohmyzsh/ohmyzsh/issues/11686 +[[ "$(emulate)" = zsh ]] || { + printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded in \`$(emulate)\` emulation mode.$(omz_f 0)\n" >&2 + return 1 +} + +unset -f omz_f + # If ZSH is not defined, use the current script's directory. [[ -z "$ZSH" ]] && export ZSH="${${(%):-%x}:a:h}" -- cgit v1.2.3-70-g09d2 From c74f2a1be980c60d937046364db0c9497187457a Mon Sep 17 00:00:00 2001 From: Tjark <16938041+tjarbo@users.noreply.github.com> Date: Mon, 4 Sep 2023 19:43:06 +0200 Subject: feat(podman): add plugin (#11695) Closes #7489 Closes #9721 --- plugins/podman/README.md | 47 ++++++++++++++++++++++++++++++++++++++++ plugins/podman/podman.plugin.zsh | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 plugins/podman/README.md create mode 100644 plugins/podman/podman.plugin.zsh diff --git a/plugins/podman/README.md b/plugins/podman/README.md new file mode 100644 index 000000000..99daa28cd --- /dev/null +++ b/plugins/podman/README.md @@ -0,0 +1,47 @@ +# Podman plugin + +This plugin adds auto-completion and aliases for [podman](https://podman.io/). + +To use it add `podman` to the plugins array in your zshrc file. + +```zsh +plugins=(... podman) +``` + +## Aliases + +| Alias | Command | Description | +| :------ | :-------------------------------------------- | :--------------------------------------------------------------------------------------- | +| pbl | `podman build` | Build an image from a Dockerfile | +| pcin | `podman container inspect` | Display detailed information on one or more containers | +| pcls | `podman container ls` | List all the running podman containers | +| pclsa | `podman container ls --all` | List all running and stopped containers | +| pib | `podman image build` | Build an image from a Dockerfile (same as podman build) | +| pii | `podman image inspect` | Display detailed information on one or more images | +| pils | `podman image ls` | List podman images | +| pipu | `podman image push` | Push an image or repository to a remote registry | +| pirm | `podman image rm` | Remove one or more images | +| pit | `podman image tag` | Add a name and tag to a particular image | +| plo | `podman container logs` | Fetch the logs of a podman container | +| pnc | `podman network create` | Create a new network | +| pncn | `podman network connect` | Connect a container to a network | +| pndcn | `podman network disconnect` | Disconnect a container from a network | +| pni | `podman network inspect` | Return information about one or more networks | +| pnls | `podman network ls` | List all networks the engine daemon knows about, including those spanning multiple hosts | +| pnrm | `podman network rm` | Remove one or more networks | +| ppo | `podman container port` | List port mappings or a specific mapping for the container | +| ppu | `podman pull` | Pull an image or a repository from a registry | +| pr | `podman container run` | Create a new container and start it using the specified command | +| prit | `podman container run --interactive --tty` | Create a new container and start it in an interactive shell | +| prm | `podman container rm` | Remove the specified container(s) | +| prm! | `podman container rm --force` | Force the removal of a running container (uses SIGKILL) | +| pst | `podman container start` | Start one or more stopped containers | +| prs | `podman container restart` | Restart one or more containers | +| psta | `podman stop $(podman ps -q)` | Stop all running containers | +| pstp | `podman container stop` | Stop one or more running containers | +| ptop | `podman top` | Display the running processes of a container | +| pvi | `podman volume inspect` | Display detailed information about one or more volumes | +| pvls | `podman volume ls` | List all the volumes known to podman | +| pvprune | `podman volume prune` | Cleanup dangling volumes | +| pxc | `podman container exec` | Run a new command in a running container | +| pxcit | `podman container exec --interactive --tty` | Run a new command in a running container in an interactive shell | diff --git a/plugins/podman/podman.plugin.zsh b/plugins/podman/podman.plugin.zsh new file mode 100644 index 000000000..97cf92b2a --- /dev/null +++ b/plugins/podman/podman.plugin.zsh @@ -0,0 +1,47 @@ +if (( ! $+commands[podman] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `podman`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_podman" ]]; then + typeset -g -A _comps + autoload -Uz _podman + _comps[podman]=_podman +fi + +podman completion zsh 2> /dev/null >| "$ZSH_CACHE_DIR/completions/_podman" &| + +alias pbl='podman build' +alias pcin='podman container inspect' +alias pcls='podman container ls' +alias pclsa='podman container ls --all' +alias pib='podman image build' +alias pii='podman image inspect' +alias pils='podman image ls' +alias pipu='podman image push' +alias pirm='podman image rm' +alias pit='podman image tag' +alias plo='podman container logs' +alias pnc='podman network create' +alias pncn='podman network connect' +alias pndcn='podman network disconnect' +alias pni='podman network inspect' +alias pnls='podman network ls' +alias pnrm='podman network rm' +alias ppo='podman container port' +alias ppu='podman pull' +alias pr='podman container run' +alias prit='podman container run --interactive --tty' +alias prm='podman container rm' +alias 'prm!'='podman container rm --force' +alias pst='podman container start' +alias prs='podman container restart' +alias psta='podman stop $(podman ps --quiet)' +alias pstp='podman container stop' +alias ptop='podman top' +alias pvi='podman volume inspect' +alias pvls='podman volume ls' +alias pvprune='podman volume prune' +alias pxc='podman container exec' +alias pxcit='podman container exec --interactive --tty' -- cgit v1.2.3-70-g09d2 From bae577d6b2eb621fedc994d6309b6f819855c2f8 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 5 Sep 2023 11:41:50 +0100 Subject: fix(git)!: remove `-b` from `blame` alias (#11864) --- plugins/git/README.md | 2 +- plugins/git/git.plugin.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index c3e6dd27d..44ed6f320 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -34,7 +34,7 @@ plugins=(... git) | gbsg | git bisect good | | gbsr | git bisect reset | | gbss | git bisect start | -| gbl | git blame -b -w | +| gbl | git blame -w | | gb | git branch | | gba | git branch --all | | gbd | git branch --delete | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 8886aac6d..e20373de5 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -115,7 +115,7 @@ alias gbsb='git bisect bad' alias gbsg='git bisect good' alias gbsr='git bisect reset' alias gbss='git bisect start' -alias gbl='git blame -b -w' +alias gbl='git blame -w' alias gb='git branch' alias gba='git branch --all' alias gbd='git branch --delete' -- cgit v1.2.3-70-g09d2 From 8e8ec1348b3d4ae5fa156e26c07040ade461c83a Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 6 Sep 2023 10:54:11 +0200 Subject: fix(git-commit): avoid conflict with `aliases` var Closes #11876 --- plugins/git-commit/git-commit.plugin.zsh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 70d541f21..2ac8aa5f4 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -1,10 +1,11 @@ -_register() { - if ! git config --global --get-all alias.$1 &>/dev/null; then +function _git_commit_register { + if ! git config --global --get-all alias.$1 >/dev/null 2>&1; then git config --global alias.$1 '!a() { if [[ "$1" == "-s" || "$1" == "--scope" ]]; then git commit -m "'$1'(${2}): ${@:3}"; else git commit -m "'$1': ${@}"; fi }; a' fi } -aliases=( +local -a _git_commit_aliases +_git_commit_aliases=( 'build' 'chore' 'ci' @@ -18,6 +19,9 @@ aliases=( 'test' ) -for alias in "${aliases[@]}"; do - _register $alias -done \ No newline at end of file +for _alias in "${_git_commit_aliases[@]}"; do + _git_commit_register $_alias +done + +unfunction _git_commit_register +unset _alias -- cgit v1.2.3-70-g09d2 From 76e541a3fe71075c8ef75ecf44cd60f17b5292bb Mon Sep 17 00:00:00 2001 From: Felipe Gallois Date: Wed, 6 Sep 2023 10:18:36 +0100 Subject: feat(gallois): big rewrite to `gallois` theme (#11867) --- themes/gallois.zsh-theme | 136 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 126 insertions(+), 10 deletions(-) diff --git a/themes/gallois.zsh-theme b/themes/gallois.zsh-theme index bb97bfb17..3fc349072 100644 --- a/themes/gallois.zsh-theme +++ b/themes/gallois.zsh-theme @@ -1,24 +1,140 @@ # Depends on the git plugin for work_in_progress() (( $+functions[work_in_progress] )) || work_in_progress() {} -ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" -ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}[%{$fg[green]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[cyan]%}]" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_CLEAN="" # Customized git status, oh-my-zsh currently does not allow render dirty status before branch git_custom_status() { local branch=$(git_current_branch) [[ -n "$branch" ]] || return 0 - echo "$(parse_git_dirty)\ -%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\ -${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}" + print "%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\ +${ZSH_THEME_GIT_PROMPT_PREFIX}$(parse_git_dirty)${branch}\ +${ZSH_THEME_GIT_PROMPT_SUFFIX}" +} +autoload -U colors && colors + +#export VCS_PROMPT=hg_prompt_info +export VCS_PROMPT=git_custom_status + +base_prompt="%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b " +custom_prompt="" +last_run_time="" +last_vcs_info="" + + +function pipestatus_parse { + PIPESTATUS="$pipestatus" + ERROR=0 + for i in "${(z)PIPESTATUS}"; do + if [[ "$i" -ne 0 ]]; then + ERROR=1 + fi + done + + if [[ "$ERROR" -ne 0 ]]; then + print "[%{$fg[red]%}$PIPESTATUS%{$fg[cyan]%}]" + fi } -# RVM component of prompt -ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}[" -ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}" # Combine it all into a final right-side prompt -RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}" PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b ' +function preexec() { + last_run_time=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time') +} + +function duration() { + local duration + local now=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time') + local last=$1 + local last_split=("${(@s/./)last}") + local now_split=("${(@s/./)now}") + local T=$((now_split[1] - last_split[1])) + local D=$((T/60/60/24)) + local H=$((T/60/60%24)) + local M=$((T/60%60)) + local S=$((T%60)) + local s=$(((now_split[2] - last_split[2]) / 1000000000.)) + local m=$(((now_split[2] - last_split[2]) / 1000000.)) + + (( $D > 0 )) && duration+="${D}d" + (( $H > 0 )) && duration+="${H}h" + (( $M > 0 )) && duration+="${M}m" + + if [[ $S -le 0 ]]; then + printf "%ims" "$m" + else + if ! [[ -z $duration ]] && printf "%s" "$duration" + local sec_milli=$((S + s)) + printf "%.3fs" "$sec_milli" + fi +} + +function precmd() { + RETVAL=$(pipestatus_parse) + local info="" + + if [ ! -z "$last_run_time" ]; then + local elapsed=$(duration $last_run_time) + last_run_time=$(print $last_run_time | tr -d ".") + if [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 120 * 1000 * 1000 * 1000 )) ]; then + local elapsed_color="%{$fg[magenta]%}" + elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 60 * 1000 * 1000 * 1000 )) ]; then + local elapsed_color="%{$fg[red]%}" + elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 10 * 1000 * 1000 * 1000 )) ]; then + local elapsed_color="%{$fg[yellow]%}" + else + local elapsed_color="%{$fg[green]%}" + fi + info=$(printf "%s%s%s%s%s" "%{$fg[cyan]%}[" "$elapsed_color" "$elapsed" "%{$fg[cyan]%}]" "$RETVAL") + unset last_run_time + fi + + if [ -z "$info" -a ! -z "$last_vcs_info" ]; then + custom_prompt="$last_vcs_info$base_prompt" + return; + fi + + if (( ${+VCS_PROMPT} )); then + last_vcs_info=$($VCS_PROMPT) + if [ ! -z "$last_vcs_info" ]; then + [ -z "$info" ] && info=$last_vcs_info || info="$info$last_vcs_info" + fi + fi + + [ -z "$info" ] && custom_prompt="$base_prompt" || custom_prompt="$info$base_prompt" +} + +function hg_prompt_info() { + unset output info parts branch_parts branch + + local output="" + if ! output="$(hg status 2> /dev/null)"; then + return + fi + + local info=$(hg log -l1 --template '{author}:{node|short}:{remotenames}:{phabdiff}') + local parts=(${(@s/:/)info}) + local branch_parts=(${(@s,/,)parts[3]}) + local branch=${branch_parts[-1]} + [ ! -z "${parts[3]}" ] && [[ "${parts[1]}" =~ "$USER@" ]] && branch=${parts[3]} + [ -z "${parts[3]}" ] && branch=${parts[2]} + + if [[ ! -z "$output" ]]; then + local color="%{$fg[red]%}" + elif [[ "${branch}" == "master" || "${branch}" == "warm" ]]; then + local color="%{$fg[yellow]%}" + else + local color="%{$fg[green]%}" + fi + + print "%{$fg[cyan]%}[${color}${branch}%{$fg[cyan]%}]" +} + +setopt PROMPT_SUBST +PROMPT='$custom_prompt' + + -- cgit v1.2.3-70-g09d2 From 331f3c8b2e28e47af41ae309aa814dab524a3374 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 6 Sep 2023 11:36:57 +0100 Subject: feat(git): add bisect aliases `gbsn` and `gbso` (#11869) --- plugins/git/README.md | 2 ++ plugins/git/git.plugin.zsh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index 44ed6f320..922cbee55 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -32,6 +32,8 @@ plugins=(... git) | gbs | git bisect | | gbsb | git bisect bad | | gbsg | git bisect good | +| gbsn | git bisect new | +| gbso | git bisect old | | gbsr | git bisect reset | | gbss | git bisect start | | gbl | git blame -w | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index e20373de5..4afe34e99 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -113,6 +113,8 @@ alias gapt='git apply --3way' alias gbs='git bisect' alias gbsb='git bisect bad' alias gbsg='git bisect good' +alias gbsn='git bisect new' +alias gbso='git bisect old' alias gbsr='git bisect reset' alias gbss='git bisect start' alias gbl='git blame -w' -- cgit v1.2.3-70-g09d2 From 6a7aab47dd6071b7f264477195b06efb7e7bd480 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 6 Sep 2023 11:42:09 +0100 Subject: docs(git): align markdown table borders (#11878) --- plugins/git/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 922cbee55..6eb63ea40 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -36,7 +36,7 @@ plugins=(... git) | gbso | git bisect old | | gbsr | git bisect reset | | gbss | git bisect start | -| gbl | git blame -w | +| gbl | git blame -w | | gb | git branch | | gba | git branch --all | | gbd | git branch --delete | -- cgit v1.2.3-70-g09d2 From 079dbff2c4f22935a71101c511e2285327d8ab68 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 6 Sep 2023 19:01:41 +0200 Subject: feat(pipenv): add option to disable auto shell feature Closes #11472 --- plugins/pipenv/README.md | 15 ++++++++++++++- plugins/pipenv/pipenv.plugin.zsh | 38 ++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/plugins/pipenv/README.md b/plugins/pipenv/README.md index 4329feb32..e78ef0e3b 100644 --- a/plugins/pipenv/README.md +++ b/plugins/pipenv/README.md @@ -1,6 +1,7 @@ # Pipenv ## Installation + In your `.zshrc` file, add `pipenv` to the plugins section ``` @@ -8,7 +9,9 @@ plugins=(... pipenv ...) ``` ## Features -This plugin provides some features to simplify the use of Pipenv while working on ZSH. + +This plugin provides some features to simplify the use of Pipenv while working on ZSH. + - Adds completion for pipenv - Auto activates and deactivates pipenv shell - Adds short aliases for common pipenv commands @@ -27,3 +30,13 @@ This plugin provides some features to simplify the use of Pipenv while working o - `pwh` is aliased to `pipenv --where` - `pvenv` is aliased to `pipenv --venv` - `ppy` is aliased to `pipenv --py` + +## Configuration + +### Shell activation + +If you want to disable the shell activation and deactivation feature, add the following style to your `.zshrc` before sourcing `oh-my-zsh.sh`: + +```zsh +zstyle ':omz:plugins:pipenv' auto-shell no +``` diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh index 22d1a3131..f81c266a4 100644 --- a/plugins/pipenv/pipenv.plugin.zsh +++ b/plugins/pipenv/pipenv.plugin.zsh @@ -12,28 +12,30 @@ fi _PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &| -# Automatic pipenv shell activation/deactivation -_togglePipenvShell() { - # deactivate shell if Pipfile doesn't exist and not in a subdir - if [[ ! -f "$PWD/Pipfile" ]]; then - if [[ "$PIPENV_ACTIVE" == 1 ]]; then - if [[ "$PWD" != "$pipfile_dir"* ]]; then - exit +if zstyle -T ':omz:plugins:pipenv' auto-shell; then + # Automatic pipenv shell activation/deactivation + _togglePipenvShell() { + # deactivate shell if Pipfile doesn't exist and not in a subdir + if [[ ! -f "$PWD/Pipfile" ]]; then + if [[ "$PIPENV_ACTIVE" == 1 ]]; then + if [[ "$PWD" != "$pipfile_dir"* ]]; then + exit + fi fi fi - fi - # activate the shell if Pipfile exists - if [[ "$PIPENV_ACTIVE" != 1 ]]; then - if [[ -f "$PWD/Pipfile" ]]; then - export pipfile_dir="$PWD" - pipenv shell + # activate the shell if Pipfile exists + if [[ "$PIPENV_ACTIVE" != 1 ]]; then + if [[ -f "$PWD/Pipfile" ]]; then + export pipfile_dir="$PWD" + pipenv shell + fi fi - fi -} -autoload -U add-zsh-hook -add-zsh-hook chpwd _togglePipenvShell -_togglePipenvShell + } + autoload -U add-zsh-hook + add-zsh-hook chpwd _togglePipenvShell + _togglePipenvShell +fi # Aliases alias pch="pipenv check" -- cgit v1.2.3-70-g09d2 From b07c8cfe692bc6c7702f0aef5d493b12dfb43392 Mon Sep 17 00:00:00 2001 From: Haltarys <45515869+Haltarys@users.noreply.github.com> Date: Sun, 10 Sep 2023 09:28:33 +0200 Subject: fix(git-commit): fix compatibility of alias functions (#11883) --- plugins/git-commit/git-commit.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 2ac8aa5f4..4ad4c0177 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -1,6 +1,6 @@ function _git_commit_register { if ! git config --global --get-all alias.$1 >/dev/null 2>&1; then - git config --global alias.$1 '!a() { if [[ "$1" == "-s" || "$1" == "--scope" ]]; then git commit -m "'$1'(${2}): ${@:3}"; else git commit -m "'$1': ${@}"; fi }; a' + git config --global alias.$1 '!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$1'(${scope}): ${@}"; else git commit -m "'$1': ${@}"; fi }; a' fi } -- cgit v1.2.3-70-g09d2 From cd18bce53e01d0f614ffcbb7429053fb508cb095 Mon Sep 17 00:00:00 2001 From: AJ Jordan Date: Mon, 11 Sep 2023 03:31:53 -0400 Subject: feat(mortalscumbag): show toolbox info (#11884) --- themes/mortalscumbag.zsh-theme | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/themes/mortalscumbag.zsh-theme b/themes/mortalscumbag.zsh-theme index d81a7ca06..36301cb76 100644 --- a/themes/mortalscumbag.zsh-theme +++ b/themes/mortalscumbag.zsh-theme @@ -51,8 +51,14 @@ function ssh_connection() { fi } +function _toolbox_prompt_info() { + if typeset -f toolbox_prompt_info > /dev/null; then + toolbox_prompt_info + fi +} + local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}" -PROMPT=$'\n$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# ' +PROMPT=$'\n$(_toolbox_prompt_info)$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# ' ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}" ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}" -- cgit v1.2.3-70-g09d2 From 7077989d28e9cd723afcb4355874683d847278b4 Mon Sep 17 00:00:00 2001 From: Samuel Beckley Date: Mon, 11 Sep 2023 03:35:28 -0400 Subject: feat(macos): update spotify plugin to upstream (#11534) --- plugins/macos/spotify | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/plugins/macos/spotify b/plugins/macos/spotify index 5fb40517c..ae42db425 100644 --- a/plugins/macos/spotify +++ b/plugins/macos/spotify @@ -1,7 +1,7 @@ #!/usr/bin/env bash function spotify() { -# Copyright (c) 2012--2019 Harish Narayanan +# Copyright (c) 2012--2023 Harish Narayanan # # Contains numerous helpful contributions from Jorge Colindres, Thomas # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin @@ -35,6 +35,9 @@ if ! [[ -f "${USER_CONFIG_FILE}" ]]; then fi source "${USER_CONFIG_FILE}"; +# Set the percent change in volume for vol up and vol down +VOL_INCREMENT=10 + showAPIHelp() { echo; echo "Connecting to Spotify's API:"; @@ -170,12 +173,12 @@ while [ $# -gt 0 ]; do if [ -z "${CLIENT_ID}" ]; then cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}"; showAPIHelp; - return 1 + return 1; fi if [ -z "${CLIENT_SECRET}" ]; then cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}"; showAPIHelp; - return 1 + return 1; fi SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r'); SPOTIFY_PLAY_URI=""; @@ -198,7 +201,7 @@ while [ $# -gt 0 ]; do fi SPOTIFY_ACCESS_TOKEN=$( \ printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \ - | grep -E -o '"access_token":".*",' \ + | command grep -E -o '"access_token":".*",' \ | sed 's/"access_token"://g' \ | sed 's/"//g' \ | sed 's/,.*//g' \ @@ -219,9 +222,8 @@ while [ $# -gt 0 ]; do -H "Accept: application/json" \ --data-urlencode "q=$Q" \ -d "type=$type&limit=1&offset=0" \ - | grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1 + | command grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1 ) - echo "play uri: ${SPOTIFY_PLAY_URI}" } case $2 in @@ -235,11 +237,11 @@ while [ $# -gt 0 ]; do results=$( \ curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \ - | grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \ + | command grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \ ) count=$( \ - echo "$results" | grep -c "spotify:playlist" \ + echo "$results" | command grep -c "spotify:playlist" \ ) if [ "$count" -gt 0 ]; then @@ -333,16 +335,16 @@ while [ $# -gt 0 ]; do cecho "Current Spotify volume level is $vol."; break ; elif [ "$2" = "up" ]; then - if [ $vol -le 90 ]; then - newvol=$(( vol+10 )); + if [ $vol -le $(( 100-$VOL_INCREMENT )) ]; then + newvol=$(( vol+$VOL_INCREMENT )); cecho "Increasing Spotify volume to $newvol."; else newvol=100; cecho "Spotify volume level is at max."; fi elif [ "$2" = "down" ]; then - if [ $vol -ge 10 ]; then - newvol=$(( vol-10 )); + if [ $vol -ge $(( $VOL_INCREMENT )) ]; then + newvol=$(( vol-$VOL_INCREMENT )); cecho "Reducing Spotify volume to $newvol."; else newvol=0; @@ -354,11 +356,11 @@ while [ $# -gt 0 ]; do else echo "Improper use of 'vol' command" echo "The 'vol' command should be used as follows:" - echo " vol up # Increases the volume by 10%."; - echo " vol down # Decreases the volume by 10%."; + echo " vol up # Increases the volume by $VOL_INCREMENT%."; + echo " vol down # Decreases the volume by $VOL_INCREMENT%."; echo " vol [amount] # Sets the volume to an amount between 0 and 100."; echo " vol # Shows the current Spotify volume."; - return 1 + return 1; fi osascript -e "tell application \"Spotify\" to set sound volume to $newvol"; @@ -468,10 +470,9 @@ while [ $# -gt 0 ]; do "help" ) showHelp; break ;; - * ) showHelp; - return 1 ;; + return 1; esac done -- cgit v1.2.3-70-g09d2 From 38ef5192cb1c43159b516d15ab8fed96f847b36b Mon Sep 17 00:00:00 2001 From: Felipe Gallois Date: Mon, 11 Sep 2023 10:05:50 +0100 Subject: feat(oldgalois): add theme (#11880) Closes #11879 --- themes/oldgallois.zsh-theme | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 themes/oldgallois.zsh-theme diff --git a/themes/oldgallois.zsh-theme b/themes/oldgallois.zsh-theme new file mode 100644 index 000000000..bb97bfb17 --- /dev/null +++ b/themes/oldgallois.zsh-theme @@ -0,0 +1,24 @@ +# Depends on the git plugin for work_in_progress() +(( $+functions[work_in_progress] )) || work_in_progress() {} + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" +ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +# Customized git status, oh-my-zsh currently does not allow render dirty status before branch +git_custom_status() { + local branch=$(git_current_branch) + [[ -n "$branch" ]] || return 0 + echo "$(parse_git_dirty)\ +%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\ +${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}" +} + +# RVM component of prompt +ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}[" +ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}" + +# Combine it all into a final right-side prompt +RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}" +PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b ' -- cgit v1.2.3-70-g09d2 From 01f55123118601a935f28ff6c49e625448bdd32d Mon Sep 17 00:00:00 2001 From: bretello Date: Tue, 12 Sep 2023 21:41:07 +0200 Subject: feat(systemd): add alias for --failed commands (#11847) --- plugins/systemd/README.md | 1 + plugins/systemd/systemd.plugin.zsh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/plugins/systemd/README.md b/plugins/systemd/README.md index ffa0567a8..755c649a1 100644 --- a/plugins/systemd/README.md +++ b/plugins/systemd/README.md @@ -12,6 +12,7 @@ plugins=(... systemd) | Alias | Command | Description | |:-----------------------|:-----------------------------------|:-----------------------------------------------------------------| +| `sc-failed` | `systemctl --failed` | List failed systemd units | | `sc-list-units` | `systemctl list-units` | List all units systemd has in memory | | `sc-is-active` | `systemctl is-active` | Show whether a unit is active | | `sc-status` | `systemctl status` | Show terse runtime status information about one or more units | diff --git a/plugins/systemd/systemd.plugin.zsh b/plugins/systemd/systemd.plugin.zsh index 1270bea0e..382a57b29 100644 --- a/plugins/systemd/systemd.plugin.zsh +++ b/plugins/systemd/systemd.plugin.zsh @@ -93,6 +93,9 @@ alias scu-enable-now="scu-enable --now" alias scu-disable-now="scu-disable --now" alias scu-mask-now="scu-mask --now" +# --failed commands +alias scu-failed='systemctl --user --failed' +alias sc-failed='systemctl --failed' function systemd_prompt_info { local unit -- cgit v1.2.3-70-g09d2 From 7e4c26860d74a01cd6d91fd10fcc28fccd740ddd Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 13 Sep 2023 10:48:16 +0200 Subject: feat(brew): add support for custom `BREW_LOCATION` Fixes #11888 Co-authored-by: Matt Cable --- plugins/brew/README.md | 20 +++++++++++--------- plugins/brew/brew.plugin.zsh | 7 ++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/plugins/brew/README.md b/plugins/brew/README.md index 4730194bc..299393b28 100644 --- a/plugins/brew/README.md +++ b/plugins/brew/README.md @@ -10,10 +10,12 @@ plugins=(... brew) ## Shellenv -If `brew` is not found in the PATH, this plugin will attempt to find it in common -locations, and execute `brew shellenv` to set the environment appropriately. -This plugin will also export `HOMEBREW_PREFIX="$(brew --prefix)"` if not previously -defined for convenience. +If `brew` is not found in the PATH, this plugin will attempt to find it in common locations, and execute +`brew shellenv` to set the environment appropriately. This plugin will also export +`HOMEBREW_PREFIX="$(brew --prefix)"` if not previously defined for convenience. + +In case you installed `brew` in a non-common location, you can still set `BREW_LOCATION` variable pointing to +the `brew` binary before sourcing `oh-my-zsh.sh` and it'll set up the environment. ## Aliases @@ -33,9 +35,9 @@ defined for convenience. ## Completion -This plugin configures paths with Homebrew's completion functions automatically, so you don't need to do it manually. See: https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh. +This plugin configures paths with Homebrew's completion functions automatically, so you don't need to do it +manually. See: https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh. -With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the -brew installation, so we no longer ship it with the brew plugin; now it only has brew -aliases. If you find that brew completion no longer works, make sure you have your Homebrew -installation fully up to date. +With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the brew installation, +so we no longer ship it with the brew plugin; now it only has brew aliases. If you find that brew completion +no longer works, make sure you have your Homebrew installation fully up to date. diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh index b52664a39..447036376 100644 --- a/plugins/brew/brew.plugin.zsh +++ b/plugins/brew/brew.plugin.zsh @@ -1,5 +1,10 @@ if (( ! $+commands[brew] )); then - if [[ -x /opt/homebrew/bin/brew ]]; then + if [[ -n "$BREW_LOCATION" ]]; then + if [[ ! -x "$BREW_LOCATION" ]]; then + echo "[oh-my-zsh] $BREW_LOCATION is not executable" + return + fi + elif [[ -x /opt/homebrew/bin/brew ]]; then BREW_LOCATION="/opt/homebrew/bin/brew" elif [[ -x /usr/local/bin/brew ]]; then BREW_LOCATION="/usr/local/bin/brew" -- cgit v1.2.3-70-g09d2 From 4167474f124bfc39d0e6cd612c95acf0a1ae9904 Mon Sep 17 00:00:00 2001 From: Jérôme Benoit Date: Wed, 13 Sep 2023 16:31:24 +0200 Subject: feat(grc): add support for arm64 macos (#11890) --- plugins/grc/grc.plugin.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/grc/grc.plugin.zsh b/plugins/grc/grc.plugin.zsh index b709b9e02..e036b8d89 100644 --- a/plugins/grc/grc.plugin.zsh +++ b/plugins/grc/grc.plugin.zsh @@ -2,8 +2,9 @@ # common grc.zsh paths files=( - /etc/grc.zsh # default - /usr/local/etc/grc.zsh # homebrew + /etc/grc.zsh # default + /usr/local/etc/grc.zsh # homebrew darwin-x64 + /opt/homebrew/etc/grc.zsh # homebrew darwin-arm64 ) # verify the file is readable and source it -- cgit v1.2.3-70-g09d2 From bbda81fe4b338f00bbf7c7f33e6d1b12d067dc05 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 13 Sep 2023 19:23:41 +0200 Subject: fix(changelog): fix regression for unstyled code in commit subjects --- tools/changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 1af74e42d..6d768963e 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -366,7 +366,7 @@ function display-release { # In text mode, highlight (#) and dim text between `backticks` text) if supports_hyperlinks; then - sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g' <<< "$subject" + sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" else sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" fi ;; -- cgit v1.2.3-70-g09d2 From cdd7dab5db4c668b962f908b57e244aa1ff4b574 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 17 Sep 2023 16:20:46 +0200 Subject: ci(installer): remove `vc link` which generates the wrong project `vc link` is not needed, as we already have `VERCEL_PROJECT_ID` defined as an env variable. Currently the `vc link` only creates a second empty project with the name `installer` as seen in logs: Linked to ohmyzsh/installer (created .vercel and added it to .gitignore) Vercel CLI 32.2.4 --- .github/workflows/installer.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml index ac88d10b0..4a25c8079 100644 --- a/.github/workflows/installer.yml +++ b/.github/workflows/installer.yml @@ -51,5 +51,4 @@ jobs: run: | cp tools/install.sh .github/workflows/installer/install.sh cd .github/workflows/installer - vc link --yes -t ${{ secrets.VERCEL_TOKEN }} vc deploy --prod -t ${{ secrets.VERCEL_TOKEN }} -- cgit v1.2.3-70-g09d2 From 91cd5341b9e682bf1c1be4a4051249cffdab7943 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Godde Date: Wed, 20 Sep 2023 12:09:46 +0200 Subject: fix(gcloud): source `path.zsh.inc` always (#11901) --- plugins/gcloud/gcloud.plugin.zsh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/gcloud/gcloud.plugin.zsh b/plugins/gcloud/gcloud.plugin.zsh index 5c57302d3..9a4213aaf 100644 --- a/plugins/gcloud/gcloud.plugin.zsh +++ b/plugins/gcloud/gcloud.plugin.zsh @@ -29,11 +29,9 @@ if [[ -z "${CLOUDSDK_HOME}" ]]; then fi if (( ${+CLOUDSDK_HOME} )); then - # Only source this if gcloud isn't already on the path - if (( ! $+commands[gcloud] )); then - if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then - source "${CLOUDSDK_HOME}/path.zsh.inc" - fi + # Source path file + if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then + source "${CLOUDSDK_HOME}/path.zsh.inc" fi # Look for completion file in different paths -- cgit v1.2.3-70-g09d2 From 350427dea2293a3e23f9823b5dc2574c1b1ae2a2 Mon Sep 17 00:00:00 2001 From: Trick van Staveren Date: Wed, 20 Sep 2023 09:09:26 -0500 Subject: feat(hitchhiker): clean up refs to magic string (#11900) --- plugins/hitchhiker/fortunes/hitchhiker | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/hitchhiker/fortunes/hitchhiker b/plugins/hitchhiker/fortunes/hitchhiker index 825b86cd6..b0448b21e 100644 --- a/plugins/hitchhiker/fortunes/hitchhiker +++ b/plugins/hitchhiker/fortunes/hitchhiker @@ -194,31 +194,31 @@ ARTHUR It probably seems a terrible thing to say, but you know what I sometimes - One of the more preferable pieces of advice contained in the Guide. % -"His eyes seemed to be popping out of his head. He wasn't certain if this was because they were trying to see more clearly, or if they simply wanted to leave at this point."QUOTEHERESTRINGMAGIC1234- Arthur trying to see who had diverted him from going to a party. +"His eyes seemed to be popping out of his head. He wasn't certain if this was because they were trying to see more clearly, or if they simply wanted to leave at this point." - Arthur trying to see who had diverted him from going to a party. % -"Arthur yawed wildly as his skin tried to jump one way and his skeleton the other, whilst his brain tried to work out which of his ears it most wanted to crawl out of. `Bet you weren't expecting to see me again,' said the monster, which Arthur couldn't help thinking was a strange remark for it to make, seeing as he had never met the creature before. He could tell that he hadn't met the creature before from the simple fact that he was able to sleep at nights."QUOTEHERESTRINGMAGIC1234- Arthur discovering who had diverted him from going to a party. +"Arthur yawed wildly as his skin tried to jump one way and his skeleton the other, whilst his brain tried to work out which of his ears it most wanted to crawl out of. `Bet you weren't expecting to see me again,' said the monster, which Arthur couldn't help thinking was a strange remark for it to make, seeing as he had never met the creature before. He could tell that he hadn't met the creature before from the simple fact that he was able to sleep at nights." - Arthur discovering who had diverted him from going to a party. % -"`That young girl is one of the least benightedly unintelligent organic life forms it has been my profound lack of pleasure not to be able to avoid meeting.'"QUOTEHERESTRINGMAGIC1234- Marvin's first ever compliment about anybody. +"`That young girl is one of the least benightedly unintelligent organic life forms it has been my profound lack of pleasure not to be able to avoid meeting.'" - Marvin's first ever compliment about anybody. % -"Arthur hoped and prayed that there wasn't an afterlife. Then he realised there was a contradiction there and merely hoped that there wasn't an afterlife."QUOTEHERESTRINGMAGIC1234- Arthur realising that he's in a certain death situation with a supernova bomb that is shaped like a cricket ball. +"Arthur hoped and prayed that there wasn't an afterlife. Then he realised there was a contradiction there and merely hoped that there wasn't an afterlife." - Arthur realising that he's in a certain death situation with a supernova bomb that is shaped like a cricket ball. % -"`Credit?' he said. `Aaaargggh...' These two words are usually coupled together in the Old Pink Dog Bar."QUOTEHERESTRINGMAGIC1234- Ford in a spot of bother. +"`Credit?' he said. `Aaaargggh...' These two words are usually coupled together in the Old Pink Dog Bar." - Ford in a spot of bother. % -"`...we might as well start with where your hand is now.' Arthur said, `So which way do I go?' `Down,' said Fenchurch, `on this occasion.' He moved his hand. `Down,' she said, `is in fact the other way.' `Oh yes.'"QUOTEHERESTRINGMAGIC1234- Arthur trying to discover which part of Fenchurch is wrong. +"`...we might as well start with where your hand is now.' Arthur said, `So which way do I go?' `Down,' said Fenchurch, `on this occasion.' He moved his hand. `Down,' she said, `is in fact the other way.' `Oh yes.'" - Arthur trying to discover which part of Fenchurch is wrong. % -"There was a point to this story, but it has temporarily escaped the chronicler's mind."QUOTEHERESTRINGMAGIC1234- This line perhaps best sums up the whole book. +"There was a point to this story, but it has temporarily escaped the chronicler's mind." - This line perhaps best sums up the whole book. % -"The last time anybody made a list of the top hundred character attributes of New Yorkers, common sense snuck in at number 79. .... When it's fall in New York, the air smells as if someone's been frying goats in it, and if you are keen to breathe the best plan is to open a window and stick your head in a building."QUOTEHERESTRINGMAGIC1234- Nuff said?? +"The last time anybody made a list of the top hundred character attributes of New Yorkers, common sense snuck in at number 79. .... When it's fall in New York, the air smells as if someone's been frying goats in it, and if you are keen to breathe the best plan is to open a window and stick your head in a building." - Nuff said?? % -"`What's been happening here?' he demanded. `Oh just the nicest things, sir, just the nicest things. can I sit on your lap please?'" "`Colin, I am going to abandon you to your fate.' `I'm so happy.'" "`It will be very, very nasty for you, and that's just too bad. Got it?' `I gurgle with pleasure.'"QUOTEHERESTRINGMAGIC1234- Ford and Colin the robot. +"`What's been happening here?' he demanded. `Oh just the nicest things, sir, just the nicest things. can I sit on your lap please?'" "`Colin, I am going to abandon you to your fate.' `I'm so happy.'" "`It will be very, very nasty for you, and that's just too bad. Got it?' `I gurgle with pleasure.'" - Ford and Colin the robot. % -"What the hell, he thought, you're only young once, and threw himself out of the window. That would at least keep the element of surprise on his side."QUOTEHERESTRINGMAGIC1234- Ford outwitting a Vogon with a rocket launcher by going into another certain death situation. +"What the hell, he thought, you're only young once, and threw himself out of the window. That would at least keep the element of surprise on his side." - Ford outwitting a Vogon with a rocket launcher by going into another certain death situation. % -"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."QUOTEHERESTRINGMAGIC1234- One of the laws of computers and programming revealed. +"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair." - One of the laws of computers and programming revealed. % -"`You know they've reintroduced the death penalty for insurance company directors?' `Really?' said Arthur. `No I didn't. For what offence?' Trillian frowned. `What do you mean, offence?' `I see.'"QUOTEHERESTRINGMAGIC1234- Evidence that there will be some justice in the Universe eventually. +"`You know they've reintroduced the death penalty for insurance company directors?' `Really?' said Arthur. `No I didn't. For what offence?' Trillian frowned. `What do you mean, offence?' `I see.'" - Evidence that there will be some justice in the Universe eventually. % -"`She hit me on the head with the rock again.' `I think I can confirm that that was my daughter.' `Sweet kid.' `You have to get to know her,' said Arthur. `She eases up does she?' `No,' said Arthur, `but you get a better sense of when to duck.'"QUOTEHERESTRINGMAGIC1234- Ford and Arthur on Random. +"`She hit me on the head with the rock again.' `I think I can confirm that that was my daughter.' `Sweet kid.' `You have to get to know her,' said Arthur. `She eases up does she?' `No,' said Arthur, `but you get a better sense of when to duck.'" - Ford and Arthur on Random. % "Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the Galaxy lies a small unregarded yellow sun. " % -- cgit v1.2.3-70-g09d2 From 1cc32be5f632ff933b3e3f1c7bd9e612a274c095 Mon Sep 17 00:00:00 2001 From: ajatkj Date: Wed, 20 Sep 2023 20:21:27 +0530 Subject: feat(poetry-env): create plugin (#11069) --- plugins/poetry-env/README.md | 10 ++++++++++ plugins/poetry-env/poetry-env.plugin.zsh | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 plugins/poetry-env/README.md create mode 100644 plugins/poetry-env/poetry-env.plugin.zsh diff --git a/plugins/poetry-env/README.md b/plugins/poetry-env/README.md new file mode 100644 index 000000000..a7d16563e --- /dev/null +++ b/plugins/poetry-env/README.md @@ -0,0 +1,10 @@ +# Poetry Environment Plugin + +This plugin automatically changes poetry environment when you cd into or out of the project directory. +Note: Script looks for pyproject.toml file to determine poetry if its a poetry environment + +To use it, add `poetry-env` to the plugins array in your zshrc file: + +```zsh +plugins=(... poetry-env) +``` diff --git a/plugins/poetry-env/poetry-env.plugin.zsh b/plugins/poetry-env/poetry-env.plugin.zsh new file mode 100644 index 000000000..86e5fad4e --- /dev/null +++ b/plugins/poetry-env/poetry-env.plugin.zsh @@ -0,0 +1,27 @@ +# Automatic poetry environment activation/deactivation +_togglePoetryShell() { + # deactivate environment if pyproject.toml doesn't exist and not in a subdir + if [[ ! -f "$PWD/pyproject.toml" ]] ; then + if [[ "$poetry_active" == 1 ]]; then + if [[ "$PWD" != "$poetry_dir"* ]]; then + export poetry_active=0 + deactivate + return + fi + fi + fi + + # activate the environment if pyproject.toml exists + if [[ "$poetry_active" != 1 ]]; then + if [[ -f "$PWD/pyproject.toml" ]]; then + if grep -q 'tool.poetry' "$PWD/pyproject.toml"; then + export poetry_active=1 + export poetry_dir="$PWD" + source "$(poetry env info --path)/bin/activate" + fi + fi + fi +} +autoload -U add-zsh-hook +add-zsh-hook chpwd _togglePoetryShell +_togglePoetryShell -- cgit v1.2.3-70-g09d2 From 1c55a0fe5246487ec9f18e03b7f28862b76cb7ab Mon Sep 17 00:00:00 2001 From: Marcus Müller Date: Thu, 21 Sep 2023 12:43:00 +0200 Subject: feat(dnf): use `dnf5` if available (#11904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marcus Müller --- plugins/dnf/README.md | 3 +++ plugins/dnf/dnf.plugin.zsh | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/plugins/dnf/README.md b/plugins/dnf/README.md index dc0d1e0a0..f45c8778c 100644 --- a/plugins/dnf/README.md +++ b/plugins/dnf/README.md @@ -10,6 +10,9 @@ To use it, add `dnf` to the plugins array in your zshrc file: plugins=(... dnf) ``` +Classic `dnf` is getting superseded by `dnf5`; this plugin detects the presence +of `dnf5` and uses it as drop-in alternative to the slower `dnf`. + ## Aliases | Alias | Command | Description | diff --git a/plugins/dnf/dnf.plugin.zsh b/plugins/dnf/dnf.plugin.zsh index 653ce7dda..642422fe1 100644 --- a/plugins/dnf/dnf.plugin.zsh +++ b/plugins/dnf/dnf.plugin.zsh @@ -1,15 +1,19 @@ ## Aliases +local dnfprog="dnf" -alias dnfl="dnf list" # List packages -alias dnfli="dnf list installed" # List installed packages -alias dnfgl="dnf grouplist" # List package groups -alias dnfmc="dnf makecache" # Generate metadata cache -alias dnfp="dnf info" # Show package information -alias dnfs="dnf search" # Search package +# Prefer dnf5 if installed +command -v dnf5 > /dev/null && dnfprog=dnf5 -alias dnfu="sudo dnf upgrade" # Upgrade package -alias dnfi="sudo dnf install" # Install package -alias dnfgi="sudo dnf groupinstall" # Install package group -alias dnfr="sudo dnf remove" # Remove package -alias dnfgr="sudo dnf groupremove" # Remove package group -alias dnfc="sudo dnf clean all" # Clean cache +alias dnfl="${dnfprog} list" # List packages +alias dnfli="${dnfprog} list installed" # List installed packages +alias dnfgl="${dnfprog} grouplist" # List package groups +alias dnfmc="${dnfprog} makecache" # Generate metadata cache +alias dnfp="${dnfprog} info" # Show package information +alias dnfs="${dnfprog} search" # Search package + +alias dnfu="sudo ${dnfprog} upgrade" # Upgrade package +alias dnfi="sudo ${dnfprog} install" # Install package +alias dnfgi="sudo ${dnfprog} groupinstall" # Install package group +alias dnfr="sudo ${dnfprog} remove" # Remove package +alias dnfgr="sudo ${dnfprog} groupremove" # Remove package group +alias dnfc="sudo ${dnfprog} clean all" # Clean cache -- cgit v1.2.3-70-g09d2 From c91684bb1b723833a96415c2c724332a6e2e620f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 25 Sep 2023 08:20:20 +0100 Subject: docs(web-search): add `youtube` entry --- plugins/web-search/README.md | 62 ++++++++++++++++---------------- plugins/web-search/web-search.plugin.zsh | 1 - 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/plugins/web-search/README.md b/plugins/web-search/README.md index 0bf9f26ad..6e4b4d7b8 100644 --- a/plugins/web-search/README.md +++ b/plugins/web-search/README.md @@ -12,8 +12,8 @@ plugins=( ... web-search) You can use the `web-search` plugin in these two forms: -* `web_search [more terms if you want]` -* ` [more terms if you want]` +- `web_search [more terms if you want]` +- ` [more terms if you want]` For example, these two are equivalent: @@ -24,43 +24,42 @@ $ google oh-my-zsh Available search contexts are: -| Context | URL | -| --------------------- | ---------------------------------------- | -| `bing` | `https://www.bing.com/search?q=` | -| `google` | `https://www.google.com/search?q=` | -| `brs` or `brave` | `https://search.brave.com/search?q=` | -| `yahoo` | `https://search.yahoo.com/search?p=` | -| `ddg` or `duckduckgo` | `https://www.duckduckgo.com/?q=` | -| `sp` or `startpage` | `https://www.startpage.com/do/search?q=` | -| `yandex` | `https://yandex.ru/yandsearch?text=` | -| `github` | `https://github.com/search?q=` | -| `baidu` | `https://www.baidu.com/s?wd=` | -| `ecosia` | `https://www.ecosia.org/search?q=` | -| `goodreads` | `https://www.goodreads.com/search?q=` | -| `qwant` | `https://www.qwant.com/?q=` | -| `givero` | `https://www.givero.com/search?q=` | -| `stackoverflow` | `https://stackoverflow.com/search?q=` | -| `wolframalpha` | `https://wolframalpha.com/input?i=` | -| `archive` | `https://web.archive.org/web/*/` | -| `scholar` | `https://scholar.google.com/scholar?q=` | -| `ask` | `https://www.ask.com/web?q=` | +| Context | URL | +| --------------------- | ----------------------------------------------- | +| `bing` | `https://www.bing.com/search?q=` | +| `google` | `https://www.google.com/search?q=` | +| `brs` or `brave` | `https://search.brave.com/search?q=` | +| `yahoo` | `https://search.yahoo.com/search?p=` | +| `ddg` or `duckduckgo` | `https://www.duckduckgo.com/?q=` | +| `sp` or `startpage` | `https://www.startpage.com/do/search?q=` | +| `yandex` | `https://yandex.ru/yandsearch?text=` | +| `github` | `https://github.com/search?q=` | +| `baidu` | `https://www.baidu.com/s?wd=` | +| `ecosia` | `https://www.ecosia.org/search?q=` | +| `goodreads` | `https://www.goodreads.com/search?q=` | +| `qwant` | `https://www.qwant.com/?q=` | +| `givero` | `https://www.givero.com/search?q=` | +| `stackoverflow` | `https://stackoverflow.com/search?q=` | +| `wolframalpha` | `https://wolframalpha.com/input?i=` | +| `archive` | `https://web.archive.org/web/*/` | +| `scholar` | `https://scholar.google.com/scholar?q=` | +| `ask` | `https://www.ask.com/web?q=` | +| `youtube` | `https://www.youtube.com/results?search_query=` | Also there are aliases for bang-searching DuckDuckGo: | Context | Bang | -|-----------|-------| +| --------- | ----- | | `wiki` | `!w` | | `news` | `!n` | -| `youtube` | `!yt` | | `map` | `!m` | | `image` | `!i` | | `ducky` | `!` | ### Custom search engines -If you want to add other search contexts to the plugin, you can use the -`$ZSH_WEB_SEARCH_ENGINES` variable. Set it before Oh My Zsh is sourced, -with the following format: +If you want to add other search contexts to the plugin, you can use the `$ZSH_WEB_SEARCH_ENGINES` variable. +Set it before Oh My Zsh is sourced, with the following format: ```zsh ZSH_WEB_SEARCH_ENGINES=( @@ -69,13 +68,12 @@ ZSH_WEB_SEARCH_ENGINES=( ) ``` -where `` is the name of the search context, and `` a URL of -the same type as the search contexts above. For example, to add `reddit`, -you'd do: +where `` is the name of the search context, and `` a URL of the same type as the search contexts +above. For example, to add `reddit`, you'd do: ```zsh ZSH_WEB_SEARCH_ENGINES=(reddit "https://www.reddit.com/search/?q=") ``` -These custom search engines will also be turned to aliases, so you can -both do `web_search reddit ` or `reddit `. +These custom search engines will also be turned to aliases, so you can both do `web_search reddit ` or +`reddit `. diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index fc87a3495..a8848fd95 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -72,7 +72,6 @@ alias youtube='web_search youtube' #add your own !bang searches here alias wiki='web_search duckduckgo \!w' alias news='web_search duckduckgo \!n' -#alias youtube='web_search duckduckgo \!yt' alias map='web_search duckduckgo \!m' alias image='web_search duckduckgo \!i' alias ducky='web_search duckduckgo \!' -- cgit v1.2.3-70-g09d2 From a17789eedea4f6b9b5a9c970174d6d5dc0ef64ee Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 25 Sep 2023 09:49:22 +0100 Subject: docs(git): improve tables and language (#11895) --- plugins/git/README.md | 463 +++++++++++++++++++++++++------------------------- 1 file changed, 231 insertions(+), 232 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 6eb63ea40..9621a312e 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -10,204 +10,204 @@ plugins=(... git) ## Aliases -| Alias | Command | -| :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| grt | cd "$(git rev-parse --show-toplevel || echo .)" | -| ggpnp | ggl && ggp | -| ggpur | ggu | -| g | git | -| ga | git add | -| gaa | git add --all | -| gapa | git add --patch | -| gau | git add --update | -| gav | git add --verbose | -| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]" | -| gam | git am | -| gama | git am --abort | -| gamc | git am --continue | -| gamscp | git am --show-current-patch | -| gams | git am --skip | -| gap | git apply | -| gapt | git apply --3way | -| gbs | git bisect | -| gbsb | git bisect bad | -| gbsg | git bisect good | -| gbsn | git bisect new | -| gbso | git bisect old | -| gbsr | git bisect reset | -| gbss | git bisect start | -| gbl | git blame -w | -| gb | git branch | -| gba | git branch --all | -| gbd | git branch --delete | -| gbD | git branch --delete --force | -| gbda | git branch --no-color --merged | grep -vE "^([+]|\s($(git_main_branch)|$(git_develop_branch))\s\*$)" | xargs git branch --delete 2>/dev/null | -| gbgd | LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d | -| gbgD | LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D | -| gbnm | git branch --no-merged | -| gbr | git branch --remote | -| ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | -| gbg | LANG=C git branch -vv | grep ": gone\]" | -| gco | git checkout | -| gcor | git checkout --recurse-submodules | -| gcb | git checkout -b | -| gcd | git checkout $(git_develop_branch) | -| gcm | git checkout $(git_main_branch) | -| gcp | git cherry-pick | -| gcpa | git cherry-pick --abort | -| gcpc | git cherry-pick --continue | -| gclean | git clean --interactive -d | -| gcl | git clone --recurse-submodules | -| gccd | git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)" | -| gcam | git commit --all --message | -| gcas | git commit --all --signoff | -| gcasm | git commit --all --signoff --message | -| gcmsg | git commit --message | -| gcsm | git commit --signoff --message | -| gc | git commit --verbose | -| gca | git commit --verbose --all | -| gca! | git commit --verbose --all --amend | -| gcan! | git commit --verbose --all --no-edit --amend | -| gcans! | git commit --verbose --all --signoff --no-edit --amend | -| gc! | git commit --verbose --amend | -| gcn! | git commit --verbose --no-edit --amend | -| gcs | git commit -S | -| gcss | git commit -S -s | -| gcssm | git commit -S -s -m | -| gcf | git config --list | -| gdct | git describe --tags $(git rev-list --tags --max-count=1) | -| gd | git diff | -| gdca | git diff --cached | -| gdcw | git diff --cached --word-diff | -| gds | git diff --staged | -| gdw | git diff --word-diff | -| gdv | git diff -w $@ | view - | -| gdup | git diff @{upstream} | -| gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock" | -| gdt | git diff-tree --no-commit-id --name-only -r | -| gf | git fetch | -| gfa | git fetch --all --prune | -| gfo | git fetch origin | -| gg | git gui citool | -| gga | git gui citool --amend | -| ghh | git help | -| glgg | git log --graph | -| glgga | git log --graph --decorate --all | -| glgm | git log --graph --max-count=10 | -| glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | -| glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short | -| glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' | -| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all | -| glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat | -| glo | git log --oneline --decorate | -| glog | git log --oneline --decorate --graph | -| gloga | git log --oneline --decorate --graph --all | -| glp | git log --pretty=\ | -| glg | git log --stat | -| glgp | git log --stat --patch | -| gignored | git ls-files -v | grep "^[[:lower:]]" | -| gfg | git ls-files | grep | -| gm | git merge | -| gma | git merge --abort | -| gms | git merge --squash | -| gmom | git merge origin/$(git_main_branch) | -| gmum | git merge upstream/$(git_main_branch) | -| gmtl | git mergetool --no-prompt | -| gmtlvim | git mergetool --no-prompt --tool=vimdiff | -| gl | git pull | -| gpr | git pull --rebase | -| gup | git pull --rebase | -| gupa | git pull --rebase --autostash | -| gupav | git pull --rebase --autostash --verbose | -| gupv | git pull --rebase --verbose | -| ggu | git pull --rebase origin $(current_branch) | -| gupom | git pull --rebase origin $(git_main_branch) | -| gupomi | git pull --rebase=interactive origin $(git_main_branch) | -| ggpull | git pull origin "$(git_current_branch)" | -| ggl | git pull origin $(current_branch) | -| gluc | git pull upstream $(git_current_branch) | -| glum | git pull upstream $(git_main_branch) | -| gp | git push | -| gpd | git push --dry-run | -| gpf! | git push --force | -| ggf | git push --force origin $(current_branch) | -| gpf | git push --force-with-lease --force-if-includes (git version >= 2.30) | -| gpf | git push --force-with-lease (git version < 2.30) | -| ggfl | git push --force-with-lease origin $(current_branch) | -| gpsup | git push --set-upstream origin $(git_current_branch) | -| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30) | -| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30) | -| gpv | git push --verbose | -| gpoat | git push origin --all && git push origin --tags | -| gpod | git push origin --delete | -| ggpush | git push origin "$(git_current_branch)" | -| ggp | git push origin $(current_branch) | -| gpu | git push upstream | -| grb | git rebase | -| grba | git rebase --abort | -| grbc | git rebase --continue | -| grbi | git rebase --interactive | -| grbo | git rebase --onto | -| grbs | git rebase --skip | -| grbd | git rebase $(git_develop_branch) | -| grbm | git rebase $(git_main_branch) | -| grbom | git rebase origin/$(git_main_branch) | -| gr | git remote | -| grv | git remote --verbose | -| gra | git remote add | -| grrm | git remote remove | -| grmv | git remote rename | -| grset | git remote set-url | -| grup | git remote update | -| grh | git reset | -| gru | git reset -- | -| grhh | git reset --hard | -| gpristine | git reset --hard && git clean -dffx | -| groh | git reset origin/$(git_current_branch) --hard | -| grs | git restore | -| grss | git restore --source | -| grst | git restore --staged | -| gunwip | git rev-list --max-count=1 --format="%s" HEAD | grep -q "--wip--" && git reset HEAD~1 | -| grev | git revert | -| grm | git rm | -| grmc | git rm --cached | -| gcount | git shortlog --summary -n | -| gsh | git show | -| gsps | git show --pretty=short --show-signature | -| gstall | git stash --all | -| gstu | git stash --include-untracked | -| gstaa | git stash apply | -| gstc | git stash clear | -| gstd | git stash drop | -| gstl | git stash list | -| gstp | git stash pop | -| gsta | git stash push (git version >= 2.13) | -| gsta | git stash save (git version < 2.13) | -| gsts | git stash show --text | -| gst | git status | -| gss | git status --short | -| gsb | git status --short -b | -| gsi | git submodule init | -| gsu | git submodule update | -| gsd | git svn dcommit | -| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk | -| gsr | git svn rebase | -| gsw | git switch | -| gswc | git switch -c | -| gswd | git switch $(git_develop_branch) | -| gswm | git switch $(git_main_branch) | -| gts | git tag -s | -| gtv | git tag | sort -V | -| gignore | git update-index --assume-unchanged | -| gunignore | git update-index --no-assume-unchanged | -| gwch | git whatchanged -p --abbrev-commit --pretty=medium | -| gwt | git worktree | -| gwtls | git worktree list | -| gwtmv | git worktree move | -| gwtrm | git worktree remove | -| gk | gitk --all --branches &! | -| gke | gitk --all $(git log --walk-reflogs --pretty=%h) &! | -| gtl | gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl | +| Alias | Command | +| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `grt` | `cd "$(git rev-parse --show-toplevel \|\| echo .)"` | +| `ggpnp` | `ggl && ggp` | +| `ggpur` | `ggu` | +| `g` | `git` | +| `ga` | `git add` | +| `gaa` | `git add --all` | +| `gapa` | `git add --patch` | +| `gau` | `git add --update` | +| `gav` | `git add --verbose` | +| `gwip` | `git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"` | +| `gam` | `git am` | +| `gama` | `git am --abort` | +| `gamc` | `git am --continue` | +| `gamscp` | `git am --show-current-patch` | +| `gams` | `git am --skip` | +| `gap` | `git apply` | +| `gapt` | `git apply --3way` | +| `gbs` | `git bisect` | +| `gbsb` | `git bisect bad` | +| `gbsg` | `git bisect good` | +| `gbsn` | `git bisect new` | +| `gbso` | `git bisect old` | +| `gbsr` | `git bisect reset` | +| `gbss` | `git bisect start` | +| `gbl` | `git blame -w` | +| `gb` | `git branch` | +| `gba` | `git branch --all` | +| `gbd` | `git branch --delete` | +| `gbD` | `git branch --delete --force` | +| `gbda` | `git branch --no-color --merged \| command grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| command xargs git branch --delete 2>/dev/null` | +| `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` | +| `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` | +| `gbnm` | `git branch --no-merged` | +| `gbr` | `git branch --remote` | +| `ggsup` | `git branch --set-upstream-to=origin/$(git_current_branch)` | +| `gbg` | `LANG=C git branch -vv \| grep ": gone\]"` | +| `gco` | `git checkout` | +| `gcor` | `git checkout --recurse-submodules` | +| `gcb` | `git checkout -b` | +| `gcd` | `git checkout $(git_develop_branch)` | +| `gcm` | `git checkout $(git_main_branch)` | +| `gcp` | `git cherry-pick` | +| `gcpa` | `git cherry-pick --abort` | +| `gcpc` | `git cherry-pick --continue` | +| `gclean` | `git clean --interactive -d` | +| `gcl` | `git clone --recurse-submodules` | +| `gccd` | `git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)"` | +| `gcam` | `git commit --all --message` | +| `gcas` | `git commit --all --signoff` | +| `gcasm` | `git commit --all --signoff --message` | +| `gcmsg` | `git commit --message` | +| `gcsm` | `git commit --signoff --message` | +| `gc` | `git commit --verbose` | +| `gca` | `git commit --verbose --all` | +| `gca!` | `git commit --verbose --all --amend` | +| `gcan!` | `git commit --verbose --all --no-edit --amend` | +| `gcans!` | `git commit --verbose --all --signoff --no-edit --amend` | +| `gc!` | `git commit --verbose --amend` | +| `gcn!` | `git commit --verbose --no-edit --amend` | +| `gcs` | `git commit -S` | +| `gcss` | `git commit -S -s` | +| `gcssm` | `git commit -S -s -m` | +| `gcf` | `git config --list` | +| `gdct` | `git describe --tags $(git rev-list --tags --max-count=1)` | +| `gd` | `git diff` | +| `gdca` | `git diff --cached` | +| `gdcw` | `git diff --cached --word-diff` | +| `gds` | `git diff --staged` | +| `gdw` | `git diff --word-diff` | +| `gdv` | `git diff -w "$@" \| view -` | +| `gdup` | `git diff @{upstream}` | +| `gdnolock` | `git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock"` | +| `gdt` | `git diff-tree --no-commit-id --name-only -r` | +| `gf` | `git fetch` | +| `gfa` | `git fetch --all --prune` | +| `gfo` | `git fetch origin` | +| `gg` | `git gui citool` | +| `gga` | `git gui citool --amend` | +| `ghh` | `git help` | +| `glgg` | `git log --graph` | +| `glgga` | `git log --graph --decorate --all` | +| `glgm` | `git log --graph --max-count=10` | +| `glod` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'` | +| `glods` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short` | +| `glol` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` | +| `glola` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all` | +| `glols` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat` | +| `glo` | `git log --oneline --decorate` | +| `glog` | `git log --oneline --decorate --graph` | +| `gloga` | `git log --oneline --decorate --graph --all` | +| `glp` | `git log --pretty=` | +| `glg` | `git log --stat` | +| `glgp` | `git log --stat --patch` | +| `gignored` | `git ls-files -v \| grep "^[[:lower:]]"` | +| `gfg` | `git ls-files \| grep` | +| `gm` | `git merge` | +| `gma` | `git merge --abort` | +| `gms` | `git merge --squash` | +| `gmom` | `git merge origin/$(git_main_branch)` | +| `gmum` | `git merge upstream/$(git_main_branch)` | +| `gmtl` | `git mergetool --no-prompt` | +| `gmtlvim` | `git mergetool --no-prompt --tool=vimdiff` | +| `gl` | `git pull` | +| `gpr` | `git pull --rebase` | +| `gup` | `git pull --rebase` | +| `gupa` | `git pull --rebase --autostash` | +| `gupav` | `git pull --rebase --autostash --verbose` | +| `gupv` | `git pull --rebase --verbose` | +| `ggu` | `git pull --rebase origin $(current_branch)` | +| `gupom` | `git pull --rebase origin $(git_main_branch)` | +| `gupomi` | `git pull --rebase=interactive origin $(git_main_branch)` | +| `ggpull` | `git pull origin "$(git_current_branch)"` | +| `ggl` | `git pull origin $(current_branch)` | +| `gluc` | `git pull upstream $(git_current_branch)` | +| `glum` | `git pull upstream $(git_main_branch)` | +| `gp` | `git push` | +| `gpd` | `git push --dry-run` | +| `gpf!` | `git push --force` | +| `ggf` | `git push --force origin $(current_branch)` | +| `gpf` | On Git >= 2.30: `git push --force-with-lease --force-if-includes` | +| `gpf` | On Git < 2.30: `git push --force-with-lease` | +| `ggfl` | `git push --force-with-lease origin $(current_branch)` | +| `gpsup` | `git push --set-upstream origin $(git_current_branch)` | +| `gpsupf` | On Git >= 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes` | +| `gpsupf` | On Git < 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease` | +| `gpv` | `git push --verbose` | +| `gpoat` | `git push origin --all && git push origin --tags` | +| `gpod` | `git push origin --delete` | +| `ggpush` | `git push origin "$(git_current_branch)"` | +| `ggp` | `git push origin $(current_branch)` | +| `gpu` | `git push upstream` | +| `grb` | `git rebase` | +| `grba` | `git rebase --abort` | +| `grbc` | `git rebase --continue` | +| `grbi` | `git rebase --interactive` | +| `grbo` | `git rebase --onto` | +| `grbs` | `git rebase --skip` | +| `grbd` | `git rebase $(git_develop_branch)` | +| `grbm` | `git rebase $(git_main_branch)` | +| `grbom` | `git rebase origin/$(git_main_branch)` | +| `gr` | `git remote` | +| `grv` | `git remote --verbose` | +| `gra` | `git remote add` | +| `grrm` | `git remote remove` | +| `grmv` | `git remote rename` | +| `grset` | `git remote set-url` | +| `grup` | `git remote update` | +| `grh` | `git reset` | +| `gru` | `git reset --` | +| `grhh` | `git reset --hard` | +| `gpristine` | `git reset --hard && git clean -dffx` | +| `groh` | `git reset origin/$(git_current_branch) --hard` | +| `grs` | `git restore` | +| `grss` | `git restore --source` | +| `grst` | `git restore --staged` | +| `gunwip` | `git rev-list --max-count=1 --format="%s" HEAD \| grep -q "--wip--" && git reset HEAD~1` | +| `grev` | `git revert` | +| `grm` | `git rm` | +| `grmc` | `git rm --cached` | +| `gcount` | `git shortlog --summary -n` | +| `gsh` | `git show` | +| `gsps` | `git show --pretty=short --show-signature` | +| `gstall` | `git stash --all` | +| `gstu` | `git stash --include-untracked` | +| `gstaa` | `git stash apply` | +| `gstc` | `git stash clear` | +| `gstd` | `git stash drop` | +| `gstl` | `git stash list` | +| `gstp` | `git stash pop` | +| `gsta` | On Git >= 2.13: `git stash push` | +| `gsta` | On Git < 2.13: `git stash save` | +| `gsts` | `git stash show --text` | +| `gst` | `git status` | +| `gss` | `git status --short` | +| `gsb` | `git status --short -b` | +| `gsi` | `git submodule init` | +| `gsu` | `git submodule update` | +| `gsd` | `git svn dcommit` | +| `git-svn-dcommit-push` | `git svn dcommit && git push github $(git_main_branch):svntrunk` | +| `gsr` | `git svn rebase` | +| `gsw` | `git switch` | +| `gswc` | `git switch -c` | +| `gswd` | `git switch $(git_develop_branch)` | +| `gswm` | `git switch $(git_main_branch)` | +| `gts` | `git tag -s` | +| `gtv` | `git tag \| sort -V` | +| `gignore` | `git update-index --assume-unchanged` | +| `gunignore` | `git update-index --no-assume-unchanged` | +| `gwch` | `git whatchanged -p --abbrev-commit --pretty=medium` | +| `gwt` | `git worktree` | +| `gwtls` | `git worktree list` | +| `gwtmv` | `git worktree move` | +| `gwtrm` | `git worktree remove` | +| `gk` | `gitk --all --branches &!` | +| `gke` | `gitk --all $(git log --walk-reflogs --pretty=%h) &!` | +| `gtl` | `gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl` | ### Main branch preference @@ -221,50 +221,49 @@ branch exists. We do this via the function `git_main_branch`. These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support. -| Alias | Command | Modification | -| :----- | :----------------------------------------------------- | :----------------------------------------------------- | -| gap | `git add --patch` | new alias `gapa` | -| gcl | `git config --list` | new alias `gcf` | -| gdc | `git diff --cached` | new alias `gdca` | -| gdt | `git difftool` | no replacement | -| ggpull | `git pull origin $(current_branch)` | new alias `ggl` (`ggpull` still exists for now though) | -| ggpur | `git pull --rebase origin $(current_branch)` | new alias `ggu` (`ggpur` still exists for now though) | -| ggpush | `git push origin $(current_branch)` | new alias `ggp` (`ggpush` still exists for now though) | -| gk | `gitk --all --branches` | now aliased to `gitk --all --branches` | -| glg | `git log --stat --max-count = 10` | now aliased to `git log --stat --color` | -| glgg | `git log --graph --max-count = 10` | now aliased to `git log --graph --color` | -| gwc | `git whatchanged -p --abbrev-commit --pretty = medium` | new alias `gwch` | +| Alias | Command | Modification | +| :------- | :----------------------------------------------------- | :-------------------------------------------------------- | +| `gap` | `git add --patch` | New alias: `gapa`. | +| `gcl` | `git config --list` | New alias: `gcf`. | +| `gdc` | `git diff --cached` | New alias: `gdca`. | +| `gdt` | `git difftool` | No replacement. | +| `ggpull` | `git pull origin $(current_branch)` | New alias: `ggl`. (`ggpull` still exists for now though.) | +| `ggpur` | `git pull --rebase origin $(current_branch)` | New alias: `ggu`. (`ggpur` still exists for now though.) | +| `ggpush` | `git push origin $(current_branch)` | New alias: `ggp`. (`ggpush` still exists for now though.) | +| `gk` | `gitk --all --branches` | Now aliased to `gitk --all --branches`. | +| `glg` | `git log --stat --max-count=10` | Now aliased to `git log --stat --color`. | +| `glgg` | `git log --graph --max-count=10` | Now aliased to `git log --graph --color`. | +| `gwc` | `git whatchanged -p --abbrev-commit --pretty = medium` | New alias: `gwch`. | ## Functions ### Current -| Command | Description | -| :--------------------- | :------------------------------------------------------------------------------------------------------- | -| current_branch | Return the name of the current branch | -| git_current_user_email | Returns the `user.email` config value (lives in lib/git.zsh) | -| git_current_user_name | Returns the `user.name` config value (lives in lib/git.zsh) | -| git_develop_branch | Returns the name of the develop branch: `dev`, `devel`, `development` if they exist, `develop` otherwise | -| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise | -| grename \ \ | Rename `old` branch to `new`, including in origin remote | +| Command | Description | +| :----------------------- | :-------------------------------------------------------------------------------------------------------------- | +| `current_branch` | Returns the name of the current branch. | +| `git_current_user_email` | Returns the `user.email` config value. (Lives in `lib/git.zsh`.) | +| `git_current_user_name` | Returns the `user.name` config value. (Lives in `lib/git.zsh`.) | +| `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise. | +| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. | +| `grename ` | Renames branch `` to ``, including on the origin remote. | ### Work in Progress (WIP) -These features allow to pause a branch development and switch to another one (_"Work in Progress"_, or wip). -When you want to go back to work, just unwip it. +These features allow you to pause developing one branch and switch to another one (_"Work in Progress"_, or +“wip”). When you want to go back to work, just “unwip” it. -| Command | Description | -| :--------------- | :---------------------------------------------- | -| gwip | Commit wip branch | -| gunwip | Uncommit wip branch | -| gunwipall | Uncommit all recent `--wip--` commits | -| work_in_progress | Echoes a warning if the current branch is a wip | +| Command | Description | +| :----------------- | :---------------------------------------------- | +| `gwip` | Commit wip branch | +| `gunwip` | Uncommit wip branch | +| `gunwipall` | Uncommit all recent `--wip--` commits | +| `work_in_progress` | Echoes a warning if the current branch is a wip | -Note that `gwip` and `gunwip` are effectivly alias, but are also documented here to group all related WIP -features. +Note that `gwip` and `gunwip` are aliases, but are also documented here to group all related WIP features. ### Deprecated functions -| Command | Description | Reason | -| :----------------- | :-------------------------------------- | :-------------------------------------------------------------- | -| current_repository | Return the names of the current remotes | Didn't work properly. Use `git remote -v` instead (`grv` alias) | +| Command | Description | Reason | +| :------------------- | :-------------------------------------- | :--------------------------------------------------------------- | +| `current_repository` | Return the names of the current remotes | Didn't work properly. Use `git remote -v` instead (`grv` alias). | -- cgit v1.2.3-70-g09d2 From aaa74964a8f5908716f5bc8658116db096467702 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 26 Sep 2023 08:18:54 +0100 Subject: fix(git): remove `--text` from `gsts` (#11897) --- plugins/git/README.md | 2 +- plugins/git/git.plugin.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 9621a312e..390f52001 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -183,7 +183,7 @@ plugins=(... git) | `gstp` | `git stash pop` | | `gsta` | On Git >= 2.13: `git stash push` | | `gsta` | On Git < 2.13: `git stash save` | -| `gsts` | `git stash show --text` | +| `gsts` | `git stash show` | | `gst` | `git status` | | `gss` | `git status --short` | | `gsb` | `git status --short -b` | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 4afe34e99..426f51979 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -331,7 +331,7 @@ alias gstp='git stash pop' is-at-least 2.13 "$git_version" \ && alias gsta='git stash push' \ || alias gsta='git stash save' -alias gsts='git stash show --text' +alias gsts='git stash show' alias gst='git status' alias gss='git status --short' alias gsb='git status --short --branch' -- cgit v1.2.3-70-g09d2 From bca62f78e23247afdc44882111a27a7333e5acb0 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 26 Sep 2023 08:22:32 +0100 Subject: feat(git): add branch rename alias `gbm` (#11909) Co-authored-by: Gabriel Akinyosoye --- plugins/git/README.md | 1 + plugins/git/git.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index 390f52001..e7c32e97f 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -44,6 +44,7 @@ plugins=(... git) | `gbda` | `git branch --no-color --merged \| command grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| command xargs git branch --delete 2>/dev/null` | | `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` | | `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` | +| `gbm` | `git branch --move` | | `gbnm` | `git branch --no-merged` | | `gbr` | `git branch --remote` | | `ggsup` | `git branch --set-upstream-to=origin/$(git_current_branch)` | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 426f51979..01eab682e 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -125,6 +125,7 @@ alias gbD='git branch --delete --force' alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null' alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' +alias gbm='git branch --move' alias gbnm='git branch --no-merged' alias gbr='git branch --remote' alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' -- cgit v1.2.3-70-g09d2 From e2b855341bfd587590734da860d75ead7788810f Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 26 Sep 2023 08:27:48 +0100 Subject: feat(git): add tag aliases `gt` and `gta` (#11910) Co-authored-by: hasecilu Co-authored-by: Rik Co-authored-by: Carlo Sala --- plugins/git/README.md | 2 ++ plugins/git/git.plugin.zsh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index e7c32e97f..5a732ed63 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -197,6 +197,8 @@ plugins=(... git) | `gswc` | `git switch -c` | | `gswd` | `git switch $(git_develop_branch)` | | `gswm` | `git switch $(git_main_branch)` | +| `gt` | `git tag` | +| `gta` | `git tag --annotate` | | `gts` | `git tag -s` | | `gtv` | `git tag \| sort -V` | | `gignore` | `git update-index --assume-unchanged` | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 01eab682e..527093c28 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -345,6 +345,8 @@ alias gsw='git switch' alias gswc='git switch --create' alias gswd='git switch $(git_develop_branch)' alias gswm='git switch $(git_main_branch)' +alias gt='git tag' +alias gta='git tag --annotate' alias gts='git tag --sign' alias gtv='git tag | sort -V' alias gignore='git update-index --assume-unchanged' -- cgit v1.2.3-70-g09d2 From 4fb5d02db94fa87d22afea9825bd5f866e0cd1ac Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 26 Sep 2023 08:31:32 +0100 Subject: feat(git): add reset aliases `grhk` and `grhs` (#11896) --- plugins/git/README.md | 2 ++ plugins/git/git.plugin.zsh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index 5a732ed63..5b2db55fa 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -163,6 +163,8 @@ plugins=(... git) | `grh` | `git reset` | | `gru` | `git reset --` | | `grhh` | `git reset --hard` | +| `grhk` | `git reset --keep` | +| `grhs` | `git reset --soft` | | `gpristine` | `git reset --hard && git clean -dffx` | | `groh` | `git reset origin/$(git_current_branch) --hard` | | `grs` | `git restore` | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 527093c28..ba90c936e 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -310,6 +310,8 @@ alias grup='git remote update' alias grh='git reset' alias gru='git reset --' alias grhh='git reset --hard' +alias grhk='git reset --keep' +alias grhs='git reset --soft' alias gpristine='git reset --hard && git clean --force -dfx' alias groh='git reset origin/$(git_current_branch) --hard' alias grs='git restore' -- cgit v1.2.3-70-g09d2 From 0e1e877ea9182f87b3ab34cbc2ea944b34f5345e Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 27 Sep 2023 08:19:57 +0200 Subject: fix(git)!: remove `gt` alias BREAKING CHANGE: `gt` alias clashes with Graphite CLI (https://graphite.dev). See https://github.com/ohmyzsh/ohmyzsh/pull/11910#issuecomment-1736340910 --- plugins/git/README.md | 1 - plugins/git/git.plugin.zsh | 1 - 2 files changed, 2 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 5b2db55fa..9c16cb6e7 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -199,7 +199,6 @@ plugins=(... git) | `gswc` | `git switch -c` | | `gswd` | `git switch $(git_develop_branch)` | | `gswm` | `git switch $(git_main_branch)` | -| `gt` | `git tag` | | `gta` | `git tag --annotate` | | `gts` | `git tag -s` | | `gtv` | `git tag \| sort -V` | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index ba90c936e..cb848b407 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -347,7 +347,6 @@ alias gsw='git switch' alias gswc='git switch --create' alias gswd='git switch $(git_develop_branch)' alias gswm='git switch $(git_main_branch)' -alias gt='git tag' alias gta='git tag --annotate' alias gts='git tag --sign' alias gtv='git tag | sort -V' -- cgit v1.2.3-70-g09d2 From d3b6f1fd5e42deafb3a6458213762a492e484073 Mon Sep 17 00:00:00 2001 From: Piotr Minkina Date: Thu, 28 Sep 2023 23:43:06 +0200 Subject: fix(gradle): remove look for settings.gradle files (#11917) --- plugins/gradle/gradle.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/gradle/gradle.plugin.zsh b/plugins/gradle/gradle.plugin.zsh index 5bca364d1..dacc46478 100644 --- a/plugins/gradle/gradle.plugin.zsh +++ b/plugins/gradle/gradle.plugin.zsh @@ -6,7 +6,7 @@ function gradle-or-gradlew() { # taken from https://github.com/gradle/gradle-completion local dir="$PWD" project_root="$PWD" while [[ "$dir" != / ]]; do - if [[ -f "$dir/settings.gradle" || -f "$dir/settings.gradle.kts" || -f "$dir/gradlew" ]]; then + if [[ -x "$dir/gradlew" ]]; then project_root="$dir" break fi -- cgit v1.2.3-70-g09d2 From 27402e2603b9354f419af3695bad8ff17ed33bac Mon Sep 17 00:00:00 2001 From: Jake Conway Date: Fri, 29 Sep 2023 05:24:40 -0500 Subject: docs(gas): update plugin url (#11918) --- plugins/gas/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/gas/README.md b/plugins/gas/README.md index 47b3fb9df..a0a7a568f 100644 --- a/plugins/gas/README.md +++ b/plugins/gas/README.md @@ -1,6 +1,6 @@ # Gas plugin -This plugin adds autocompletion for the [gas](http://walle.github.com/gas) command, +This plugin adds autocompletion for the [gas](http://ramblingsby.me/gas/) command, a utility to manage Git authors. To use it, add `gas` to the plugins array of your zshrc file: -- cgit v1.2.3-70-g09d2 From 278bcfc93bed91d1095a9ea7981c4a1109da7abd Mon Sep 17 00:00:00 2001 From: Thomas Faugier Date: Mon, 2 Oct 2023 20:25:17 +0200 Subject: feat(asdf): load zsh completions instead of bash ones Closes #11143 Closes #8779 Co-authored-by: Carlo Sala --- plugins/asdf/asdf.plugin.zsh | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/plugins/asdf/asdf.plugin.zsh b/plugins/asdf/asdf.plugin.zsh index 3016282c6..7635d20c3 100644 --- a/plugins/asdf/asdf.plugin.zsh +++ b/plugins/asdf/asdf.plugin.zsh @@ -2,26 +2,29 @@ ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}" ASDF_COMPLETIONS="$ASDF_DIR/completions" -# If not found, check for archlinux/AUR package (/opt/asdf-vm/) -if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/asdf.bash" ]] && [[ -f "/opt/asdf-vm/asdf.sh" ]]; then - ASDF_DIR="/opt/asdf-vm" - ASDF_COMPLETIONS="$ASDF_DIR" -fi - -# If not found, check for Homebrew package -if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/asdf.bash" ]] && (( $+commands[brew] )); then - brew_prefix="$(brew --prefix asdf)" - ASDF_DIR="${brew_prefix}/libexec" - ASDF_COMPLETIONS="${brew_prefix}/etc/bash_completion.d" - unset brew_prefix +if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/_asdf" ]]; then + # If not found, check for archlinux/AUR package (/opt/asdf-vm/) + if [[ -f "/opt/asdf-vm/asdf.sh" ]]; then + ASDF_DIR="/opt/asdf-vm" + ASDF_COMPLETIONS="$ASDF_DIR" + # If not found, check for Homebrew package + elif (( $+commands[brew] )); then + _ASDF_PREFIX="$(brew --prefix asdf)" + ASDF_DIR="${_ASDF_PREFIX}/libexec" + ASDF_COMPLETIONS="${_ASDF_PREFIX}/share/zsh/site-functions" + unset _ASDF_PREFIX + else + return + fi fi # Load command if [[ -f "$ASDF_DIR/asdf.sh" ]]; then - . "$ASDF_DIR/asdf.sh" - + source "$ASDF_DIR/asdf.sh" # Load completions - if [[ -f "$ASDF_COMPLETIONS/asdf.bash" ]]; then - . "$ASDF_COMPLETIONS/asdf.bash" + if [[ -f "$ASDF_COMPLETIONS/_asdf" ]]; then + fpath+=("$ASDF_COMPLETIONS") + autoload -Uz _asdf + compdef _asdf asdf # compdef is already loaded before loading plugins fi fi -- cgit v1.2.3-70-g09d2 From fea4584cebf98fc58334b7cca841ab1ef224a35e Mon Sep 17 00:00:00 2001 From: HeroCC Date: Mon, 2 Oct 2023 14:34:57 -0400 Subject: fix(tmux): don't autostart inside background intelliJ (#11927) --- plugins/tmux/tmux.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 680f72598..6ed91c447 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -109,7 +109,7 @@ compdef _tmux _zsh_tmux_plugin_run alias tmux=_zsh_tmux_plugin_run # Autostart if not already in tmux and enabled. -if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" ]]; then +if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" ]]; then # Actually don't autostart if we already did and multiple autostarts are disabled. if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]; then export ZSH_TMUX_AUTOSTARTED=true -- cgit v1.2.3-70-g09d2 From df80a2da5475fc3c068bc5f700fa176a47f7adbe Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 2 Oct 2023 20:41:01 +0200 Subject: feat(vi-mode): copy to clipboard when using `vi-change*` and `vi-yank*` widgets (#11861) --- plugins/vi-mode/README.md | 6 ++++++ plugins/vi-mode/vi-mode.plugin.zsh | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 0cb516751..821c12adb 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -144,11 +144,17 @@ NOTE: this used to be bound to `v`. That is now the default (`visual-mode`). - `c{motion}` : Delete {motion} text and start insert - `cc` : Delete line and start insert - `C` : Delete to the end of the line and start insert +- `P` : Insert the contents of the clipboard before the cursor +- `p` : Insert the contents of the clipboard after the cursor - `r{char}` : Replace the character under the cursor with {char} - `R` : Enter replace mode: Each character replaces existing one - `x` : Delete `count` characters under and after the cursor - `X` : Delete `count` characters before the cursor +NOTE: delete/kill commands (`dd`, `D`, `c{motion}`, `C`, `x`,`X`) and yank commands +(`y`, `Y`) will copy to the clipboard. Contents can then be put back using paste commands +(`P`, `p`). + ## Known issues ### Low `$KEYTIMEOUT` diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index cc9817a74..d1493e02f 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -147,8 +147,15 @@ function wrap_clipboard_widgets() { done } -wrap_clipboard_widgets copy vi-yank vi-yank-eol vi-backward-kill-word vi-change-whole-line vi-delete vi-delete-char -wrap_clipboard_widgets paste vi-put-{before,after} +wrap_clipboard_widgets copy \ + vi-yank vi-yank-eol vi-yank-whole-line \ + vi-change vi-change-eol vi-change-whole-line \ + vi-kill-line vi-kill-eol vi-backward-kill-word \ + vi-delete vi-delete-char vi-backward-delete-char + +wrap_clipboard_widgets paste \ + vi-put-{before,after} + unfunction wrap_clipboard_widgets # if mode indicator wasn't setup by theme, define default, we'll leave INSERT_MODE_INDICATOR empty by default -- cgit v1.2.3-70-g09d2 From 7400d469b67e2e72a6405df39c5f28cba646e1a8 Mon Sep 17 00:00:00 2001 From: jack Date: Tue, 3 Oct 2023 02:41:18 +0800 Subject: fix(ruby): add missing `-run` in `rserver` alias (#11913) --- plugins/ruby/ruby.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index 408512110..e09b22c75 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -23,4 +23,4 @@ alias gel="gem lock" alias geo="gem open" alias geoe="gem open -e" alias rrun="ruby -e" -alias rserver="ruby -e httpd . -p 8080" # requires webrick +alias rserver="ruby -run -e httpd . -p 8080" # requires webrick -- cgit v1.2.3-70-g09d2 From f36c6db0eac17b022eee87411e6996a5f5fc8457 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 3 Oct 2023 00:28:42 +0530 Subject: feat(shell-proxy): allow excluding endpoints with `NO_PROXY` (#11924) --- plugins/shell-proxy/README.md | 5 +++++ plugins/shell-proxy/proxy.py | 23 ++++++++++++++++++----- plugins/shell-proxy/shell-proxy.plugin.zsh | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/plugins/shell-proxy/README.md b/plugins/shell-proxy/README.md index b19888c56..102e46b6b 100644 --- a/plugins/shell-proxy/README.md +++ b/plugins/shell-proxy/README.md @@ -23,6 +23,7 @@ Set `SHELLPROXY_URL` environment variable to the URL of the proxy server: ```sh SHELLPROXY_URL="http://127.0.0.1:8123" +SHELLPROXY_NO_PROXY="localhost,127.0.0.1" proxy enable ``` @@ -36,11 +37,15 @@ Example: ```sh #!/bin/bash +# HTTP Proxy if [[ "$(uname)" = Darwin ]]; then echo "http://127.0.0.1:6152" # Surge Mac else echo "http://127.0.0.1:8123" # polipo fi + +# No Proxy +echo "localhost,127.0.0.1" ``` ### Method 3 diff --git a/plugins/shell-proxy/proxy.py b/plugins/shell-proxy/proxy.py index 14f2944cc..8c2aaf9f3 100755 --- a/plugins/shell-proxy/proxy.py +++ b/plugins/shell-proxy/proxy.py @@ -6,6 +6,7 @@ from subprocess import check_output, list2cmdline cwd = os.path.dirname(__file__) ssh_agent = os.path.join(cwd, "ssh-agent.py") proxy_env = "SHELLPROXY_URL" +no_proxy_env = "SHELLPROXY_NO_PROXY" proxy_config = os.environ.get("SHELLPROXY_CONFIG") or os.path.expandvars("$HOME/.config/proxy") usage="""shell-proxy: no proxy configuration found. @@ -15,18 +16,30 @@ See the plugin README for more information.""".format(env=proxy_env, config=prox def get_http_proxy(): default_proxy = os.environ.get(proxy_env) - if default_proxy: - return default_proxy + no_proxy = os.environ.get(no_proxy_env) + if default_proxy and no_proxy: + return default_proxy, no_proxy + if os.path.isfile(proxy_config): - return check_output(proxy_config).decode("utf-8").strip() + proxy_configdata = [line.strip() for line in check_output(proxy_config).decode("utf-8").splitlines()] + if len(proxy_configdata) >= 1: + if not default_proxy: + default_proxy = proxy_configdata[0] + if len(proxy_configdata) == 2 and not no_proxy: + no_proxy = proxy_configdata[1] + + if default_proxy: + return default_proxy, no_proxy print(usage, file=sys.stderr) sys.exit(1) -def make_proxies(url: str): +def make_proxies(url: str, no_proxy: str): proxies = {"%s_PROXY" % _: url for _ in ("HTTP", "HTTPS", "FTP", "RSYNC", "ALL")} proxies.update({name.lower(): value for (name, value) in proxies.items()}) proxies["GIT_SSH"] = ssh_agent + if no_proxy: + proxies.update({"NO_PROXY": no_proxy, "no_proxy": no_proxy}) return proxies @@ -35,7 +48,7 @@ def merge(mapping: dict): class CommandSet: - proxies = make_proxies(get_http_proxy()) + proxies = make_proxies(*get_http_proxy()) aliases = { _: "env __SSH_PROGRAM_NAME__=%s %s" % (_, ssh_agent) for _ in ("ssh", "sftp", "scp", "slogin", "ssh-copy-id") diff --git a/plugins/shell-proxy/shell-proxy.plugin.zsh b/plugins/shell-proxy/shell-proxy.plugin.zsh index 4fdbe9322..f6c31da45 100644 --- a/plugins/shell-proxy/shell-proxy.plugin.zsh +++ b/plugins/shell-proxy/shell-proxy.plugin.zsh @@ -27,7 +27,7 @@ eval ' # capture the output of the proxy script and bail out if it fails local output - output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" || + output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_NO_PROXY="$SHELLPROXY_NO_PROXY" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" || return $? # evaluate the output generated by the proxy script -- cgit v1.2.3-70-g09d2 From 974055f638dac907cfb10281bce9cf998641febd Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Sun, 8 Oct 2023 13:47:16 +0200 Subject: Adding Mastadon and updating X badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a30595581..d915bd720 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ Finally, you'll begin to get the sort of attention that you have always felt you To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twitter.com/ohmyzsh) on Twitter, and join us on [Discord](https://discord.gg/ohmyzsh). [![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) +![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ohmyzsh?style=flat) +![Mastodon Follow](https://img.shields.io/mastodon/follow/111169632522566717?domain=https%3A%2F%2Fmstdn.social&style=flat) [![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) [![huntr.dev](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev/bounties/disclose/?utm_campaign=ohmyzsh%2Fohmyzsh&utm_medium=social&utm_source=github&target=https%3A%2F%2Fgithub.com%2Fohmyzsh%2Fohmyzsh) -- cgit v1.2.3-70-g09d2 From ee857e3acf4beba9e3121bc8e776a048c46fa85f Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Sun, 8 Oct 2023 14:05:03 +0200 Subject: Adding operating system compatibility chart --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d915bd720..70c4faaf0 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,21 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi ## Getting Started +### Operating System Compatibility + +| O/S | Status | +| :---------------- | :------: | +| Android | ✅ | +| FreeBSD | ✅ | +| LCARS | 🛸 | +| Linux | ✅ | +| MacOS | ✅ | +| OS/2 Warp | ❌ | +| Windows (WSL2) | ✅ | + + ### Prerequisites -- A Unix-like operating system: macOS, Linux, BSD. On Windows: WSL2 is preferred, but cygwin or msys also mostly work. - [Zsh](https://www.zsh.org) should be installed (v4.3.9 or more recent is fine but we prefer 5.0.8 and newer). If not pre-installed (run `zsh --version` to confirm), check the following wiki instructions here: [Installing ZSH](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH) - `curl` or `wget` should be installed - `git` should be installed (recommended v2.4.11 or higher) -- cgit v1.2.3-70-g09d2 From 7105e37ef09ff890f7eca3e64d48b8b7ff94a494 Mon Sep 17 00:00:00 2001 From: DemonKiller <55846983+demonkillerr@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:27:55 +0100 Subject: feat(rtx) Added new polyglot runtime manager (asdf rust clone) (#11932) * add readme.md for rtx * add rtx plugin * update install info * remove redundant slashes --- plugins/rtx/README.md | 30 ++++++++++++++++++++++++++++++ plugins/rtx/rtx.plugin.zsh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 plugins/rtx/README.md create mode 100644 plugins/rtx/rtx.plugin.zsh diff --git a/plugins/rtx/README.md b/plugins/rtx/README.md new file mode 100644 index 000000000..c6436d3a7 --- /dev/null +++ b/plugins/rtx/README.md @@ -0,0 +1,30 @@ +## rtx + + +Adds integration with [rtx](https://github.com/jdx/rtx), a runtime executor compatible with npm, nodenv, pyenv, etc. rtx is written in rust and is very fast. 20x-200x faster than asdf. With that being said, rtx is compatible with asdf plugins and .tool-versions files. It can be used as a drop-in replacement. + +### Installation + +1. [Download & install rtx](https://github.com/jdx/rtx#installation) by running the following: + + ``` + curl https://rtx.pub/install.sh | sh + ``` + + +2. [Enable rtx](https://github.com/jdx/rtx#quickstart) by adding it to your `plugins` definition in `~/.zshrc`. + + ``` + plugins=(rtx) + ``` + +### Usage + +See the [rtx readme](https://github.com/jdx/rtx#table-of-contents) for information on how to use rtx. Here are a few examples: + +``` +rtx install node Install the current version specified in .tool-versions/.rtx.toml +rtx use -g node@system Use system node as global default +rtx install node@20.0.0 Install a specific version number +rtx use -g node@20 Use node-20.x as global default +``` diff --git a/plugins/rtx/rtx.plugin.zsh b/plugins/rtx/rtx.plugin.zsh new file mode 100644 index 000000000..aaccaf015 --- /dev/null +++ b/plugins/rtx/rtx.plugin.zsh @@ -0,0 +1,30 @@ +# Find where rtx should be installed +RTX_DIR="${RTX_DIR:-$HOME/.rtx}" +RTX_COMPLETIONS="$RTX_DIR/completions" + +if [[ ! -f "$RTX_DIR/rtx.sh" || ! -f "$RTX_COMPLETIONS/_rtx" ]]; then + # If not found, check for archlinux/AUR package (/opt/rtx-vm/) + if [[ -f "/opt/rtx-vm/rtx.sh" ]]; then + RTX_DIR="/opt/rtx-vm" + RTX_COMPLETIONS="$RTX_DIR" + # If not found, check for Homebrew package + elif (( $+commands[brew] )); then + _RTX_PREFIX="$(brew --prefix rtx)" + RTX_DIR="${_RTX_PREFIX}/libexec" + RTX_COMPLETIONS="${_RTX_PREFIX}/share/zsh/site-functions" + unset _RTX_PREFIX + else + return + fi +fi + +# Load command +if [[ -f "$RTX_DIR/rtx.sh" ]]; then + source "$RTX_DIR/rtx.sh" + # Load completions + if [[ -f "$RTX_COMPLETIONS/_rtx" ]]; then + fpath+=("$RTX_COMPLETIONS") + autoload -Uz _rtx + compdef _rtx rtx # compdef is already loaded before loading plugins + fi +fi -- cgit v1.2.3-70-g09d2 From b75b01a3092e59cd10ff01084d4a5e3ac0be3e3a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 8 Oct 2023 20:01:46 +0200 Subject: chore: update README badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70c4faaf0..c83e16218 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Finally, you'll begin to get the sort of attention that you have always felt you To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twitter.com/ohmyzsh) on Twitter, and join us on [Discord](https://discord.gg/ohmyzsh). [![CI](https://github.com/ohmyzsh/ohmyzsh/workflows/CI/badge.svg)](https://github.com/ohmyzsh/ohmyzsh/actions?query=workflow%3ACI) -![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ohmyzsh?style=flat) -![Mastodon Follow](https://img.shields.io/mastodon/follow/111169632522566717?domain=https%3A%2F%2Fmstdn.social&style=flat) +[![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ohmyzsh?label=%40ohmyzsh&logo=x&style=flat)](https://twitter.com/intent/follow?screen_name=ohmyzsh) +[![Mastodon Follow](https://img.shields.io/mastodon/follow/111169632522566717?label=%40ohmyzsh&domain=https%3A%2F%2Fmstdn.social&logo=mastodon&style=flat)](https://mstdn.social/@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) [![huntr.dev](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev/bounties/disclose/?utm_campaign=ohmyzsh%2Fohmyzsh&utm_medium=social&utm_source=github&target=https%3A%2F%2Fgithub.com%2Fohmyzsh%2Fohmyzsh) -- cgit v1.2.3-70-g09d2 From 30a8a5d3e2f36e395c439c3346ef96e40e7bd277 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 9 Oct 2023 17:53:00 +0200 Subject: fix(rtx): fix `rtx` init procedure (#11949) --- plugins/rtx/rtx.plugin.zsh | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/plugins/rtx/rtx.plugin.zsh b/plugins/rtx/rtx.plugin.zsh index aaccaf015..a01828afd 100644 --- a/plugins/rtx/rtx.plugin.zsh +++ b/plugins/rtx/rtx.plugin.zsh @@ -1,30 +1,18 @@ -# Find where rtx should be installed -RTX_DIR="${RTX_DIR:-$HOME/.rtx}" -RTX_COMPLETIONS="$RTX_DIR/completions" - -if [[ ! -f "$RTX_DIR/rtx.sh" || ! -f "$RTX_COMPLETIONS/_rtx" ]]; then - # If not found, check for archlinux/AUR package (/opt/rtx-vm/) - if [[ -f "/opt/rtx-vm/rtx.sh" ]]; then - RTX_DIR="/opt/rtx-vm" - RTX_COMPLETIONS="$RTX_DIR" - # If not found, check for Homebrew package - elif (( $+commands[brew] )); then - _RTX_PREFIX="$(brew --prefix rtx)" - RTX_DIR="${_RTX_PREFIX}/libexec" - RTX_COMPLETIONS="${_RTX_PREFIX}/share/zsh/site-functions" - unset _RTX_PREFIX - else - return - fi +# rtx needs to be in $PATH +if (( ! ${+commands[rtx]} )); then + return fi -# Load command -if [[ -f "$RTX_DIR/rtx.sh" ]]; then - source "$RTX_DIR/rtx.sh" - # Load completions - if [[ -f "$RTX_COMPLETIONS/_rtx" ]]; then - fpath+=("$RTX_COMPLETIONS") - autoload -Uz _rtx - compdef _rtx rtx # compdef is already loaded before loading plugins - fi +# Load rtx hooks +eval "$(rtx activate zsh)" + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `rtx`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_rtx" ]]; then + typeset -g -A _comps + autoload -Uz _rtx + _comps[rtx]=_rtx fi + +# Generate and load rtx completion +rtx completion zsh >! "$ZSH_CACHE_DIR/completions/_rtx" &| -- cgit v1.2.3-70-g09d2 From 29b99c2c7b16f22f3ca2bdf9478ba700ac6c48b5 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 9 Oct 2023 18:00:17 +0200 Subject: feat(updater): add `background-alpha` update mode (preview) (#11928) NOTE: this feature is in alpha / preview mode, it is not guaranteed to work 100% of the time in all cases. If you experience any issues, open an issue or search for an open one describing your same situation. To use this, use the zstyle update mode settings [1] with the value `background-alpha`: zstyle ':omz:update' mode background-alpha [1] https://github.com/ohmyzsh/ohmyzsh#getting-updates --- tools/check_for_upgrade.sh | 230 ++++++++++++++++++++++++++++++--------------- 1 file changed, 156 insertions(+), 74 deletions(-) diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 3210e4375..1cc193bde 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -9,6 +9,7 @@ fi # - prompt (default): the user is asked before updating when it's time to update # - auto: the update is performed automatically when it's time # - reminder: a reminder is shown to the user when it's time to update +# - background-alpha: an experimental update-on-the-background option # - disabled: automatic update is turned off zstyle -s ':omz:update' mode update_mode || { update_mode=prompt @@ -91,13 +92,37 @@ function is_update_available() { } function update_last_updated_file() { - echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update" + local exit_status="$1" error="$2" + + if [[ -z "${1}${2}" ]]; then + echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update" + return + fi + + cat >! "${ZSH_CACHE_DIR}/.zsh-update" <&1); then + update_last_updated_file 0 "Update successful" + else + exit_status=$? + update_last_updated_file $exit_status "$error" + return $exit_status fi } @@ -126,88 +151,145 @@ function has_typed_input() { } } -() { - emulate -L zsh +function handle_update() { + () { + emulate -L zsh - local epoch_target mtime option LAST_EPOCH + local epoch_target mtime option LAST_EPOCH - # Remove lock directory if older than a day - zmodload zsh/datetime - zmodload -F zsh/stat b:zstat - if mtime=$(zstat +mtime "$ZSH/log/update.lock" 2>/dev/null); then - if (( (mtime + 3600 * 24) < EPOCHSECONDS )); then - command rm -rf "$ZSH/log/update.lock" + # Remove lock directory if older than a day + zmodload zsh/datetime + zmodload -F zsh/stat b:zstat + if mtime=$(zstat +mtime "$ZSH/log/update.lock" 2>/dev/null); then + if (( (mtime + 3600 * 24) < EPOCHSECONDS )); then + command rm -rf "$ZSH/log/update.lock" + fi fi - fi - # Check for lock directory - if ! command mkdir "$ZSH/log/update.lock" 2>/dev/null; then - return - fi + # Check for lock directory + if ! command mkdir "$ZSH/log/update.lock" 2>/dev/null; then + return + fi - # Remove lock directory on exit. `return $ret` is important for when trapping a SIGINT: - # The return status from the function is handled specially. If it is zero, the signal is - # assumed to have been handled, and execution continues normally. Otherwise, the shell - # will behave as interrupted except that the return status of the trap is retained. - # This means that for a CTRL+C, the trap needs to return the same exit status so that - # the shell actually exits what it's running. - trap " - ret=\$? - unset update_mode - unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh 2>/dev/null - command rm -rf '$ZSH/log/update.lock' - return \$ret - " EXIT INT QUIT - - # Create or update .zsh-update file if missing or malformed - if ! source "${ZSH_CACHE_DIR}/.zsh-update" 2>/dev/null || [[ -z "$LAST_EPOCH" ]]; then - update_last_updated_file - return - fi + # Remove lock directory on exit. `return $ret` is important for when trapping a SIGINT: + # The return status from the function is handled specially. If it is zero, the signal is + # assumed to have been handled, and execution continues normally. Otherwise, the shell + # will behave as interrupted except that the return status of the trap is retained. + # This means that for a CTRL+C, the trap needs to return the same exit status so that + # the shell actually exits what it's running. + trap " + ret=\$? + unset update_mode + unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh handle_update 2>/dev/null + command rm -rf '$ZSH/log/update.lock' + return \$ret + " EXIT INT QUIT - # Number of days before trying to update again - zstyle -s ':omz:update' frequency epoch_target || epoch_target=${UPDATE_ZSH_DAYS:-13} - # Test if enough time has passed until the next update - if (( ( $(current_epoch) - $LAST_EPOCH ) < $epoch_target )); then - return - fi + # Create or update .zsh-update file if missing or malformed + if ! source "${ZSH_CACHE_DIR}/.zsh-update" 2>/dev/null || [[ -z "$LAST_EPOCH" ]]; then + update_last_updated_file + return + fi - # Test if Oh My Zsh directory is a git repository - if ! (builtin cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then - echo >&2 "[oh-my-zsh] Can't update: not a git repository." - return - fi + # Number of days before trying to update again + zstyle -s ':omz:update' frequency epoch_target || epoch_target=${UPDATE_ZSH_DAYS:-13} + # Test if enough time has passed until the next update + if (( ( $(current_epoch) - $LAST_EPOCH ) < $epoch_target )); then + return + fi - # Check if there are updates available before proceeding - if ! is_update_available; then - update_last_updated_file - return - fi + # Test if Oh My Zsh directory is a git repository + if ! (builtin cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then + echo >&2 "[oh-my-zsh] Can't update: not a git repository." + return + fi - # If in reminder mode or user has typed input, show reminder and exit - if [[ "$update_mode" = reminder ]] || has_typed_input; then - printf '\r\e[0K' # move cursor to first column and clear whole line - echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`" - return 0 - fi + # Check if there are updates available before proceeding + if ! is_update_available; then + update_last_updated_file + return + fi - # Don't ask for confirmation before updating if in auto mode - if [[ "$update_mode" = auto ]]; then - update_ohmyzsh - return $? - fi + # If in reminder mode or user has typed input, show reminder and exit + if [[ "$update_mode" = reminder ]] || { [[ "$update_mode" != background-alpha ]] && has_typed_input }; then + printf '\r\e[0K' # move cursor to first column and clear whole line + echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`" + return 0 + fi - # Ask for confirmation and only update on 'y', 'Y' or Enter - # Otherwise just show a reminder for how to update - echo -n "[oh-my-zsh] Would you like to update? [Y/n] " - read -r -k 1 option - [[ "$option" = $'\n' ]] || echo - case "$option" in - [yY$'\n']) update_ohmyzsh ;; - [nN]) update_last_updated_file ;& - *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;; - esac + # Don't ask for confirmation before updating if in auto mode + if [[ "$update_mode" = (auto|background-alpha) ]]; then + update_ohmyzsh + return $? + fi + + # Ask for confirmation and only update on 'y', 'Y' or Enter + # Otherwise just show a reminder for how to update + echo -n "[oh-my-zsh] Would you like to update? [Y/n] " + read -r -k 1 option + [[ "$option" = $'\n' ]] || echo + case "$option" in + [yY$'\n']) update_ohmyzsh ;; + [nN]) update_last_updated_file ;& + *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;; + esac + } + + unset update_mode + unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh handle_update } -unset update_mode -unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh +case "$update_mode" in + background-alpha) + autoload -Uz add-zsh-hook + + _omz_bg_update() { + # do the update in a subshell + (handle_update) &| + + # register update results function + add-zsh-hook precmd _omz_bg_update_status + + # deregister background function + add-zsh-hook -d precmd _omz_bg_update + unset -f _omz_bg_update + } + + _omz_bg_update_status() { + { + local LAST_EPOCH EXIT_STATUS ERROR + if [[ ! -f "$ZSH_CACHE_DIR"/.zsh-update ]]; then + return 1 + fi + + # check update results until timeout is reached + . "$ZSH_CACHE_DIR/.zsh-update" + if [[ -z "$EXIT_STATUS" || -z "$ERROR" ]]; then + return 1 + fi + + if [[ "$EXIT_STATUS" -eq 0 ]]; then + print -P "\n%F{green}[oh-my-zsh] Update successful.%f" + return 0 + elif [[ "$EXIT_STATUS" -ne 0 ]]; then + print -P "\n%F{red}[oh-my-zsh] There was an error updating:%f" + printf "\n${fg[yellow]}%s${reset_color}" "$ERROR" + return 0 + fi + } always { + if (( TRY_BLOCK_ERROR == 0 )); then + # if last update results have been handled, remove them from the status file + update_last_updated_file + + # deregister background function + add-zsh-hook -d precmd _omz_bg_update_status + unset -f _omz_bg_update_status + fi + } + } + + add-zsh-hook precmd _omz_bg_update + ;; + *) + handle_update ;; +esac -- cgit v1.2.3-70-g09d2 From 24b2600558f999dd53f0d354ad61fc07cf7d6e2b Mon Sep 17 00:00:00 2001 From: tobi1805 <66414944+tobi1805@users.noreply.github.com> Date: Mon, 9 Oct 2023 18:07:51 +0200 Subject: feat(git): delete squash-merged branches in `gbda` (#11948) --- plugins/git/README.md | 2 +- plugins/git/git.plugin.zsh | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 9c16cb6e7..33c10ffd0 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -41,7 +41,6 @@ plugins=(... git) | `gba` | `git branch --all` | | `gbd` | `git branch --delete` | | `gbD` | `git branch --delete --force` | -| `gbda` | `git branch --no-color --merged \| command grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| command xargs git branch --delete 2>/dev/null` | | `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` | | `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` | | `gbm` | `git branch --move` | @@ -251,6 +250,7 @@ receive further support. | `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise. | | `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. | | `grename ` | Renames branch `` to ``, including on the origin remote. | +| `gbda` | Deletes all merged and squash-merged branches | ### Work in Progress (WIP) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index cb848b407..ceb2011f9 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -122,7 +122,22 @@ alias gb='git branch' alias gba='git branch --all' alias gbd='git branch --delete' alias gbD='git branch --delete --force' -alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null' + +# Copied and modified from James Roeder (jmaroeder) under MIT License +# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish +function gbda() { + git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null + + local default_branch=$(git_main_branch) + git for-each-ref refs/heads/ "--format=%(refname:short)" | \ + while read branch; do + local merge_base=$(git merge-base $default_branch $branch) + if [[ '-*' == $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) ]]; then + git branch -D $branch + fi + done +} + alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' alias gbm='git branch --move' -- cgit v1.2.3-70-g09d2 From 38db3e16ef3266800e1a9516c0615ff04ec97cb6 Mon Sep 17 00:00:00 2001 From: Adam Henley <71472057+ajh-sr@users.noreply.github.com> Date: Tue, 10 Oct 2023 07:28:09 +1300 Subject: feat(kind): add plugin for Kind k8s tool (#9827) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: jxlwqq Co-authored-by: Francesco Ilario Co-authored-by: Marc Cornellà --- plugins/kind/README.md | 22 ++++++++++++++++++++++ plugins/kind/kind.plugin.zsh | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 plugins/kind/README.md create mode 100644 plugins/kind/kind.plugin.zsh diff --git a/plugins/kind/README.md b/plugins/kind/README.md new file mode 100644 index 000000000..49024648d --- /dev/null +++ b/plugins/kind/README.md @@ -0,0 +1,22 @@ +# Kind plugin + +This plugin adds completion for the [Kind](https://kind.sigs.k8s.io/) tool, as well +as a few aliases for easier use. + +To use it, add `kind` to the plugins array in your zshrc file: + +```zsh +plugins=(... kind) +``` + +## Aliases + +| Alias | Command | +| ------- | ---------------------------- | +| `kicc` | `kind create cluster` | +| `kiccn` | `kind create cluster --name` | +| `kigc` | `kind get clusters` | +| `kidc` | `kind delete cluster` | +| `kidcn` | `kind delete cluster --name` | +| `kidca` | `kind delete clusters -A` | +| `kigk` | `kind get kubeconfig` | diff --git a/plugins/kind/kind.plugin.zsh b/plugins/kind/kind.plugin.zsh new file mode 100644 index 000000000..183eb7bd6 --- /dev/null +++ b/plugins/kind/kind.plugin.zsh @@ -0,0 +1,23 @@ +if (( ! $+commands[kind] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `kind`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_kind" ]]; then + typeset -g -A _comps + autoload -Uz _kind + _comps[kind]=_kind +fi + +# Generate and load kind completion +kind completion zsh >! "$ZSH_CACHE_DIR/completions/_kind" &| + +# Register aliases +alias kicc="kind create cluster" +alias kiccn="kind create cluster --name" +alias kigc="kind get clusters" +alias kidc="kind delete cluster" +alias kidcn="kind delete cluster --name" +alias kidca="kind delete clusters -A" +alias kigk="kind get kubeconfig" -- cgit v1.2.3-70-g09d2 From b1821a24f0574488554de8e7f6d0735fb851de8b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 10 Oct 2023 16:56:54 +0100 Subject: fix(git): restore showing patch in `gsts` (#11951) --- plugins/git/README.md | 2 +- plugins/git/git.plugin.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 33c10ffd0..a4e9f4c4a 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -185,7 +185,7 @@ plugins=(... git) | `gstp` | `git stash pop` | | `gsta` | On Git >= 2.13: `git stash push` | | `gsta` | On Git < 2.13: `git stash save` | -| `gsts` | `git stash show` | +| `gsts` | `git stash show --patch` | | `gst` | `git status` | | `gss` | `git status --short` | | `gsb` | `git status --short -b` | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index ceb2011f9..b0376308f 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -349,7 +349,7 @@ alias gstp='git stash pop' is-at-least 2.13 "$git_version" \ && alias gsta='git stash push' \ || alias gsta='git stash save' -alias gsts='git stash show' +alias gsts='git stash show --patch' alias gst='git status' alias gss='git status --short' alias gsb='git status --short --branch' -- cgit v1.2.3-70-g09d2 From da3b8fcb6a6bcf4d440b9768d2deab27f787929a Mon Sep 17 00:00:00 2001 From: Lukas Elmer Date: Wed, 11 Oct 2023 18:06:22 +0200 Subject: fix(yarn): output completion entries in UTF-8 (#11955) --- plugins/yarn/_yarn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn index 1237ba672..f15756ff4 100644 --- a/plugins/yarn/_yarn +++ b/plugins/yarn/_yarn @@ -144,7 +144,7 @@ _yarn_scripts() { fi if [[ -n $packageJson ]]; then - scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}") + scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E 'binmode(STDOUT, ":encoding(UTF-8)"); %r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}") fi commands=('env' $scripts $binaries) -- cgit v1.2.3-70-g09d2 From fedef5dbd5f8ffef16815cb3a2c611eb0f7f00b1 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 11 Oct 2023 19:23:44 +0200 Subject: fix(xcode): open Xcode in current Desk if already open in another (#10384) Fixes #10384 --- plugins/xcode/xcode.plugin.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/xcode/xcode.plugin.zsh b/plugins/xcode/xcode.plugin.zsh index 5d1f901a3..f09434e69 100644 --- a/plugins/xcode/xcode.plugin.zsh +++ b/plugins/xcode/xcode.plugin.zsh @@ -17,6 +17,13 @@ function xc { local active_path active_path=${"$(xcode-select -p)"%%/Contents/Developer*} echo "Found ${xcode_files[1]}. Opening with ${active_path}" + + # If Xcode is already opened in another Desk, we need this double call + # with -g to open the project window in the current Desk and focus it. + # See https://github.com/ohmyzsh/ohmyzsh/issues/10384 + if command pgrep -q "^Xcode"; then + open -g -a "$active_path" "${xcode_files[1]}" + fi open -a "$active_path" "${xcode_files[1]}" } -- cgit v1.2.3-70-g09d2 From 53cb50acb5c2c70f6ba9d26d3d2ffb37c8a19e8f Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 11 Oct 2023 20:43:55 +0200 Subject: refactor(systemadmin): use `ss` instead of `netstat` when available (#11957) --- plugins/systemadmin/systemadmin.plugin.zsh | 116 +++++++++++++++++------------ 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh index 7ce62bac1..03dd995b6 100644 --- a/plugins/systemadmin/systemadmin.plugin.zsh +++ b/plugins/systemadmin/systemadmin.plugin.zsh @@ -13,11 +13,11 @@ # ------------------------------------------------------------------------------ function retlog() { - if [[ -z $1 ]];then - echo '/var/log/nginx/access.log' - else - echo $1 - fi + if [[ -z $1 ]];then + echo '/var/log/nginx/access.log' + else + echo $1 + fi } alias ping='ping -c 5' @@ -28,142 +28,160 @@ alias mkdir='mkdir -pv' alias psmem='ps -e -orss=,args= | sort -b -k1 -nr' alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -n 10' # get top process eating cpu if not work try execute : export LC_ALL='C' -alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr' -alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr | head -n 10' +alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr' +alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr | head -n 10' # top10 of the history alias hist10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10' function ip() { - if [ -t 1 ]; then - command ip -color "$@" - else - command ip "$@" - fi + if [ -t 1 ]; then + command ip -color "$@" + else + command ip "$@" + fi } # directory LS function dls() { - print -l *(/) + print -l *(/) } function psgrep() { - ps aux | grep "${1:-.}" | grep -v grep + ps aux | grep "${1:-.}" | grep -v grep } # Kills any process that matches a regexp passed to it function killit() { - ps aux | grep -v "grep" | grep "$@" | awk '{print $2}' | xargs sudo kill + ps aux | grep -v "grep" | grep "$@" | awk '{print $2}' | xargs sudo kill } # list contents of directories in a tree-like format if ! (( $+commands[tree] )); then - function tree() { - find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' - } + function tree() { + find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' + } fi # Sort connection state function sortcons() { - netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn + { + LANG= ss -nat | awk 'NR > 1 {print $1}' \ + || LANG= netstat -nat | awk 'NR > 2 {print $6}' + } | sort | uniq -c | sort -rn } # View all 80 Port Connections function con80() { - netstat -nat|grep -i ":80"|wc -l + { + LANG= ss -nat || LANG= netstat -nat + } | grep -E ":80[^0-9]" | wc -l } # On the connected IP sorted by the number of connections function sortconip() { - netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n + { + LANG= ss -ntu | awk 'NR > 1 {print $6}' \ + || LANG= netstat -ntu | awk 'NR > 2 {print $5}' + } | cut -d: -f1 | sort | uniq -c | sort -n } # top20 of Find the number of requests on 80 port function req20() { - netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20 + { + LANG= ss -tn | awk '$4 ~ /:80$/ {print $5}' \ + || LANG= netstat -tn | awk '$4 ~ /:80$/ {print $5}' + } | awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n 20 } # top20 of Using tcpdump port 80 access to view function http20() { - sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -n 20 + sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | head -n 20 } # top20 of Find time_wait connection function timewait20() { - netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20 + { + LANG= ss -nat | awk 'NR > 1 && /TIME-WAIT/ {print $5}' \ + || LANG= netstat -nat | awk 'NR > 2 && /TIME_WAIT/ {print $5}' + } | sort | uniq -c | sort -rn | head -n 20 } # top20 of Find SYN connection function syn20() { - netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr|head -n20 + { + LANG= ss -an | awk '/SYN/ {print $5}' \ + || LANG= netstat -an | awk '/SYN/ {print $5}' + } | awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n20 } # Printing process according to the port number function port_pro() { - netstat -ntlp | grep "${1:-.}" | awk '{print $7}' | cut -d/ -f1 + LANG= ss -ntlp | awk "NR > 1 && /:${1:-}/ {print \$6}" | sed 's/.*pid=\([^,]*\).*/\1/' \ + || LANG= netstat -ntlp | awk "NR > 2 && /:${1:-}/ {print \$7}" | cut -d/ -f1 } # top10 of gain access to the ip address function accessip10() { - awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}' "$(retlog)" + awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}' "$(retlog)" } # top20 of Most Visited file or page function visitpage20() { - awk '{print $11}' "$(retlog)"|sort|uniq -c|sort -nr|head -n 20 + awk '{print $11}' "$(retlog)" | sort | uniq -c | sort -nr | head -n 20 } # top100 of Page lists the most time-consuming (more than 60 seconds) as well as the corresponding page number of occurrences function consume100() { - awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100 - # if django website or other website make by no suffix language - # awk '{print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100 + awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" | sort -n | uniq -c | sort -nr | head -n 100 + # if django website or other website make by no suffix language + # awk '{print $7}' "$(retlog)" | sort -n | uniq -c | sort -nr | head -n 100 } # Website traffic statistics (G) function webtraffic() { - awk "{sum+=$10} END {print sum/1024/1024/1024}" "$(retlog)" + awk "{sum+=$10} END {print sum/1024/1024/1024}" "$(retlog)" } # Statistical connections 404 function c404() { - awk '($9 ~/404/)' "$(retlog)" | awk '{print $9,$7}' | sort + awk '($9 ~ /404/)' "$(retlog)" | awk '{print $9,$7}' | sort } # Statistical http status. function httpstatus() { - awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}' "$(retlog)" + awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}' "$(retlog)" } # Delete 0 byte file function d0() { - find "${1:-.}" -type f -size 0 -exec rm -rf {} \; + find "${1:-.}" -type f -size 0 -exec rm -rf {} \; } # gather external ip address function geteip() { - curl -s -S -4 https://icanhazip.com + curl -s -S -4 https://icanhazip.com - # handle case when there is no IPv6 external IP, which shows error - # curl: (7) Couldn't connect to server - curl -s -S -6 https://icanhazip.com 2>/dev/null - local ret=$? - (( ret == 7 )) && print -P -u2 "%F{red}error: no IPv6 route to host%f" - return $ret + # handle case when there is no IPv6 external IP, which shows error + # curl: (7) Couldn't connect to server + curl -s -S -6 https://icanhazip.com 2>/dev/null + local ret=$? + (( ret == 7 )) && print -P -u2 "%F{red}error: no IPv6 route to host%f" + return $ret } # determine local IP address(es) function getip() { - if (( ${+commands[ip]} )); then - ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1 - else - ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1 - fi + if (( ${+commands[ip]} )); then + ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1 + else + ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1 + fi } # Clear zombie processes function clrz() { - ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9 + ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9 } # Second concurrent function conssec() { - awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)"|sort -k 2 -nr|head -n10 + awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)" | sort -k 2 -nr | head -n10 } -- cgit v1.2.3-70-g09d2 From 408330e131110c8b86ce60ab0492b35657cb4d57 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 11 Oct 2023 20:44:46 +0200 Subject: ci: remove redundant macos runner for CI tests Currently the macOS runner is not needed, as we are only checking zsh syntax. We can reactivate it in the future if needed. --- .github/workflows/main.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57403629c..de7d98262 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,16 +20,12 @@ permissions: jobs: tests: name: Run tests - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest if: github.repository == 'ohmyzsh/ohmyzsh' - strategy: - matrix: - os: [ubuntu-latest, macos-latest] steps: - name: Set up git repository uses: actions/checkout@v3 - name: Install zsh - if: runner.os == 'Linux' run: sudo apt-get update; sudo apt-get install zsh - name: Check syntax run: | -- cgit v1.2.3-70-g09d2 From 6768906d07151140db901510b2c8b1ce2622f365 Mon Sep 17 00:00:00 2001 From: sattisumasri <73093486+sattisumasri@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:27:01 +0530 Subject: chore: change headings in README to Title Case (#11956) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- README.md | 69 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index c83e16218..308d117e1 100644 --- a/README.md +++ b/README.md @@ -23,32 +23,33 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi Table of Contents - [Getting Started](#getting-started) + - [Operating System Compatibility](#operating-system-compatibility) - [Prerequisites](#prerequisites) - [Basic Installation](#basic-installation) - - [Manual inspection](#manual-inspection) + - [Manual Inspection](#manual-inspection) - [Using Oh My Zsh](#using-oh-my-zsh) - [Plugins](#plugins) - [Enabling Plugins](#enabling-plugins) - [Using Plugins](#using-plugins) - [Themes](#themes) - - [Selecting a Theme](#selecting-a-theme) + - [Selecting A Theme](#selecting-a-theme) - [FAQ](#faq) - [Advanced Topics](#advanced-topics) - [Advanced Installation](#advanced-installation) - [Custom Directory](#custom-directory) - - [Unattended install](#unattended-install) - - [Installing from a forked repository](#installing-from-a-forked-repository) + - [Unattended Install](#unattended-install) + - [Installing From A Forked Repository](#installing-from-a-forked-repository) - [Manual Installation](#manual-installation) - [Installation Problems](#installation-problems) - - [Custom Plugins and Themes](#custom-plugins-and-themes) - - [Enable GNU ls in macOS and freeBSD systems](#enable-gnu-ls) - - [Skip aliases](#skip-aliases) + - [Custom Plugins And Themes](#custom-plugins-and-themes) + - [Enable GNU ls In macOS And freeBSD Systems](#enable-gnu-ls-in-macos-and-freebsd-systems) + - [Skip Aliases](#skip-aliases) - [Getting Updates](#getting-updates) - - [Updates verbosity](#updates-verbosity) + - [Updates Verbosity](#updates-verbosity) - [Manual Updates](#manual-updates) - [Uninstalling Oh My Zsh](#uninstalling-oh-my-zsh) -- [How do I contribute to Oh My Zsh?](#how-do-i-contribute-to-oh-my-zsh) - - [Do NOT send us themes](#do-not-send-us-themes) +- [How Do I Contribute To Oh My Zsh?](#how-do-i-contribute-to-oh-my-zsh) + - [Do Not Send Us Themes](#do-not-send-us-themes) - [Contributors](#contributors) - [Follow Us](#follow-us) - [Merchandise](#merchandise) @@ -61,15 +62,15 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi ### Operating System Compatibility -| O/S | Status | -| :---------------- | :------: | -| Android | ✅ | -| FreeBSD | ✅ | -| LCARS | 🛸 | -| Linux | ✅ | -| MacOS | ✅ | -| OS/2 Warp | ❌ | -| Windows (WSL2) | ✅ | +| O/S | Status | +| :------------- | :-----: | +| Android | ✅ | +| freeBSD | ✅ | +| LCARS | 🛸 | +| Linux | ✅ | +| macOS | ✅ | +| OS/2 Warp | ❌ | +| Windows (WSL2) | ✅ | ### Prerequisites @@ -90,7 +91,7 @@ Oh My Zsh is installed by running one of the following commands in your terminal _Note that any previous `.zshrc` will be renamed to `.zshrc.pre-oh-my-zsh`. After installation, you can move the configuration you want to preserve into the new `.zshrc`._ -#### Manual inspection +#### Manual Inspection It's a good idea to inspect the install script from projects you don't yet know. You can do that by downloading the install script first, looking through it so everything looks normal, @@ -139,7 +140,7 @@ Each built-in plugin includes a **README**, documenting it. This README should s We'll admit it. Early in the Oh My Zsh world, we may have gotten a bit too theme happy. We have over one hundred and fifty themes now bundled. Most of them have [screenshots](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes) on the wiki (We are working on updating this!). Check them out! -#### Selecting a Theme +#### Selecting A Theme _Robby's theme is the default one. It's not the fanciest one. It's not the simplest one. It's just the right one (for him)._ @@ -210,7 +211,7 @@ like this: ZSH="$HOME/.dotfiles/oh-my-zsh" sh install.sh ``` -#### Unattended install +#### Unattended Install If you're running the Oh My Zsh install script as part of an automated install, you can pass the `--unattended` flag to the `install.sh` script. This will have the effect of not trying to change @@ -220,7 +221,7 @@ the default shell, and it also won't run `zsh` when the installation has finishe sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended ``` -#### Installing from a forked repository +#### Installing From A Forked Repository The install script also accepts these variables to allow installation of a different repository: @@ -245,19 +246,19 @@ REPO=apjanke/oh-my-zsh BRANCH=edge sh install.sh #### Manual Installation -##### 1. Clone the repository +##### 1. Clone The Repository ```sh git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh ``` -##### 2. _Optionally_, backup your existing `~/.zshrc` file +##### 2. _Optionally_, Backup Your Existing `~/.zshrc` File ```sh cp ~/.zshrc ~/.zshrc.orig ``` -##### 3. Create a new zsh configuration file +##### 3. Create A New Zsh Configuration File You can create a new zsh config file by copying the template that we have included for you. @@ -265,7 +266,7 @@ You can create a new zsh config file by copying the template that we have includ cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc ``` -##### 4. Change your default shell +##### 4. Change Your Default Shell ```sh chsh -s $(which zsh) @@ -273,7 +274,7 @@ chsh -s $(which zsh) You must log out from your user session and log back in to see this change. -##### 5. Initialize your new zsh configuration +##### 5. Initialize Your New Zsh Configuration Once you open up a new terminal window, it should load zsh with Oh My Zsh's configuration. @@ -284,7 +285,7 @@ If you have any hiccups installing, here are a few common fixes. - You _might_ need to modify your `PATH` in `~/.zshrc` if you're not able to find some commands after switching to `oh-my-zsh`. - If you installed manually or changed the install location, check the `ZSH` environment variable in `~/.zshrc`. -### Custom Plugins and Themes +### Custom Plugins And Themes If you want to override any of the default behaviors, just add a new file (ending in `.zsh`) in the `custom/` directory. @@ -292,7 +293,7 @@ If you have many functions that go well together, you can put them as a `XYZ.plu If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`. -### Enable GNU ls in macOS and freeBSD systems +### Enable GNU ls In macOS And freeBSD Systems @@ -306,7 +307,7 @@ zstyle ':omz:lib:theme-and-appearance' gnu-ls yes _Note: this is not compatible with `DISABLE_LS_COLORS=true`_ -### Skip aliases +### Skip Aliases @@ -389,7 +390,7 @@ zstyle ':omz:update' frequency 7 zstyle ':omz:update' frequency 0 ``` -### Updates verbosity +### Updates Verbosity You can also limit the update verbosity with the following settings: @@ -417,7 +418,7 @@ Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy b If you want to uninstall `oh-my-zsh`, just run `uninstall_oh_my_zsh` from the command-line. It will remove itself and revert your previous `bash` or `zsh` configuration. -## How do I contribute to Oh My Zsh? +## How Do I Contribute To Oh My Zsh? Before you participate in our delightful community, please read the [code of conduct](CODE_OF_CONDUCT.md). @@ -427,7 +428,7 @@ We also need people to test out pull requests. So take a look through [the open See [Contributing](CONTRIBUTING.md) for more details. -### Do NOT send us themes +### Do Not Send Us Themes We have (more than) enough themes for the time being. Please add your theme to the [external themes](https://github.com/ohmyzsh/ohmyzsh/wiki/External-themes) wiki page. -- cgit v1.2.3-70-g09d2 From 5743198e0ed5de137b4aa1b948cf4c82b02bdd8e Mon Sep 17 00:00:00 2001 From: Preston Button Date: Thu, 12 Oct 2023 04:32:48 -0400 Subject: docs(aliases): fix typo (#11958) --- plugins/aliases/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aliases/README.md b/plugins/aliases/README.md index 53b68ea01..14f9c5c53 100644 --- a/plugins/aliases/README.md +++ b/plugins/aliases/README.md @@ -17,7 +17,7 @@ Requirements: Python needs to be installed. - `als`: show all aliases by group -- `als -h/--help`: print help mesage +- `als -h/--help`: print help message - `als `: filter and highlight aliases by `` -- cgit v1.2.3-70-g09d2 From 7329b2fbb1787651d4900d5ef280b926c5696c01 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 12 Oct 2023 11:46:49 +0200 Subject: docs(debian): clarify override behavior for `apt_pref` and `apt_upgr` Fixes #11959 --- plugins/debian/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/debian/README.md b/plugins/debian/README.md index 1db534f13..6835ad65c 100644 --- a/plugins/debian/README.md +++ b/plugins/debian/README.md @@ -13,7 +13,12 @@ plugins=(... debian) - `$apt_pref`: use aptitude or apt if installed, fallback is apt-get. - `$apt_upgr`: use upgrade or safe-upgrade (for aptitude). -Set `$apt_pref` and `$apt_upgr` to whatever command you want (before sourcing Oh My Zsh) to override this behavior. +Set **both** `$apt_pref` and `$apt_upgr` to whatever command you want (before sourcing Oh My Zsh) to override this behavior, e.g.: + +```sh +apt_pref='apt' +apt_upgr='full-upgrade' +``` ## Common Aliases -- cgit v1.2.3-70-g09d2 From 772b41ea5a362206e1498453dd053e638752c5dc Mon Sep 17 00:00:00 2001 From: Sandesh Pyakurel <82999440+Sandesh-Pyakurel@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:09:40 +0545 Subject: chore(zsh-navigation-tools): fix typo (#11960) --- plugins/zsh-navigation-tools/n-list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/zsh-navigation-tools/n-list b/plugins/zsh-navigation-tools/n-list index f25db8f60..a852b083a 100644 --- a/plugins/zsh-navigation-tools/n-list +++ b/plugins/zsh-navigation-tools/n-list @@ -467,7 +467,7 @@ while (( 1 )); do elif [ -n "$keypad" ]; then final_key="$keypad" else - _nlist_status_msg "Inproper input detected" + _nlist_status_msg "Improper input detected" zcurses refresh main inner fi -- cgit v1.2.3-70-g09d2 From 3efdbf9e1e6663adf9d8a2d113ec62855c621ef7 Mon Sep 17 00:00:00 2001 From: Sandesh Pyakurel <82999440+Sandesh-Pyakurel@users.noreply.github.com> Date: Fri, 13 Oct 2023 13:38:48 +0545 Subject: chore(hitchhiker): fix typos (#11961) --- plugins/hitchhiker/fortunes/hitchhiker | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/hitchhiker/fortunes/hitchhiker b/plugins/hitchhiker/fortunes/hitchhiker index b0448b21e..94cc1c835 100644 --- a/plugins/hitchhiker/fortunes/hitchhiker +++ b/plugins/hitchhiker/fortunes/hitchhiker @@ -80,7 +80,7 @@ % "The fronting for the eighty-yard-long marble-topped bar had been made by stitching together nearly twenty thousand Antarean Mosaic Lizard skins, despite the fact that the twenty thousand lizards concerned had needed them to keep their insides in." -- The Book decribing Milliways' politically incorrect decor. +- The Book describing Milliways' politically incorrect decor. % "`...and the Universe,' continued the waiter, determined not to be deflected on his home stretch, `will explode later for your pleasure.' Ford's head swivelled slowly towards him. He spoke with feeling. `Wow,' he said, `What sort of drinks do you serve in this place?' The waiter laughed a polite little waiter's laugh. `Ah,' he said, `I think sir has perhaps misunderstood me.' `Oh, I hope not,' breathed Ford." @@ -104,7 +104,7 @@ % "`The first ten million years were the worst,' said Marvin, `and the second ten million, they were the worst too. The third ten million I didn't enjoy at all. After that I went into a bit of a decline.'" -- Marvin reflecting back on his 576,000,003,579 year career as Milliways' car park attendent. +- Marvin reflecting back on his 576,000,003,579 year career as Milliways' car park attendant. % "`Incidentally,' he said, `what does teleport mean?' Another moment passed. Slowly, the others turned to face him. `Probably the wrong moment to ask,' said Arthur, `It's just I remember you use the word a short while ago and I only bring it up because...' `Where,' said Ford quietly, `does it say teleport?' `Well, just over here in fact,' said Arthur, pointing at a dark control box in the rear of the cabin, `Just under the word "emergency", above the word "system" and beside the sign saying "out of order".'" @@ -122,7 +122,7 @@ - Ford "debating" what to do with fire with a marketing girl. % -"The story goes that I first had the idea for THHGTTG while lying drunk in a field in Innsbruck (or `Spain' as the BBC TV publicity department authoritatively has it, probably because it's easier to spell)." - Foreward by DNA. +"The story goes that I first had the idea for THHGTTG while lying drunk in a field in Innsbruck (or `Spain' as the BBC TV publicity department authoritatively has it, probably because it's easier to spell)." - Foreword by DNA. FORD Six pints of bitter. And quickly please, the world's about to end. BARMAN Oh yes, sir? Nice weather for it. % @@ -162,7 +162,7 @@ ARTHUR It probably seems a terrible thing to say, but you know what I sometimes - Arthur discovering a way of coping with life on Prehistoric Earth. % -"`... then I decided that I was a lemon for a couple of weeks. I kept myself amused all that time jumping in and out of a gin and tonic.' Arthur cleared his throat, and then did it again. `Where,' he said, `did you...?' `Find a gin and tonic?' said Ford brightly. `I found a small lake that thought it was a gin and tonic, and jumped in and out of that. At least, I think it thought it was a gin and tonic.' `I may,' he addded with a grin which would have sent sane men scampering into the trees, `have been imagining it.'" +"`... then I decided that I was a lemon for a couple of weeks. I kept myself amused all that time jumping in and out of a gin and tonic.' Arthur cleared his throat, and then did it again. `Where,' he said, `did you...?' `Find a gin and tonic?' said Ford brightly. `I found a small lake that thought it was a gin and tonic, and jumped in and out of that. At least, I think it thought it was a gin and tonic.' `I may,' he added with a grin which would have sent sane men scampering into the trees, `have been imagining it.'" - Ford updating Arthur about what he's been doing for the past four years. % -- cgit v1.2.3-70-g09d2 From 8d9c9b6174466cc432a9946b0459c214586cb1b2 Mon Sep 17 00:00:00 2001 From: Sandesh Pyakurel <82999440+Sandesh-Pyakurel@users.noreply.github.com> Date: Fri, 13 Oct 2023 20:45:28 +0545 Subject: chore(postgres): fix typo (#11967) --- plugins/postgres/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/postgres/README.md b/plugins/postgres/README.md index 59445f31c..3f59a8fe4 100644 --- a/plugins/postgres/README.md +++ b/plugins/postgres/README.md @@ -19,4 +19,4 @@ plugins=(... postgres) | stoppost | `pg_ctl -D /usr/local/var/postgres stop -s -m fast` | Stop postgres server | | restartpost | `stoppost && sleep 1 && startpost` | Restart (calls stop, then start) | | reloadpost | `pg_ctl reload -D /usr/local/var/postgres -s` | Reload postgres configuration (some setting require restart)| -| statuspost | `pg_ctl status -D /usr/local/var/postgres -s` | Check startus of postgres server (running, stopped) | +| statuspost | `pg_ctl status -D /usr/local/var/postgres -s` | Check status of postgres server (running, stopped) | -- cgit v1.2.3-70-g09d2 From 48a62a9f713449a014d66b01afd99a4fcf1911fe Mon Sep 17 00:00:00 2001 From: Kapil Pau Date: Fri, 13 Oct 2023 23:11:47 +0100 Subject: feat(span): Introducing Snapcraft CLI plugin (#9357) --- plugins/snap/README.md | 18 ++++++++++++++++++ plugins/snap/snap.plugin.zsh | 10 ++++++++++ 2 files changed, 28 insertions(+) create mode 100644 plugins/snap/README.md create mode 100644 plugins/snap/snap.plugin.zsh diff --git a/plugins/snap/README.md b/plugins/snap/README.md new file mode 100644 index 000000000..75c5ec19a --- /dev/null +++ b/plugins/snap/README.md @@ -0,0 +1,18 @@ +# snap plugin + +This plugin sets up aliases for the common [snap](https://snapcraft.io/docs/getting-started) commands + +## Aliases + +| Alias | Full command | +| --- | ---| +| sv | snap version | +| sf | snap find | +| si | snap install | +| sin | snap info | +| sr | snap remove | +| sref | snap refresh | +| srev | snap revert | +| sl | snap list | +| sd | snap disable | +| se | snap enable | diff --git a/plugins/snap/snap.plugin.zsh b/plugins/snap/snap.plugin.zsh new file mode 100644 index 000000000..af2346978 --- /dev/null +++ b/plugins/snap/snap.plugin.zsh @@ -0,0 +1,10 @@ +alias sv="snap version" +alias sf="snap find" +alias si="snap install" +alias sin="snap info" +alias sr="snap remove" +alias sref="snap refresh" +alias srev="snap revert" +alias sl="snap list" +alias sd="snap disable" +alias se="snap enable" -- cgit v1.2.3-70-g09d2 From 2db53ff1da078b2207cb98736370f1f145e5c667 Mon Sep 17 00:00:00 2001 From: Steve Lessard Jr Date: Fri, 13 Oct 2023 18:26:16 -0400 Subject: fix(avit): RPROMPT Fix for #10307 (#11131) Co-authored-by: Steve Lessard --- themes/avit.zsh-theme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme index 1279ea919..206274462 100644 --- a/themes/avit.zsh-theme +++ b/themes/avit.zsh-theme @@ -11,7 +11,12 @@ $(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info) PROMPT2='%{%(!.${fg[red]}.${fg[white]})%}◀%{$reset_color%} ' -RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' +__RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' +if [[ -z $RPROMPT ]]; then + RPROMPT=$__RPROMPT +else + RPROMPT="${RPROMPT} ${__RPROMPT}" +fi function _user_host() { local me -- cgit v1.2.3-70-g09d2 From f7130bb529a2d15652f739c552688b34aac63315 Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Fri, 13 Oct 2023 15:38:13 -0700 Subject: fix(gnzh): Don't show .local for local hostnames in theme Fixes #10871 --- themes/gnzh.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/gnzh.zsh-theme b/themes/gnzh.zsh-theme index 1e6c4e93b..ca62320e2 100644 --- a/themes/gnzh.zsh-theme +++ b/themes/gnzh.zsh-theme @@ -21,7 +21,7 @@ fi if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then PR_HOST='%F{red}%M%f' # SSH else - PR_HOST='%F{green}%M%f' # no SSH + PR_HOST='%F{green}%m%f' # no SSH fi -- cgit v1.2.3-70-g09d2 From f93976875133409297be864ce94d50f20a9bc18d Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 14 Oct 2023 16:40:45 +0200 Subject: fix(git): fix fallback to develop branch if `master` not found (#11966) --- plugins/git/git.plugin.zsh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index b0376308f..d053a7638 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -20,26 +20,31 @@ function current_branch() { function git_develop_branch() { command git rev-parse --git-dir &>/dev/null || return local branch - for branch in dev devel development; do + for branch in dev devel develop development; do if command git show-ref -q --verify refs/heads/$branch; then echo $branch - return + return 0 fi done + echo develop + return 1 } # Check if main exists and use instead of master function git_main_branch() { command git rev-parse --git-dir &>/dev/null || return local ref - for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default}; do + for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}; do if command git show-ref -q --verify $ref; then echo ${ref:t} - return + return 0 fi done + + # If no main branch was found, fall back to master but return error echo master + return 1 } function grename() { @@ -129,6 +134,8 @@ function gbda() { git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null local default_branch=$(git_main_branch) + (( ! $? )) || default_branch=$(git_develop_branch) + git for-each-ref refs/heads/ "--format=%(refname:short)" | \ while read branch; do local merge_base=$(git merge-base $default_branch $branch) -- cgit v1.2.3-70-g09d2 From 96c976637a4112e1e72a1a449ac51d78acc67597 Mon Sep 17 00:00:00 2001 From: nishanthps-cai <123212871+nishanthps-cai@users.noreply.github.com> Date: Tue, 17 Oct 2023 00:55:05 -0700 Subject: feat(bazel): use completion also for bazelisk (#11984) --- plugins/bazel/_bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bazel/_bazel b/plugins/bazel/_bazel index c34c572b0..ea1f4cace 100644 --- a/plugins/bazel/_bazel +++ b/plugins/bazel/_bazel @@ -1,4 +1,4 @@ -#compdef bazel +#compdef bazel bazelisk # Copyright 2015 The Bazel Authors. All rights reserved. # -- cgit v1.2.3-70-g09d2 From d3112d67a3eb55fc39975f917467704ebb2c296b Mon Sep 17 00:00:00 2001 From: Vyacheslav Scherbinin Date: Wed, 18 Oct 2023 14:18:05 +0700 Subject: feat(vscode): allow arguments to `vsc` alias (#11903) Co-authored-by: Carlo Sala --- plugins/vscode/README.md | 3 ++- plugins/vscode/vscode.plugin.zsh | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/vscode/README.md b/plugins/vscode/README.md index e95ed5d4f..726b23d35 100644 --- a/plugins/vscode/README.md +++ b/plugins/vscode/README.md @@ -31,7 +31,7 @@ the Command Palette via (F1 or ⇧⌘P) and type shell command to find the Shell ## Using multiple flavours -If for any reason, you ever require to use multiple flavours of VS Code i.e. VS Code (stable) and VS Code Insiders, you can +If for any reason, you ever require to use multiple flavours of VS Code i.e. VS Code (stable) and VS Code Insiders, you can manually specify the flavour's executable. Add the following line to the .zshrc file (between the `ZSH_THEME` and the `plugins=()` lines). This will make the plugin use your manually defined executable. @@ -53,6 +53,7 @@ source $ZSH/oh-my-zsh.sh | Alias | Command | Description | | ----------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------- | | vsc | code . | Open the current folder in VS code | +| vsc `dir` | code `dir` | Open passed folder in VS code | | vsca `dir` | code --add `dir` | Add folder(s) to the last active window | | vscd `file` `file` | code --diff `file` `file` | Compare two files with each other. | | vscg `file:line[:char]` | code --goto `file:line[:char]` | Open a file at the path on the specified line and character position. | diff --git a/plugins/vscode/vscode.plugin.zsh b/plugins/vscode/vscode.plugin.zsh index 48d904377..356c62360 100644 --- a/plugins/vscode/vscode.plugin.zsh +++ b/plugins/vscode/vscode.plugin.zsh @@ -23,7 +23,14 @@ if [[ -z "$VSCODE" ]]; then fi fi -alias vsc="$VSCODE ." +function vsc { + if (( $# )); then + $VSCODE $@ + else + $VSCODE . + fi +} + alias vsca="$VSCODE --add" alias vscd="$VSCODE --diff" alias vscg="$VSCODE --goto" -- cgit v1.2.3-70-g09d2 From f10cd5281d805bb5679dd46b304d9b8997f98981 Mon Sep 17 00:00:00 2001 From: Patryk Krawaczyński Date: Wed, 18 Oct 2023 13:59:28 +0200 Subject: feat(history): add `hl` alias (#11990) --- plugins/history/README.md | 1 + plugins/history/history.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/history/README.md b/plugins/history/README.md index a9d480f46..73d6a5052 100644 --- a/plugins/history/README.md +++ b/plugins/history/README.md @@ -13,5 +13,6 @@ plugins=(... history) | Alias | Command | Description | |-------|----------------------|------------------------------------------------------------------| | `h` | `history` | Prints your command history | +| `hl` | `history \| less` | Pipe history output to less to search and navigate it easily | | `hs` | `history \| grep` | Use grep to search your command history | | `hsi` | `history \| grep -i` | Use grep to do a case-insensitive search of your command history | diff --git a/plugins/history/history.plugin.zsh b/plugins/history/history.plugin.zsh index 9cee48fe4..fb3e31389 100644 --- a/plugins/history/history.plugin.zsh +++ b/plugins/history/history.plugin.zsh @@ -1,3 +1,4 @@ alias h='history' +alias hl='history | less' alias hs='history | grep' alias hsi='history | grep -i' -- cgit v1.2.3-70-g09d2 From b696288337618ca749369a679bd77989bd4cd47e Mon Sep 17 00:00:00 2001 From: Jérémy Date: Wed, 18 Oct 2023 19:27:47 +0200 Subject: feat(kubectl): add `kgdsa` alias (#11863) --- 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 315d3ce93..0dd4e691a 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -162,6 +162,7 @@ alias kdelsa="kubectl delete sa" # DaemonSet management. alias kgds='kubectl get daemonset' +alias kgdsa='kubectl get daemonset --all-namespaces' alias kgdsw='kgds --watch' alias keds='kubectl edit daemonset' alias kdds='kubectl describe daemonset' -- cgit v1.2.3-70-g09d2 From 8152dc673b14c89dc12e816583e24532ed77e8ae Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 18 Oct 2023 20:01:58 +0200 Subject: fix(git): move squash-merged branch deletion from `gbda` to `gbds` function (#11991) --- plugins/git/README.md | 3 ++- plugins/git/git.plugin.zsh | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index a4e9f4c4a..724965302 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -250,7 +250,8 @@ receive further support. | `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise. | | `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. | | `grename ` | Renames branch `` to ``, including on the origin remote. | -| `gbda` | Deletes all merged and squash-merged branches | +| `gbda` | Deletes all merged branches | +| `gbds` | Deletes all squash-merged branches (**Note: performance degrades with number of branches**) | ### Work in Progress (WIP) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index d053a7638..48937cb83 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -128,11 +128,13 @@ alias gba='git branch --all' alias gbd='git branch --delete' alias gbD='git branch --delete --force' -# Copied and modified from James Roeder (jmaroeder) under MIT License -# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish function gbda() { git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null +} +# Copied and modified from James Roeder (jmaroeder) under MIT License +# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish +function gbds() { local default_branch=$(git_main_branch) (( ! $? )) || default_branch=$(git_develop_branch) -- cgit v1.2.3-70-g09d2 From 0da416986aadbaf89dc5596b01f9b42403f4d9fd Mon Sep 17 00:00:00 2001 From: Vishal Sharma <106011641+vishal-sharma-369@users.noreply.github.com> Date: Wed, 18 Oct 2023 23:44:47 +0530 Subject: fix(ssh-agent): add error message if `~/.ssh` is not found (#11929) Closes #11829 Co-authored-by: Carlo Sala --- plugins/ssh-agent/ssh-agent.plugin.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 78ac46b13..49ad95a11 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -13,6 +13,11 @@ function _start_agent() { fi fi + if [[ ! -d "$HOME/.ssh" ]]; then + echo "[oh-my-zsh] ssh-agent plugin requires ~/.ssh directory" + return 1 + fi + # Set a maximum lifetime for identities added to ssh-agent local lifetime zstyle -s :omz:plugins:ssh-agent lifetime lifetime -- cgit v1.2.3-70-g09d2 From 104041a018dc9a3eb74f93815192dba4c9386e1a Mon Sep 17 00:00:00 2001 From: Peat Bakke Date: Thu, 19 Oct 2023 02:49:38 -0700 Subject: feat(tmux): add `tds` alias for directory sessions (#11987) --- plugins/tmux/README.md | 1 + plugins/tmux/tmux.plugin.zsh | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 0f8473daf..b4516ef26 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -25,6 +25,7 @@ The plugin also supports the following: | `tkss` | tmux kill-session -t | Terminate named running tmux session | | `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session | | `tmuxconf` | `$EDITOR $ZSH_TMUX_CONFIG` | Open .tmux.conf file with an editor | +| `tds` | `_tmux_directory_session` | Creates or attaches to a session for the current path | ## Configuration Variables diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 6ed91c447..72cdd4818 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -108,6 +108,19 @@ compdef _tmux _zsh_tmux_plugin_run # Alias tmux to our wrapper function. alias tmux=_zsh_tmux_plugin_run +function _tmux_directory_session() { + # current directory without leading path + local dir=${PWD##*/} + # md5 hash for the full working directory path + local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1) + # human friendly unique session name for this directory + local session_name="${dir}-${md5:0:6}" + # create or attach to the session + tmux new -As "$session_name" +} + +alias tds=_tmux_directory_session + # Autostart if not already in tmux and enabled. if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" ]]; then # Actually don't autostart if we already did and multiple autostarts are disabled. -- cgit v1.2.3-70-g09d2 From a8dee63ffe8839d3bcf1066f8359fa43caccf3f2 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Thu, 19 Oct 2023 09:41:36 -0500 Subject: feat(lando): bypass `lando` if command is not available in container (#11993) Closes #11993 --- plugins/lando/lando.plugin.zsh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh index af53e7e5a..b5fa80092 100644 --- a/plugins/lando/lando.plugin.zsh +++ b/plugins/lando/lando.plugin.zsh @@ -11,15 +11,23 @@ function artisan \ php \ wp \ yarn { - if checkForLandoFile; then - lando "$0" "$@" + # If the lando task is available in `lando --help`, then it means: + # + # 1. `lando` is in a project with a `.lando.yml` file. + # 2. The lando task is available for lando, based on the .lando.yml config file. + # + # This has a penalty of about 250ms, so we still want to check if the lando file + # exists before, which is the fast path. If it exists, checking help output is + # still faster than running the command and failing. + if _lando_file_exists && lando --help 2>&1 | command grep -Eq "^ +lando $0 "; then + command lando "$0" "$@" else command "$0" "$@" fi } # Check for the file in the current and parent directories. -checkForLandoFile() { +_lando_file_exists() { # Only bother checking for lando within the Sites directory. if [[ "$PWD/" != "$LANDO_ZSH_SITES_DIRECTORY"/* ]]; then # Not within $LANDO_ZSH_SITES_DIRECTORY @@ -38,4 +46,4 @@ checkForLandoFile() { # 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 +} -- cgit v1.2.3-70-g09d2 From d082d87580f05cca524c546d54eb8009cf8bb10c Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 19 Oct 2023 20:35:01 +0200 Subject: refactor(lando): add `LANDO_ZSH_WRAPPED_COMMANDS` setting and refactor --- plugins/lando/README.md | 24 +++++++++++++++++++++--- plugins/lando/lando.plugin.zsh | 19 +++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/plugins/lando/README.md b/plugins/lando/README.md index 6daeae4e4..2f881cf3d 100644 --- a/plugins/lando/README.md +++ b/plugins/lando/README.md @@ -8,7 +8,7 @@ To use it, add `lando` to the plugins array in your zshrc file: plugins=(... lando) ``` -## ALIASES: +## Wrapped Commands | Alias | Description | |:----------:|:----------------:| @@ -21,16 +21,34 @@ plugins=(... lando) | `wp` | `lando wp` | | `yarn` | `lando yarn` | +More or different commands can be wrapped by setting the `LANDO_ZSH_WRAPPED_COMMANDS` setting, see [Settings](#settings) below. + ## 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. +- If the command is not a part of the commands available in the lando environment, it will run the command without `lando`. ## 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. +> NOTE: these settings must be set *before* the plugin is loaded, and any changes require a restart of the shell to be applied. + +- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory: + ```sh + LANDO_ZSH_SITES_DIRECTORY="$HOME/Code" + ``` + +- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando: + ```sh + LANDO_ZSH_CONFIG_FILE=".lando.dev.yml" + ``` + +- `LANDO_ZSH_WRAPPED_COMMANDS`: The list of commands to wrap, as a string of commands separated by whitespace: + ```sh + LANDO_ZSH_WRAPPED_COMMANDS="mysql php composer test artisan" + ``` ## Author: diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh index b5fa80092..ee796d212 100644 --- a/plugins/lando/lando.plugin.zsh +++ b/plugins/lando/lando.plugin.zsh @@ -1,16 +1,19 @@ # Settings : ${LANDO_ZSH_SITES_DIRECTORY:="$HOME/Sites"} : ${LANDO_ZSH_CONFIG_FILE:=.lando.yml} +: ${LANDO_ZSH_WRAPPED_COMMANDS:=" + artisan + composer + drush + gulp + npm + php + wp + yarn +"} # Enable multiple commands with lando. -function artisan \ - composer \ - drush \ - gulp \ - npm \ - php \ - wp \ - yarn { +function ${=LANDO_ZSH_WRAPPED_COMMANDS} { # If the lando task is available in `lando --help`, then it means: # # 1. `lando` is in a project with a `.lando.yml` file. -- cgit v1.2.3-70-g09d2 From 9f84ba085425800dee0b4e391d8cf377806dc75e Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 19 Oct 2023 20:47:26 +0200 Subject: feat(command-not-found): add support for Homebrew on Linux Fixes #11151 --- plugins/command-not-found/command-not-found.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/command-not-found/command-not-found.plugin.zsh b/plugins/command-not-found/command-not-found.plugin.zsh index cb8a8989c..c741e18a2 100644 --- a/plugins/command-not-found/command-not-found.plugin.zsh +++ b/plugins/command-not-found/command-not-found.plugin.zsh @@ -3,9 +3,10 @@ for file ( # Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found /usr/share/doc/pkgfile/command-not-found.zsh - # macOS (M1 and classic Homebrew): https://github.com/Homebrew/homebrew-command-not-found + # Homebrew: https://github.com/Homebrew/homebrew-command-not-found /opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh /usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh + /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh ); do if [[ -r "$file" ]]; then source "$file" -- cgit v1.2.3-70-g09d2 From 207d29b716301c77392ae140b1482eeba44e9102 Mon Sep 17 00:00:00 2001 From: Zeeshan Date: Tue, 4 Oct 2022 18:51:24 +0530 Subject: fix(git)!: standardize `git pull --rebase` aliases (#11224) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: The alias `gup` for `git pull --rebase` and its derivatives are replaced by `gpr` for standardization. This means the previous aliases will no longer be available after a few months. Meanwhile, the original aliases are still working, with a deprecation notice. See https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/README.md#deprecated-aliases for the full list of deprecated aliases. Fixes #11104 Closes #11224 Co-authored-by: Marc Cornellà --- plugins/git/README.md | 434 +++++++++++++++++++++++---------------------- plugins/git/git.plugin.zsh | 29 ++- 2 files changed, 242 insertions(+), 221 deletions(-) diff --git a/plugins/git/README.md b/plugins/git/README.md index 724965302..93dc8ccea 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -10,207 +10,205 @@ plugins=(... git) ## Aliases -| Alias | Command | -| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `grt` | `cd "$(git rev-parse --show-toplevel \|\| echo .)"` | -| `ggpnp` | `ggl && ggp` | -| `ggpur` | `ggu` | -| `g` | `git` | -| `ga` | `git add` | -| `gaa` | `git add --all` | -| `gapa` | `git add --patch` | -| `gau` | `git add --update` | -| `gav` | `git add --verbose` | -| `gwip` | `git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"` | -| `gam` | `git am` | -| `gama` | `git am --abort` | -| `gamc` | `git am --continue` | -| `gamscp` | `git am --show-current-patch` | -| `gams` | `git am --skip` | -| `gap` | `git apply` | -| `gapt` | `git apply --3way` | -| `gbs` | `git bisect` | -| `gbsb` | `git bisect bad` | -| `gbsg` | `git bisect good` | -| `gbsn` | `git bisect new` | -| `gbso` | `git bisect old` | -| `gbsr` | `git bisect reset` | -| `gbss` | `git bisect start` | -| `gbl` | `git blame -w` | -| `gb` | `git branch` | -| `gba` | `git branch --all` | -| `gbd` | `git branch --delete` | -| `gbD` | `git branch --delete --force` | -| `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` | -| `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` | -| `gbm` | `git branch --move` | -| `gbnm` | `git branch --no-merged` | -| `gbr` | `git branch --remote` | -| `ggsup` | `git branch --set-upstream-to=origin/$(git_current_branch)` | -| `gbg` | `LANG=C git branch -vv \| grep ": gone\]"` | -| `gco` | `git checkout` | -| `gcor` | `git checkout --recurse-submodules` | -| `gcb` | `git checkout -b` | -| `gcd` | `git checkout $(git_develop_branch)` | -| `gcm` | `git checkout $(git_main_branch)` | -| `gcp` | `git cherry-pick` | -| `gcpa` | `git cherry-pick --abort` | -| `gcpc` | `git cherry-pick --continue` | -| `gclean` | `git clean --interactive -d` | -| `gcl` | `git clone --recurse-submodules` | -| `gccd` | `git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)"` | -| `gcam` | `git commit --all --message` | -| `gcas` | `git commit --all --signoff` | -| `gcasm` | `git commit --all --signoff --message` | -| `gcmsg` | `git commit --message` | -| `gcsm` | `git commit --signoff --message` | -| `gc` | `git commit --verbose` | -| `gca` | `git commit --verbose --all` | -| `gca!` | `git commit --verbose --all --amend` | -| `gcan!` | `git commit --verbose --all --no-edit --amend` | -| `gcans!` | `git commit --verbose --all --signoff --no-edit --amend` | -| `gc!` | `git commit --verbose --amend` | -| `gcn!` | `git commit --verbose --no-edit --amend` | -| `gcs` | `git commit -S` | -| `gcss` | `git commit -S -s` | -| `gcssm` | `git commit -S -s -m` | -| `gcf` | `git config --list` | -| `gdct` | `git describe --tags $(git rev-list --tags --max-count=1)` | -| `gd` | `git diff` | -| `gdca` | `git diff --cached` | -| `gdcw` | `git diff --cached --word-diff` | -| `gds` | `git diff --staged` | -| `gdw` | `git diff --word-diff` | -| `gdv` | `git diff -w "$@" \| view -` | -| `gdup` | `git diff @{upstream}` | -| `gdnolock` | `git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock"` | -| `gdt` | `git diff-tree --no-commit-id --name-only -r` | -| `gf` | `git fetch` | -| `gfa` | `git fetch --all --prune` | -| `gfo` | `git fetch origin` | -| `gg` | `git gui citool` | -| `gga` | `git gui citool --amend` | -| `ghh` | `git help` | -| `glgg` | `git log --graph` | -| `glgga` | `git log --graph --decorate --all` | -| `glgm` | `git log --graph --max-count=10` | -| `glod` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'` | -| `glods` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short` | -| `glol` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` | -| `glola` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all` | -| `glols` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat` | -| `glo` | `git log --oneline --decorate` | -| `glog` | `git log --oneline --decorate --graph` | -| `gloga` | `git log --oneline --decorate --graph --all` | -| `glp` | `git log --pretty=` | -| `glg` | `git log --stat` | -| `glgp` | `git log --stat --patch` | -| `gignored` | `git ls-files -v \| grep "^[[:lower:]]"` | -| `gfg` | `git ls-files \| grep` | -| `gm` | `git merge` | -| `gma` | `git merge --abort` | -| `gms` | `git merge --squash` | -| `gmom` | `git merge origin/$(git_main_branch)` | -| `gmum` | `git merge upstream/$(git_main_branch)` | -| `gmtl` | `git mergetool --no-prompt` | -| `gmtlvim` | `git mergetool --no-prompt --tool=vimdiff` | -| `gl` | `git pull` | -| `gpr` | `git pull --rebase` | -| `gup` | `git pull --rebase` | -| `gupa` | `git pull --rebase --autostash` | -| `gupav` | `git pull --rebase --autostash --verbose` | -| `gupv` | `git pull --rebase --verbose` | -| `ggu` | `git pull --rebase origin $(current_branch)` | -| `gupom` | `git pull --rebase origin $(git_main_branch)` | -| `gupomi` | `git pull --rebase=interactive origin $(git_main_branch)` | -| `ggpull` | `git pull origin "$(git_current_branch)"` | -| `ggl` | `git pull origin $(current_branch)` | -| `gluc` | `git pull upstream $(git_current_branch)` | -| `glum` | `git pull upstream $(git_main_branch)` | -| `gp` | `git push` | -| `gpd` | `git push --dry-run` | -| `gpf!` | `git push --force` | -| `ggf` | `git push --force origin $(current_branch)` | -| `gpf` | On Git >= 2.30: `git push --force-with-lease --force-if-includes` | -| `gpf` | On Git < 2.30: `git push --force-with-lease` | -| `ggfl` | `git push --force-with-lease origin $(current_branch)` | -| `gpsup` | `git push --set-upstream origin $(git_current_branch)` | -| `gpsupf` | On Git >= 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes` | -| `gpsupf` | On Git < 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease` | -| `gpv` | `git push --verbose` | -| `gpoat` | `git push origin --all && git push origin --tags` | -| `gpod` | `git push origin --delete` | -| `ggpush` | `git push origin "$(git_current_branch)"` | -| `ggp` | `git push origin $(current_branch)` | -| `gpu` | `git push upstream` | -| `grb` | `git rebase` | -| `grba` | `git rebase --abort` | -| `grbc` | `git rebase --continue` | -| `grbi` | `git rebase --interactive` | -| `grbo` | `git rebase --onto` | -| `grbs` | `git rebase --skip` | -| `grbd` | `git rebase $(git_develop_branch)` | -| `grbm` | `git rebase $(git_main_branch)` | -| `grbom` | `git rebase origin/$(git_main_branch)` | -| `gr` | `git remote` | -| `grv` | `git remote --verbose` | -| `gra` | `git remote add` | -| `grrm` | `git remote remove` | -| `grmv` | `git remote rename` | -| `grset` | `git remote set-url` | -| `grup` | `git remote update` | -| `grh` | `git reset` | -| `gru` | `git reset --` | -| `grhh` | `git reset --hard` | -| `grhk` | `git reset --keep` | -| `grhs` | `git reset --soft` | -| `gpristine` | `git reset --hard && git clean -dffx` | -| `groh` | `git reset origin/$(git_current_branch) --hard` | -| `grs` | `git restore` | -| `grss` | `git restore --source` | -| `grst` | `git restore --staged` | -| `gunwip` | `git rev-list --max-count=1 --format="%s" HEAD \| grep -q "--wip--" && git reset HEAD~1` | -| `grev` | `git revert` | -| `grm` | `git rm` | -| `grmc` | `git rm --cached` | -| `gcount` | `git shortlog --summary -n` | -| `gsh` | `git show` | -| `gsps` | `git show --pretty=short --show-signature` | -| `gstall` | `git stash --all` | -| `gstu` | `git stash --include-untracked` | -| `gstaa` | `git stash apply` | -| `gstc` | `git stash clear` | -| `gstd` | `git stash drop` | -| `gstl` | `git stash list` | -| `gstp` | `git stash pop` | -| `gsta` | On Git >= 2.13: `git stash push` | -| `gsta` | On Git < 2.13: `git stash save` | -| `gsts` | `git stash show --patch` | -| `gst` | `git status` | -| `gss` | `git status --short` | -| `gsb` | `git status --short -b` | -| `gsi` | `git submodule init` | -| `gsu` | `git submodule update` | -| `gsd` | `git svn dcommit` | -| `git-svn-dcommit-push` | `git svn dcommit && git push github $(git_main_branch):svntrunk` | -| `gsr` | `git svn rebase` | -| `gsw` | `git switch` | -| `gswc` | `git switch -c` | -| `gswd` | `git switch $(git_develop_branch)` | -| `gswm` | `git switch $(git_main_branch)` | -| `gta` | `git tag --annotate` | -| `gts` | `git tag -s` | -| `gtv` | `git tag \| sort -V` | -| `gignore` | `git update-index --assume-unchanged` | -| `gunignore` | `git update-index --no-assume-unchanged` | -| `gwch` | `git whatchanged -p --abbrev-commit --pretty=medium` | -| `gwt` | `git worktree` | -| `gwtls` | `git worktree list` | -| `gwtmv` | `git worktree move` | -| `gwtrm` | `git worktree remove` | -| `gk` | `gitk --all --branches &!` | -| `gke` | `gitk --all $(git log --walk-reflogs --pretty=%h) &!` | -| `gtl` | `gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl` | +| Alias | Command | +| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------ | +| `grt` | `cd "$(git rev-parse --show-toplevel \|\| echo .)"` | +| `ggpnp` | `ggl && ggp` | +| `ggpur` | `ggu` | +| `g` | `git` | +| `ga` | `git add` | +| `gaa` | `git add --all` | +| `gapa` | `git add --patch` | +| `gau` | `git add --update` | +| `gav` | `git add --verbose` | +| `gwip` | `git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"` | +| `gam` | `git am` | +| `gama` | `git am --abort` | +| `gamc` | `git am --continue` | +| `gamscp` | `git am --show-current-patch` | +| `gams` | `git am --skip` | +| `gap` | `git apply` | +| `gapt` | `git apply --3way` | +| `gbs` | `git bisect` | +| `gbsb` | `git bisect bad` | +| `gbsg` | `git bisect good` | +| `gbsn` | `git bisect new` | +| `gbso` | `git bisect old` | +| `gbsr` | `git bisect reset` | +| `gbss` | `git bisect start` | +| `gbl` | `git blame -w` | +| `gb` | `git branch` | +| `gba` | `git branch --all` | +| `gbd` | `git branch --delete` | +| `gbD` | `git branch --delete --force` | +| `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` | +| `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` | +| `gbm` | `git branch --move` | +| `gbnm` | `git branch --no-merged` | +| `gbr` | `git branch --remote` | +| `ggsup` | `git branch --set-upstream-to=origin/$(git_current_branch)` | +| `gbg` | `LANG=C git branch -vv \| grep ": gone\]"` | +| `gco` | `git checkout` | +| `gcor` | `git checkout --recurse-submodules` | +| `gcb` | `git checkout -b` | +| `gcd` | `git checkout $(git_develop_branch)` | +| `gcm` | `git checkout $(git_main_branch)` | +| `gcp` | `git cherry-pick` | +| `gcpa` | `git cherry-pick --abort` | +| `gcpc` | `git cherry-pick --continue` | +| `gclean` | `git clean --interactive -d` | +| `gcl` | `git clone --recurse-submodules` | +| `gccd` | `git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)"` | +| `gcam` | `git commit --all --message` | +| `gcas` | `git commit --all --signoff` | +| `gcasm` | `git commit --all --signoff --message` | +| `gcmsg` | `git commit --message` | +| `gcsm` | `git commit --signoff --message` | +| `gc` | `git commit --verbose` | +| `gca` | `git commit --verbose --all` | +| `gca!` | `git commit --verbose --all --amend` | +| `gcan!` | `git commit --verbose --all --no-edit --amend` | +| `gcans!` | `git commit --verbose --all --signoff --no-edit --amend` | +| `gc!` | `git commit --verbose --amend` | +| `gcn!` | `git commit --verbose --no-edit --amend` | +| `gcs` | `git commit -S` | +| `gcss` | `git commit -S -s` | +| `gcssm` | `git commit -S -s -m` | +| `gcf` | `git config --list` | +| `gdct` | `git describe --tags $(git rev-list --tags --max-count=1)` | +| `gd` | `git diff` | +| `gdca` | `git diff --cached` | +| `gdcw` | `git diff --cached --word-diff` | +| `gds` | `git diff --staged` | +| `gdw` | `git diff --word-diff` | +| `gdv` | `git diff -w "$@" \| view -` | +| `gdup` | `git diff @{upstream}` | +| `gdnolock` | `git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock"` | +| `gdt` | `git diff-tree --no-commit-id --name-only -r` | +| `gf` | `git fetch` | +| `gfa` | `git fetch --all --prune` | +| `gfo` | `git fetch origin` | +| `gg` | `git gui citool` | +| `gga` | `git gui citool --amend` | +| `ghh` | `git help` | +| `glgg` | `git log --graph` | +| `glgga` | `git log --graph --decorate --all` | +| `glgm` | `git log --graph --max-count=10` | +| `glod` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'` | +| `glods` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short` | +| `glol` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` | +| `glola` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all` | +| `glols` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat` | +| `glo` | `git log --oneline --decorate` | +| `glog` | `git log --oneline --decorate --graph` | +| `gloga` | `git log --oneline --decorate --graph --all` | +| `glp` | `git log --pretty=` | +| `glg` | `git log --stat` | +| `glgp` | `git log --stat --patch` | +| `gignored` | `git ls-files -v \| grep "^[[:lower:]]"` | +| `gfg` | `git ls-files \| grep` | +| `gm` | `git merge` | +| `gma` | `git merge --abort` | +| `gms` | `git merge --squash` | +| `gmom` | `git merge origin/$(git_main_branch)` | +| `gmum` | `git merge upstream/$(git_main_branch)` | +| `gmtl` | `git mergetool --no-prompt` | +| `gmtlvim` | `git mergetool --no-prompt --tool=vimdiff` | +| `gl` | `git pull` | +| `gpr` | `git pull --rebase` | +| `gprv` | `git pull --rebase -v` | +| `gpra` | `git pull --rebase --autostash` | +| `gprav` | `git pull --rebase --autostash -v` | +| `gprom` | `git pull --rebase origin $(git_main_branch)` | +| `gpromi` | `git pull --rebase=interactive origin $(git_main_branch)` | +| `ggpull` | `git pull origin "$(git_current_branch)"` | +| `ggl` | `git pull origin $(current_branch)` | +| `gluc` | `git pull upstream $(git_current_branch)` | +| `glum` | `git pull upstream $(git_main_branch)` | +| `gp` | `git push` | +| `gpd` | `git push --dry-run` | +| `gpf!` | `git push --force` | +| `ggf` | `git push --force origin $(current_branch)` | +| `gpf` | On Git >= 2.30: `git push --force-with-lease --force-if-includes` | +| `gpf` | On Git < 2.30: `git push --force-with-lease` | +| `ggfl` | `git push --force-with-lease origin $(current_branch)` | +| `gpsup` | `git push --set-upstream origin $(git_current_branch)` | +| `gpsupf` | On Git >= 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes` | +| `gpsupf` | On Git < 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease` | +| `gpv` | `git push --verbose` | +| `gpoat` | `git push origin --all && git push origin --tags` | +| `gpod` | `git push origin --delete` | +| `ggpush` | `git push origin "$(git_current_branch)"` | +| `ggp` | `git push origin $(current_branch)` | +| `gpu` | `git push upstream` | +| `grb` | `git rebase` | +| `grba` | `git rebase --abort` | +| `grbc` | `git rebase --continue` | +| `grbi` | `git rebase --interactive` | +| `grbo` | `git rebase --onto` | +| `grbs` | `git rebase --skip` | +| `grbd` | `git rebase $(git_develop_branch)` | +| `grbm` | `git rebase $(git_main_branch)` | +| `grbom` | `git rebase origin/$(git_main_branch)` | +| `gr` | `git remote` | +| `grv` | `git remote --verbose` | +| `gra` | `git remote add` | +| `grrm` | `git remote remove` | +| `grmv` | `git remote rename` | +| `grset` | `git remote set-url` | +| `grup` | `git remote update` | +| `grh` | `git reset` | +| `gru` | `git reset --` | +| `grhh` | `git reset --hard` | +| `grhk` | `git reset --keep` | +| `grhs` | `git reset --soft` | +| `gpristine` | `git reset --hard && git clean -dffx` | +| `groh` | `git reset origin/$(git_current_branch) --hard` | +| `grs` | `git restore` | +| `grss` | `git restore --source` | +| `grst` | `git restore --staged` | +| `gunwip` | `git rev-list --max-count=1 --format="%s" HEAD \| grep -q "--wip--" && git reset HEAD~1` | +| `grev` | `git revert` | +| `grm` | `git rm` | +| `grmc` | `git rm --cached` | +| `gcount` | `git shortlog --summary -n` | +| `gsh` | `git show` | +| `gsps` | `git show --pretty=short --show-signature` | +| `gstall` | `git stash --all` | +| `gstu` | `git stash --include-untracked` | +| `gstaa` | `git stash apply` | +| `gstc` | `git stash clear` | +| `gstd` | `git stash drop` | +| `gstl` | `git stash list` | +| `gstp` | `git stash pop` | +| `gsta` | On Git >= 2.13: `git stash push` | +| `gsta` | On Git < 2.13: `git stash save` | +| `gsts` | `git stash show --patch` | +| `gst` | `git status` | +| `gss` | `git status --short` | +| `gsb` | `git status --short -b` | +| `gsi` | `git submodule init` | +| `gsu` | `git submodule update` | +| `gsd` | `git svn dcommit` | +| `git-svn-dcommit-push` | `git svn dcommit && git push github $(git_main_branch):svntrunk` | +| `gsr` | `git svn rebase` | +| `gsw` | `git switch` | +| `gswc` | `git switch -c` | +| `gswd` | `git switch $(git_develop_branch)` | +| `gswm` | `git switch $(git_main_branch)` | +| `gta` | `git tag --annotate` | +| `gts` | `git tag -s` | +| `gtv` | `git tag \| sort -V` | +| `gignore` | `git update-index --assume-unchanged` | +| `gunignore` | `git update-index --no-assume-unchanged` | +| `gwch` | `git whatchanged -p --abbrev-commit --pretty=medium` | +| `gwt` | `git worktree` | +| `gwtls` | `git worktree list` | +| `gwtmv` | `git worktree move` | +| `gwtrm` | `git worktree remove` | +| `gk` | `gitk --all --branches &!` | +| `gke` | `gitk --all $(git log --walk-reflogs --pretty=%h) &!` | +| `gtl` | `gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl` | ### Main branch preference @@ -224,19 +222,25 @@ branch exists. We do this via the function `git_main_branch`. These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support. -| Alias | Command | Modification | -| :------- | :----------------------------------------------------- | :-------------------------------------------------------- | -| `gap` | `git add --patch` | New alias: `gapa`. | -| `gcl` | `git config --list` | New alias: `gcf`. | -| `gdc` | `git diff --cached` | New alias: `gdca`. | -| `gdt` | `git difftool` | No replacement. | -| `ggpull` | `git pull origin $(current_branch)` | New alias: `ggl`. (`ggpull` still exists for now though.) | -| `ggpur` | `git pull --rebase origin $(current_branch)` | New alias: `ggu`. (`ggpur` still exists for now though.) | -| `ggpush` | `git push origin $(current_branch)` | New alias: `ggp`. (`ggpush` still exists for now though.) | -| `gk` | `gitk --all --branches` | Now aliased to `gitk --all --branches`. | -| `glg` | `git log --stat --max-count=10` | Now aliased to `git log --stat --color`. | -| `glgg` | `git log --graph --max-count=10` | Now aliased to `git log --graph --color`. | -| `gwc` | `git whatchanged -p --abbrev-commit --pretty = medium` | New alias: `gwch`. | +| Alias | Command | Modification | +| :------- | :-------------------------------------------------------- | :-------------------------------------------------------- | +| `gap` | `git add --patch` | New alias: `gapa`. | +| `gcl` | `git config --list` | New alias: `gcf`. | +| `gdc` | `git diff --cached` | New alias: `gdca`. | +| `gdt` | `git difftool` | No replacement. | +| `ggpull` | `git pull origin $(current_branch)` | New alias: `ggl`. (`ggpull` still exists for now though.) | +| `ggpur` | `git pull --rebase origin $(current_branch)` | New alias: `ggu`. (`ggpur` still exists for now though.) | +| `ggpush` | `git push origin $(current_branch)` | New alias: `ggp`. (`ggpush` still exists for now though.) | +| `gk` | `gitk --all --branches` | Now aliased to `gitk --all --branches`. | +| `glg` | `git log --stat --max-count=10` | Now aliased to `git log --stat --color`. | +| `glgg` | `git log --graph --max-count=10` | Now aliased to `git log --graph --color`. | +| `gwc` | `git whatchanged -p --abbrev-commit --pretty = medium` | New alias: `gwch`. | +| `gup` | `git pull --rebase` | now alias `gpr` | +| `gupv` | `git pull --rebase -v` | now alias `gprv` | +| `gupa` | `git pull --rebase --autostash` | now alias `gpra` | +| `gupav` | `git pull --rebase --autostash -v` | now alias `gprav` | +| `gupom` | `git pull --rebase origin $(git_main_branch)` | now alias `gprom` | +| `gupomi` | `git pull --rebase=interactive origin $(git_main_branch)` | now alias `gpromi` | ## Functions @@ -250,7 +254,7 @@ receive further support. | `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise. | | `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. | | `grename ` | Renames branch `` to ``, including on the origin remote. | -| `gbda` | Deletes all merged branches | +| `gbda` | Deletes all merged branches | | `gbds` | Deletes all squash-merged branches (**Note: performance degrades with number of branches**) | ### Work in Progress (WIP) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 48937cb83..5ec2bbe2b 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -246,12 +246,12 @@ alias gmom='git merge origin/$(git_main_branch)' alias gmum='git merge upstream/$(git_main_branch)' alias gmtl='git mergetool --no-prompt' alias gmtlvim='git mergetool --no-prompt --tool=vimdiff' + alias gl='git pull' alias gpr='git pull --rebase' -alias gup='git pull --rebase' -alias gupa='git pull --rebase --autostash' -alias gupav='git pull --rebase --autostash --verbose' -alias gupv='git pull --rebase --verbose' +alias gprv='git pull --rebase -v' +alias gpra='git pull --rebase --autostash' +alias gprav='git pull --rebase --autostash -v' function ggu() { [[ "$#" != 1 ]] && local b="$(git_current_branch)" @@ -259,8 +259,8 @@ function ggu() { } compdef _git ggu=git-checkout -alias gupom='git pull --rebase origin $(git_main_branch)' -alias gupomi='git pull --rebase=interactive origin $(git_main_branch)' +alias gprom='git pull --rebase origin $(git_main_branch)' +alias gpromi='git pull --rebase=interactive origin $(git_main_branch)' alias ggpull='git pull origin "$(git_current_branch)"' function ggl() { @@ -388,3 +388,20 @@ alias gk='\gitk --all --branches &!' alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!' unset git_version + +# Logic for adding warnings on deprecated aliases +local old_alias new_alias +for old_alias new_alias ( + # TODO(2023-10-19): remove deprecated `git pull --rebase` aliases + gup gpr + gupv gprv + gupa gpra + gupav gprav + gupom gprom + gupomi gpromi +); do + aliases[$old_alias]=" + print -Pu2 \"%F{yellow}[oh-my-zsh] '%F{red}${old_alias}%F{yellow}' is a deprecated alias, using '%F{green}${new_alias}%F{yellow}' instead.%f\" + $new_alias" +done +unset old_alias new_alias -- cgit v1.2.3-70-g09d2 From f79647dba5df47cd87917bcf527c5825be6511dc Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 19 Oct 2023 22:05:03 +0200 Subject: fix(git): fix check in `gbds` function --- plugins/git/git.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 5ec2bbe2b..eef538b75 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -141,7 +141,7 @@ function gbds() { git for-each-ref refs/heads/ "--format=%(refname:short)" | \ while read branch; do local merge_base=$(git merge-base $default_branch $branch) - if [[ '-*' == $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) ]]; then + if [[ $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) = -* ]]; then git branch -D $branch fi done -- cgit v1.2.3-70-g09d2 From ff6dac56a256e376a10b19a4948ada7df4509c71 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 19 Oct 2023 23:04:08 +0200 Subject: fix(git): fix smart cd to cloned directory in `gccd` function --- plugins/git/git.plugin.zsh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index eef538b75..6ea1d1177 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -166,8 +166,15 @@ alias gclean='git clean --interactive -d' alias gcl='git clone --recurse-submodules' function gccd() { - command git clone --recurse-submodules "$@" - [[ -d "$_" ]] && cd "$_" || cd "${${_:t}%.git}" + # get repo URI from args based on valid formats: https://git-scm.com/docs/git-clone#URLS + local repo="${${@[(r)(ssh://*|git://*|ftp(s)#://*|http(s)#://*|*@*)(.git/#)#]}:-$_}" + + # clone repository and exit if it fails + command git clone --recurse-submodules "$@" || return + + # if last arg passed was a directory, that's where the repo was cloned + # otherwise parse the repo URI and use the last part as the directory + [[ -d "$_" ]] && cd "$_" || cd "${${repo:t}%.git/#}" } compdef _git gccd=git-clone -- cgit v1.2.3-70-g09d2 From 8428442ff0e0114fab32b90443911b11a4b7f5df Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 19 Oct 2023 23:24:55 +0200 Subject: fix(termsupport): add workaround for directory tracking issues in Konsole Fixes #11683 Related: 50c6786 --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index a800e651f..d170ffcbf 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -151,7 +151,7 @@ function omz_termsupport_cwd { URL_PATH="$(omz_urlencode -P $PWD)" || return 1 # Konsole errors if the HOST is provided - [[ -z "$KONSOLE_VERSION" ]] || URL_HOST="" + [[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST="" # common control sequence (OSC 7) to set current host and path printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}" -- cgit v1.2.3-70-g09d2 From 465253396df1865d3c73b1b3cff243798960ca3f Mon Sep 17 00:00:00 2001 From: Amir Hosseini <19665344+itsamirhn@users.noreply.github.com> Date: Sun, 22 Oct 2023 12:00:25 +0330 Subject: fix(direnv): use `hook` instead of `export` (#12000) --- plugins/direnv/direnv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/direnv/direnv.plugin.zsh b/plugins/direnv/direnv.plugin.zsh index 5e32c4c23..6f8debb62 100644 --- a/plugins/direnv/direnv.plugin.zsh +++ b/plugins/direnv/direnv.plugin.zsh @@ -3,7 +3,7 @@ command -v direnv &>/dev/null || return _direnv_hook() { trap -- '' SIGINT; - eval "$(direnv export zsh)"; + eval "$(direnv hook zsh)"; trap - SIGINT; } typeset -ag precmd_functions; -- cgit v1.2.3-70-g09d2 From 1868c15ec6b13c2da20375780f1e8b8f61458be5 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 23 Oct 2023 13:24:35 +0200 Subject: chore: remove mentions of huntr.dev huntr.dev has pivoted to ML/AI-only vulnerability reporting, and we are now already using GitHub's private vulnerability reports. --- README.md | 1 - SECURITY.md | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 308d117e1..499986879 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi [![Mastodon Follow](https://img.shields.io/mastodon/follow/111169632522566717?label=%40ohmyzsh&domain=https%3A%2F%2Fmstdn.social&logo=mastodon&style=flat)](https://mstdn.social/@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) -[![huntr.dev](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev/bounties/disclose/?utm_campaign=ohmyzsh%2Fohmyzsh&utm_medium=social&utm_source=github&target=https%3A%2F%2Fgithub.com%2Fohmyzsh%2Fohmyzsh)
Table of Contents diff --git a/SECURITY.md b/SECURITY.md index 7e5c8eed0..ae7458ee2 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -17,8 +17,7 @@ In the near future we will introduce versioning, so expect this section to chang **Do not submit an issue or pull request**: this might reveal the vulnerability. -Instead, you should email the maintainers directly at: [**security@ohmyz.sh**](mailto:security@ohmyz.sh). +Instead, you should email the maintainers directly at: [**security@ohmyz.sh**](mailto:security@ohmyz.sh), +or using the link to [privately report a vulnerability with GitHub](https://github.com/ohmyzsh/ohmyzsh/security/advisories/new). We will deal with the vulnerability privately and submit a patch as soon as possible. - -You can also submit your vulnerability report to [huntr.dev](https://huntr.dev/bounties/disclose/?utm_campaign=ohmyzsh%2Fohmyzsh&utm_medium=social&utm_source=github&target=https%3A%2F%2Fgithub.com%2Fohmyzsh%2Fohmyzsh) and see if you can get a bounty reward. -- cgit v1.2.3-70-g09d2 From b7904ae54867cd9e64dfd3c1f952d72b5cfe17be Mon Sep 17 00:00:00 2001 From: 家鳖大帝 Date: Tue, 24 Oct 2023 19:33:04 +0800 Subject: fix(firewalld): remove ` (default)` from the end of zone string (#11998) --- plugins/firewalld/firewalld.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/firewalld/firewalld.plugin.zsh b/plugins/firewalld/firewalld.plugin.zsh index 5b1090636..b2c0f64be 100644 --- a/plugins/firewalld/firewalld.plugin.zsh +++ b/plugins/firewalld/firewalld.plugin.zsh @@ -9,7 +9,7 @@ function fwl () { zones=("${(@f)$(sudo firewall-cmd --get-active-zones | grep -v 'interfaces\|sources')}") for i in $zones; do - sudo firewall-cmd --zone $i --list-all + sudo firewall-cmd --zone ${i/ \(default\)} --list-all done echo 'Direct Rules:' -- cgit v1.2.3-70-g09d2 From 5c22c5812ec8b980d223b8252edc7759dd354014 Mon Sep 17 00:00:00 2001 From: alps2006 Date: Tue, 24 Oct 2023 20:00:26 +0800 Subject: feat(vi-mode): allow replacing on visual mode (#12006) --- plugins/vi-mode/vi-mode.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index d1493e02f..8fefaf86c 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -154,7 +154,8 @@ wrap_clipboard_widgets copy \ vi-delete vi-delete-char vi-backward-delete-char wrap_clipboard_widgets paste \ - vi-put-{before,after} + vi-put-{before,after} \ + put-replace-selection unfunction wrap_clipboard_widgets -- cgit v1.2.3-70-g09d2 From 048455ccefdc67c4f137b8f7886769c55c2e5417 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 25 Oct 2023 19:47:10 +0200 Subject: fix(git-commit): fix revert alias conflict (#12007) Fixes #12007 --- plugins/git-commit/README.md | 14 ++++++++++---- plugins/git-commit/git-commit.plugin.zsh | 24 ++++++++++++++---------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/plugins/git-commit/README.md b/plugins/git-commit/README.md index dc10d8ad5..91cc73b44 100644 --- a/plugins/git-commit/README.md +++ b/plugins/git-commit/README.md @@ -10,7 +10,7 @@ plugins=(... git-commit) ## Syntax -```zshrc +```zsh git [(-s, --scope) ""] "" ``` @@ -26,11 +26,17 @@ Where `type` is one of the following: - `fix` - `perf` - `refactor` -- `revert` +- `rev` - `style` - `test` +> NOTE: the alias for `revert` type is `rev`, as otherwise it conflicts with the git command of the same name. +> It will still generate a commit message in the format `revert: ` + ## Examples -`git style "remove trailing whitespace"` -> `git commit -m "style: remove trailing whitespace"` -`git fix -s "router" "correct redirect link"` -> `git commit -m "fix(router): correct redirect link"` +| Git alias | Command | +| --------------------------------------------- | ---------------------------------------------------- | +| `git style "remove trailing whitespace"` | `git commit -m "style: remove trailing whitespace"` | +| `git fix -s "router" "correct redirect link"` | `git commit -m "fix(router): correct redirect link"` | +| `git rev -s "api" "rollback v2"` | `git commit -m "revert(api): rollback v2"` | diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 4ad4c0177..72cecb1d6 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -1,9 +1,3 @@ -function _git_commit_register { - if ! git config --global --get-all alias.$1 >/dev/null 2>&1; then - git config --global alias.$1 '!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$1'(${scope}): ${@}"; else git commit -m "'$1': ${@}"; fi }; a' - fi -} - local -a _git_commit_aliases _git_commit_aliases=( 'build' @@ -19,9 +13,19 @@ _git_commit_aliases=( 'test' ) -for _alias in "${_git_commit_aliases[@]}"; do - _git_commit_register $_alias +local alias type +for type in "${_git_commit_aliases[@]}"; do + # an alias can't be named "revert" because the git command takes precedence + # https://stackoverflow.com/a/3538791 + case "$type" in + revert) alias=rev ;; + *) alias=$type ;; + esac + + local func='!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$type'(${scope}): ${@}"; else git commit -m "'$type': ${@}"; fi }; a' + if ! git config --global --get-all alias.${alias} >/dev/null 2>&1; then + git config --global alias.${alias} "$func" + fi done -unfunction _git_commit_register -unset _alias +unset _git_commit_aliases alias type func -- cgit v1.2.3-70-g09d2 From 7348d12f8e5cd755037aa6f5d347eab0ac2efb0b Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 28 Oct 2023 10:24:24 +0200 Subject: ci(vercel): add Content-Disposition header on installer This allows doing something like curl -O https://install.ohmyz.sh and have the `install.sh` file automatically saved to its right name. --- .github/workflows/installer/vercel.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/installer/vercel.json b/.github/workflows/installer/vercel.json index 8c5aec5e0..524dc3c0f 100644 --- a/.github/workflows/installer/vercel.json +++ b/.github/workflows/installer/vercel.json @@ -2,7 +2,16 @@ "headers": [ { "source": "/((?!favicon.ico).*)", - "headers": [{ "key": "Content-Type", "value": "text/plain" }] + "headers": [ + { + "key": "Content-Type", + "value": "text/plain" + }, + { + "key": "Content-Disposition", + "value": "inline; filename=\"install.sh\"" + } + ] } ], "rewrites": [ -- cgit v1.2.3-70-g09d2 From 7733e3ab57ee3f666cf6f3e699d03b69aca2d373 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 28 Oct 2023 10:29:54 +0200 Subject: ci: fix path filtering in installer workflow See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-paths --- .github/workflows/installer.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml index 4a25c8079..a70c483d1 100644 --- a/.github/workflows/installer.yml +++ b/.github/workflows/installer.yml @@ -3,9 +3,9 @@ on: workflow_dispatch: {} push: paths: - - tools/install.sh - - .github/workflows/installer - - .github/workflows/installer.yml + - 'tools/install.sh' + - '.github/workflows/installer/**' + - '.github/workflows/installer.yml' concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} -- cgit v1.2.3-70-g09d2 From cb86d378f287f1731cc6ad907f6248e35b52dc25 Mon Sep 17 00:00:00 2001 From: Josh Hubbard Date: Sat, 28 Oct 2023 04:37:50 -0400 Subject: feat(git-auto-fetch): fetch also submodules (#12001) --- plugins/git-auto-fetch/git-auto-fetch.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 2df34bb7b..f8dfec759 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -29,7 +29,7 @@ function git-fetch-all { date -R &>! "$gitdir/FETCH_LOG" GIT_SSH_COMMAND="command ssh -o BatchMode=yes" \ GIT_TERMINAL_PROMPT=0 \ - command git fetch --all 2>/dev/null &>> "$gitdir/FETCH_LOG" + command git fetch --all --recurse-submodules=yes 2>/dev/null &>> "$gitdir/FETCH_LOG" ) &| } -- cgit v1.2.3-70-g09d2 From 38c01a235fef0d990be5ece0d62f94fd06b10571 Mon Sep 17 00:00:00 2001 From: Sarah Noor <88581241+sarah-noor-12232@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:48:45 +0500 Subject: feat(npm): add alias for `npm run build` (#12012) Closes #12010 --- plugins/npm/README.md | 1 + plugins/npm/npm.plugin.zsh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/plugins/npm/README.md b/plugins/npm/README.md index 420dd710a..7848a1290 100644 --- a/plugins/npm/README.md +++ b/plugins/npm/README.md @@ -30,6 +30,7 @@ plugins=(... npm) | `npmi` | `npm info` | Run npm info | | `npmSe` | `npm search` | Run npm search | | `npmrd` | `npm run dev` | Run npm run dev | +| `npmrb` | `npm run build` | Run npm run build | ## `npm install` / `npm uninstall` toggle diff --git a/plugins/npm/npm.plugin.zsh b/plugins/npm/npm.plugin.zsh index 3cba18f6c..23377b085 100644 --- a/plugins/npm/npm.plugin.zsh +++ b/plugins/npm/npm.plugin.zsh @@ -73,6 +73,9 @@ alias npmSe="npm search" # Run npm run dev alias npmrd="npm run dev" +# Run npm run build +alias npmrb="npm run build" + npm_toggle_install_uninstall() { # Look up to the previous 2 history commands local line -- cgit v1.2.3-70-g09d2 From 632ed413a9ce62747ded83d7736491b081be4b49 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 1 Nov 2023 21:24:28 +0100 Subject: fix(wd): use `(( ))` instead of `[[ ]]` zsh versions prior to 5.0.6 mark `[[ ]]` as invalid syntax Closes #12017 --- plugins/wd/wd.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wd/wd.sh b/plugins/wd/wd.sh index e51cf906a..840e92d61 100644 --- a/plugins/wd/wd.sh +++ b/plugins/wd/wd.sh @@ -396,7 +396,7 @@ fi # disable extendedglob for the complete wd execution time setopt | grep -q extendedglob wd_extglob_is_set=$? -[[ $wd_extglob_is_set ]] && setopt noextendedglob +(( ! $wd_extglob_is_set )) && setopt noextendedglob # load warp points typeset -A points @@ -484,7 +484,7 @@ fi # if not, next time warp will pick up variables from this run # remember, there's no sub shell -[[ $wd_extglob_is_set ]] && setopt extendedglob +(( ! $wd_extglob_is_set )) && setopt extendedglob unset wd_extglob_is_set unset wd_warp -- cgit v1.2.3-70-g09d2