From edbd86cd956266ee80f6b128588f5673f0cdb3c7 Mon Sep 17 00:00:00 2001 From: Sayan Roy Date: Sun, 7 Jun 2020 12:14:55 +0530 Subject: [PATCH 01/88] Updating some gem command reference # Updating some gem command reference gem_info,gem help , etc. --- plugins/ruby/ruby.plugin.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index 177b35b31..88e769d39 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -12,3 +12,14 @@ alias rb="ruby" alias gin="gem install" alias gun="gem uninstall" alias gli="gem list" +alias gi="gem info" +alias giall="gem info --all" +alias gca="gem cert --add" +alias gcr="gem cert --remove" +alias gcb="gem cert --build" +alias gclup="gem cleanup -n" +alias ggi="gem generate_index" +alias gh="gem help" +alias gl="gem lock" +alias go="gem open" +alias goe="gem open -e" From c268d176bf5e1efbf31bb1f3c00c182c1b369e9b Mon Sep 17 00:00:00 2001 From: Sayan Roy Date: Tue, 9 Jun 2020 00:48:50 +0530 Subject: [PATCH 02/88] Updating the README.md --- plugins/ruby/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/ruby/README.md b/plugins/ruby/README.md index ad2755bbf..a4a9c5036 100644 --- a/plugins/ruby/README.md +++ b/plugins/ruby/README.md @@ -18,3 +18,14 @@ plugins=(... ruby) | gin | `gem install` | Install a gem into the local repository | | gun | `gem uninstall` | Uninstall gems from the local repository | | gli | `gem list` | Display gems installed locally | +| gi | `gem info` | Show information for the given gem | +| giall | `gem info --all` | Display all gem versions | +| gca | `gem cert --add` | Add a trusted certificate | +| gcr | `gem cert --remove` | Remove a trusted certificate | +| gcb | `gem cert --build` | Build private key and self-signed certificate | +| gclup | `gem cleanup -n` | Do not uninstall gem | +| ggi | `gem generate_index` | Generate index file for gem server | +| gh | `gem help` | Provide additional help | +| gl | `gem lock` | Generate a lockdown list of gems | +| go | `gem open` | Open gem source in default editor | +| goe | `gem open -e` | Open gem sources in preferred editor | From e751d2519d586a2c022beeb0b40dfe9b7a1ed6eb Mon Sep 17 00:00:00 2001 From: Sayan Roy Date: Wed, 1 Jul 2020 08:58:27 +0530 Subject: [PATCH 03/88] spacing changed --- plugins/ruby/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ruby/README.md b/plugins/ruby/README.md index a4a9c5036..a2de11991 100644 --- a/plugins/ruby/README.md +++ b/plugins/ruby/README.md @@ -19,7 +19,7 @@ plugins=(... ruby) | gun | `gem uninstall` | Uninstall gems from the local repository | | gli | `gem list` | Display gems installed locally | | gi | `gem info` | Show information for the given gem | -| giall | `gem info --all` | Display all gem versions | +| giall | `gem info --all` | Display all gem versions | | gca | `gem cert --add` | Add a trusted certificate | | gcr | `gem cert --remove` | Remove a trusted certificate | | gcb | `gem cert --build` | Build private key and self-signed certificate | From c6c364317d1762aafc575951c08c2cccce76fffa Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sun, 3 Oct 2021 16:18:33 +0900 Subject: [PATCH 04/88] fix(pyenv): fix pyenv-virtualenv detection under macOS. --- plugins/pyenv/pyenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index d91b5daa7..39897ed16 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -78,7 +78,7 @@ if [[ $FOUND_PYENV -eq 1 ]]; then eval "$(pyenv init - --no-rehash zsh)" # If pyenv-virtualenv exists, load it - if [[ -d "$(pyenv root)/plugins/pyenv-virtualenv" && "$ZSH_PYENV_VIRTUALENV" != false ]]; then + if [[ "$(pyenv commands)" =~ "virtualenv-init" && "$ZSH_PYENV_VIRTUALENV" != false ]]; then eval "$(pyenv virtualenv-init - zsh)" fi From 7152a942802b01cb74d7c0b99f3106f8af17439d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 4 Oct 2021 10:34:13 +0200 Subject: [PATCH 05/88] feat(init): show error and process tree if OMZ is loaded from non-zsh shells (#10234) --- oh-my-zsh.sh | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index bf5902fc8..c389fc963 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -1,8 +1,40 @@ # Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here) [ -n "$ZSH_VERSION" ] || { - # ANSI (\033[m): 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red - printf "\033[1;31mERROR:\033[22m Oh My Zsh can't be loaded from: \033[1m${0#-}\033[22m. " >&2 - printf "You need to run \033[1;4mzsh\033[22;24m instead.\033[0m\n" >&2 + # ANSI formatting function (\033[m) + # 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow + f() { + [ $# -gt 0 ] || return + IFS=";" printf "\033[%sm" $* + } + # If stdout is not a terminal ignore all formatting + [ -t 1 ] || f() { :; } + + ptree() { + # Get process tree of the current process + pid=$$; pids="$pid" + while [ ${pid-0} -ne 1 ] && ppid=$(ps -e -o pid,ppid | awk "\$1 == $pid { print \$2 }"); do + pids="$pids $pid"; pid=$ppid + done + + # Show process tree + case "$(uname)" in + Linux) ps -o ppid,pid,command -f -p $pids 2>/dev/null ;; + Darwin|*) ps -o ppid,pid,command -p $pids 2>/dev/null ;; + esac + + # If ps command failed, try Busybox ps + [ $? -eq 0 ] || ps -o ppid,pid,comm | awk "NR == 1 || index(\"$pids\", \$2) != 0" + } + + { + shell=$(ps -o pid,comm | awk "\$1 == $$ { print \$2 }") + printf "$(f 1 31)Error:$(f 22) Oh My Zsh can't be loaded from: $(f 1)${shell}$(f 22). " + printf "You need to run $(f 1)zsh$(f 22) instead.$(f 0)\n" + printf "$(f 33)Here's the process tree:$(f 22)\n\n" + ptree + printf "$(f 0)\n" + } >&2 + return 1 } From adef0e6081789498156fa11455f3ab4f4d36525c Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 4 Oct 2021 10:43:13 +0200 Subject: [PATCH 06/88] feat(git): run `gitk` in the background in `gk` and `gke` aliases (#9657) --- 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 e53d93b0b..05ef25099 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -90,8 +90,8 @@ plugins=(... git) | 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 -g --pretty=%h) | +| gk | gitk --all --branches &! | +| gke | gitk --all $(git log -g --pretty=%h) &! | | gl | git pull | | glg | git log --stat | | glgp | git log --stat -p | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 76e0faed3..11dff99d9 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -201,8 +201,8 @@ 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 -g --pretty=%h)' +alias gk='\gitk --all --branches &!' +alias gke='\gitk --all $(git log -g --pretty=%h) &!' alias gl='git pull' alias glg='git log --stat' From 3c9743313cc916a6cede71e333eecef4b07ce3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 30 Sep 2021 17:20:22 +0200 Subject: [PATCH 07/88] refactor(updater): change auto-update settings to use `zstyle` --- templates/zshrc.zsh-template | 10 ++++------ tools/check_for_upgrade.sh | 27 +++++++++++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index 4a998c2fc..7cb87078c 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -23,14 +23,12 @@ ZSH_THEME="robbyrussell" # Case-sensitive completion must be off. _ and - will be interchangeable. # HYPHEN_INSENSITIVE="true" -# Uncomment the following line to disable bi-weekly auto-update checks. -# DISABLE_AUTO_UPDATE="true" - -# Uncomment the following line to automatically update without prompting. -# DISABLE_UPDATE_PROMPT="true" +# Uncomment the following lines to change the auto-update behavior +# zstyle ':omz:update' mode disabled # disable automatic updates +# zstyle ':omz:update' mode auto # update automatically without asking # Uncomment the following line to change how often to auto-update (in days). -# export UPDATE_ZSH_DAYS=13 +# zstyle ':omz:update' frequency 13 # Uncomment the following line if pasting URLs and other text is messed up. # DISABLE_MAGIC_FUNCTIONS="true" diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index e87da3487..fa832ffac 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -3,17 +3,30 @@ if [[ -f ~/.zsh-update && ! -f "${ZSH_CACHE_DIR}/.zsh-update" ]]; then mv ~/.zsh-update "${ZSH_CACHE_DIR}/.zsh-update" fi +# Get user's update preferences +# +# Supported update modes: +# - 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 +# - disabled: automatic update is turned off +zstyle -s ':omz:update' mode update_mode || update_mode=prompt + +# Support old-style settings +[[ "$DISABLE_UPDATE_PROMPT" != true ]] || update_mode=auto +[[ "$DISABLE_AUTO_UPDATE" != true ]] || update_mode=disabled + # Cancel update if: # - the automatic update is disabled. # - the current user doesn't have write permissions nor owns the $ZSH directory. # - git is unavailable on the system. -if [[ "$DISABLE_AUTO_UPDATE" = true ]] \ +if [[ "$update_mode" = disabled ]] \ || [[ ! -w "$ZSH" || ! -O "$ZSH" ]] \ || ! command -v git &>/dev/null; then + unset update_mode return fi - function current_epoch() { zmodload zsh/datetime echo $(( EPOCHSECONDS / 60 / 60 / 24 )) @@ -56,7 +69,6 @@ function update_ohmyzsh() { # the shell actually exits what it's running. trap " ret=\$? - unset -f current_epoch update_last_updated_file update_ohmyzsh 2>/dev/null command rm -rf '$ZSH/log/update.lock' return \$ret " EXIT INT QUIT @@ -68,14 +80,14 @@ function update_ohmyzsh() { fi # Number of days before trying to update again - epoch_target=${UPDATE_ZSH_DAYS:-13} + 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 - # Ask for confirmation before updating unless disabled - if [[ "$DISABLE_UPDATE_PROMPT" = true ]]; then + # Ask for confirmation before updating unless in auto mode + if [[ "$update_mode" = auto ]]; then update_ohmyzsh else # input sink to swallow all characters typed before the prompt @@ -92,3 +104,6 @@ function update_ohmyzsh() { esac fi } + +unset update_mode +unset -f current_epoch update_last_updated_file update_ohmyzsh From 0120749a54d147405beebe6f8416da0e4443ebc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 30 Sep 2021 17:22:04 +0200 Subject: [PATCH 08/88] feat(updater): add mode to only remind you to update when it's time (#10187) Fixes #10187 Co-authored-by: NoPreserveRoot --- templates/zshrc.zsh-template | 1 + tools/check_for_upgrade.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index 7cb87078c..58642bc41 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -26,6 +26,7 @@ ZSH_THEME="robbyrussell" # Uncomment the following lines to change the auto-update behavior # zstyle ':omz:update' mode disabled # disable automatic updates # zstyle ':omz:update' mode auto # update automatically without asking +# zstyle ':omz:update' mode reminder # just remind me to update when it's time # Uncomment the following line to change how often to auto-update (in days). # zstyle ':omz:update' frequency 13 diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index fa832ffac..e6a4a3d69 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -89,6 +89,8 @@ function update_ohmyzsh() { # Ask for confirmation before updating unless in auto mode if [[ "$update_mode" = auto ]]; then update_ohmyzsh + elif [[ "$update_mode" = reminder ]]; then + echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`" else # input sink to swallow all characters typed before the prompt # and add a newline if there wasn't one after characters typed From 30d441713c47306fe63c1ce6833ff7a6120c9a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 30 Sep 2021 17:56:02 +0200 Subject: [PATCH 09/88] feat(updater): check if there are updates before prompting (#8387) Fixes #8387 --- tools/check_for_upgrade.sh | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index e6a4a3d69..157b0cce2 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -32,6 +32,41 @@ function current_epoch() { echo $(( EPOCHSECONDS / 60 / 60 / 24 )) } +function is_update_available() { + local branch + branch=${"$(git -C "$ZSH" config --local oh-my-zsh.branch)":-master} + + local remote remote_url remote_repo + remote=${"$(git -C "$ZSH" config --local oh-my-zsh.remote)":-origin} + remote_url=$(git -C "$ZSH" config remote.$remote.url) + + local repo + case "$remote_url" in + https://github.com/*) repo=${${remote_url#https://github.com/}%.git} ;; + git@github.com:*) repo=${${remote_url#git@github.com:}%.git} ;; + *) + # If the remote is not using GitHub we can't check for updates + # Let's assume there are updates + return 0 ;; + esac + + # If the remote repo is not the official one, let's assume there are updates available + [[ "$repo" = ohmyzsh/ohmyzsh ]] || return 0 + local api_url="https://api.github.com/repos/${repo}/commits/${branch}" + + # Get local and remote HEADs and compare them. If we can't get either assume there are updates + local local_head remote_head + local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0 + + remote_head=$(curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null) \ + || remote_head=$(wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null) \ + || remote_head=$(HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null) \ + || return 0 + + # Compare local and remote HEADs + [[ "$local_head" != "$remote_head" ]] +} + function update_last_updated_file() { echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update" } @@ -69,6 +104,8 @@ function update_ohmyzsh() { # 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 @@ -86,6 +123,11 @@ function update_ohmyzsh() { return fi + # Check if there are updates available before proceeding + if ! is_update_available; then + return + fi + # Ask for confirmation before updating unless in auto mode if [[ "$update_mode" = auto ]]; then update_ohmyzsh @@ -108,4 +150,4 @@ function update_ohmyzsh() { } unset update_mode -unset -f current_epoch update_last_updated_file update_ohmyzsh +unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh From c396efbee3217f1d5cc433cd788a67f747a579cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 4 Oct 2021 11:26:39 +0200 Subject: [PATCH 10/88] fix(docker-compose): support Compose V2 `docker compose` command (#10248) --- .../docker-compose/docker-compose.plugin.zsh | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh index 85e03d343..2eba20a09 100644 --- a/plugins/docker-compose/docker-compose.plugin.zsh +++ b/plugins/docker-compose/docker-compose.plugin.zsh @@ -1,28 +1,22 @@ -# Authors: -# https://github.com/tristola -# -# Docker-compose related zsh aliases +# support Compose v2 as docker CLI plugin +command docker compose &>/dev/null && dccmd='docker compose' || dccmd='docker-compose' -# Aliases ################################################################### +alias dco="$dccmd" +alias dcb="$dccmd build" +alias dce="$dccmd exec" +alias dcps="$dccmd ps" +alias dcrestart="$dccmd restart" +alias dcrm="$dccmd rm" +alias dcr="$dccmd run" +alias dcstop="$dccmd stop" +alias dcup="$dccmd up" +alias dcupb="$dccmd up --build" +alias dcupd="$dccmd up -d" +alias dcdn="$dccmd down" +alias dcl="$dccmd logs" +alias dclf="$dccmd logs -f" +alias dcpull="$dccmd pull" +alias dcstart="$dccmd start" +alias dck="$dccmd kill" -# Use dco as alias for docker-compose, since dc on *nix is 'dc - an arbitrary precision calculator' -# https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html - -alias dco='docker-compose' - -alias dcb='docker-compose build' -alias dce='docker-compose exec' -alias dcps='docker-compose ps' -alias dcrestart='docker-compose restart' -alias dcrm='docker-compose rm' -alias dcr='docker-compose run' -alias dcstop='docker-compose stop' -alias dcup='docker-compose up' -alias dcupb='docker-compose up --build' -alias dcupd='docker-compose up -d' -alias dcdn='docker-compose down' -alias dcl='docker-compose logs' -alias dclf='docker-compose logs -f' -alias dcpull='docker-compose pull' -alias dcstart='docker-compose start' -alias dck='docker-compose kill' +unset dccmd From a3289c11f67ec84a6a56d3bde33c1ec191800470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 4 Oct 2021 12:02:08 +0200 Subject: [PATCH 11/88] feat(docker-compose): update completion (4fa72a0, 2021-01-19) Source: https://github.com/docker/compose/blob/4fa72a0/contrib/completion/zsh/_docker-compose Closes #9494 Co-authored-by: "Bakhir A.D" --- plugins/docker-compose/_docker-compose | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/docker-compose/_docker-compose b/plugins/docker-compose/_docker-compose index 808b068a3..c6b733500 100644 --- a/plugins/docker-compose/_docker-compose +++ b/plugins/docker-compose/_docker-compose @@ -121,12 +121,6 @@ __docker-compose_subcommand() { '--parallel[Build images in parallel.]' \ '*:services:__docker-compose_services_from_build' && ret=0 ;; - (bundle) - _arguments \ - $opts_help \ - '--push-images[Automatically push images for any services which have a `build` option specified.]' \ - '(--output -o)'{--output,-o}'[Path to write the bundle file to. Defaults to ".dab".]:file:_files' && ret=0 - ;; (config) _arguments \ $opts_help \ @@ -290,7 +284,7 @@ __docker-compose_subcommand() { (up) _arguments \ $opts_help \ - '(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit.]' \ + '(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit and --attach-dependencies.]' \ $opts_no_color \ $opts_no_deps \ $opts_force_recreate \ @@ -298,6 +292,7 @@ __docker-compose_subcommand() { $opts_no_build \ "(--no-build)--build[Build images before starting containers.]" \ "(-d)--abort-on-container-exit[Stops all containers if any container was stopped. Incompatible with -d.]" \ + "(-d)--attach-dependencies[Attach to dependent containers. Incompatible with -d.]" \ '(-t --timeout)'{-t,--timeout}"[Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10)]:seconds: " \ '--scale[SERVICE=NUM Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.]:service scale SERVICE=NUM: ' \ '--exit-code-from=[Return the exit code of the selected service container. Implies --abort-on-container-exit]:service:__docker-compose_services' \ @@ -341,11 +336,13 @@ _docker-compose() { '(- :)'{-h,--help}'[Get help]' \ '*'{-f,--file}"[${file_description}]:file:_files -g '*.yml'" \ '(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \ + '--env-file[Specify an alternate environment file (default: .env)]:env-file:_files' \ "--compatibility[If set, Compose will attempt to convert keys in v3 files to their non-Swarm equivalent]" \ '(- :)'{-v,--version}'[Print version and exit]' \ '--verbose[Show more output]' \ '--log-level=[Set log level]:level:(DEBUG INFO WARNING ERROR CRITICAL)' \ '--no-ansi[Do not print ANSI control characters]' \ + '--ansi=[Control when to print ANSI control characters]:when:(never always auto)' \ '(-H --host)'{-H,--host}'[Daemon socket to connect to]:host:' \ '--tls[Use TLS; implied by --tlsverify]' \ '--tlscacert=[Trust certs signed only by this CA]:ca path:' \ @@ -359,6 +356,7 @@ _docker-compose() { local -a relevant_compose_flags relevant_compose_repeatable_flags relevant_docker_flags compose_options docker_options relevant_compose_flags=( + "--env-file" "--file" "-f" "--host" "-H" "--project-name" "-p" From 5dbb30342e1b7c4a04c3464bb16ffeb33abde139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 4 Oct 2021 12:45:59 +0200 Subject: [PATCH 12/88] feat(yarn): update completion from zsh-completions (73505e4) Fixes #10195 --- plugins/yarn/_yarn | 184 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 140 insertions(+), 44 deletions(-) diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn index 70e783b86..70ed55929 100644 --- a/plugins/yarn/_yarn +++ b/plugins/yarn/_yarn @@ -32,15 +32,21 @@ # ------- # # * Massimiliano Torromeo +# * Shohei YOSHIDA # # ------------------------------------------------------------------------------ +declare -g _yarn_run_cwd + _commands=( 'access' + 'audit:Checks for known security issues with the installed packages' 'autoclean:Clean and remove unnecessary files from package dependencies' 'cache:List or clean every cached package' - "check:Verify package dependencies agains yarn's lock file" + "check:Verify package dependencies against yarn's lock file" 'config:Manages the yarn configuration files' + 'create:Creates new projects from any create-* starter kits' + 'exec' 'generate-lock-entry:Generates a lock file entry' 'global:Install packages globally on your operating system' 'help:Show information about a command' @@ -50,25 +56,30 @@ _commands=( 'install:Install all the dependencies listed within package.json' 'licenses:List licenses for installed packages' 'link:Symlink a package folder during development' - 'list:List installed packages' 'login:Store registry username and email' 'logout:Clear registry username and email' + 'node:Runs Node with the same version that the one used by Yarn itself' 'outdated:Check for outdated package dependencies' 'owner:Manage package owners' 'pack:Create a compressed gzip archive of package dependencies' + 'policies:Defines project-wide policies for your project' 'publish:Publish a package to the npm registry' 'run:Run a defined package script' 'tag:Add, remove, or list tags on a package' 'team:Maintain team memberships' 'unlink:Unlink a previously created symlink for a package' + 'unplug:Temporarily copies a package outside of the global cache for debugging purposes' 'version:Update the package version' 'versions:Display version information of currently installed Yarn, Node.js, and its dependencies' 'why:Show information about why a package is installed' + 'workspace' + 'workspaces:Show information about your workspaces' ) _global_commands=( 'add:Installs a package and any packages that it depends on' 'bin:Displays the location of the yarn bin folder' + 'list:List installed packages' 'remove:Remove installed package from dependencies updating package.json' 'upgrade:Upgrades packages to their latest version based on the specified range' 'upgrade-interactive:Interactively upgrade packages' @@ -76,7 +87,12 @@ _global_commands=( _yarn_commands_scripts() { local -a scripts - scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g')) + if [[ -n $opt_args[--cwd] ]]; then + scripts=($(cd $opt_args[--cwd] && yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g')) + else + scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g')) + fi + _describe 'command or script' _commands -- _global_commands -- scripts } @@ -85,7 +101,11 @@ _yarn_scripts() { local -a scriptNames scriptCommands local i runJSON - runJSON=$(yarn run --json 2>/dev/null) + if [[ -n $_yarn_run_cwd ]]; then + runJSON=$(cd $_yarn_run_cwd && yarn run --json 2>/dev/null) + else + runJSON=$(yarn run --json 2>/dev/null) + fi # Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement # pattern as a newline. See https://superuser.com/q/307165 binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON")) @@ -96,7 +116,7 @@ _yarn_scripts() { scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}") done - commands=($scripts $binaries) + commands=('env' $scripts $binaries) _describe 'command' commands } @@ -110,6 +130,17 @@ _yarn_commands() { _describe 'command' _commands -- _global_commands } +_yarn_add_files() { + if compset -P "(file|link):"; then + _files + fi +} + +_yarn_workspaces() { + local -a workspaces=(${(@f)$(yarn workspaces info |sed -n -e 's/^ "\([^"]*\)": {/\1/p')}) + _describe 'workspace' workspaces +} + _yarn() { local context state state_descr line typeset -A opt_args @@ -118,37 +149,51 @@ _yarn() { '(-h --help)'{-h,--help}'[output usage information]' \ '(-V --version)'{-V,--version}'[output the version number]' \ '--verbose[output verbose messages on internal operations]' \ - '--offline[trigger an error if any required dependencies are not available in local cache]' \ - '--prefer-offline[use network only if dependencies are not available in local cache]' \ - '--strict-semver' \ - '--json' \ - "--ignore-scripts[don't run lifecycle scripts]" \ - '--har[save HAR output of network traffic]' \ - '--ignore-platform[ignore platform checks]' \ - '--ignore-engines[ignore engines check]' \ - '--ignore-optional[ignore optional dependencies]' \ - '--force[install and build packages even if they were built before, overwrite lockfile]' \ - '--skip-integrity-check[run install without checking if node_modules is installed]' \ - '--check-files[install will verify file tree of packages for consistency]' \ - "--no-bin-links[don't generate bin links when setting up packages]" \ - '--flat[only allow one version of a package]' \ - '(--prod --production)'{--prod,--production} \ - "--no-lockfile[don't read or generate a lockfile]" \ - "--pure-lockfile[don't generate a lockfile]" \ - "--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \ - '--link-duplicates[create hardlinks to the repeated modules in node_modules]' \ - '--global-folder=[modules folder]:folder:_files -/' \ - '--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \ '--cache-folder=[specify a custom folder to store the yarn cache]:folder:_files -/' \ + '--check-files[install will verify file tree of packages for consistency]' \ + '--cwd=[working directory to use]:path:_files -/' \ + "(--enable-pnp --pnp)--disable-pnp[disable the Plug'n'Play installation]" \ + '(--no-emoji)--emoji=[enable emoji in output(default: false)]:enabled:(true false)' \ + '(--emoji)--no-emoji[disable emoji in output]' \ + '(--disable-pnp)'{--enable-pnp,--pnp}"[enable the Plug'n'Play installation]" \ + '--flat[only allow one version of a package]' \ + '--focus[Focus on a single workspace by installing remote copies of its sibiling workspaces]' \ + '--force[install and build packages even if they were built before, overwrite lockfile]' \ + "--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \ + '--global-folder=[modules folder]:folder:_files -/' \ + '--har[save HAR output of network traffic]' \ + '--https-proxy=[HTTPS proxy]:host:_hosts' \ + '--ignore-engines[ignore engines check]' \ + "--ignore-scripts[don't run lifecycle scripts]" \ + '--ignore-optional[ignore optional dependencies]' \ + '--ignore-platform[ignore platform checks]' \ + '--json[format Yarn log messages as lines of JSON]' \ + '--link-duplicates[create hardlinks to the repeated modules in node_modules]' \ + '--link-folder=[specify a custom folder to store global links]' \ + '--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \ '--mutex=[use a mutex to ensure only one yarn instance is executing]:type[\:specifier]' \ - '--no-emoji[disable emoji in output]' \ - '(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \ - '--proxy=:host:_hosts' \ - '--https-proxy=:host:_hosts' \ - '--no-progress[disable progress bar]' \ '--network-concurrency=[maximum number of concurrent network requests]:number' \ '--network-timeout=[TCP timeout for network requests]:milliseconds' \ + "--no-bin-links[don't generate bin links when setting up packages]" \ + '--no-default-rc[prevent Yarn from automatically detecting yarnrc and npmrc files]' \ + "--no-lockfile[don't read or generate a lockfile]" \ '--non-interactive[do not show interactive prompts]' \ + '--no-node-version-check[do not warn when using a potentially unsupported Node version]' \ + '--no-progress[disable progress bar]' \ + '--offline[trigger an error if any required dependencies are not available in local cache]' \ + '--otp=[one-time password for two factor authentication]:otpcode' \ + '--prefer-offline[use network only if dependencies are not available in local cache]' \ + '--preferred-cache-folder=[specify a custom folder to store the yarn cache if possible]:folder:_files -/' \ + '(--prod --production)'{--prod,--production}'[install only production dependencies]' \ + '--proxy=[HTTP proxy]:host:_hosts' \ + "--pure-lockfile[don't generate a lockfile]" \ + '--registry=[override configuration registry]:url:_urls' \ + '(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \ + '--scripts-prepend-node-path=[prepend the node executable dir to the PATH in scripts]:bool:(true false)' \ + '--skip-integrity-check[run install without checking if node_modules is installed]' \ + "--strict-semver[don't compare semver loosely]" \ + '--update-checksum[update package checksums from current repository]' \ + '--use-yarnrc=[specifies a yarnrc that Yarn should use]:yarnrc:_files' \ '1: :_yarn_commands_scripts' \ '*:: :->command_args' @@ -173,18 +218,29 @@ _yarn() { '(-O --optional)'{-O,--optional}'[install packages in optionalDependencies]' \ '(-E --exact)'{-E,--exact}'[install packages as exact versions]' \ '(-T --tilde)'{-T,--tilde}'[install the most recent release of the packages that have the same minor version]' \ - '*:package-name:' + '(--ignore-workspace-root-check -W)'{--ignore-workspace-root-check,-W}'[allows a package to be installed at the workspaces root]' \ + '--audit[checks for known security issues with the installed packages]' \ + '*:package-name:_yarn_add_files' + ;; + + audit) + _arguments \ + '--verbose[output verbose message]' \ + '--json[format Yarn log messages as lines of JSON]' \ + '--level=[only print advisories with severity greater than or equal to]:level:(info low moderate high critical)' \ + '--groups=[only audit dependencies from listed groups]:groups:->groups_args' ;; cache) _arguments \ - '1: :(ls dir clean)' + '1: :(list dir clean)' \ + '*:: :->cache_args' ;; check) _arguments \ - '--integrity' \ - '--verify-tree' + '--integrity[Verifies that versions and hashed values of the package contents in package.json]' \ + '--verify-tree[Recursively verifies that the dependencies in package.json are present in node_modules]' ;; config) @@ -223,12 +279,13 @@ _yarn() { list) _arguments \ - '--depth[Limit the depth of the shown dependencies]:depth' + '--depth=[Limit the depth of the shown dependencies]:depth' \ + '--pattern=[filter the list of dependencies by the pattern]' ;; owner) _arguments \ - '1: :(ls add rm)' \ + '1: :(list add rm)' \ '*:: :->owner_args' ;; @@ -247,12 +304,22 @@ _yarn() { '1: :_files' ;; + policies) + _arguments \ + '1: :(set-version)' + ;; + remove|upgrade) _arguments \ '*:package:' ;; run) + if [[ -n $opt_args[--cwd] ]]; then + _yarn_run_cwd=$opt_args[--cwd] + else + _yarn_run_cwd='' + fi _arguments \ '1: :_yarn_scripts' \ '*:: :_default' @@ -260,26 +327,33 @@ _yarn() { tag) _arguments \ - '1: :(ls add rm)' \ + '1: :(lists add rm)' \ '*:: :->tag_args' ;; team) _arguments \ - '1: :(create destroy add rm ls)' \ + '1: :(create destroy add rm list)' \ '*:: :->team_args' ;; upgrade-interactive) _arguments \ - '--latest:use the version tagged latest in the registry:' + '--latest[use the version tagged latest in the registry]' ;; version) _arguments \ - '--new-version:version:' \ - '--message:message:' \ - '--no-git-tag-version' + '--new-version[create a new version using an interactive session to prompt you]:version:' \ + '--major[creates a new version by incrementing the major version]' \ + '--minor[creates a new version by incrementing the minor version]' \ + '--patch[creates a new version by incrementing the patch version]' \ + '--premajor[creates a new prerelease version by incrementing the major version]' \ + '--preminor[creates a new prerelease version by incrementing the minor version]' \ + '--prepatch[creates a new prerelease version by incrementing the patch version]' \ + '--prerelease[increments the prerelease version number keeping the main version]' \ + '--no-git-tag-version[creates a new version without creating a git tag]' \ + '--no-commit-hooks[bypasses running commit hooks when committing the new version]' ;; why) @@ -287,7 +361,19 @@ _yarn() { '1:query:_files' ;; - *) + workspace) + _arguments \ + '1:workspace:_yarn_workspaces' \ + '*:: :_yarn_global_commands' + ;; + + workspaces) + _arguments \ + '--json[format Yarn log messages as lines of JSON]' \ + '1:commands:(info run)' + ;; + + *) _default ;; esac @@ -295,6 +381,12 @@ _yarn() { esac case $state in + cache_args) + if [[ $words[1] == "list" ]]; then + _arguments \ + '--pattern=[print out every cached package that matches the pattern]:pattern:' + fi + ;; config_args) case $words[1] in get|delete) @@ -310,6 +402,10 @@ _yarn() { ;; esac ;; + groups_args) + local dependency_groups=(devDependencies dependencies optionalDependencies peerDependencies bundledDependencies) + _values -s ',' 'groups' $dependency_groups + ;; owner_args) case $words[1] in From d304635b8c70c6d9400d1246f1446eb76c64406c Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Mon, 4 Oct 2021 13:07:55 +0200 Subject: [PATCH 13/88] feat(yarn): add `ylnf` alias to fix linting problems (#9219) --- plugins/yarn/README.md | 1 + plugins/yarn/yarn.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/yarn/README.md b/plugins/yarn/README.md index fd748b742..9a0d1708d 100644 --- a/plugins/yarn/README.md +++ b/plugins/yarn/README.md @@ -28,6 +28,7 @@ plugins=(... yarn) | yi | `yarn init` | Interactively creates or updates a package.json file | | yin | `yarn install` | Install dependencies defined in `package.json` | | yln | `yarn lint` | Run the lint script defined in `package.json` | +| ylnf | `yarn lint --fix` | Run the lint script defined in `package.json`to automatically fix problems | | yls | `yarn list` | List installed packages | | yout | `yarn outdated` | Check for outdated package dependencies | | yp | `yarn pack` | Create a compressed gzip archive of package dependencies | diff --git a/plugins/yarn/yarn.plugin.zsh b/plugins/yarn/yarn.plugin.zsh index 4a5192c61..a240cb88e 100644 --- a/plugins/yarn/yarn.plugin.zsh +++ b/plugins/yarn/yarn.plugin.zsh @@ -13,6 +13,7 @@ alias yh="yarn help" alias yi="yarn init" alias yin="yarn install" alias yln="yarn lint" +alias ylnf="yarn lint --fix" alias yls="yarn list" alias yout="yarn outdated" alias yp="yarn pack" From 717ece07efea5e74e6d18bd647387607a6f5fc49 Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Mon, 4 Oct 2021 09:55:18 -0400 Subject: [PATCH 14/88] feat(mercurial): add `hg log` aliases (#9979) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Kielan --- plugins/mercurial/README.md | 3 ++- plugins/mercurial/mercurial.plugin.zsh | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/mercurial/README.md b/plugins/mercurial/README.md index 80ea2de31..756964896 100644 --- a/plugins/mercurial/README.md +++ b/plugins/mercurial/README.md @@ -30,7 +30,8 @@ plugins=(... mercurial) | `hgl` | `hg pull -u` | | `hglr` | `hg pull --rebase` | | `hgo` | `hg outgoing` | - +| `hglg` | `hg log --stat -v` | +| `hglgp`| `hg log --stat -p -v` | ## Prompt usage - Switch to a theme which uses `hg_prompt_info` diff --git a/plugins/mercurial/mercurial.plugin.zsh b/plugins/mercurial/mercurial.plugin.zsh index f4efc2b4a..e098664c0 100644 --- a/plugins/mercurial/mercurial.plugin.zsh +++ b/plugins/mercurial/mercurial.plugin.zsh @@ -17,6 +17,8 @@ alias hgi='hg incoming' alias hgl='hg pull -u' alias hglr='hg pull --rebase' alias hgo='hg outgoing' +alias hglg='hg log --stat -v' +alias hglgp='hg log --stat -p -v' function in_hg() { if $(hg branch > /dev/null 2>&1); then From 56ab66b19429e5609e4331a987368ce2c844c7be Mon Sep 17 00:00:00 2001 From: Dani Torramilans Date: Mon, 4 Oct 2021 15:57:03 +0200 Subject: [PATCH 15/88] docs(python): update README to include new `py` alias (#9995) --- plugins/python/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/python/README.md b/plugins/python/README.md index 0180218a2..b95ffe679 100644 --- a/plugins/python/README.md +++ b/plugins/python/README.md @@ -11,6 +11,7 @@ plugins=(... python) | Command | Description | |------------------|---------------------------------------------------------------------------------| +| `py` | Runs `python` | | `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv | | `pyfind` | Finds .py files recursively in the current directory | | `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one | From be4a952972de03d501fbff79435ae41594f06bac Mon Sep 17 00:00:00 2001 From: Monson Shao Date: Fri, 3 Jul 2020 12:16:58 +0800 Subject: [PATCH 16/88] feat(cli)!: add `omz reload` command and deprecate `zsh_reload` plugin (#9078) BREAKING CHANGE: the `zsh_reload` plugin is deprecated. Instead of using its `src` function, use `omz reload` or `exec zsh` to reload zsh after making changes to your `.zshrc` file. Closes #9078 --- lib/cli.zsh | 12 ++++++++++++ plugins/zsh_reload/README.md | 22 +-------------------- plugins/zsh_reload/zsh_reload.plugin.zsh | 25 +++++------------------- 3 files changed, 18 insertions(+), 41 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index cadc82e27..773891fce 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -26,6 +26,7 @@ function _omz { 'help:Usage information' 'plugin:Manage plugins' 'pr:Manage Oh My Zsh Pull Requests' + 'reload:Reload the current zsh session' 'theme:Manage themes' 'update:Update Oh My Zsh' ) @@ -159,6 +160,7 @@ Available commands: changelog Print the changelog plugin Manage plugins pr Manage Oh My Zsh Pull Requests + reload Reload the current zsh session theme Manage themes update Update Oh My Zsh @@ -598,6 +600,16 @@ function _omz::pr::test { ) } +function _omz::reload { + # Delete current completion cache + command rm -f $_comp_dumpfile $ZSH_COMPDUMP + + # Old zsh versions don't have ZSH_ARGZERO + local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}" + # Check whether to run a login shell + [[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh" +} + function _omz::theme { (( $# > 0 && $+functions[_omz::theme::$1] )) || { cat >&2 < Date: Mon, 4 Oct 2021 17:14:34 +0200 Subject: [PATCH 17/88] fix(per-directory-history): fix use of global history on shell start (#9008) Updated from upstream: https://github.com/jimhester/per-directory-history/blob/d2e291d/per-directory-history.zsh Fixes #9007 Closese #9008 Co-authored-by: Sebastian Marsching --- .../per-directory-history.zsh | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/plugins/per-directory-history/per-directory-history.zsh b/plugins/per-directory-history/per-directory-history.zsh index 41de2f91d..7cd673cdb 100644 --- a/plugins/per-directory-history/per-directory-history.zsh +++ b/plugins/per-directory-history/per-directory-history.zsh @@ -32,7 +32,7 @@ # # Copyright (c) 2014 Jim Hester # -# This software is provided 'as-is', without any express or implied warranty. +# This software is provided 'as-is', without any express or implied warranty. # In no event will the authors be held liable for any damages arising from the # use of this software. # @@ -57,6 +57,7 @@ #------------------------------------------------------------------------------- [[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history" +[[ -z $HISTORY_START_WITH_GLOBAL ]] && HISTORY_START_WITH_GLOBAL=false [[ -z $PER_DIRECTORY_HISTORY_TOGGLE ]] && PER_DIRECTORY_HISTORY_TOGGLE='^G' #------------------------------------------------------------------------------- @@ -66,9 +67,11 @@ function per-directory-history-toggle-history() { if [[ $_per_directory_history_is_global == true ]]; then _per-directory-history-set-directory-history + _per_directory_history_is_global=false print -n "\nusing local history" else _per-directory-history-set-global-history + _per_directory_history_is_global=true print -n "\nusing global history" fi zle .push-line @@ -114,43 +117,58 @@ function _per-directory-history-addhistory() { true else print -Sr -- "${1%%$'\n'}" + # instantly write history if set options require it. + if [[ -o share_history ]] || \ + [[ -o inc_append_history ]] || \ + [[ -o inc_append_history_time ]]; then + fc -AI $HISTFILE + fc -AI $_per_directory_history_directory + fi fc -p $_per_directory_history_directory fi } +function _per-directory-history-precmd() { + if [[ $_per_directory_history_initialized == false ]]; then + _per_directory_history_initialized=true + + if [[ $HISTORY_START_WITH_GLOBAL == true ]]; then + _per-directory-history-set-global-history + _per_directory_history_is_global=true + else + _per-directory-history-set-directory-history + _per_directory_history_is_global=false + fi + fi +} function _per-directory-history-set-directory-history() { - if [[ $_per_directory_history_is_global == true ]]; then - fc -AI $HISTFILE - local original_histsize=$HISTSIZE - HISTSIZE=0 - HISTSIZE=$original_histsize - if [[ -e "$_per_directory_history_directory" ]]; then - fc -R "$_per_directory_history_directory" - fi + fc -AI $HISTFILE + local original_histsize=$HISTSIZE + HISTSIZE=0 + HISTSIZE=$original_histsize + if [[ -e "$_per_directory_history_directory" ]]; then + fc -R "$_per_directory_history_directory" fi - _per_directory_history_is_global=false -} -function _per-directory-history-set-global-history() { - if [[ $_per_directory_history_is_global == false ]]; then - fc -AI $_per_directory_history_directory - local original_histsize=$HISTSIZE - HISTSIZE=0 - HISTSIZE=$original_histsize - if [[ -e "$HISTFILE" ]]; then - fc -R "$HISTFILE" - fi - fi - _per_directory_history_is_global=true } +function _per-directory-history-set-global-history() { + fc -AI $_per_directory_history_directory + local original_histsize=$HISTSIZE + HISTSIZE=0 + HISTSIZE=$original_histsize + if [[ -e "$HISTFILE" ]]; then + fc -R "$HISTFILE" + fi +} + +mkdir -p ${_per_directory_history_directory:h} #add functions to the exec list for chpwd and zshaddhistory autoload -U add-zsh-hook add-zsh-hook chpwd _per-directory-history-change-directory add-zsh-hook zshaddhistory _per-directory-history-addhistory +add-zsh-hook precmd _per-directory-history-precmd -#start in directory mode -mkdir -p ${_per_directory_history_directory:h} -_per_directory_history_is_global=true -_per-directory-history-set-directory-history +# set initialized flag to false +_per_directory_history_initialized=false From 714399a7c33963384ef7f21ce21f6d134416f9aa Mon Sep 17 00:00:00 2001 From: fanuch Date: Sun, 6 Oct 2019 13:19:14 +1100 Subject: [PATCH 18/88] feat(git): add `gccd` alias to clone and cd into git repository (#8220) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #8216 Closes #8220 Co-authored-by: Nelson Estevão --- plugins/git/README.md | 1 + plugins/git/git.plugin.zsh | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index 05ef25099..b68dc552e 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -47,6 +47,7 @@ plugins=(... git) | gcb | git checkout -b | | gcf | git config --list | | gcl | git clone --recurse-submodules | +| gccd | git clone --recurse-submodules "$@" && cd "$(basename $_ .git)" | | gclean | git clean -id | | gpristine | git reset --hard && git clean -dffx | | gcm | git checkout $(git_main_branch) | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 11dff99d9..f2431fde5 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -97,6 +97,13 @@ alias gcas='git commit -a -s' alias gcasm='git commit -a -s -m' alias gcb='git checkout -b' alias gcf='git config --list' + +function gccd() { + command git clone --recurse-submodules "$@" + [[ -d "$_" ]] && cd "$_" || cd "${${_:h}%.git}" +} +compdef _git gccd=git-clone + alias gcl='git clone --recurse-submodules' alias gclean='git clean -id' alias gpristine='git reset --hard && git clean -dffx' From a54148a43e14f1ba8d4f602ce7d452111e70ad4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 4 Oct 2021 17:51:22 +0200 Subject: [PATCH 19/88] fix(init): rename function `f` due to clash with `f` alias (#10260) Fixes #10260 --- oh-my-zsh.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index c389fc963..b388b341d 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -2,14 +2,14 @@ [ -n "$ZSH_VERSION" ] || { # ANSI formatting function (\033[m) # 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow - f() { + omz_f() { [ $# -gt 0 ] || return IFS=";" printf "\033[%sm" $* } # If stdout is not a terminal ignore all formatting - [ -t 1 ] || f() { :; } + [ -t 1 ] || omz_f() { :; } - ptree() { + omz_ptree() { # Get process tree of the current process pid=$$; pids="$pid" while [ ${pid-0} -ne 1 ] && ppid=$(ps -e -o pid,ppid | awk "\$1 == $pid { print \$2 }"); do @@ -28,11 +28,11 @@ { shell=$(ps -o pid,comm | awk "\$1 == $$ { print \$2 }") - printf "$(f 1 31)Error:$(f 22) Oh My Zsh can't be loaded from: $(f 1)${shell}$(f 22). " - printf "You need to run $(f 1)zsh$(f 22) instead.$(f 0)\n" - printf "$(f 33)Here's the process tree:$(f 22)\n\n" - ptree - printf "$(f 0)\n" + printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded from: $(omz_f 1)${shell}$(omz_f 22). " + printf "You need to run $(omz_f 1)zsh$(omz_f 22) instead.$(omz_f 0)\n" + printf "$(omz_f 33)Here's the process tree:$(omz_f 22)\n\n" + omz_ptree + printf "$(omz_f 0)\n" } >&2 return 1 From b621eee21f269498d072ca60823ecde9777821bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 5 Oct 2021 11:58:39 +0200 Subject: [PATCH 20/88] fix(cli): fix zsh array syntax for szh 5.0.2 --- lib/cli.zsh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 773891fce..4b14360c1 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -91,7 +91,8 @@ function _omz { # NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which # has a space after them. This is to avoid removing plugins partially passed, which makes # the completion not add a space after the completed plugin. - local -a args=(${words[4,$(( CURRENT - 1))]}) + local -a args + args=(${words[4,$(( CURRENT - 1))]}) valid_plugins=(${valid_plugins:|args}) _describe 'plugin' valid_plugins ;; @@ -214,7 +215,7 @@ function _omz::plugin::disable { fi # Check that plugin is in $plugins - local -a dis_plugins=() + local -a dis_plugins for plugin in "$@"; do if [[ ${plugins[(Ie)$plugin]} -eq 0 ]]; then _omz::log warn "plugin '$plugin' is not enabled." @@ -303,7 +304,7 @@ function _omz::plugin::enable { fi # Check that plugin is not in $plugins - local -a add_plugins=() + local -a add_plugins for plugin in "$@"; do if [[ ${plugins[(Ie)$plugin]} -ne 0 ]]; then _omz::log warn "plugin '$plugin' is already enabled." @@ -424,10 +425,8 @@ function _omz::plugin::load { return 1 fi - local plugins=("$@") local plugin base has_completion=0 - - for plugin in $plugins; do + for plugin in "$@"; do if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then base="$ZSH_CUSTOM/plugins/$plugin" elif [[ -d "$ZSH/plugins/$plugin" ]]; then From f793baf370bdfcbe3004f7746f3c945feefb56c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 5 Oct 2021 11:59:09 +0200 Subject: [PATCH 21/88] fix(jsontools): fix broken conditional in zsh 5.0.2 (#10262) Fixes #10262 --- plugins/jsontools/jsontools.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/jsontools/jsontools.plugin.zsh b/plugins/jsontools/jsontools.plugin.zsh index ed45cfa8e..857ca0ec9 100644 --- a/plugins/jsontools/jsontools.plugin.zsh +++ b/plugins/jsontools/jsontools.plugin.zsh @@ -7,7 +7,7 @@ if [[ -n "$JSONTOOLS_METHOD" ]]; then fi # If method undefined, find the first one that is installed -if [[ ! -v JSONTOOLS_METHOD ]]; then +if [[ -z "$JSONTOOLS_METHOD" ]]; then for JSONTOOLS_METHOD in node python ruby; do # If method found, break out of loop (( $+commands[$JSONTOOLS_METHOD] )) && break @@ -16,7 +16,7 @@ if [[ ! -v JSONTOOLS_METHOD ]]; then done # If no methods were found, exit the plugin - [[ -v JSONTOOLS_METHOD ]] || return 1 + [[ -n "$JSONTOOLS_METHOD" ]] || return 1 fi # Define json tools for each method From 49bc55f966d91b2a407c883cf1d0f21d0cdd9f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 5 Oct 2021 13:23:05 +0200 Subject: [PATCH 22/88] fix(docker-compose): fix for slow `docker compose` call on remote Docker contexts (#10264) Fixes #10264 Co-authored-by: Frederick Zhang --- plugins/docker-compose/docker-compose.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh index 2eba20a09..13985fc82 100644 --- a/plugins/docker-compose/docker-compose.plugin.zsh +++ b/plugins/docker-compose/docker-compose.plugin.zsh @@ -1,5 +1,7 @@ # support Compose v2 as docker CLI plugin -command docker compose &>/dev/null && dccmd='docker compose' || dccmd='docker-compose' +DOCKER_CONTEXT=default command docker compose &>/dev/null \ + && dccmd='docker compose' \ + || dccmd='docker-compose' alias dco="$dccmd" alias dcb="$dccmd build" From e5b9b80008a2fd71b441ef39fe620ed47dad82e5 Mon Sep 17 00:00:00 2001 From: Dapeng Gao <31944689+dpgao@users.noreply.github.com> Date: Tue, 5 Oct 2021 19:54:53 +0800 Subject: [PATCH 23/88] fix(gpg-agent): correctly overwrite `$SSH_AUTH_SOCK` and other improvements (#7059) --- plugins/gpg-agent/README.md | 2 +- plugins/gpg-agent/gpg-agent.plugin.zsh | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/gpg-agent/README.md b/plugins/gpg-agent/README.md index 9c1e6d2cc..8eeb94f92 100644 --- a/plugins/gpg-agent/README.md +++ b/plugins/gpg-agent/README.md @@ -2,7 +2,7 @@ Enables [GPG's gpg-agent](https://www.gnupg.org/documentation/manuals/gnupg/) if it is not running. -To use it, add gpg-agent to the plugins array of your zshrc file: +To use it, add `gpg-agent` to the plugins array of your zshrc file: ```zsh plugins=(... gpg-agent) diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh index 3e24c2527..0adc8de5d 100644 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -1,16 +1,17 @@ -# Enable gpg-agent if it is not running- -# --use-standard-socket will work from version 2 upwards - -AGENT_SOCK=$(gpgconf --list-dirs | grep agent-socket | cut -d : -f 2) - -if [[ ! -S $AGENT_SOCK ]]; then - gpg-agent --daemon --use-standard-socket &>/dev/null -fi export GPG_TTY=$TTY -# Set SSH to use gpg-agent if it's enabled -GNUPGCONFIG="${GNUPGHOME:-"$HOME/.gnupg"}/gpg-agent.conf" -if [[ -r $GNUPGCONFIG ]] && command grep -q enable-ssh-support "$GNUPGCONFIG"; then - export SSH_AUTH_SOCK="$AGENT_SOCK.ssh" +# Fix for passphrase prompt on the correct tty +# See https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002denable_002dssh_002dsupport +function _gpg-agent_update-tty_preexec { + gpg-connect-agent updatestartuptty /bye &>/dev/null +} +autoload -U add-zsh-hook +add-zsh-hook preexec _gpg-agent_update-tty_preexec + +# If enable-ssh-support is set, fix ssh agent integration +if [[ $(gpgconf --list-options gpg-agent | awk -F: '$1=="enable-ssh-support" {print $10}') = 1 ]]; then unset SSH_AGENT_PID + if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then + export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" + fi fi From 53c9661b003b91e8af356c3ecbb95a025ffcd412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 5 Oct 2021 16:45:49 +0200 Subject: [PATCH 24/88] refactor(chucknorris): refresh plugin code --- plugins/chucknorris/README.md | 4 +-- plugins/chucknorris/chucknorris.plugin.zsh | 38 ++++++++++------------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/plugins/chucknorris/README.md b/plugins/chucknorris/README.md index 35f989180..b51875de9 100644 --- a/plugins/chucknorris/README.md +++ b/plugins/chucknorris/README.md @@ -1,8 +1,6 @@ # chucknorris -Chuck Norris fortunes plugin for oh-my-zsh. Perfectly suitable as MOTD. - -**Maintainers**: [apjanke](https://github.com/apjanke) [maff](https://github.com/maff) +Chuck Norris fortunes plugin for Oh My Zsh. Perfectly suitable as MOTD. To use it add `chucknorris` to the plugins array in you zshrc file. diff --git a/plugins/chucknorris/chucknorris.plugin.zsh b/plugins/chucknorris/chucknorris.plugin.zsh index 1dbb04ef0..b90abe320 100644 --- a/plugins/chucknorris/chucknorris.plugin.zsh +++ b/plugins/chucknorris/chucknorris.plugin.zsh @@ -1,28 +1,24 @@ -# chucknorris: Chuck Norris fortunes - -# Automatically generate or update Chuck's compiled fortune data file -# $0 must be used outside a local function. This variable name is unlikly to collide. -CHUCKNORRIS_PLUGIN_DIR=${0:h} - () { -local DIR=$CHUCKNORRIS_PLUGIN_DIR/fortunes -if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then - # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default - local strfile=strfile - if ! which strfile &>/dev/null && [[ -f /usr/sbin/strfile ]]; then - strfile=/usr/sbin/strfile + # %x: name of file containing code being executed + local fortunes_dir="${${(%):-%x}:h}/fortunes" + + # Aliases + alias chuck="fortune -a $fortunes_dir" + alias chuck_cow="chuck | cowthink" + + # Automatically generate or update Chuck's compiled fortune data file + if [[ "$fortunes_dir/chucknorris" -ot "$fortunes_dir/chucknorris.dat" ]]; then + return fi - if which $strfile &> /dev/null; then - $strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null - else + + # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default + local strfile="${commands[strfile]:-/usr/sbin/strfile}" + if [[ ! -x "$strfile" ]]; then echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2 echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2 + return fi -fi -# Aliases -alias chuck="fortune -a $DIR" -alias chuck_cow="chuck | cowthink" + # Generate the compiled fortune data file + $strfile "$fortunes_dir/chucknorris" "$fortunes_dir/chucknorris.dat" >/dev/null } - -unset CHUCKNORRIS_PLUGIN_DIR From 9e41cffbf8515ba64ab2cf21b49dc78949707553 Mon Sep 17 00:00:00 2001 From: Ryan McAllen Date: Tue, 5 Oct 2021 10:47:28 -0400 Subject: [PATCH 25/88] chore(chucknorris): add a few more Chuck Norris quotes (#10210) --- plugins/chucknorris/fortunes/chucknorris | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/chucknorris/fortunes/chucknorris b/plugins/chucknorris/fortunes/chucknorris index 0ddb6c03b..6ba5bb9b5 100644 --- a/plugins/chucknorris/fortunes/chucknorris +++ b/plugins/chucknorris/fortunes/chucknorris @@ -558,3 +558,11 @@ You know Chuck Norris' pet lizard, right? Last I heard, he was in the movie "God % http://chucknorrisfacts.com/ is built in Drupal because Chuck Norris knows a good CMS when he sees one. % +Chuck Norris made the first Giraffe by uppercutting a horse. +% +Chuck Norris can hear sign language. +% +Chuck Norris make onions cry. +% +Chuck Norris doesn't shake hands, he makes them tremble. +% From 63b7e5767d551b1d839888a7216f2bed01e8eb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 5 Oct 2021 16:56:00 +0200 Subject: [PATCH 26/88] fix(changelog): don't parse commits of ignored types --- tools/changelog.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 7329a9526..71caa2b6c 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -120,7 +120,7 @@ function parse-commit { fi # Parse commit with hash $1 - local hash="$1" subject body warning rhash + local hash="$1" subject body type warning rhash subject="$(command git show -s --format=%s $hash)" body="$(command git show -s --format=%b $hash)" @@ -132,8 +132,12 @@ function parse-commit { # commit body # [BREAKING CHANGE: warning] + # if commit type is not going to be displayed, do nothing else + type="$(commit:type "$subject")" + (( ${MAIN_TYPES[(Ie)$type]} || ${OTHER_TYPES[(Ie)$type]} )) || return + # commits holds the commit type - commits[$hash]="$(commit:type "$subject")" + commits[$hash]="$type" # scopes holds the commit scope scopes[$hash]="$(commit:scope "$subject")" # subjects holds the commit subject From bf7c1b160d164f080a276e6ed6b21ef8008079ee Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 6 Oct 2021 10:13:38 +0200 Subject: [PATCH 27/88] fix(git)!: rename `gdu` alias to `gdup` (#10263) BREAKING CHANGE: the `gdu` alias has been renamed to `gdup` to avoid a conflict with `go disk usage` (https://github.com/dundee/gdu). --- 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 b68dc552e..12e3676e8 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -67,7 +67,7 @@ plugins=(... git) | gds | git diff --staged | | gdt | git diff-tree --no-commit-id --name-only -r | | gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)*.lock" | -| gdu | git diff @{u} | +| gdup | git diff @{upstream} | | gdv | git diff -w $@ \| view - | | gdw | git diff --word-diff | | gf | git fetch | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index f2431fde5..5c5db9972 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -126,7 +126,7 @@ 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 gdu='git diff @{u}' +alias gdup='git diff @{upstream}' alias gdw='git diff --word-diff' function gdnolock() { From 7418814677a1b64d584d84be03fbfe38c7760e61 Mon Sep 17 00:00:00 2001 From: Ryan Zegray Date: Wed, 6 Oct 2021 04:14:22 -0400 Subject: [PATCH 28/88] feat(z): update z to latest version (#10267) --- plugins/z/z.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/z/z.sh b/plugins/z/z.sh index 13008a60e..67f504e27 100644 --- a/plugins/z/z.sh +++ b/plugins/z/z.sh @@ -42,6 +42,8 @@ _z() { [ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return _z_dirs () { + [ -f "$datafile" ] || return + local line while read line; do # only count directories @@ -54,14 +56,16 @@ _z() { if [ "$1" = "--add" ]; then shift - # $HOME isn't worth matching - [ "$*" = "$HOME" ] && return + # $HOME and / aren't worth matching + [ "$*" = "$HOME" -o "$*" = '/' ] && return # don't track excluded directory trees - local exclude - for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do - case "$*" in "$exclude*") return;; esac - done + if [ ${#_Z_EXCLUDE_DIRS[@]} -gt 0 ]; then + local exclude + for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do + case "$*" in "$exclude"*) return;; esac + done + fi # maintain the data file local tempfile="$datafile.$RANDOM" From 69a45a9c98291dc485ee9c46c9bf79ec8533217b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 6 Oct 2021 10:04:30 +0200 Subject: [PATCH 29/88] chore: zshrc update settings rewording --- templates/zshrc.zsh-template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index 58642bc41..7e1c7997c 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -23,7 +23,7 @@ ZSH_THEME="robbyrussell" # Case-sensitive completion must be off. _ and - will be interchangeable. # HYPHEN_INSENSITIVE="true" -# Uncomment the following lines to change the auto-update behavior +# Uncomment one of the following lines to change the auto-update behavior # zstyle ':omz:update' mode disabled # disable automatic updates # zstyle ':omz:update' mode auto # update automatically without asking # zstyle ':omz:update' mode reminder # just remind me to update when it's time From 29b5c182bec4cec7704fb8bac9ee0ab971dfb89a Mon Sep 17 00:00:00 2001 From: HoshinoArika Date: Wed, 6 Oct 2021 17:01:20 +0800 Subject: [PATCH 30/88] feat(sublime): add support for Sublime Text 4 on Windows (#10063) --- plugins/sublime/sublime.plugin.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/sublime/sublime.plugin.zsh b/plugins/sublime/sublime.plugin.zsh index 618dd8ee8..dadf37574 100644 --- a/plugins/sublime/sublime.plugin.zsh +++ b/plugins/sublime/sublime.plugin.zsh @@ -17,6 +17,7 @@ alias stn=create_project if [[ "$OSTYPE" == linux* ]]; then if [[ "$(uname -r)" = *icrosoft* ]]; then _sublime_paths=( + "$(wslpath -u 'C:\Program Files\Sublime Text\sublime_text.exe' 2>/dev/null)" "$(wslpath -u 'C:\Program Files\Sublime Text 3\subl.exe' 2>/dev/null)" "$(wslpath -u 'C:\Program Files\Sublime Text 2\subl.exe' 2>/dev/null)" ) @@ -52,6 +53,7 @@ alias stn=create_project ) elif [[ "$OSTYPE" = msys ]]; then _sublime_paths=( + "/c/Program Files/Sublime Text/sublime_text.exe" "/c/Program Files/Sublime Text 2/subl.exe" "/c/Program Files/Sublime Text 3/subl.exe" ) From f0bbef1a070b7b00a36010c44af3c88807c73e6f Mon Sep 17 00:00:00 2001 From: Cxarli <10348289+Cxarli@users.noreply.github.com> Date: Sat, 31 Oct 2020 16:01:18 +0100 Subject: [PATCH 31/88] feat(yarn): add global bin directory to `$PATH` (#9410) Fixes #9177 Closes #9410 --- plugins/yarn/yarn.plugin.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/yarn/yarn.plugin.zsh b/plugins/yarn/yarn.plugin.zsh index a240cb88e..a4f595c61 100644 --- a/plugins/yarn/yarn.plugin.zsh +++ b/plugins/yarn/yarn.plugin.zsh @@ -1,3 +1,10 @@ +# Add yarn bin directory to $PATH if it exists and not in $PATH already +bindir=$(yarn global bin 2>/dev/null) \ + && [[ -d "$bindir" ]] \ + && (( ! ${path[(Ie)$bindir]} )) \ + && path+=("$bindir") +unset bindir + alias y="yarn" alias ya="yarn add" alias yad="yarn add --dev" From 607d2f1eda6f7a8a8036a6608e99c512db75c602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 7 Oct 2021 13:35:07 +0200 Subject: [PATCH 32/88] Revert "fix(changelog): don't parse commits of ignored types" This reverts commit 63b7e5767d551b1d839888a7216f2bed01e8eb1f. --- tools/changelog.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 71caa2b6c..7329a9526 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -120,7 +120,7 @@ function parse-commit { fi # Parse commit with hash $1 - local hash="$1" subject body type warning rhash + local hash="$1" subject body warning rhash subject="$(command git show -s --format=%s $hash)" body="$(command git show -s --format=%b $hash)" @@ -132,12 +132,8 @@ function parse-commit { # commit body # [BREAKING CHANGE: warning] - # if commit type is not going to be displayed, do nothing else - type="$(commit:type "$subject")" - (( ${MAIN_TYPES[(Ie)$type]} || ${OTHER_TYPES[(Ie)$type]} )) || return - # commits holds the commit type - commits[$hash]="$type" + commits[$hash]="$(commit:type "$subject")" # scopes holds the commit scope scopes[$hash]="$(commit:scope "$subject")" # subjects holds the commit subject From dc83d0b7204cf66315471e980729490813b7d915 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Thu, 7 Oct 2021 15:16:30 -0400 Subject: [PATCH 33/88] fix(battery): support `acpitool` and multiple batteries under Linux (#9609) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/battery/battery.plugin.zsh | 54 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index a525fd7da..24bff8ae6 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -12,15 +12,12 @@ ########################################### if [[ "$OSTYPE" = darwin* ]]; then - function battery_is_charging() { ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes' } - function battery_pct() { pmset -g batt | grep -Eo "\d+%" | cut -d% -f1 } - function battery_pct_remaining() { if battery_is_charging; then echo "External Power" @@ -28,7 +25,6 @@ if [[ "$OSTYPE" = darwin* ]]; then battery_pct fi } - function battery_time_remaining() { local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then @@ -42,7 +38,6 @@ if [[ "$OSTYPE" = darwin* ]]; then echo "∞" fi } - function battery_pct_prompt () { local battery_pct color if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then @@ -61,17 +56,14 @@ if [[ "$OSTYPE" = darwin* ]]; then } elif [[ "$OSTYPE" = freebsd* ]]; then - function battery_is_charging() { [[ $(sysctl -n hw.acpi.battery.state) -eq 2 ]] } - function battery_pct() { if (( $+commands[sysctl] )); then sysctl -n hw.acpi.battery.life fi } - function battery_pct_remaining() { if ! battery_is_charging; then battery_pct @@ -79,7 +71,6 @@ elif [[ "$OSTYPE" = freebsd* ]]; then echo "External Power" fi } - function battery_time_remaining() { local remaining_time remaining_time=$(sysctl -n hw.acpi.battery.time) @@ -89,7 +80,6 @@ elif [[ "$OSTYPE" = freebsd* ]]; then printf %02d:%02d $hour $minute fi } - function battery_pct_prompt() { local battery_pct color battery_pct=$(battery_pct_remaining) @@ -106,19 +96,42 @@ elif [[ "$OSTYPE" = freebsd* ]]; then echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } - elif [[ "$OSTYPE" = linux* ]]; then - function battery_is_charging() { - ! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging' - } - - function battery_pct() { - if (( $+commands[acpi] )); then - acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -E '^Battery.*(Full|(Disc|C)harging)' | cut -f2 -d ',' | tr -cd '[:digit:]' + if (( $+commands[acpitool] )); then + ! acpitool 2>/dev/null | command grep -qE '^\s+Battery.*Discharging' + elif (( $+commands[acpi] )); then + ! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging' + fi + } + function battery_pct() { + if (( $+commands[acpitool] )); then + # Sample output: + # Battery #1 : Unknown, 99.55% + # Battery #2 : Discharging, 49.58%, 01:12:05 + # All batteries : 62.60%, 02:03:03 + acpitool 2>/dev/null | command awk -F, ' + /^\s+All batteries/ { + gsub(/[^0-9.]/, "", $1) + pct=$1 + exit + } + !pct && /^\s+Battery/ { + gsub(/[^0-9.]/, "", $2) + pct=$2 + } + END { print pct } + ' + elif (( $+commands[acpi] )); then + # Sample output: + # Battery 0: Discharging, 0%, rate information unavailable + # Battery 1: Full, 100% + acpi 2>/dev/null | command awk -F, ' + /rate information unavailable/ { next } + /^Battery.*: /{ gsub(/[^0-9]/, "", $2); print $2; exit } + ' fi } - function battery_pct_remaining() { if ! battery_is_charging; then battery_pct @@ -126,13 +139,11 @@ elif [[ "$OSTYPE" = linux* ]]; then echo "External Power" fi } - function battery_time_remaining() { if ! battery_is_charging; then acpi 2>/dev/null | command grep -v "rate information unavailable" | cut -f3 -d ',' fi } - function battery_pct_prompt() { local battery_pct color battery_pct=$(battery_pct_remaining) @@ -149,7 +160,6 @@ elif [[ "$OSTYPE" = linux* ]]; then echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } - else # Empty functions so we don't cause errors in prompts function battery_is_charging { false } From f26a1ecdf01185218004dd6d15ce02541e6a2b26 Mon Sep 17 00:00:00 2001 From: Avneet Singh <4151485+kalsi-avneet@users.noreply.github.com> Date: Sun, 21 Mar 2021 00:06:33 +0530 Subject: [PATCH 34/88] feat(battery): add support for Android via Termux (#9752) --- plugins/battery/README.md | 19 ++++++++----- plugins/battery/battery.plugin.zsh | 43 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/plugins/battery/README.md b/plugins/battery/README.md index c2554a36d..18e5bd882 100644 --- a/plugins/battery/README.md +++ b/plugins/battery/README.md @@ -8,15 +8,22 @@ To use, add `battery` to the list of plugins in your `.zshrc` file: Then, add the `battery_pct_prompt` function to your custom theme. For example: -``` +```zsh RPROMPT='$(battery_pct_prompt) ...' ``` ## Requirements -On Linux, you must have the `acpi` tool installed on your operating system. +- On Linux, you must have the `acpi` or `acpitool` commands installed on your operating system. + On Debian/Ubuntu, you can do that with `sudo apt install acpi` or `sudo apt install acpitool`. -Here's an example of how to install with apt: -``` -sudo apt-get install acpi -``` +- On Android (via [Termux](https://play.google.com/store/apps/details?id=com.termux)), you must have: + + 1. The `Termux:API` addon app installed: + [Google Play](https://play.google.com/store/apps/details?id=com.termux.api) | [F-Droid](https://f-droid.org/packages/com.termux.api/) + + 2. The `termux-api` package installed within termux: + + ```sh + pkg install termux-api + ``` diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 24bff8ae6..8e6afe65e 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -10,6 +10,9 @@ # Author: J (927589452) # # Modified to add support for FreeBSD # ########################################### +# Author: Avneet Singh (kalsi-avneet) # +# Modified to add support for Android # +########################################### if [[ "$OSTYPE" = darwin* ]]; then function battery_is_charging() { @@ -160,6 +163,46 @@ elif [[ "$OSTYPE" = linux* ]]; then echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } +elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} )); then + function battery_is_charging() { + termux-battery-status 2>/dev/null | command awk '/status/ { exit ($0 ~ /DISCHARGING/) }' + } + function battery_pct() { + # Sample output: + # { + # "health": "GOOD", + # "percentage": 93, + # "plugged": "UNPLUGGED", + # "status": "DISCHARGING", + # "temperature": 29.0, + # "current": 361816 + # } + termux-battery-status 2>/dev/null | command awk '/percentage/ { gsub(/[,]/,""); print $2}' + } + function battery_pct_remaining() { + if ! battery_is_charging; then + battery_pct + else + echo "External Power" + fi + } + function battery_time_remaining() { } # Not available on android + 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 + } else # Empty functions so we don't cause errors in prompts function battery_is_charging { false } From 9aeb967581061ca12c1679d3fdce8a5b516a9796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 8 Oct 2021 12:34:04 +0200 Subject: [PATCH 35/88] fix(battery): fix system check so Termux uses the correct method --- plugins/battery/battery.plugin.zsh | 80 +++++++++++++++--------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 8e6afe65e..0e96b00aa 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -99,6 +99,46 @@ elif [[ "$OSTYPE" = freebsd* ]]; then echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } +elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} )); then + function battery_is_charging() { + termux-battery-status 2>/dev/null | command awk '/status/ { exit ($0 ~ /DISCHARGING/) }' + } + function battery_pct() { + # Sample output: + # { + # "health": "GOOD", + # "percentage": 93, + # "plugged": "UNPLUGGED", + # "status": "DISCHARGING", + # "temperature": 29.0, + # "current": 361816 + # } + termux-battery-status 2>/dev/null | command awk '/percentage/ { gsub(/[,]/,""); print $2}' + } + function battery_pct_remaining() { + if ! battery_is_charging; then + battery_pct + else + echo "External Power" + fi + } + function battery_time_remaining() { } # Not available on android + 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 @@ -163,46 +203,6 @@ elif [[ "$OSTYPE" = linux* ]]; then echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } -elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} )); then - function battery_is_charging() { - termux-battery-status 2>/dev/null | command awk '/status/ { exit ($0 ~ /DISCHARGING/) }' - } - function battery_pct() { - # Sample output: - # { - # "health": "GOOD", - # "percentage": 93, - # "plugged": "UNPLUGGED", - # "status": "DISCHARGING", - # "temperature": 29.0, - # "current": 361816 - # } - termux-battery-status 2>/dev/null | command awk '/percentage/ { gsub(/[,]/,""); print $2}' - } - function battery_pct_remaining() { - if ! battery_is_charging; then - battery_pct - else - echo "External Power" - fi - } - function battery_time_remaining() { } # Not available on android - 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 - } else # Empty functions so we don't cause errors in prompts function battery_is_charging { false } From 5fb204fa7469a89f31ffb8ee8a9b3c36bea926a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 8 Oct 2021 15:42:43 +0200 Subject: [PATCH 36/88] fix(battery): force battery percentage as integer --- plugins/battery/battery.plugin.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 0e96b00aa..db5eeb93a 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -153,7 +153,7 @@ elif [[ "$OSTYPE" = linux* ]]; then # Battery #1 : Unknown, 99.55% # Battery #2 : Discharging, 49.58%, 01:12:05 # All batteries : 62.60%, 02:03:03 - acpitool 2>/dev/null | command awk -F, ' + local -i pct=$(acpitool 2>/dev/null | command awk -F, ' /^\s+All batteries/ { gsub(/[^0-9.]/, "", $1) pct=$1 @@ -164,7 +164,8 @@ elif [[ "$OSTYPE" = linux* ]]; then pct=$2 } END { print pct } - ' + ') + echo $pct elif (( $+commands[acpi] )); then # Sample output: # Battery 0: Discharging, 0%, rate information unavailable @@ -227,7 +228,7 @@ function battery_level_gauge() { local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow} local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'} - local battery_remaining_percentage=$(battery_pct) + local -i battery_remaining_percentage=$(battery_pct) local filled empty gauge_color if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then From 1c9a64ece6dce901aac114deaa71b298a32fbfb4 Mon Sep 17 00:00:00 2001 From: Michael Fryar Date: Fri, 8 Oct 2021 08:24:00 -0700 Subject: [PATCH 37/88] feat(git): add `gswm` and `gswd` aliases (#9897) Co-authored-by: Nathaniel Young --- 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 12e3676e8..113080874 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -169,6 +169,8 @@ plugins=(... git) | 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 -l ${1}* }; noglob gtl | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 5c5db9972..dbcc7bddb 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -295,6 +295,8 @@ alias gstall='git stash --all' alias gsu='git submodule update' alias gsw='git switch' alias gswc='git switch -c' +alias gswm='git switch $(git_main_branch)' +alias gswd='git switch $(git_develop_branch)' alias gts='git tag -s' alias gtv='git tag | sort -V' From 07cdd7a53931a17a2c24f834c5e1ea0f62609c42 Mon Sep 17 00:00:00 2001 From: Pooya Vahidi <56851682+pooyavahidi@users.noreply.github.com> Date: Sat, 9 Oct 2021 21:02:49 +1100 Subject: [PATCH 38/88] fix(lib): fix status exit code check in `git_prompt_status` (#10275) --- lib/git.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index c9363274c..9a615e77b 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -206,7 +206,8 @@ function git_prompt_status() { STASHED UNMERGED AHEAD BEHIND DIVERGED ) - local status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)" + local status_text + status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)" # Don't continue on a catastrophic failure if [[ $? -eq 128 ]]; then From 6ac1ff69053525d94b8bc6c5243d2bb67fb61930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Sat, 9 Oct 2021 13:42:17 +0200 Subject: [PATCH 39/88] fix(git): fix directory parse from URL in `gccd` (#10276) --- 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 dbcc7bddb..5a3c98287 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -100,7 +100,7 @@ alias gcf='git config --list' function gccd() { command git clone --recurse-submodules "$@" - [[ -d "$_" ]] && cd "$_" || cd "${${_:h}%.git}" + [[ -d "$_" ]] && cd "$_" || cd "${${_:t}%.git}" } compdef _git gccd=git-clone From f82aa819310752ad754c4ebfd1ae499285ee556e Mon Sep 17 00:00:00 2001 From: michael-yuji Date: Mon, 11 Oct 2021 01:15:24 +0800 Subject: [PATCH 40/88] fix(lib): fix `diff --color` argument check for BSD systems (#10269) --- 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 0b71de372..00947f72d 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -40,7 +40,7 @@ if [[ "$DISABLE_LS_COLORS" != "true" ]]; then fi # enable diff color if possible. -if command diff --color . . &>/dev/null; then +if command diff --color /dev/null /dev/null &>/dev/null; then alias diff='diff --color' fi From 9bd0ac9b005189edceb0ac53f361fcc020f8e6b6 Mon Sep 17 00:00:00 2001 From: Arthur Maltson Date: Mon, 11 Oct 2021 05:40:17 -0400 Subject: [PATCH 41/88] feat(mvn): support using `mvnw` in multi-module projects (#9413) --- plugins/mvn/mvn.plugin.zsh | 531 +++++++++++++++++++------------------ 1 file changed, 269 insertions(+), 262 deletions(-) diff --git a/plugins/mvn/mvn.plugin.zsh b/plugins/mvn/mvn.plugin.zsh index 27d63a6f9..e32729aa6 100644 --- a/plugins/mvn/mvn.plugin.zsh +++ b/plugins/mvn/mvn.plugin.zsh @@ -1,39 +1,46 @@ -# Calls ./mvnw if found, otherwise execute the original mvn +# Calls mvnw if found in the current project, otherwise execute the original mvn mvn-or-mvnw() { - if [ -x ./mvnw ]; then - echo "executing mvnw instead of mvn" - ./mvnw "$@" - else - command mvn "$@" - fi + local dir="$PWD" + while [[ ! -x "$dir/mvnw" && "$dir" != / ]]; do + dir="${dir:h}" + done + + if [[ -x "$dir/mvnw" ]]; then + echo "Running \`$dir/mvnw\`..." >&2 + "$dir/mvnw" "$@" + return $? + fi + + command mvn "$@" } # Wrapper function for Maven's mvn command. Based on https://gist.github.com/1027800 mvn-color() { - local BOLD=$(echoti bold) - local TEXT_RED=$(echoti setaf 1) - local TEXT_GREEN=$(echoti setaf 2) - local TEXT_YELLOW=$(echoti setaf 3) - local TEXT_BLUE=$(echoti setaf 4) - local TEXT_WHITE=$(echoti setaf 7) - local RESET_FORMATTING=$(echoti sgr0) - ( - # Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations - unset LANG - LC_CTYPE=C mvn "$@" | sed \ - -e "s/\(\[INFO\]\)\(.*\)/${TEXT_BLUE}${BOLD}\1${RESET_FORMATTING}\2/g" \ - -e "s/\(\[DEBUG\]\)\(.*\)/${TEXT_WHITE}${BOLD}\1${RESET_FORMATTING}\2/g" \ - -e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \ - -e "s/\(\[WARNING\]\)\(.*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}\2/g" \ - -e "s/\(\[ERROR\]\)\(.*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}\2/g" \ - -e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g" + local BOLD=$(echoti bold) + local TEXT_RED=$(echoti setaf 1) + local TEXT_GREEN=$(echoti setaf 2) + local TEXT_YELLOW=$(echoti setaf 3) + local TEXT_BLUE=$(echoti setaf 4) + local TEXT_WHITE=$(echoti setaf 7) + local RESET_FORMATTING=$(echoti sgr0) - # Make sure formatting is reset - echo -ne "${RESET_FORMATTING}" - ) + ( + # Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations + unset LANG + LC_CTYPE=C mvn "$@" | sed \ + -e "s/\(\[INFO\]\)\(.*\)/${TEXT_BLUE}${BOLD}\1${RESET_FORMATTING}\2/g" \ + -e "s/\(\[DEBUG\]\)\(.*\)/${TEXT_WHITE}${BOLD}\1${RESET_FORMATTING}\2/g" \ + -e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \ + -e "s/\(\[WARNING\]\)\(.*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}\2/g" \ + -e "s/\(\[ERROR\]\)\(.*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}\2/g" \ + -e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g" + + # Make sure formatting is reset + echo -ne "${RESET_FORMATTING}" + ) } -# either use orignal mvn or the mvn wrapper +# either use original mvn or the mvn wrapper alias mvn="mvn-or-mvnw" # Run mvn against the pom found in a project's root directory (assumes a git repo) @@ -72,262 +79,262 @@ alias mvn-updates='mvn versions:display-dependency-updates' function listMavenCompletions { - local file new_file - local -a profiles POM_FILES modules + local file new_file + local -a profiles POM_FILES modules - # Root POM - POM_FILES=(~/.m2/settings.xml) + # Root POM + POM_FILES=(~/.m2/settings.xml) - # POM in the current directory - if [[ -f pom.xml ]]; then - local file=pom.xml - POM_FILES+=("${file:A}") - fi + # POM in the current directory + if [[ -f pom.xml ]]; then + local file=pom.xml + POM_FILES+=("${file:A}") + fi - # Look for POM files in parent directories - while [[ -n "$file" ]] && grep -q "" "$file"; do - # look for a new relativePath for parent pom.xml - new_file=$(grep -e ".*" "$file" | sed -e 's/.*\(.*\)<\/relativePath>.*/\1/') + # Look for POM files in parent directories + while [[ -n "$file" ]] && grep -q "" "$file"; do + # look for a new relativePath for parent pom.xml + new_file=$(grep -e ".*" "$file" | sed -e 's/.*\(.*\)<\/relativePath>.*/\1/') - # if is present but not defined, assume ../pom.xml - if [[ -z "$new_file" ]]; then - new_file="../pom.xml" - fi + # if is present but not defined, assume ../pom.xml + if [[ -z "$new_file" ]]; then + new_file="../pom.xml" + fi - # if file doesn't exist break - file="${file:h}/${new_file}" - if ! [[ -e "$file" ]]; then - break - fi + # if file doesn't exist break + file="${file:h}/${new_file}" + if ! [[ -e "$file" ]]; then + break + fi - POM_FILES+=("${file:A}") - done + POM_FILES+=("${file:A}") + done - # Get profiles from found files - for file in $POM_FILES; do - [[ -e $file ]] || continue - profiles+=($(sed 's///' "$file" | sed '//d' | grep -e "" -A 1 | grep -e ".*" | sed 's?.*\(.*\)<\/id>.*?-P\1?')) - done + # Get profiles from found files + for file in $POM_FILES; do + [[ -e $file ]] || continue + profiles+=($(sed 's///' "$file" | sed '//d' | grep -e "" -A 1 | grep -e ".*" | sed 's?.*\(.*\)<\/id>.*?-P\1?')) + done - # List modules - modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|')) + # List modules + modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|')) - reply=( - # common lifecycle - clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site + reply=( + # common lifecycle + clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site - # integration testing - pre-integration-test integration-test + # integration testing + pre-integration-test integration-test - # common plugins - deploy failsafe install site surefire checkstyle javadoc jxr pmd ant antrun archetype assembly dependency enforcer gpg help release repository source eclipse idea jetty cargo jboss tomcat tomcat6 tomcat7 exec versions war ear ejb android scm buildnumber nexus repository sonar license hibernate3 liquibase flyway gwt + # common plugins + deploy failsafe install site surefire checkstyle javadoc jxr pmd ant antrun archetype assembly dependency enforcer gpg help release repository source eclipse idea jetty cargo jboss tomcat tomcat6 tomcat7 exec versions war ear ejb android scm buildnumber nexus repository sonar license hibernate3 liquibase flyway gwt - # deploy - deploy:deploy-file - # failsafe - failsafe:integration-test failsafe:verify - # install - install:install-file install:help - # site - site:site site:deploy site:run site:stage site:stage-deploy site:attach-descriptor site:jar site:effective-site - # surefire - surefire:test + # deploy + deploy:deploy-file + # failsafe + failsafe:integration-test failsafe:verify + # install + install:install-file install:help + # site + site:site site:deploy site:run site:stage site:stage-deploy site:attach-descriptor site:jar site:effective-site + # surefire + surefire:test - # checkstyle - checkstyle:checkstyle checkstyle:check checkstyle:checkstyle-aggregate - # javadoc - javadoc:javadoc javadoc:test-javadoc javadoc:javadoc-no-fork javadoc:test-javadoc-no-fork javadoc:aggregate javadoc:test-aggregate javadoc:jar javadoc:test-jar javadoc:aggregate-jar javadoc:test-aggregate-jar javadoc:fix javadoc:test-fix javadoc:resource-bundle javadoc:test-resource-bundle - # jxr - jxr:jxr jxr:aggregate jxr:test-jxr jxr:test-aggregate - # pmd - pmd:pmd pmd:cpd pmd:check pmd:cpd-check + # checkstyle + checkstyle:checkstyle checkstyle:check checkstyle:checkstyle-aggregate + # javadoc + javadoc:javadoc javadoc:test-javadoc javadoc:javadoc-no-fork javadoc:test-javadoc-no-fork javadoc:aggregate javadoc:test-aggregate javadoc:jar javadoc:test-jar javadoc:aggregate-jar javadoc:test-aggregate-jar javadoc:fix javadoc:test-fix javadoc:resource-bundle javadoc:test-resource-bundle + # jxr + jxr:jxr jxr:aggregate jxr:test-jxr jxr:test-aggregate + # pmd + pmd:pmd pmd:cpd pmd:check pmd:cpd-check - # ant - ant:ant ant:clean - # antrun - antrun:run - # archetype - archetype:generate archetype:create-from-project archetype:crawl - # assembly - assembly:single assembly:assembly - # dependency - dependency:analyze dependency:analyze-dep-mgt dependency:analyze-only dependency:analyze-report dependency:analyze-duplicate dependency:build-classpath dependency:copy dependency:copy-dependencies dependency:display-ancestors dependency:get dependency:go-offline dependency:list dependency:list-repositories dependency:properties dependency:purge-local-repository dependency:resolve dependency:resolve-plugins dependency:sources dependency:tree dependency:unpack dependency:unpack-dependencies - # enforcer - enforcer:enforce enforcer:display-info - # gpg - gpg:sign gpg:sign-and-deploy-file - # help - help:active-profiles help:all-profiles help:describe help:effective-pom help:effective-settings help:evaluate help:expressions help:system - # release - release:clean release:prepare release:prepare-with-pom release:rollback release:perform release:stage release:branch release:update-versions - # jgitflow - jgitflow:feature-start jgitflow:feature-finish jgitflow:release-start jgitflow:release-finish jgitflow:hotfix-start jgitflow:hotfix-finish jgitflow:build-number - # repository - repository:bundle-create repository:bundle-pack - # source - source:aggregate source:jar source:jar-no-fork source:test-jar source:test-jar-no-fork + # ant + ant:ant ant:clean + # antrun + antrun:run + # archetype + archetype:generate archetype:create-from-project archetype:crawl + # assembly + assembly:single assembly:assembly + # dependency + dependency:analyze dependency:analyze-dep-mgt dependency:analyze-only dependency:analyze-report dependency:analyze-duplicate dependency:build-classpath dependency:copy dependency:copy-dependencies dependency:display-ancestors dependency:get dependency:go-offline dependency:list dependency:list-repositories dependency:properties dependency:purge-local-repository dependency:resolve dependency:resolve-plugins dependency:sources dependency:tree dependency:unpack dependency:unpack-dependencies + # enforcer + enforcer:enforce enforcer:display-info + # gpg + gpg:sign gpg:sign-and-deploy-file + # help + help:active-profiles help:all-profiles help:describe help:effective-pom help:effective-settings help:evaluate help:expressions help:system + # release + release:clean release:prepare release:prepare-with-pom release:rollback release:perform release:stage release:branch release:update-versions + # jgitflow + jgitflow:feature-start jgitflow:feature-finish jgitflow:release-start jgitflow:release-finish jgitflow:hotfix-start jgitflow:hotfix-finish jgitflow:build-number + # repository + repository:bundle-create repository:bundle-pack + # source + source:aggregate source:jar source:jar-no-fork source:test-jar source:test-jar-no-fork - # eclipse - eclipse:clean eclipse:eclipse - # idea - idea:clean idea:idea + # eclipse + eclipse:clean eclipse:eclipse + # idea + idea:clean idea:idea - # jetty - jetty:run jetty:run-exploded - # cargo - cargo:start cargo:run cargo:stop cargo:deploy cargo:undeploy cargo:help - # jboss - jboss:start jboss:stop jboss:deploy jboss:undeploy jboss:redeploy - # tomcat - tomcat:start tomcat:stop tomcat:deploy tomcat:undeploy tomcat:redeploy - # tomcat6 - tomcat6:run tomcat6:run-war tomcat6:run-war-only tomcat6:stop tomcat6:deploy tomcat6:undeploy - # tomcat7 - tomcat7:run tomcat7:run-war tomcat7:run-war-only tomcat7:deploy - # tomee - tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy - # spring-boot - spring-boot:run spring-boot:repackage - # quarkus - quarkus:dev quarkus:list-extensions quarkus:add-extension quarkus:add-extensions quarkus:generate-config quarkus:help - # exec - exec:exec exec:java - # versions - versions:display-dependency-updates versions:display-plugin-updates versions:display-property-updates versions:update-parent versions:update-properties versions:update-child-modules versions:lock-snapshots versions:unlock-snapshots versions:resolve-ranges versions:set versions:use-releases versions:use-next-releases versions:use-latest-releases versions:use-next-snapshots versions:use-latest-snapshots versions:use-next-versions versions:use-latest-versions versions:commit versions:revert - # scm - scm:add scm:bootstrap scm:branch scm:changelog scm:check-local-modification scm:checkin scm:checkout scm:diff scm:edit scm:export scm:list scm:remove scm:status scm:tag scm:unedit scm:update scm:update-subprojects scm:validate - # buildnumber - buildnumber:create buildnumber:create-timestamp buildnumber:help buildnumber:hgchangeset + # jetty + jetty:run jetty:run-exploded + # cargo + cargo:start cargo:run cargo:stop cargo:deploy cargo:undeploy cargo:help + # jboss + jboss:start jboss:stop jboss:deploy jboss:undeploy jboss:redeploy + # tomcat + tomcat:start tomcat:stop tomcat:deploy tomcat:undeploy tomcat:redeploy + # tomcat6 + tomcat6:run tomcat6:run-war tomcat6:run-war-only tomcat6:stop tomcat6:deploy tomcat6:undeploy + # tomcat7 + tomcat7:run tomcat7:run-war tomcat7:run-war-only tomcat7:deploy + # tomee + tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy + # spring-boot + spring-boot:run spring-boot:repackage + # quarkus + quarkus:dev quarkus:list-extensions quarkus:add-extension quarkus:add-extensions quarkus:generate-config quarkus:help + # exec + exec:exec exec:java + # versions + versions:display-dependency-updates versions:display-plugin-updates versions:display-property-updates versions:update-parent versions:update-properties versions:update-child-modules versions:lock-snapshots versions:unlock-snapshots versions:resolve-ranges versions:set versions:use-releases versions:use-next-releases versions:use-latest-releases versions:use-next-snapshots versions:use-latest-snapshots versions:use-next-versions versions:use-latest-versions versions:commit versions:revert + # scm + scm:add scm:bootstrap scm:branch scm:changelog scm:check-local-modification scm:checkin scm:checkout scm:diff scm:edit scm:export scm:list scm:remove scm:status scm:tag scm:unedit scm:update scm:update-subprojects scm:validate + # buildnumber + buildnumber:create buildnumber:create-timestamp buildnumber:help buildnumber:hgchangeset - # war - war:war war:exploded war:inplace war:manifest - # ear - ear:ear ear:generate-application-xml - # ejb - ejb:ejb - # android - android:apk android:apklib android:deploy android:deploy-dependencies android:dex android:emulator-start android:emulator-stop android:emulator-stop-all android:generate-sources android:help android:instrument android:manifest-update android:pull android:push android:redeploy android:run android:undeploy android:unpack android:version-update android:zipalign android:devices - # nexus - nexus:staging-list nexus:staging-close nexus:staging-drop nexus:staging-release nexus:staging-build-promotion nexus:staging-profiles-list nexus:settings-download - # repository - repository:bundle-create repository:bundle-pack repository:help + # war + war:war war:exploded war:inplace war:manifest + # ear + ear:ear ear:generate-application-xml + # ejb + ejb:ejb + # android + android:apk android:apklib android:deploy android:deploy-dependencies android:dex android:emulator-start android:emulator-stop android:emulator-stop-all android:generate-sources android:help android:instrument android:manifest-update android:pull android:push android:redeploy android:run android:undeploy android:unpack android:version-update android:zipalign android:devices + # nexus + nexus:staging-list nexus:staging-close nexus:staging-drop nexus:staging-release nexus:staging-build-promotion nexus:staging-profiles-list nexus:settings-download + # repository + repository:bundle-create repository:bundle-pack repository:help - # sonar - sonar:sonar - # license - license:format license:check - # hibernate3 - hibernate3:hbm2ddl hibernate3:help - # liquibase - liquibase:changelogSync liquibase:changelogSyncSQL liquibase:clearCheckSums liquibase:dbDoc liquibase:diff liquibase:dropAll liquibase:help liquibase:migrate liquibase:listLocks liquibase:migrateSQL liquibase:releaseLocks liquibase:rollback liquibase:rollbackSQL liquibase:status liquibase:tag liquibase:update liquibase:updateSQL liquibase:updateTestingRollback - # flyway - flyway:clean flyway:history flyway:init flyway:migrate flyway:status flyway:validate - # gwt - gwt:browser gwt:clean gwt:compile gwt:compile-report gwt:css gwt:debug gwt:eclipse gwt:eclipseTest gwt:generateAsync gwt:help gwt:i18n gwt:mergewebxml gwt:resources gwt:run gwt:sdkInstall gwt:source-jar gwt:soyc gwt:test - # asciidoctor - asciidoctor:process-asciidoc asciidoctor:auto-refresh asciidoctor:http asciidoctor:zip - # compiler - compiler:compile compiler:testCompile - # resources - resources:resources resources:testResources resources:copy-resources - # verifier - verifier:verify - # jar - jar:jar jar:test-jar - # rar - rar:rar - # acr - acr:acr - # shade - shade:shade - # changelog - changelog:changelog changelog:dev-activity changelog:file-activity - # changes - changes:announcement-mail changes:announcement-generate changes:changes-check changes:changes-validate changes:changes-report changes:jira-report changes:trac-report changes:github-report - # doap - doap:generate - # docck - docck:check - # jdeps - jdeps:jdkinternals jdeps:test-jdkinternals - # linkcheck - linkcheck:linkcheck - # project-info-reports - project-info-reports:cim project-info-reports:dependencies project-info-reports:dependency-convergence project-info-reports:dependency-info project-info-reports:dependency-management project-info-reports:distribution-management project-info-reports:help project-info-reports:index project-info-reports:issue-tracking project-info-reports:license project-info-reports:mailing-list project-info-reports:modules project-info-reports:plugin-management project-info-reports:plugins project-info-reports:project-team project-info-reports:scm project-info-reports:summary - # surefire-report - surefire-report:failsafe-report-only surefire-report:report surefire-report:report-only - # invoker - invoker:install invoker:integration-test invoker:verify invoker:run - # jarsigner - jarsigner:sign jarsigner:verify - # patch - patch:apply - # pdf - pdf:pdf - # plugin - plugin:descriptor plugin:report plugin:updateRegistry plugin:addPluginArtifactMetadata plugin:helpmojo - # remote-resources - remote-resources:bundle remote-resources:process - # scm-publish - scm-publish:help scm-publish:publish-scm scm-publish:scmpublish - # stage - stage:copy - # toolchain - toolchain:toolchain - #liberty - liberty:clean-server liberty:compile-jsp liberty:configure-arquillian liberty:create-server liberty:debug liberty:debug-server liberty:deploy liberty:dev liberty:display-url liberty:dump-server liberty:install-apps liberty:install-feature liberty:install-server liberty:java-dump-server liberty:package-server liberty:run liberty:run-server liberty:server-status liberty:start liberty:start-server liberty:status liberty:stop liberty:stop-server liberty:test-start-server liberty:test-stop-server liberty:undeploy liberty:uninstall-feature + # sonar + sonar:sonar + # license + license:format license:check + # hibernate3 + hibernate3:hbm2ddl hibernate3:help + # liquibase + liquibase:changelogSync liquibase:changelogSyncSQL liquibase:clearCheckSums liquibase:dbDoc liquibase:diff liquibase:dropAll liquibase:help liquibase:migrate liquibase:listLocks liquibase:migrateSQL liquibase:releaseLocks liquibase:rollback liquibase:rollbackSQL liquibase:status liquibase:tag liquibase:update liquibase:updateSQL liquibase:updateTestingRollback + # flyway + flyway:clean flyway:history flyway:init flyway:migrate flyway:status flyway:validate + # gwt + gwt:browser gwt:clean gwt:compile gwt:compile-report gwt:css gwt:debug gwt:eclipse gwt:eclipseTest gwt:generateAsync gwt:help gwt:i18n gwt:mergewebxml gwt:resources gwt:run gwt:sdkInstall gwt:source-jar gwt:soyc gwt:test + # asciidoctor + asciidoctor:process-asciidoc asciidoctor:auto-refresh asciidoctor:http asciidoctor:zip + # compiler + compiler:compile compiler:testCompile + # resources + resources:resources resources:testResources resources:copy-resources + # verifier + verifier:verify + # jar + jar:jar jar:test-jar + # rar + rar:rar + # acr + acr:acr + # shade + shade:shade + # changelog + changelog:changelog changelog:dev-activity changelog:file-activity + # changes + changes:announcement-mail changes:announcement-generate changes:changes-check changes:changes-validate changes:changes-report changes:jira-report changes:trac-report changes:github-report + # doap + doap:generate + # docck + docck:check + # jdeps + jdeps:jdkinternals jdeps:test-jdkinternals + # linkcheck + linkcheck:linkcheck + # project-info-reports + project-info-reports:cim project-info-reports:dependencies project-info-reports:dependency-convergence project-info-reports:dependency-info project-info-reports:dependency-management project-info-reports:distribution-management project-info-reports:help project-info-reports:index project-info-reports:issue-tracking project-info-reports:license project-info-reports:mailing-list project-info-reports:modules project-info-reports:plugin-management project-info-reports:plugins project-info-reports:project-team project-info-reports:scm project-info-reports:summary + # surefire-report + surefire-report:failsafe-report-only surefire-report:report surefire-report:report-only + # invoker + invoker:install invoker:integration-test invoker:verify invoker:run + # jarsigner + jarsigner:sign jarsigner:verify + # patch + patch:apply + # pdf + pdf:pdf + # plugin + plugin:descriptor plugin:report plugin:updateRegistry plugin:addPluginArtifactMetadata plugin:helpmojo + # remote-resources + remote-resources:bundle remote-resources:process + # scm-publish + scm-publish:help scm-publish:publish-scm scm-publish:scmpublish + # stage + stage:copy + # toolchain + toolchain:toolchain + #liberty + liberty:clean-server liberty:compile-jsp liberty:configure-arquillian liberty:create-server liberty:debug liberty:debug-server liberty:deploy liberty:dev liberty:display-url liberty:dump-server liberty:install-apps liberty:install-feature liberty:install-server liberty:java-dump-server liberty:package-server liberty:run liberty:run-server liberty:server-status liberty:start liberty:start-server liberty:status liberty:stop liberty:stop-server liberty:test-start-server liberty:test-stop-server liberty:undeploy liberty:uninstall-feature - # options - "-Dmaven.test.skip=true" -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile "-Dpmd.skip=true" "-Dcheckstyle.skip=true" "-Dtycho.mode=maven" "-Dmaven.test.failure.ignore=true" "-DgroupId=" "-DartifactId=" "-Dversion=" "-Dpackaging=jar" "-Dfile=" + # options + "-Dmaven.test.skip=true" -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile "-Dpmd.skip=true" "-Dcheckstyle.skip=true" "-Dtycho.mode=maven" "-Dmaven.test.failure.ignore=true" "-DgroupId=" "-DartifactId=" "-Dversion=" "-Dpackaging=jar" "-Dfile=" - # arguments - -am --also-make - -amd --also-make-dependents-am - -B --batch-mode - -b --builder - -C --strict-checksums - -c --lax-checksums - -cpu --check-plugin-updates - -D --define - -e --errors - -emp --encrypt-master-password - -ep --encrypt-password - -f --file - -fae --fail-at-end - -ff --fail-fast - -fn --fail-never - -gs --global-settings - -gt --global-toolchains - -h --help - -l --log-file - -llr --legacy-local-repository - -N --non-recursive - -npr --no-plugin-registry - -npu --no-plugin-updates - -nsu --no-snapshot-updates - -o --offline - -P --activate-profiles - -pl --projects - -q --quiet - -rf --resume-from - -s --settings - -t --toolchains - -T --threads - -U --update-snapshots - -up --update-plugins - -v --version - -V --show-version - -X --debug + # arguments + -am --also-make + -amd --also-make-dependents-am + -B --batch-mode + -b --builder + -C --strict-checksums + -c --lax-checksums + -cpu --check-plugin-updates + -D --define + -e --errors + -emp --encrypt-master-password + -ep --encrypt-password + -f --file + -fae --fail-at-end + -ff --fail-fast + -fn --fail-never + -gs --global-settings + -gt --global-toolchains + -h --help + -l --log-file + -llr --legacy-local-repository + -N --non-recursive + -npr --no-plugin-registry + -npu --no-plugin-updates + -nsu --no-snapshot-updates + -o --offline + -P --activate-profiles + -pl --projects + -q --quiet + -rf --resume-from + -s --settings + -t --toolchains + -T --threads + -U --update-snapshots + -up --update-plugins + -v --version + -V --show-version + -X --debug - cli:execute cli:execute-phase - archetype:generate generate-sources - cobertura:cobertura - -Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi) - -Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi) + cli:execute cli:execute-phase + archetype:generate generate-sources + cobertura:cobertura + -Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi) + -Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi) - $profiles - $modules - ) + $profiles + $modules + ) } compctl -K listMavenCompletions mvn mvnw From a0ac789f2abf475346505cd372a3843b3b93d91e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 11 Oct 2021 12:15:47 +0200 Subject: [PATCH 42/88] feat(ssh-agent): allow lazy-loading SSH identities (#6309) Fixes #7477 --- plugins/ssh-agent/README.md | 18 +++++++++++++++++- plugins/ssh-agent/ssh-agent.plugin.zsh | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plugins/ssh-agent/README.md b/plugins/ssh-agent/README.md index d1a504b1e..1d6914ec6 100644 --- a/plugins/ssh-agent/README.md +++ b/plugins/ssh-agent/README.md @@ -21,7 +21,23 @@ zstyle :omz:plugins:ssh-agent agent-forwarding on ---- -To **load multiple identities** use the `identities` style, For example: +To **NOT load any identities on start** use the `lazy` setting. This is particularly +useful when combined with the `AddKeysToAgent` setting (available since OpenSSH 7.2), +since it allows to enter the password only on first use. _NOTE: you can know your +OpenSSH version with `ssh -V`._ + +```zsh +zstyle :omz:plugins:ssh-agent lazy yes +``` + +You can enable `AddKeysToAgent` by passing `-o AddKeysToAgent=yes` to the `ssh` command, +or by adding `AddKeysToAgent yes` to your `~/.ssh/config` file [1]. +See the [OpenSSH 7.2 Release Notes](http://www.openssh.com/txt/release-7.2). + +---- + +To **load multiple identities** use the `identities` style (**this has no effect +if the `lazy` setting is enabled**). For example: ```zsh zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 2d7d8a2a0..4bd2dedcc 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -96,7 +96,10 @@ else _start_agent fi -_add_identities +# Don't add identities if lazy-loading is enabled +if ! zstyle -b :omz:plugins:ssh-agent lazy; then + _add_identities +fi unset agent_forwarding ssh_env_cache unfunction _start_agent _add_identities From beeda72826f7288d3edf6cec4114bbda9bbae347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 11 Oct 2021 15:21:42 +0200 Subject: [PATCH 43/88] fix(ssh-agent): fix for bad `zstyle` command argument Fixes #10282 --- plugins/ssh-agent/ssh-agent.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 4bd2dedcc..c006f1413 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -97,7 +97,7 @@ else fi # Don't add identities if lazy-loading is enabled -if ! zstyle -b :omz:plugins:ssh-agent lazy; then +if ! zstyle -t :omz:plugins:ssh-agent lazy; then _add_identities fi From dbf555438e48fe447736200bd6f6d969a51a8086 Mon Sep 17 00:00:00 2001 From: Igor Gavelyuk Date: Wed, 13 Oct 2021 11:00:46 +0300 Subject: [PATCH 44/88] feat(obraun): display time with leading zeros (#10289) --- themes/obraun.zsh-theme | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/themes/obraun.zsh-theme b/themes/obraun.zsh-theme index cc2769e4b..c64362b04 100644 --- a/themes/obraun.zsh-theme +++ b/themes/obraun.zsh-theme @@ -2,10 +2,9 @@ if [ "$USERNAME" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -PROMPT='%{$fg[green]%}[%*]%{$reset_color%} %{$fg_no_bold[cyan]%}%n %{${fg_bold[blue]}%}::%{$reset_color%} %{$fg[yellow]%}%m%{$reset_color%} %{$fg_no_bold[magenta]%} ➜ %{$reset_color%} %{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} ' +PROMPT='%{$fg[green]%}[%D{%H:%M:%S}]%{$reset_color%} %{$fg_no_bold[cyan]%}%n %{${fg_bold[blue]}%}::%{$reset_color%} %{$fg[yellow]%}%m%{$reset_color%} %{$fg_no_bold[magenta]%} ➜ %{$reset_color%} %{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} ' RPS1="${return_code}" ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}‹" ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$reset_color%}" - From 19f9b6f1ade7788b07480be685cf3fcb117cad84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 13 Oct 2021 11:58:56 +0200 Subject: [PATCH 45/88] feat(updater): add support for terminal hyperlinks --- tools/upgrade.sh | 101 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 8 deletions(-) diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 1424d1433..7642858fe 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -15,11 +15,98 @@ cd "$ZSH" # Use colors, but only if connected to a terminal # and that terminal supports them. +# 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 or Konsole also support hyperlinks + if [ -n "$WT_SESSION" ] || [ -n "$KONSOLE_VERSION" ]; then + return 0 + fi + + return 1 +} + +fmt_link() { + # $1: text, $2: url, $3: fallback mode + if supports_hyperlinks; then + printf '\033]8;;%s\a%s\033]8;;\a\n' "$2" "$1" + return + fi + + case "$3" in + --text) printf '%s\n' "$1" ;; + --url|*) fmt_underline "$2" ;; + esac +} + +fmt_underline() { + is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*" +} + setopt typeset_silent typeset -a RAINBOW -typeset RED GREEN YELLOW BLUE BOLD DIM UNDER RESET -if [ -t 1 ]; then +if is_tty; then RAINBOW=( "$(printf '\033[38;5;196m')" "$(printf '\033[38;5;202m')" @@ -35,8 +122,6 @@ if [ -t 1 ]; then YELLOW=$(printf '\033[33m') BLUE=$(printf '\033[34m') BOLD=$(printf '\033[1m') - DIM=$(printf '\033[2m') - UNDER=$(printf '\033[4m') RESET=$(printf '\033[0m') fi @@ -104,10 +189,10 @@ if git pull --rebase --stat $remote $branch; 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 '\n' - printf "${BLUE}%s${RESET}\n" "$message" - printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "https://twitter.com/ohmyzsh" - printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Want to get involved in the community? Join our Discord:" "https://discord.gg/ohmyzsh" - printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Get your Oh My Zsh swag at:" "https://shop.planetargon.com/collections/oh-my-zsh" + 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)" else ret=$? printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?' From 75fe22b40552305ef7636b7604ba99534d4f7808 Mon Sep 17 00:00:00 2001 From: Eric <192110+scribe@users.noreply.github.com> Date: Mon, 18 Oct 2021 11:58:25 -0600 Subject: [PATCH 46/88] docs(README): document new `zstyle` update settings (#10304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- README.md | 65 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 3ebea91e0..907248beb 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ It's a good idea to inspect the install script from projects you don't yet know. that by downloading the install script first, looking through it so everything looks normal, then running it: -```shell +```sh wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh sh install.sh ``` @@ -57,13 +57,13 @@ Oh My Zsh comes with a shitload of plugins for you to take advantage of. You can Once you spot a plugin (or several) that you'd like to use with Oh My Zsh, you'll need to enable them in the `.zshrc` file. You'll find the zshrc file in your `$HOME` directory. Open it with your favorite text editor and you'll see a spot to list all the plugins you want to load. -```shell +```sh vi ~/.zshrc ``` For example, this might begin to look like this: -```shell +```sh plugins=( git bundler @@ -91,13 +91,13 @@ _Robby's theme is the default one. It's not the fanciest one. It's not the simpl Once you find a theme that you'd like to use, you will need to edit the `~/.zshrc` file. You'll see an environment variable (all caps) in there that looks like: -```shell +```sh ZSH_THEME="robbyrussell" ``` To use a different theme, simply change the value to match the name of your desired theme. For example: -```shell +```sh ZSH_THEME="agnoster" # (this is one of the fancy ones) # see https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster ``` @@ -112,13 +112,13 @@ In case you did not find a suitable theme for your needs, please have a look at If you're feeling feisty, you can let the computer select one randomly for you each time you open a new terminal window. -```shell +```sh ZSH_THEME="random" # (...please let it be pie... please be some pie..) ``` And if you want to pick random theme from a list of your favorite themes: -```shell +```sh ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" @@ -127,7 +127,7 @@ ZSH_THEME_RANDOM_CANDIDATES=( If you only know which themes you don't like, you can add them similarly to an ignored list: -```shell +```sh ZSH_THEME_RANDOM_IGNORED=(pygmalion tjkirch_mod) ``` @@ -152,7 +152,7 @@ If you'd like to change the install directory with the `ZSH` environment variabl `export ZSH=/your/path` before installing, or by setting it before the end of the install pipeline like this: -```shell +```sh ZSH="$HOME/.dotfiles/oh-my-zsh" sh install.sh ``` @@ -162,7 +162,7 @@ If you're running the Oh My Zsh install script as part of an automated install, flag `--unattended` to the `install.sh` script. This will have the effect of not trying to change the default shell, and also won't run `zsh` when the installation has finished. -```shell +```sh sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended ``` @@ -185,7 +185,7 @@ The install script also accepts these variables to allow installation of a diffe For example: -```shell +```sh REPO=apjanke/oh-my-zsh BRANCH=edge sh install.sh ``` @@ -193,13 +193,13 @@ REPO=apjanke/oh-my-zsh BRANCH=edge sh install.sh ##### 1. Clone the repository -```shell +```sh git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh ``` ##### 2. *Optionally*, backup your existing `~/.zshrc` file -```shell +```sh cp ~/.zshrc ~/.zshrc.orig ``` @@ -207,13 +207,13 @@ cp ~/.zshrc ~/.zshrc.orig You can create a new zsh config file by copying the template that we have included for you. -```shell +```sh cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc ``` ##### 4. Change your default shell -```shell +```sh chsh -s $(which zsh) ``` @@ -242,23 +242,40 @@ If you would like to override the functionality of a plugin distributed with Oh ## Getting Updates -By default, you will be prompted to check for upgrades every few weeks. If you would like `oh-my-zsh` to automatically upgrade itself without prompting you, set the following in your `~/.zshrc`: +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**: -```shell -DISABLE_UPDATE_PROMPT=true -``` +1. Automatic update without confirmation prompt: -To disable automatic upgrades, set the following in your `~/.zshrc`: + ```sh + zstyle ':omz:update' mode auto + ``` -```shell -DISABLE_AUTO_UPDATE=true +2. Just offer a reminder every few days, if there are updates available: + + ```sh + zstyle ':omz:update' mode reminder + ``` + +3. To disable automatic updates entirely: + + ```sh + zstyle ':omz:update' mode disabled + ``` + +NOTE: you can control how often Oh My Zsh checks for updates with the following setting: + +```sh +# This will check for updates every 7 days +zstyle ':omz:update' frequency 7 +# This will check for updates every time you open the terminal (not recommended) +zstyle ':omz:update' frequency 0 ``` ### Manual Updates -If you'd like to upgrade 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: +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: -```shell +```sh omz update ``` From f83bb65d47e5c0a238f4950294eeaeaa12738ce4 Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Tue, 19 Oct 2021 10:50:41 -0700 Subject: [PATCH 47/88] Swapping gh with ghlp as 'gh' is reserved for the Github CLI. #9005 --- plugins/ruby/README.md | 3 ++- plugins/ruby/ruby.plugin.zsh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/ruby/README.md b/plugins/ruby/README.md index a2de11991..d2beeb4b3 100644 --- a/plugins/ruby/README.md +++ b/plugins/ruby/README.md @@ -25,7 +25,8 @@ plugins=(... ruby) | gcb | `gem cert --build` | Build private key and self-signed certificate | | gclup | `gem cleanup -n` | Do not uninstall gem | | ggi | `gem generate_index` | Generate index file for gem server | -| gh | `gem help` | Provide additional help | +| ghlp | `gem help` | Provide additional help | | gl | `gem lock` | Generate a lockdown list of gems | | go | `gem open` | Open gem source in default editor | | goe | `gem open -e` | Open gem sources in preferred editor | + diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index 88e769d39..a7583497c 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -19,7 +19,7 @@ alias gcr="gem cert --remove" alias gcb="gem cert --build" alias gclup="gem cleanup -n" alias ggi="gem generate_index" -alias gh="gem help" +alias ghlp="gem help" alias gl="gem lock" alias go="gem open" alias goe="gem open -e" From 4b1f6d638f0783e05a9d2601ee0e1fd902416491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 19 Oct 2021 20:07:40 +0200 Subject: [PATCH 48/88] feat(ruby): add multiple `gem` aliases (#9005) Mostly empty commit to fix the changelog for merge at 6f4c7f64 --- plugins/ruby/README.md | 1 - plugins/ruby/ruby.plugin.zsh | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/ruby/README.md b/plugins/ruby/README.md index d2beeb4b3..76afc79f6 100644 --- a/plugins/ruby/README.md +++ b/plugins/ruby/README.md @@ -29,4 +29,3 @@ plugins=(... ruby) | gl | `gem lock` | Generate a lockdown list of gems | | go | `gem open` | Open gem source in default editor | | goe | `gem open -e` | Open gem sources in preferred editor | - diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index a7583497c..c235b6b69 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -1,5 +1,4 @@ -# TODO: Make this compatible with rvm. -# Run sudo gem on the system ruby, not the active ruby. +# Run sudo gem on the system ruby, not the active ruby alias sgem='sudo gem' # Find ruby file From 8c1495a18e5ba496837bf3978300519edadffaff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 20 Oct 2021 17:09:38 +0200 Subject: [PATCH 49/88] fix(ruby)!: rename aliases that start with `g` to `ge` BREAKING CHANGE: all `gem` aliases that started with `g` now start with `ge` to fix conflicting names with the `git` plugin. Also, the `ghlp` alias is now renamed `geh`. Have a look at the plugin README for more information. Fixes #10320 --- plugins/ruby/README.md | 38 ++++++++++++++++++------------------ plugins/ruby/ruby.plugin.zsh | 28 +++++++++++++------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/plugins/ruby/README.md b/plugins/ruby/README.md index 76afc79f6..59594ade7 100644 --- a/plugins/ruby/README.md +++ b/plugins/ruby/README.md @@ -10,22 +10,22 @@ plugins=(... ruby) ## Aliases -| Alias | Command | Description | -|-------|----------------------------------------|------------------------------------------------------| -| rb | `ruby` | The Ruby command | -| sgem | `sudo gem` | Run sudo gem on the system ruby, not the active ruby | -| rfind | `find . -name "*.rb" \| xargs grep -n` | Find ruby file | -| gin | `gem install` | Install a gem into the local repository | -| gun | `gem uninstall` | Uninstall gems from the local repository | -| gli | `gem list` | Display gems installed locally | -| gi | `gem info` | Show information for the given gem | -| giall | `gem info --all` | Display all gem versions | -| gca | `gem cert --add` | Add a trusted certificate | -| gcr | `gem cert --remove` | Remove a trusted certificate | -| gcb | `gem cert --build` | Build private key and self-signed certificate | -| gclup | `gem cleanup -n` | Do not uninstall gem | -| ggi | `gem generate_index` | Generate index file for gem server | -| ghlp | `gem help` | Provide additional help | -| gl | `gem lock` | Generate a lockdown list of gems | -| go | `gem open` | Open gem source in default editor | -| goe | `gem open -e` | Open gem sources in preferred editor | +| Alias | Command | Description | +|--------|----------------------------------------|------------------------------------------------------| +| rb | `ruby` | The Ruby command | +| sgem | `sudo gem` | Run sudo gem on the system ruby, not the active ruby | +| rfind | `find . -name "*.rb" \| xargs grep -n` | Find ruby file | +| gein | `gem install` | Install a gem into the local repository | +| geun | `gem uninstall` | Uninstall gems from the local repository | +| geli | `gem list` | Display gems installed locally | +| gei | `gem info` | Show information for the given gem | +| geiall | `gem info --all` | Display all gem versions | +| geca | `gem cert --add` | Add a trusted certificate | +| gecr | `gem cert --remove` | Remove a trusted certificate | +| gecb | `gem cert --build` | Build private key and self-signed certificate | +| geclup | `gem cleanup -n` | Do not uninstall gem | +| gegi | `gem generate_index` | Generate index file for gem server | +| geh | `gem help` | Provide additional help | +| gel | `gem lock` | Generate a lockdown list of gems | +| geo | `gem open` | Open gem source in default editor | +| geoe | `gem open -e` | Open gem sources in preferred editor | diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index c235b6b69..890fcb179 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -8,17 +8,17 @@ alias rfind='find . -name "*.rb" | xargs grep -n' alias rb="ruby" # Gem Command Shorthands -alias gin="gem install" -alias gun="gem uninstall" -alias gli="gem list" -alias gi="gem info" -alias giall="gem info --all" -alias gca="gem cert --add" -alias gcr="gem cert --remove" -alias gcb="gem cert --build" -alias gclup="gem cleanup -n" -alias ggi="gem generate_index" -alias ghlp="gem help" -alias gl="gem lock" -alias go="gem open" -alias goe="gem open -e" +alias gein="gem install" +alias geun="gem uninstall" +alias geli="gem list" +alias gei="gem info" +alias geiall="gem info --all" +alias geca="gem cert --add" +alias gecr="gem cert --remove" +alias gecb="gem cert --build" +alias geclup="gem cleanup -n" +alias gegi="gem generate_index" +alias geh="gem help" +alias gel="gem lock" +alias geo="gem open" +alias geoe="gem open -e" From 46f8765f4c871ef9b4e7f8bc448e45f4be15ff58 Mon Sep 17 00:00:00 2001 From: Rob Vadai Date: Wed, 20 Oct 2021 21:58:28 +0100 Subject: [PATCH 50/88] feat(osx): add `freespace` command to clean purgeable disk space (#8762) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/osx/README.md | 43 +++++++++++++++++++------------------- plugins/osx/osx.plugin.zsh | 23 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/plugins/osx/README.md b/plugins/osx/README.md index ecc9327d0..50458f60e 100644 --- a/plugins/osx/README.md +++ b/plugins/osx/README.md @@ -12,27 +12,28 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu) ## Commands -| Command | Description | -| :-------------- | :---------------------------------------------------- | -| `tab` | Open the current directory in a new tab | -| `split_tab` | Split the current terminal tab horizontally | -| `vsplit_tab` | Split the current terminal tab vertically | -| `ofd` | Open the current directory in a Finder window | -| `pfd` | Return the path of the frontmost Finder window | -| `pfs` | Return the current Finder selection | -| `cdf` | `cd` to the current Finder directory | -| `pushdf` | `pushd` to the current Finder directory | -| `pxd` | Return the current Xcode project directory | -| `cdx` | `cd` to the current Xcode project directory | -| `quick-look` | Quick-Look a specified file | -| `man-preview` | Open a specified man page in Preview app | -| `showfiles` | Show hidden files in Finder | -| `hidefiles` | Hide the hidden files in Finder | -| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on | -| `music` | Control Apple Music. Use `music -h` for usage details | -| `spotify` | Control Spotify and search by artist, album, track… | -| `rmdsstore` | Remove .DS\_Store files recursively in a directory | -| `btrestart` | Restart the Bluetooth daemon | +| Command | Description | +| :------------ | :------------------------------------------------------- | +| `tab` | Open the current directory in a new tab | +| `split_tab` | Split the current terminal tab horizontally | +| `vsplit_tab` | Split the current terminal tab vertically | +| `ofd` | Open the current directory in a Finder window | +| `pfd` | Return the path of the frontmost Finder window | +| `pfs` | Return the current Finder selection | +| `cdf` | `cd` to the current Finder directory | +| `pushdf` | `pushd` to the current Finder directory | +| `pxd` | Return the current Xcode project directory | +| `cdx` | `cd` to the current Xcode project directory | +| `quick-look` | Quick-Look a specified file | +| `man-preview` | Open a specified man page in Preview app | +| `showfiles` | Show hidden files in Finder | +| `hidefiles` | Hide the hidden files in Finder | +| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on | +| `music` | Control Apple Music. Use `music -h` for usage details | +| `spotify` | Control Spotify and search by artist, album, track… | +| `rmdsstore` | Remove .DS\_Store files recursively in a directory | +| `btrestart` | Restart the Bluetooth daemon | +| `freespace` | Erases purgeable disk space with 0s on the selected disk | ## Acknowledgements diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 5455d7c5f..16f16ddb6 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -233,6 +233,29 @@ function rmdsstore() { find "${@:-.}" -type f -name .DS_Store -delete } +# Erases purgeable disk space with 0s on the selected disk +function freespace(){ + if [[ -z "$1" ]]; then + echo "Usage: $0 " + echo "Example: $0 /dev/disk1s1" + echo + echo "Possible disks:" + df -h | awk 'NR == 1 || /^\/dev\/disk/' + return 1 + fi + + echo "Cleaning purgeable files from disk: $1 ...." + diskutil secureErase freespace 0 $1 +} + +_freespace() { + local -a disks + disks=("${(@f)"$(df | awk '/^\/dev\/disk/{ printf $1 ":"; for (i=9; i<=NF; i++) printf $i FS; print "" }')"}") + _describe disks disks +} + +compdef _freespace freespace + # Music / iTunes control function source "${0:h:A}/music" From f1dd97bb2a9df55fae9b1ca26c829b9f8b290667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 23 Oct 2021 05:16:15 +0200 Subject: [PATCH 51/88] fix(ssh-agent): fix check for running `ssh-agent` process with hidepid /proc (#8492) Fixes #8492 --- plugins/ssh-agent/ssh-agent.plugin.zsh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index c006f1413..47dfef5b0 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -6,9 +6,11 @@ function _start_agent() { if [[ -f "$ssh_env_cache" ]]; then . "$ssh_env_cache" > /dev/null - { - [[ "$USERNAME" = root ]] && command ps ax || command ps x - } | command grep ssh-agent | command grep -q $SSH_AGENT_PID && return 0 + # Test if $SSH_AUTH_SOCK is visible + zmodload zsh/net/socket + if [[ -S "$SSH_AUTH_SOCK" ]] && zsocket "$SSH_AUTH_SOCK" 2>/dev/null; then + return 0 + fi fi # Set a maximum lifetime for identities added to ssh-agent From 1e5e834e0f6486a569efd6b12ce4e33624fef0c9 Mon Sep 17 00:00:00 2001 From: Sina Tak Tehrani Date: Mon, 25 Oct 2021 20:28:22 +0200 Subject: [PATCH 52/88] fix(cli): exit `omz update` with correct error code (#10342) --- lib/cli.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 4b14360c1..0b6bbc6cb 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -755,9 +755,9 @@ function _omz::update { # Run update script if [[ "$1" != --unattended ]]; then - ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive + ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive || return $? else - ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" + ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" || return $? fi # Update last updated file From c2b9ae29371f142fe7f2da694f893f1365170bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 26 Oct 2021 13:23:07 +0200 Subject: [PATCH 53/88] fix(changelog): don't show more than 40 commits (#10345) Fixes #10345 --- tools/changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 7329a9526..ebdffba0a 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -400,7 +400,7 @@ function main { # commit if $since is unset, in short hash form. command git rev-list --abbrev-commit --abbrev=7 ${since:+$since..}$until | while read hash; do # Truncate list on versions with a lot of commits - if [[ -z "$since" ]] && (( ++read_commits > 35 )); then + if (( ++read_commits > 40 )); then truncate=1 break fi From 4f67b02a9f43b0996ad85ee600b468399e1477e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Camelo=20Freitas?= Date: Tue, 26 Oct 2021 07:07:46 -0700 Subject: [PATCH 54/88] feat(mix): update `mix` commands and descriptions (#10273) --- plugins/mix/README.md | 16 ++++++++-------- plugins/mix/_mix | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/plugins/mix/README.md b/plugins/mix/README.md index 878f370f2..f0258fe88 100644 --- a/plugins/mix/README.md +++ b/plugins/mix/README.md @@ -9,11 +9,11 @@ plugins=(... mix) ``` ## Supported Task Types -| Task Type | Documentation | -|-------------------------|----------------------------------------------------------| -| Elixir | [Elixir Lang](https://elixir-lang.org/) | -| Phoenix v1.2.1 and below| [Phoenix](https://hexdocs.pm/phoenix/1.2.1/Phoenix.html) | -| Phoenix v1.3.0 and above| [Phoenix](https://hexdocs.pm/phoenix/Phoenix.html) | -| Ecto | [Ecto](https://hexdocs.pm/ecto/Ecto.html) | -| Hex | [Hex](https://hex.pm/) | -| Nerves | [Nerves](https://nerves-project.org/) | +| Task Type | Documentation | +|--------------------------|----------------------------------------------------------| +| Elixir | [Elixir Lang](https://elixir-lang.org/) | +| Phoenix v1.2.1 and below | [Phoenix](https://hexdocs.pm/phoenix/1.2.1/Phoenix.html) | +| Phoenix v1.3.0 and above | [Phoenix](https://hexdocs.pm/phoenix/Phoenix.html) | +| Ecto | [Ecto](https://hexdocs.pm/ecto/Ecto.html) | +| Hex | [Hex](https://hex.pm/) | +| Nerves | [Nerves](https://nerves-project.org/) | diff --git a/plugins/mix/_mix b/plugins/mix/_mix index c0fe68c91..7940ff1c9 100644 --- a/plugins/mix/_mix +++ b/plugins/mix/_mix @@ -5,8 +5,10 @@ local -a _1st_arguments _1st_arguments=( + 'app.config:Configures all registered apps' 'app.start:Start all registered apps' - 'archive:List all archives' + 'app.tree:Prints the application tree' + 'archive:Lists installed archives' 'archive.build:Archive this project into a .ez file' 'archive.install:Install an archive locally' 'archive.uninstall:Uninstall archives' @@ -18,6 +20,7 @@ _1st_arguments=( "deps.clean:Remove the given dependencies' files" 'deps.compile:Compile dependencies' 'deps.get:Get all out of date dependencies' + 'deps.tree:Prints the dependency tree' 'deps.unlock:Unlock the given dependencies' 'deps.update:Update the given dependencies' 'do:Executes the tasks separated by comma' @@ -30,27 +33,39 @@ _1st_arguments=( 'ecto.migrate:Runs Ecto migration' 'ecto.migrations:Displays the up / down migration status' 'ecto.rollback:Reverts applied migrations' + 'escript:Lists installed escripts' 'escript.build:Builds an escript for the project' + 'escript.install:Installs an escript locally' + 'escript.uninstall:Uninstalls escripts' 'firmware:Nerves - Build a firmware image for the selected target platform' 'firmware.burn:Nerves - Writes the generated firmware image to an attached SDCard or file' 'firmware.image:Nerves - Create a firmware image file that can be copied byte-for-byte' 'format:Formats the given files and patterns' 'help:Print help information for tasks' 'hex:Print hex help information' - 'hex.config:Read or update hex config' - 'hex.docs:Publish docs for package' + 'hex.audit:Shows retired Hex deps for the current project' + 'hex.build:Builds a new package version locally' + 'hex.config:Reads, updates or deletes local Hex config' + 'hex.docs:Fetches or opens documentation of a package' 'hex.info:Print hex information' + 'hex.organization:Manages Hex.pm organizations' 'hex.key:Hex API key tasks' - 'hex.outdated:Shows outdated hex deps for the current project' - 'hex.owner:Hex package ownership tasks' + 'hex.outdated:Shows outdated Hex deps for the current project' + 'hex.owner:Manages Hex package ownership' + 'hex.package:Fetches or diffs packages' 'hex.publish:Publish a new package version' + 'hex.registry:Manages local Hex registries' + 'hex.repo:Manages Hex repositories' + 'hex.retire:Retires a package version' 'hex.search:Search for package names' - 'hex.user:Hex user tasks' + 'hex.sponsor:Show Hex packages accepting sponsorships' + 'hex.user:Manages your Hex user account' 'loadconfig:Loads and persists the given configuration' 'local:List local tasks' 'local.hex:Install hex locally' 'local.phoenix:Updates Phoenix locally' 'local.phx:Updates the Phoenix project generator locally' + 'local.public_keys:Manages public keys' 'local.rebar:Install rebar locally' 'nerves.artifact:Create an artifact for a specified Nerves package' 'nerves.artifact.get:Nerves get artifacts' @@ -69,21 +84,33 @@ _1st_arguments=( 'phoenix.server:Starts applications and their servers' 'phx.digest:Digests and compresses static files' 'phx.digest.clean:Removes old versions of static assets.' + 'phx.gen.auth:Generates authentication logic for a resource' + 'phx.gen.cert:Generates a self-signed certificate for HTTPS testing' 'phx.gen.channel:Generates a Phoenix channel' 'phx.gen.context:Generates a context with functions around an Ecto schema' 'phx.gen.embedded:Generates an embedded Ecto schema file' 'phx.gen.html:Generates controller, views, and context for an HTML resource' 'phx.gen.json:Generates controller, views, and context for a JSON resource' + 'phx.gen.live:Generates LiveView, templates, and context for a resource' + 'phx.gen.notifier:Generates a notifier that delivers emails by default' 'phx.gen.presence:Generates a Presence tracker' 'phx.gen.schema:Generates an Ecto schema and migration file' 'phx.gen.secret:Generates a secret' - 'phx.new:Creates a new Phoenix v1.3.0 application' + 'phx.gen.socket:Generates a Phoenix socket handler' + 'phx.new:Creates a new Phoenix application' 'phx.new.ecto:Creates a new Ecto project within an umbrella project' 'phx.new.web:Creates a new Phoenix web project within an umbrella project' 'phx.routes:Prints all routes' 'phx.server:Starts applications and their servers' + 'profile.cprof:Profiles the given file or expression with cprof' + 'profile.eprof:Profiles the given file or expression with eprof' + 'profile.fprof:Profiles the given file or expression with fprof' + 'release:Assembles a self-contained release' + 'release.init:Generates sample files for releases' 'run:Run the given file or expression' "test:Run a project's tests" + 'test.coverage:Build report from exported test coverage' + 'xref:Prints cross reference information' '--help:Describe available tasks' '--version:Prints the Elixir version information' ) @@ -93,7 +120,7 @@ __task_list () local expl declare -a tasks - tasks=(app.start archive archive.build archive.install archive.uninstall clean cmd compile compile.protocols deps deps.clean deps.compile deps.get deps.unlock deps.update do escript.build format help hex hex.config hex.docs hex.info hex.key hex.outdated hex.owner hex.publish hex.search hex.user loadconfig local local.hex local.rebar new phoenix.digest phoenix.gen.channel phoenix.gen.html phoenix.gen.json phoenix.gen.model phoenix.gen.secret phoenix.new phoenix.routes phoenix.server phx.digest phx.digest.clean phx.gen.channel phx.gen.context phx.gen.embedded phx.gen.html phx.gen.json phx.gen.presence phx.gen.schema phx.gen.secret phx.new phx.new.ecto phx.new.web phx.routes phx.server run test) + tasks=(app.config app.start app.tree archive archive.build archive.install archive.uninstall clean cmd compile compile.protocols deps deps.clean deps.compile deps.get deps.tree deps.unlock deps.update do ecto.create ecto.drop ecto.dump ecto.gen.migration ecto.gen.repo ecto.load ecto.migrate ecto.migrations ecto.rollback escript escript.build escript.install escript.uninstall firmware firmware.burn firmware.image format help hex hex.audit hex.build hex.config hex.docs hex.info hex.organization hex.key hex.outdated hex.owner hex.package hex.publish hex.registry hex.repo hex.retire hex.search hex.sponsor hex.user loadconfig local local.hex local.phoenix local.phx local.public_keys local.rebar nerves.artifact nerves.artifact.get nerves.info nerves.new nerves.release.init new phoenix.digest phoenix.gen.channel phoenix.gen.html phoenix.gen.json phoenix.gen.model phoenix.gen.secret phoenix.new phoenix.routes phoenix.server phx.digest phx.digest.clean phx.gen.auth phx.gen.cert phx.gen.channel phx.gen.context phx.gen.embedded phx.gen.html phx.gen.json phx.gen.live phx.gen.notifier phx.gen.presence phx.gen.schema phx.gen.secret phx.gen.socket phx.new phx.new.ecto phx.new.web phx.routes phx.server profile.cprof profile.eprof profile.fprof release release.init run test test.coverage xref) _wanted tasks expl 'help' compadd $tasks } From 9c8131e417a15fccb15615e3b03ce44a53678fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 26 Oct 2021 18:24:29 +0200 Subject: [PATCH 55/88] perf(changelog): use a single `git log` command to get all commit messages --- tools/changelog.sh | 50 +++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index ebdffba0a..13cfb9530 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -1,5 +1,8 @@ #!/usr/bin/env zsh +cd "$ZSH" +setopt extendedglob + ############################## # CHANGELOG SCRIPT CONSTANTS # ############################## @@ -114,15 +117,8 @@ function parse-commit { fi } - # Ignore commit if it is a merge commit - if [[ $(command git show -s --format=%p $1 | wc -w) -gt 1 ]]; then - return - fi - # Parse commit with hash $1 - local hash="$1" subject body warning rhash - subject="$(command git show -s --format=%s $hash)" - body="$(command git show -s --format=%b $hash)" + local hash="$1" subject="$2" body="$3" warning rhash # Commits following Conventional Commits (https://www.conventionalcommits.org/) # have the following format, where parts between [] are optional: @@ -384,7 +380,8 @@ function main { # Commit classification arrays local -A commits subjects scopes breaking reverts local truncate=0 read_commits=0 - local hash version tag + local version tag + local hash refs subject body # Get the first version name: # 1) try tag-like version, or @@ -396,17 +393,40 @@ function main { || version=$(command git symbolic-ref --quiet --short $until 2>/dev/null) \ || version=$(command git rev-parse --short $until 2>/dev/null) - # Get commit list from $until commit until $since commit, or until root - # commit if $since is unset, in short hash form. - command git rev-list --abbrev-commit --abbrev=7 ${since:+$since..}$until | while read hash; do + # Get commit list from $until commit until $since commit, or until root commit if $since is unset + local range=${since:+$since..}$until + + # Git log options + # -z: commits are delimited by null bytes + # --format: [7-char hash][ref names][subject][body] + # --abbrev=7: force commit hashes to be 7 characters long + # --no-merges: merge commits are omitted + local SEP="0mZmAgIcSeP" + local -a raw_commits + raw_commits=(${(0)"$(command git log -z \ + --format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=7 \ + --no-merges $range)"}) + + local raw_commit + local -a raw_fields + for raw_commit in $raw_commits; do # Truncate list on versions with a lot of commits if (( ++read_commits > 40 )); then truncate=1 break fi + # Read the commit fields (@ is needed to keep empty values) + raw_fields=("${(@ps:$SEP:)raw_commit}") + hash="${raw_fields[1]}" + refs="${raw_fields[2]}" + subject="${raw_fields[3]}" + body="${raw_fields[4]}" + # If we find a new release (exact tag) - if tag=$(command git describe --exact-match --tags $hash 2>/dev/null); then + if [[ "$refs" = *tag:\ * ]]; then + # Parse tag name (needs: setopt extendedglob) + tag="${${refs##*tag: }%%,# *}" # Output previous release display-release # Reinitialize commit storage @@ -420,7 +440,7 @@ function main { read_commits=1 fi - parse-commit "$hash" + parse-commit "$hash" "$subject" "$body" done display-release @@ -431,8 +451,6 @@ function main { fi } -cd "$ZSH" - # Use raw output if stdout is not a tty if [[ ! -t 1 && -z "$3" ]]; then main "$1" "$2" --raw From 140bfa84320d6f0a9c3b429c1c6be41878e60352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 26 Oct 2021 18:26:02 +0200 Subject: [PATCH 56/88] fix(changelog): go back to ignoring commits from merged branches --- tools/changelog.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 13cfb9530..5c3159732 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -401,17 +401,18 @@ function main { # --format: [7-char hash][ref names][subject][body] # --abbrev=7: force commit hashes to be 7 characters long # --no-merges: merge commits are omitted + # --first-parent: commits from merged branches are omitted local SEP="0mZmAgIcSeP" local -a raw_commits raw_commits=(${(0)"$(command git log -z \ --format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=7 \ - --no-merges $range)"}) + --no-merges --first-parent $range)"}) local raw_commit local -a raw_fields for raw_commit in $raw_commits; do # Truncate list on versions with a lot of commits - if (( ++read_commits > 40 )); then + if [[ -z "$since" ]] && (( ++read_commits > 35 )); then truncate=1 break fi From 0267cb89eba6dc9f2744bfba73ada391a6582249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 26 Oct 2021 18:59:39 +0200 Subject: [PATCH 57/88] perf(changelog): use regex-match instead of `sed` to parse commit subjects --- tools/changelog.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 5c3159732..3641179e2 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -52,10 +52,15 @@ function parse-commit { # make a breaking change function commit:type { - local type="$(sed -E 's/^([a-zA-Z_\-]+)(\(.+\))?!?: .+$/\1/' <<< "$1")" + local type + + # Parse commit type from the subject + if [[ "$1" =~ '^([a-zA-Z_\-]+)(\(.+\))?!?: .+$' ]]; then + type="${match[1]}" + fi # If $type doesn't appear in $TYPES array mark it as 'other' - if [[ -n "${(k)TYPES[(i)$type]}" ]]; then + if [[ -n "$type" && -n "${(k)TYPES[(i)$type]}" ]]; then echo $type else echo other @@ -66,17 +71,18 @@ function parse-commit { local scope # Try to find scope in "type():" format - scope=$(sed -nE 's/^[a-zA-Z_\-]+\((.+)\)!?: .+$/\1/p' <<< "$1") - if [[ -n "$scope" ]]; then - echo "$scope" + if [[ "$1" =~ '^[a-zA-Z_\-]+\((.+)\)!?: .+$' ]]; then + echo "${match[1]}" return fi # If no scope found, try to find it in ":" format - # Make sure it's not a type before printing it - scope=$(sed -nE 's/^([a-zA-Z_\-]+): .+$/\1/p' <<< "$1") - if [[ -z "${(k)TYPES[(i)$scope]}" ]]; then - echo "$scope" + if [[ "$1" =~ '^([a-zA-Z_\-]+): .+$' ]]; then + scope="${match[1]}" + # Make sure it's not a type before printing it + if [[ -z "${(k)TYPES[(i)$scope]}" ]]; then + echo "$scope" + fi fi } @@ -84,7 +90,11 @@ function parse-commit { # Only display the relevant part of the commit, i.e. if it has the format # type[(scope)!]: subject, where the part between [] is optional, only # displays subject. If it doesn't match the format, returns the whole string. - sed -E 's/^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$/\2/' <<< "$1" + if [[ "$1" =~ '^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$' ]]; then + echo "${match[2]}" + else + echo "$1" + fi } # Return subject if the body or subject match the breaking change format From 4b3a5c54117fa8af12878d1b659c14214cb4bbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 26 Oct 2021 20:54:39 +0200 Subject: [PATCH 58/88] fix(changelog): fix percent escapes in `printf` calls --- tools/changelog.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 3641179e2..e32d503b1 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -201,9 +201,9 @@ function display-release { #* Uses $hash from outer scope local hash="${1:-$hash}" case "$output" in - raw) printf "$hash" ;; - text) printf "\e[33m$hash\e[0m" ;; # red - md) printf "[\`$hash\`](https://github.com/ohmyzsh/ohmyzsh/commit/$hash)" ;; + raw) printf '%s' "$hash" ;; + text) printf '\e[33m%s\e[0m' "$hash" ;; # red + md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$hash" ;; esac } @@ -215,16 +215,16 @@ function display-release { case "$output" in raw) case "$level" in - 1) printf "$header\n$(printf '%.0s=' {1..${#header}})\n\n" ;; - 2) printf "$header\n$(printf '%.0s-' {1..${#header}})\n\n" ;; - *) printf "$header:\n\n" ;; + 1) printf '%s\n%s\n\n' "$header" "$(printf '%.0s=' {1..${#header}})" ;; + 2) printf '%s\n%s\n\n' "$header" "$(printf '%.0s-' {1..${#header}})" ;; + *) printf '%s:\n\n' "$header" ;; esac ;; text) case "$level" in - 1|2) printf "\e[1;4m$header\e[0m\n\n" ;; # bold, underlined - *) printf "\e[1m$header:\e[0m\n\n" ;; # bold + 1|2) printf '\e[1;4m%s\e[0m\n\n' "$header" ;; # bold, underlined + *) printf '\e[1m%s:\e[0m\n\n' "$header" ;; # bold esac ;; - md) printf "$(printf '%.0s#' {1..${level}}) $header\n\n" ;; + md) printf '%s %s\n\n' "$(printf '%.0s#' {1..${level}})" "$header" ;; esac } @@ -250,8 +250,8 @@ function display-release { # Print [scope] case "$output" in - raw|md) printf "[$scope]${padding} " ;; - text) printf "[\e[38;5;9m$scope\e[0m]${padding} " ;; # red 9 + raw|md) printf '[%s]%s ' "$scope" "$padding";; + text) printf '[\e[38;5;9m%s\e[0m]%s ' "$scope" "$padding";; # red 9 esac } @@ -264,7 +264,7 @@ function display-release { subject="${(U)subject:0:1}${subject:1}" case "$output" in - raw) printf "$subject" ;; + 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" ;; # In markdown mode, link to (#) issues @@ -277,8 +277,8 @@ function display-release { local type="${1:-${TYPES[$type]:-${(C)type}}}" [[ -z "$type" ]] && return 0 case "$output" in - raw|md) printf "$type: " ;; - text) printf "\e[4m$type\e[24m: " ;; # underlined + raw|md) printf '%s: ' "$type" ;; + text) printf '\e[4m%s\e[24m: ' "$type" ;; # underlined esac } @@ -292,7 +292,7 @@ function display-release { (( $#breaking != 0 )) || return 0 case "$output" in - text) fmt:header "\e[31mBREAKING CHANGES" 3 ;; + text) printf '\e[31m'; fmt:header "BREAKING CHANGES" 3 ;; raw) fmt:header "BREAKING CHANGES" 3 ;; md) fmt:header "BREAKING CHANGES ⚠" 3 ;; esac From 1dba1120410280699c6a97a5252bab24681b46b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 27 Oct 2021 10:12:23 +0200 Subject: [PATCH 59/88] fix(changelog): fix for `${(@ps:$sep:)var}` construct in zsh < 5.0.8 In recent zsh versions, `${(@ps:$sep:)var}` where $sep is a variable containing a separator string and $var is a string with multiple values separated by $sep, the `p` flag makes zsh correctly expand $sep before splitting $var. In versions older than 5.0.8, this doesn't happen, so we use `eval` to get the same effect. --- tools/changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index e32d503b1..664f34608 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -428,7 +428,7 @@ function main { fi # Read the commit fields (@ is needed to keep empty values) - raw_fields=("${(@ps:$SEP:)raw_commit}") + eval "raw_fields=(\"\${(@ps:$SEP:)raw_commit}\")" hash="${raw_fields[1]}" refs="${raw_fields[2]}" subject="${raw_fields[3]}" From 2e46b2a2dcb96cadd94283bdce95eca75bef1433 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Wed, 27 Oct 2021 11:40:09 +0200 Subject: [PATCH 60/88] feat(fzf): support getting fzf from nix-darwin (#10355) --- plugins/fzf/fzf.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index a979fe222..aabd62cb1 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -20,7 +20,9 @@ function setup_using_base_dir() { done if [[ -z "${fzf_base}" ]]; then - if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then + if (( ${+commands[fzf-share]} )) && dir="$(fzf-share)" && [[ -d "${dir}" ]]; then + fzf_base="${dir}" + elif (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then if [[ -d "${dir}" ]]; then fzf_base="${dir}" fi From 1861b5f175dc8f6d6408772b707c9d6deb28a53f Mon Sep 17 00:00:00 2001 From: YR Chen Date: Fri, 29 Oct 2021 23:40:23 +0800 Subject: [PATCH 61/88] feat(xcode): support `Package.swift` as project file in `xc` (#10358) --- plugins/xcode/README.md | 2 +- plugins/xcode/xcode.plugin.zsh | 28 +++++++++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/plugins/xcode/README.md b/plugins/xcode/README.md index 37f882638..664a063a3 100644 --- a/plugins/xcode/README.md +++ b/plugins/xcode/README.md @@ -26,7 +26,7 @@ plugins=(... xcode) ### `xc` -Opens the current directory in Xcode as an Xcode project. This will open one of the `.xcworkspace` and `.xcodeproj` files that it can find in the current working directory. You can also specify a directory to look in for the Xcode files. +Opens the current directory in Xcode as an Xcode project or a Swift package. This will open one of the `.xcworkspace`, `.xcodeproj` and `Package.swift` files that it can find in the current working directory. You can also specify a directory to look in for the Xcode files. Returns 1 if it didn't find any relevant files. ### `xx` diff --git a/plugins/xcode/xcode.plugin.zsh b/plugins/xcode/xcode.plugin.zsh index 89703fe3c..41b9e37e4 100644 --- a/plugins/xcode/xcode.plugin.zsh +++ b/plugins/xcode/xcode.plugin.zsh @@ -6,28 +6,18 @@ alias xcsel='sudo xcode-select --switch' # original author: @subdigital # source: https://gist.github.com/subdigital/5420709 function xc { - local xcode_proj - if [[ $# == 0 ]]; then - xcode_proj=(*.{xcworkspace,xcodeproj}(N)) - else - xcode_proj=($1/*.{xcworkspace,xcodeproj}(N)) - fi + local xcode_files + xcode_files=(${1:-.}/{*.{xcworkspace,xcodeproj},Package.swift}(N)) - - if [[ ${#xcode_proj} -eq 0 ]]; then - if [[ $# == 0 ]]; then - echo "No xcworkspace/xcodeproj file found in the current directory." - else - echo "No xcworkspace/xcodeproj file found in $1." - fi + if [[ ${#xcode_files} -eq 0 ]]; then + echo "No Xcode files found in ${1:-the current directory}." >&2 return 1 - else - local active_path - active_path=$(xcode-select -p) - active_path=${active_path%%/Contents/Developer*} - echo "Found ${xcode_proj[1]}. Opening with ${active_path}" - open -a "$active_path" "${xcode_proj[1]}" fi + + local active_path + active_path=${"$(xcode-select -p)"%%/Contents/Developer*} + echo "Found ${xcode_files[1]}. Opening with ${active_path}" + open -a "$active_path" "${xcode_files[1]}" } # Opens a file or files in the Xcode IDE. Multiple files are opened in multi-file browser From 04c96e235ff522704a6f1482e7fd06a05467cbb7 Mon Sep 17 00:00:00 2001 From: Afzal Sayed <14029371+afzalsayed96@users.noreply.github.com> Date: Sat, 30 Oct 2021 16:50:30 +0530 Subject: [PATCH 62/88] chore: fix grammar mistake in `CONTRIBUTING.md` (#10362) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4903584ee..605142845 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -202,7 +202,7 @@ type(scope)!: subject feat(archlinux): add support for aura AUR helper (#9467) ``` - - Formatted inline code by using backticks: the text inbetween backticks will also be highlighted by + - Formatted inline code by using backticks: the text between backticks will also be highlighted by the changelog tool: ``` feat(shell-proxy): enable unexported `DEFAULT_PROXY` setting (#9774) From bf88ff3f904e7b6675ff142e44d8aae3132bad96 Mon Sep 17 00:00:00 2001 From: Richard Mitchell Date: Tue, 2 Nov 2021 07:05:37 -0400 Subject: [PATCH 63/88] fix(lib): fix `1` alias to `cd` to directory 1 in stack (#10370) --- lib/directories.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/directories.zsh b/lib/directories.zsh index cf87bd7e4..6696854b0 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -9,7 +9,7 @@ alias -g .....='../../../..' alias -g ......='../../../../..' alias -- -='cd -' -alias 1='cd -' +alias 1='cd -1' alias 2='cd -2' alias 3='cd -3' alias 4='cd -4' From 49458b872d1bab1aa8338e319f27c9b3705c9fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 29 Oct 2021 18:21:13 +0200 Subject: [PATCH 64/88] docs(dirhistory): document OPT key alternative for macOS and fix style Fixes #10350 --- plugins/dirhistory/README.md | 42 ++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/plugins/dirhistory/README.md b/plugins/dirhistory/README.md index 602fc8284..ede9b5410 100644 --- a/plugins/dirhistory/README.md +++ b/plugins/dirhistory/README.md @@ -12,19 +12,27 @@ plugins=(... dirhistory) | Shortcut | Description | |-----------------------------------|-----------------------------------------------------------| -| alt + left | Go to previous directory | -| alt + right | Undo alt + left | -| alt + up | Move into the parent directory | -| alt + down | Move into the first child directory by alphabetical order | +| Alt + Left | Go to previous directory | +| Alt + Right | Go to next directory | +| Alt + Up | Move into the parent directory | +| Alt + Down | Move into the first child directory by alphabetical order | -NOTE: some terminals might override the ALT+Arrows key bindings (Windows Terminal, for example). -If these don't work check your terminal settings and change them to a different keyboard shortcut. +**For macOS: use the Option key () instead of Alt**. + +> NOTE: some terminals might override the Alt + Arrows key bindings (e.g. Windows Terminal). +> If these don't work check your terminal settings and change them to a different keyboard shortcut. ## Usage -This plugin allows you to navigate the history of previous current-working-directories using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. MAC users may alternately use OPT-LEFT and OPT-RIGHT. +This plugin allows you to navigate the history of previous working directories using Alt + Left +and Alt + Right. Alt + Left moves to past directories, and +Alt + Right goes back to recent directories. -Also, navigate directory **hierarchy** using ALT-UP and ALT-DOWN. (mac keybindings not yet implemented). ALT-UP moves to higher hierarchy (shortcut for 'cd ..'). ALT-DOWN moves into the first directory found in alphabetical order (useful to navigate long empty directories e.g. java packages) +**NOTE: the maximum directory history size is 30.** + +You can also navigate **directory hierarchies** using Alt + Up and Alt + Down. +Alt + Up moves to the parent directory, while Alt + Down moves into the first +child directory found in alphabetical order (useful to navigate long empty directories, e.g. Java packages). For example, if the shell was started, and the following commands were entered: @@ -35,8 +43,20 @@ cd share cd doc ``` -Then entering ALT-LEFT at the prompt would change directory from /usr/share/doc to /usr/share, then if pressed again to /usr/, then ~. If ALT-RIGHT were pressed the directory would be changed to /usr/ again. +the directory stack (`dirs -v`) would look like this: -After that, ALT-DOWN will probably go to /usr/bin (depends on your /usr structure), ALT-UP will return to /usr, then ALT-UP will get you to / +```console +$ dirs -v +0 /usr/share/doc +1 /usr/share +2 /usr +3 ~ +``` -**Currently the max history size is 30**. The navigation should work for xterm, PuTTY xterm mode, GNU screen, and on MAC with alternate keys as mentioned above. +then entering Alt + Left at the prompt would change directory from `/usr/share/doc` to `/usr/share`, +then if pressed again to `/usr`, then `~`. If Alt + Right were pressed the directory would be changed +to `/usr` again. + +After that, Alt + Down will probably go to `/usr/bin` if `bin` is the first directory in alphabetical +order (depends on your `/usr` folder structure). Alt + Up will return to `/usr`, and once more will get +you to the root folder (`/`). From 7f494944e6e8047b49fdbd42977b4eb4670381fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 29 Oct 2021 18:22:35 +0200 Subject: [PATCH 65/88] fix(dirhistory): fix ALT+Up/Down key bindings for Terminal.app --- plugins/dirhistory/dirhistory.plugin.zsh | 76 ++++++++++-------------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index cbac84600..d949064d8 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -121,35 +121,24 @@ function dirhistory_zle_dirhistory_future() { } zle -N dirhistory_zle_dirhistory_back -# xterm in normal mode -bindkey "\e[3D" dirhistory_zle_dirhistory_back -bindkey "\e[1;3D" dirhistory_zle_dirhistory_back -# Terminal.app -if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then - bindkey "^[b" dirhistory_zle_dirhistory_back -fi -# iTerm2 -if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[^[[D" dirhistory_zle_dirhistory_back -fi -# Putty: -bindkey "\e\e[D" dirhistory_zle_dirhistory_back -# GNU screen: -bindkey "\eO3D" dirhistory_zle_dirhistory_back +bindkey "\e[3D" dirhistory_zle_dirhistory_back # xterm in normal mode +bindkey "\e[1;3D" dirhistory_zle_dirhistory_back # xterm in normal mode +bindkey "\e\e[D" dirhistory_zle_dirhistory_back # Putty +bindkey "\eO3D" dirhistory_zle_dirhistory_back # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2 +Apple_Terminal) bindkey "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app +esac zle -N dirhistory_zle_dirhistory_future -bindkey "\e[3C" dirhistory_zle_dirhistory_future -bindkey "\e[1;3C" dirhistory_zle_dirhistory_future -# Terminal.app -if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then - bindkey "^[f" dirhistory_zle_dirhistory_future -fi -# iTerm2 -if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[^[[C" dirhistory_zle_dirhistory_future -fi -bindkey "\e\e[C" dirhistory_zle_dirhistory_future -bindkey "\eO3C" dirhistory_zle_dirhistory_future +bindkey "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode +bindkey "\e[1;3C" dirhistory_zle_dirhistory_future # xterm in normal mode +bindkey "\e\e[C" dirhistory_zle_dirhistory_future # Putty +bindkey "\eO3C" dirhistory_zle_dirhistory_future # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2 +Apple_Terminal) bindkey "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app +esac # @@ -181,22 +170,21 @@ function dirhistory_zle_dirhistory_down() { } zle -N dirhistory_zle_dirhistory_up -# xterm in normal mode -bindkey "\e[3A" dirhistory_zle_dirhistory_up -bindkey "\e[1;3A" dirhistory_zle_dirhistory_up -if [[ "$TERM_PROGRAM" == "Apple_Terminal" || "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[[A" dirhistory_zle_dirhistory_up -fi -# Putty: -bindkey "\e\e[A" dirhistory_zle_dirhistory_up -# GNU screen: -bindkey "\eO3A" dirhistory_zle_dirhistory_up +bindkey "\e[3A" dirhistory_zle_dirhistory_up # xterm in normal mode +bindkey "\e[1;3A" dirhistory_zle_dirhistory_up # xterm in normal mode +bindkey "\e\e[A" dirhistory_zle_dirhistory_up # Putty +bindkey "\eO3A" dirhistory_zle_dirhistory_up # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2 +Apple_Terminal) bindkey "^[OA" dirhistory_zle_dirhistory_up ;; # Terminal.app +esac zle -N dirhistory_zle_dirhistory_down -bindkey "\e[3B" dirhistory_zle_dirhistory_down -bindkey "\e[1;3B" dirhistory_zle_dirhistory_down -if [[ "$TERM_PROGRAM" == "Apple_Terminal" || "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[[B" dirhistory_zle_dirhistory_down -fi -bindkey "\e\e[B" dirhistory_zle_dirhistory_down -bindkey "\eO3B" dirhistory_zle_dirhistory_down +bindkey "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode +bindkey "\e[1;3B" dirhistory_zle_dirhistory_down # xterm in normal mode +bindkey "\e\e[B" dirhistory_zle_dirhistory_down # Putty +bindkey "\eO3B" dirhistory_zle_dirhistory_down # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2 +Apple_Terminal) bindkey "^[OB" dirhistory_zle_dirhistory_down ;; # Terminal.app +esac From 79cf4b3ceb9bf981ce05adc1db3f01aa551efce8 Mon Sep 17 00:00:00 2001 From: Michael Peick Date: Sun, 10 Nov 2019 15:32:41 +0100 Subject: [PATCH 66/88] feat(dirhistory): support urxvt terminal key binding (#8370) Closes #8370 --- plugins/dirhistory/dirhistory.plugin.zsh | 30 +++++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index d949064d8..26ef07494 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -1,7 +1,7 @@ -## -# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories +## +# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories # that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. -# +# # Navigate directory hierarchy using ALT-UP and ALT-DOWN. # ALT-UP moves to higher hierarchy (cd ..) # ALT-DOWN moves into the first directory found in alphabetical order @@ -14,8 +14,8 @@ export dirhistory_future export DIRHISTORY_SIZE=30 -# Pop the last element of dirhistory_past. -# Pass the name of the variable to return the result in. +# Pop the last element of dirhistory_past. +# Pass the name of the variable to return the result in. # Returns the element if the array was not empty, # otherwise returns empty string. function pop_past() { @@ -32,7 +32,7 @@ function pop_future() { fi } -# Push a new element onto the end of dirhistory_past. If the size of the array +# 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() { if [[ $#dirhistory_past -ge $DIRHISTORY_SIZE ]]; then @@ -76,7 +76,7 @@ function dirhistory_back() { local d="" # Last element in dirhistory_past is the cwd. - pop_past cw + pop_past cw if [[ "" == "$cw" ]]; then # Someone overwrote our variable. Recover it. dirhistory_past=($PWD) @@ -129,6 +129,9 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2 Apple_Terminal) bindkey "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app esac +if (( ${+terminfo[kcub1]} )); then + bindkey "^[${terminfo[kcub1]}" dirhistory_zle_dirhistory_back # urxvt +fi zle -N dirhistory_zle_dirhistory_future bindkey "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode @@ -139,11 +142,14 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2 Apple_Terminal) bindkey "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app esac +if (( ${+terminfo[kcuf1]} )); then + bindkey "^[${terminfo[kcuf1]}" dirhistory_zle_dirhistory_future # urxvt +fi -# +# # HIERARCHY Implemented in this section, in case someone wants to split it to another plugin if it clashes bindings -# +# # Move up in hierarchy function dirhistory_up() { @@ -178,6 +184,9 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2 Apple_Terminal) bindkey "^[OA" dirhistory_zle_dirhistory_up ;; # Terminal.app esac +if (( ${+terminfo[kcuu1]} )); then + bindkey "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt +fi zle -N dirhistory_zle_dirhistory_down bindkey "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode @@ -188,3 +197,6 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2 Apple_Terminal) bindkey "^[OB" dirhistory_zle_dirhistory_down ;; # Terminal.app esac +if (( ${+terminfo[kcud1]} )); then + bindkey "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt +fi From 5e8905b4b22dfec9042590f3aa399935b8b83eed Mon Sep 17 00:00:00 2001 From: Aaron Hutchinson Date: Tue, 2 Nov 2021 18:40:40 +0000 Subject: [PATCH 67/88] feat(ys): increase color contrast with light color schemes (#10295) --- themes/ys.zsh-theme | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/themes/ys.zsh-theme b/themes/ys.zsh-theme index 303c898b4..251b48827 100644 --- a/themes/ys.zsh-theme +++ b/themes/ys.zsh-theme @@ -5,8 +5,10 @@ # # Mar 2013 Yad Smood +typeset +H my_gray="$FG[247]" + # VCS -YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} " +YS_VCS_PROMPT_PREFIX1=" %{$my_gray%}on%{$reset_color%} " YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}" YS_VCS_PROMPT_SUFFIX="%{$reset_color%}" YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x" @@ -60,13 +62,13 @@ local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%})" PROMPT=" %{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \ %(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \ -%{$fg[white]%}@ \ +%{$my_gray%}@ \ %{$fg[green]%}%m \ -%{$fg[white]%}in \ +%{$my_gray%}in \ %{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ ${hg_info}\ ${git_info}\ ${venv_info}\ \ -%{$fg[white]%}[%*] $exit_code +%{$my_gray%}[%*] $exit_code %{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" From 9a02515c7c8eee90909fe72d59d2e3169cb5ed28 Mon Sep 17 00:00:00 2001 From: amnore Date: Wed, 3 Nov 2021 20:17:23 +0800 Subject: [PATCH 68/88] fix(command-not-found): pass arguments correctly in NixOS (#10381) --- plugins/command-not-found/command-not-found.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 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 3ec13429c..cb96fe063 100644 --- a/plugins/command-not-found/command-not-found.plugin.zsh +++ b/plugins/command-not-found/command-not-found.plugin.zsh @@ -50,7 +50,7 @@ fi # NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found if [[ -x /run/current-system/sw/bin/command-not-found ]]; then command_not_found_handler() { - /run/current-system/sw/bin/command-not-found -- "$@" + /run/current-system/sw/bin/command-not-found "$@" } fi From 0520c2e30934a6e01b27988dca5bbbe3511d6868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 3 Nov 2021 18:21:04 +0100 Subject: [PATCH 69/88] docs: add Security Policy --- SECURITY.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..cda53379f --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,22 @@ +# Security Policy + +## Supported Versions + +At the moment Oh My Zsh only considers the very latest commit to be supported. +We combine that with our fast response to incidents, so risk is minimized. + +| Version | Supported | +|:-------------- |:------------------ | +| master | :white_check_mark: | +| other commits | :x: | + +In the near future we will introduce versioning, so expect this section to change. + +## Reporting a Vulnerability + +If you find a vulnerability, email all the maintainers directly at: + +- Robby: robby [at] planetargon.com +- Marc: hello [at] mcornella.com + +**Do not open an issue or Pull Request directly**, because it might reveal the vulnerability. From 7a2cb106258aa7a18bcd53e45df96c4871a03d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 5 Nov 2021 19:47:29 +0100 Subject: [PATCH 70/88] fix(updater): stop update if connection unavailable --- tools/check_for_upgrade.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 157b0cce2..8264762b6 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -54,14 +54,27 @@ function is_update_available() { [[ "$repo" = ohmyzsh/ohmyzsh ]] || return 0 local api_url="https://api.github.com/repos/${repo}/commits/${branch}" - # Get local and remote HEADs and compare them. If we can't get either assume there are updates - local local_head remote_head + # Get local HEAD. If this fails assume there are updates + local local_head local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0 - remote_head=$(curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null) \ - || remote_head=$(wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null) \ - || remote_head=$(HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null) \ - || return 0 + # Get remote HEAD. If we can't get it assume there are updates unless there is no connection: + # - curl: 6 (could not resolve) or 7 (could not connect) + # - wget: 4 (network unreachable) + # - fetch: 1 (no route to host) + local remote_head ret + remote_head=$( + curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || { + [[ $? -eq 6 || $? -eq 7 ]] && exit 1 + } || wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || { + [[ $? -eq 4 ]] && exit 1 + } || HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null || { + [[ $? -eq 1 ]] && exit 1 + } || exit 0 + ) + + # If can't fetch remote HEAD, return exit code + ret=$?; [[ -n "$remote_head" ]] || return $ret # Compare local and remote HEADs [[ "$local_head" != "$remote_head" ]] From b2f35a7b98455b2bb8c7c3b11db6aa587e1d28bf Mon Sep 17 00:00:00 2001 From: Jonathan Batchelor Date: Fri, 5 Nov 2021 23:40:38 +0000 Subject: [PATCH 71/88] refactor(osx): Rename osx plugin to macos (#10341) Apple changed the name of their operating system from OS X to macOS a number of years ago. This was overdue! As per issue #10311 * refactor(osx): rename `osx` plugin to `macos` * refactor(macos): Add symbolic link from old `osx` plugin name. --- README.md | 2 +- plugins/{osx => macos}/README.md | 8 ++++---- plugins/{osx => macos}/_security | 0 .../{osx/osx.plugin.zsh => macos/macos.plugin.zsh} | 14 ++++++++++---- plugins/{osx => macos}/music | 0 plugins/macos/osx.plugin.zsh | 1 + plugins/{osx => macos}/spotify | 0 plugins/osx | 1 + 8 files changed, 17 insertions(+), 9 deletions(-) rename plugins/{osx => macos}/README.md (94%) rename plugins/{osx => macos}/_security (100%) rename plugins/{osx/osx.plugin.zsh => macos/macos.plugin.zsh} (93%) rename plugins/{osx => macos}/music (100%) create mode 120000 plugins/macos/osx.plugin.zsh rename plugins/{osx => macos}/spotify (100%) create mode 120000 plugins/osx diff --git a/README.md b/README.md index 907248beb..5712c1701 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ plugins=( git bundler dotenv - osx + macos rake rbenv ruby diff --git a/plugins/osx/README.md b/plugins/macos/README.md similarity index 94% rename from plugins/osx/README.md rename to plugins/macos/README.md index 50458f60e..1bc4244a4 100644 --- a/plugins/osx/README.md +++ b/plugins/macos/README.md @@ -1,11 +1,11 @@ -# OSX plugin +# MacOS plugin This plugin provides a few utilities to make it more enjoyable on macOS (previously named OSX). -To start using it, add the `osx` plugin to your plugins array in `~/.zshrc`: +To start using it, add the `macos` plugin to your plugins array in `~/.zshrc`: ```zsh -plugins=(... osx) +plugins=(... macos) ``` Original author: [Sorin Ionescu](https://github.com/sorin-ionescu) @@ -31,7 +31,7 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu) | `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on | | `music` | Control Apple Music. Use `music -h` for usage details | | `spotify` | Control Spotify and search by artist, album, track… | -| `rmdsstore` | Remove .DS\_Store files recursively in a directory | +| `rmdsstore` | Remove .DS_Store files recursively in a directory | | `btrestart` | Restart the Bluetooth daemon | | `freespace` | Erases purgeable disk space with 0s on the selected disk | diff --git a/plugins/osx/_security b/plugins/macos/_security similarity index 100% rename from plugins/osx/_security rename to plugins/macos/_security diff --git a/plugins/osx/osx.plugin.zsh b/plugins/macos/macos.plugin.zsh similarity index 93% rename from plugins/osx/osx.plugin.zsh rename to plugins/macos/macos.plugin.zsh index 16f16ddb6..4bcbbaead 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/macos/macos.plugin.zsh @@ -1,3 +1,9 @@ +# Check if 'osx' is still in the plugins list and prompt to change to 'macos' +if [[ -n "${plugins[(r)osx]}" ]]; then + print ${(%):-"%F{yellow}The \`osx\` plugin is deprecated and has been renamed to \`macos\`."} + print ${(%):-"Please update your .zshrc to use the \`%Bmacos%b\` plugin instead.%f"} +fi + # Open the current directory in a Finder window alias ofd='open_command $PWD' @@ -11,7 +17,7 @@ function btrestart() { sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport } -function _omz_osx_get_frontmost_app() { +function _omz_macos_get_frontmost_app() { osascript 2>/dev/null < 0 )) && command="${command}; $*" - local the_app=$(_omz_osx_get_frontmost_app) + local the_app=$(_omz_macos_get_frontmost_app) if [[ "$the_app" == 'Terminal' ]]; then # Discarding stdout to quash "tab N of window id XXX" output @@ -77,7 +83,7 @@ function vsplit_tab() { local command="cd \\\"$PWD\\\"; clear" (( $# > 0 )) && command="${command}; $*" - local the_app=$(_omz_osx_get_frontmost_app) + local the_app=$(_omz_macos_get_frontmost_app) if [[ "$the_app" == 'iTerm' ]]; then osascript < 0 )) && command="${command}; $*" - local the_app=$(_omz_osx_get_frontmost_app) + local the_app=$(_omz_macos_get_frontmost_app) if [[ "$the_app" == 'iTerm' ]]; then osascript 2>/dev/null < Date: Mon, 8 Nov 2021 14:01:34 +0100 Subject: [PATCH 72/88] refactor(percol): fix style, bind keys for vi-mode and remove dependencies --- plugins/percol/README.md | 23 ++++++++++-------- plugins/percol/percol.plugin.zsh | 41 +++++++++++++++++--------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/plugins/percol/README.md b/plugins/percol/README.md index ec5de4f86..78c881f55 100644 --- a/plugins/percol/README.md +++ b/plugins/percol/README.md @@ -1,20 +1,23 @@ -## percol +# percol -Provides some useful function to make [percol](https://github.com/mooz/percol) work with zsh history and [jump plugin](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/jump/jump.plugin.zsh) +Provides some useful function to make [percol](https://github.com/mooz/percol) work with zsh history and +the [jump plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump), optionally. -### Requirements +To use it, add `percol` to the plugins array in your zshrc: -```shell -pip install percol +```zsh +plugins=(... percol) ``` -And [jump](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/jump/jump.plugin.zsh) for `oh-my-zsh` is a optional requirement. +## Requirements -### Usage +- `percol`: install with `pip install percol`. -For default +- (_Optional_) [`jump`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump) plugin: needs to be + enabled before the `percol` plugin. -- `^-r` bind to `percol_select_history`.You can use it to grep your history with percol. +## Usage -- `^-b` bind to `percol_select_marks`.You can use it to grep your bookmarks with percol. +- CTRL-R (bound to `percol_select_history`): you can use it to grep your history with percol. +- CTRL-B (bound to `percol_select_marks`): you can use it to grep your jump bookmarks with percol. diff --git a/plugins/percol/percol.plugin.zsh b/plugins/percol/percol.plugin.zsh index c6adf4e1e..b78383eee 100644 --- a/plugins/percol/percol.plugin.zsh +++ b/plugins/percol/percol.plugin.zsh @@ -1,22 +1,25 @@ -if which percol &> /dev/null; then - function percol_select_history() { - local tac - which gtac &> /dev/null && tac="gtac" || { which tac &> /dev/null && tac="tac" || { tac="tail -r" } } - BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER") - CURSOR=$#BUFFER - zle -R -c - } +(( ${+commands[percol]} )) || return - zle -N percol_select_history - bindkey '^R' percol_select_history +function percol_select_history() { + # print history in reverse order (from -1 (latest) to 1 (oldest)) + BUFFER=$(fc -l -n -1 1 | percol --query "$LBUFFER") + CURSOR=$#BUFFER + zle -R -c +} +zle -N percol_select_history +bindkey -M emacs '^R' percol_select_history +bindkey -M viins '^R' percol_select_history +bindkey -M vicmd '^R' percol_select_history - if which marks &> /dev/null; then - function percol_select_marks() { - BUFFER=$(marks | percol --query "$LBUFFER" | awk '{print $3}') - CURSOR=$#BUFFER # move cursor - zle -R -c # refresh - } - zle -N percol_select_marks - bindkey '^B' percol_select_marks - fi +if (( ${+functions[marks]} )); then + function percol_select_marks() { + # parse directory from marks output (markname -> path) and quote if necessary + BUFFER=${(q)"$(marks | percol --query "$LBUFFER")"##*-> } + CURSOR=$#BUFFER + zle -R -c + } + zle -N percol_select_marks + bindkey -M emacs '^B' percol_select_marks + bindkey -M viins '^B' percol_select_marks + bindkey -M vicmd '^B' percol_select_marks fi From 55682e36920e2ab7633fc6eee11466d3faed0bf8 Mon Sep 17 00:00:00 2001 From: Shahin Sorkh Date: Mon, 8 Nov 2021 18:02:09 +0330 Subject: [PATCH 73/88] feat(tmux): set session name with `ZSH_TMUX_DEFAULT_SESSION_NAME` (#9063) --- plugins/tmux/README.md | 1 + plugins/tmux/tmux.plugin.zsh | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 2ceaf1ad5..551814a39 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -39,3 +39,4 @@ The plugin also supports the following: | `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 | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index e52443a71..0ea3aa02a 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -76,7 +76,11 @@ function _zsh_tmux_plugin_run() { elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then tmux_cmd+=(-f "$ZSH_TMUX_CONFIG") fi - $tmux_cmd new-session + if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then + $tmux_cmd new-session -s $ZSH_TMUX_DEFAULT_SESSION_NAME + else + $tmux_cmd new-session + fi fi if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then From e86c6f5e7fc9f024a427e2870ab70644b5454725 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Tue, 9 Nov 2021 00:04:10 -0800 Subject: [PATCH 74/88] style: use `-n` flag in `head` and `tail` commands (#10391) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- lib/diagnostics.zsh | 2 +- lib/directories.zsh | 2 +- lib/functions.zsh | 4 ++-- lib/git.zsh | 2 +- plugins/scd/scd | 2 +- plugins/systemadmin/README.md | 4 ++-- plugins/systemadmin/systemadmin.plugin.zsh | 12 ++++++------ tools/install.sh | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/diagnostics.zsh b/lib/diagnostics.zsh index 650520797..eaeba7d23 100644 --- a/lib/diagnostics.zsh +++ b/lib/diagnostics.zsh @@ -335,7 +335,7 @@ function _omz_diag_dump_os_specific_version() { builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)" ;; cygwin) - command systeminfo | command head -4 | command tail -2 + command systeminfo | command head -n 4 | command tail -n 2 ;; esac diff --git a/lib/directories.zsh b/lib/directories.zsh index 6696854b0..c62f56468 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -26,7 +26,7 @@ function d () { if [[ -n $1 ]]; then dirs "$@" else - dirs -v | head -10 + dirs -v | head -n 10 fi } compdef _dirs d diff --git a/lib/functions.zsh b/lib/functions.zsh index 73b491a59..fc53611b8 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -1,7 +1,7 @@ function zsh_stats() { fc -l 1 \ | awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \ - | grep -v "./" | sort -nr | head -20 | column -c3 -s " " -t | nl + | grep -v "./" | sort -nr | head -n 20 | column -c3 -s " " -t | nl } function uninstall_oh_my_zsh() { @@ -45,7 +45,7 @@ function takeurl() { data="$(mktemp)" curl -L "$1" > "$data" tar xf "$data" - thedir="$(tar tf "$data" | head -1)" + thedir="$(tar tf "$data" | head -n 1)" rm "$data" cd "$thedir" } diff --git a/lib/git.zsh b/lib/git.zsh index 9a615e77b..8623473b0 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -51,7 +51,7 @@ function parse_git_dirty() { FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}" ;; esac - STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -1) + STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1) fi if [[ -n $STATUS ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" diff --git a/plugins/scd/scd b/plugins/scd/scd index a7db6c265..7e9654b44 100755 --- a/plugins/scd/scd +++ b/plugins/scd/scd @@ -270,7 +270,7 @@ fi # Determine the last recorded directory if [[ -s ${SCD_HISTFILE} ]]; then - last_directory=${"$(tail -1 ${SCD_HISTFILE})"#*;} + last_directory=${"$(tail -n 1 ${SCD_HISTFILE})"#*;} fi # The "record" function adds its arguments to the directory index. diff --git a/plugins/systemadmin/README.md b/plugins/systemadmin/README.md index 052fc6edc..146b58605 100644 --- a/plugins/systemadmin/README.md +++ b/plugins/systemadmin/README.md @@ -17,9 +17,9 @@ plugins=(... systemadmin) | path | `print -l $path` | Displays PATH with each entry on a separate line | | mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output | | psmem | `ps -e -orss=,args= \| sort -b -k1 -nr` | Display the processes using the most memory | -| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -10` | Display the top 10 processes using the most memory | +| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -n 10` | Display the top 10 processes using the most memory | | pscpu | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr` | Display the top processes using the most CPU | -| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -10` | Display the top 10 processes using the most CPU | +| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -n 10` | Display the top 10 processes using the most CPU | | hist10 | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10` | Display the top 10 most used commands in the history | ## Functions diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh index a77f0069b..2f9d1ef35 100644 --- a/plugins/systemadmin/systemadmin.plugin.zsh +++ b/plugins/systemadmin/systemadmin.plugin.zsh @@ -26,10 +26,10 @@ alias path='print -l $path' alias mkdir='mkdir -pv' # get top process eating memory alias psmem='ps -e -orss=,args= | sort -b -k1 -nr' -alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -10' +alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -n 10' # get top process eating cpu if not work try excute : export LC_ALL='C' alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr' -alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr | head -10' +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' @@ -74,7 +74,7 @@ req20() { # top20 of Using tcpdump port 80 access to view http20() { - sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -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 @@ -99,14 +99,14 @@ accessip10() { # top20 of Most Visited file or page visitpage20() { - awk '{print $11}' "$(retlog)"|sort|uniq -c|sort -nr|head -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 consume100() { - awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -100 + awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100 # if django website or other webiste make by no suffix language - # awk '{print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -100 + # awk '{print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100 } # Website traffic statistics (G) diff --git a/tools/install.sh b/tools/install.sh index 7704107c8..ca996f8a7 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -311,7 +311,7 @@ EOF # 1. Use the most preceding one based on $PATH, then check that it's in the shells file # 2. If that fails, get a zsh path from the shells file, then check it actually exists if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then - if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then + if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -n 1) || [ ! -f "$zsh" ]; then fmt_error "no zsh binary found or not present in '$shells_file'" fmt_error "change your default shell manually." return From 4a74349635cf30d305766b459c7cc3246831676e Mon Sep 17 00:00:00 2001 From: Janusz Mordarski Date: Tue, 9 Nov 2021 09:50:25 +0100 Subject: [PATCH 75/88] feat(refined): allow selecting git branch by changing prefix to `:` (#10400) --- themes/refined.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/refined.zsh-theme b/themes/refined.zsh-theme index 2a4188c9d..5d39bd757 100644 --- a/themes/refined.zsh-theme +++ b/themes/refined.zsh-theme @@ -33,8 +33,8 @@ autoload -Uz vcs_info zstyle ':vcs_info:*' enable hg bzr git zstyle ':vcs_info:*:*' unstagedstr '!' zstyle ':vcs_info:*:*' stagedstr '+' -zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%%u%c" -zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%u%c (%a)" +zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%%u%c" +zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%u%c (%a)" zstyle ':vcs_info:*:*' nvcsformats "%~" "" "" # Fastest possible way to check if repo is dirty From 3dc66bd3676a564e3864fb5ccf5641c65fd42c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 10:25:23 +0100 Subject: [PATCH 76/88] fix(emotty): fix glyphs output width in emotty theme --- themes/emotty.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/emotty.zsh-theme b/themes/emotty.zsh-theme index 13adad78d..044b317e8 100644 --- a/themes/emotty.zsh-theme +++ b/themes/emotty.zsh-theme @@ -51,9 +51,9 @@ root_prompt="$emoji[skull]" warn_prompt="$emoji[collision_symbol]" vcs_unstaged_glyph="%{$emoji[circled_latin_capital_letter_m]$emoji2[emoji_style] %2G%}" -vcs_staged_glyph="%{$emoji[high_voltage_sign] %2G%}" -vcs_branch_glyph=$(print -P $'\Ue0a0') #  -vcs_action_glyph=$(print -P $'\U276f') # ❯ +vcs_staged_glyph="%{$emoji[high_voltage_sign]%2G%}" +vcs_branch_glyph=$'\Ue0a0' #  +vcs_action_glyph=$'\U276f' # ❯ red="$FG[001]" yellow="$FG[003]" From 9a11b34101a218532f5133b78e55e48e3dbeb2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 12:03:59 +0100 Subject: [PATCH 77/88] fix(cli): fix check for completion files in `omz plugin load` --- lib/cli.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 0b6bbc6cb..2975acb91 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -446,9 +446,9 @@ function _omz::plugin::load { fi # Check if it has completion to reload compinit - if [[ -f "$base/_$plugin" ]]; then - has_completion=1 - fi + local -a comp_files + comp_files=($base/_*(N)) + has_completion=$(( $#comp_files > 0 )) # Load the plugin if [[ -f "$base/$plugin.plugin.zsh" ]]; then From 5c2440cb0c2ee70afb33bda3954a93abe37c34f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 12:07:23 +0100 Subject: [PATCH 78/88] style(frontend-search): rename completion file to `_frontend` --- plugins/frontend-search/{_frontend-search.sh => _frontend} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/frontend-search/{_frontend-search.sh => _frontend} (100%) diff --git a/plugins/frontend-search/_frontend-search.sh b/plugins/frontend-search/_frontend similarity index 100% rename from plugins/frontend-search/_frontend-search.sh rename to plugins/frontend-search/_frontend From db19589fcf03690a443f1a206361963b47809b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 19:27:43 +0100 Subject: [PATCH 79/88] refactor(updater): simplify check for available updates --- tools/check_for_upgrade.sh | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 8264762b6..70cd21f84 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -58,23 +58,20 @@ function is_update_available() { local local_head local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0 - # Get remote HEAD. If we can't get it assume there are updates unless there is no connection: - # - curl: 6 (could not resolve) or 7 (could not connect) - # - wget: 4 (network unreachable) - # - fetch: 1 (no route to host) - local remote_head ret + # Get remote HEAD. If no suitable command is found assume there are updates + # On any other error, skip the update (connection may be down) + local remote_head remote_head=$( - curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || { - [[ $? -eq 6 || $? -eq 7 ]] && exit 1 - } || wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || { - [[ $? -eq 4 ]] && exit 1 - } || HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null || { - [[ $? -eq 1 ]] && exit 1 - } || exit 0 - ) - - # If can't fetch remote HEAD, return exit code - ret=$?; [[ -n "$remote_head" ]] || return $ret + if (( ${+commands[curl]} )); then + curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null + elif (( ${+commands[wget]} )); then + wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null + elif (( ${+commands[fetch]} )); then + HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null + else + exit 0 + fi + ) || return 1 # Compare local and remote HEADs [[ "$local_head" != "$remote_head" ]] From e3f7b8aa570a09186a7e3d1877b36d7e43d39197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 10 Nov 2021 11:21:59 +0100 Subject: [PATCH 80/88] fix(updater): avoid `git -C` for compatibility with git < v1.8.5 (#10404) Fixes #10404 --- tools/check_for_upgrade.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 70cd21f84..a6fdf4659 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -34,11 +34,11 @@ function current_epoch() { function is_update_available() { local branch - branch=${"$(git -C "$ZSH" config --local oh-my-zsh.branch)":-master} + branch=${"$(cd "$ZSH"; git config --local oh-my-zsh.branch)":-master} local remote remote_url remote_repo - remote=${"$(git -C "$ZSH" config --local oh-my-zsh.remote)":-origin} - remote_url=$(git -C "$ZSH" config remote.$remote.url) + remote=${"$(cd "$ZSH"; git config --local oh-my-zsh.remote)":-origin} + remote_url=$(cd "$ZSH"; git config remote.$remote.url) local repo case "$remote_url" in @@ -56,7 +56,7 @@ function is_update_available() { # Get local HEAD. If this fails assume there are updates local local_head - local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0 + local_head=$(cd "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0 # Get remote HEAD. If no suitable command is found assume there are updates # On any other error, skip the update (connection may be down) From 1d166eaaa138d7413365205c61412ccb68286b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 10 Nov 2021 11:35:17 +0100 Subject: [PATCH 81/88] fix(cli): avoid `git -C` for compatibility with git < v1.8.5 (#10404) --- lib/cli.zsh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 2975acb91..d90cc6469 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -36,7 +36,7 @@ function _omz { elif (( CURRENT == 3 )); then case "$words[2]" in changelog) local -a refs - refs=("${(@f)$(command git -C "$ZSH" for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}") + refs=("${(@f)$(cd "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}") _describe 'command' refs ;; plugin) subcmds=( 'disable:Disable plugin(s)' @@ -171,9 +171,12 @@ EOF function _omz::changelog { local version=${1:-HEAD} format=${3:-"--text"} - if ! command git -C "$ZSH" show-ref --verify refs/heads/$version &>/dev/null && \ - ! command git -C "$ZSH" show-ref --verify refs/tags/$version &>/dev/null && \ - ! command git -C "$ZSH" rev-parse --verify "${version}^{commit}" &>/dev/null; then + if ( + cd "$ZSH" + ! command git show-ref --verify refs/heads/$version && \ + ! command git show-ref --verify refs/tags/$version && \ + ! command git rev-parse --verify "${version}^{commit}" + ) &>/dev/null; then cat >&2 < Date: Wed, 10 Nov 2021 17:03:38 +0300 Subject: [PATCH 82/88] fix(command-not-found): pass arguments correctly in Termux (#10403) --- plugins/command-not-found/command-not-found.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 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 cb96fe063..e46350604 100644 --- a/plugins/command-not-found/command-not-found.plugin.zsh +++ b/plugins/command-not-found/command-not-found.plugin.zsh @@ -57,6 +57,6 @@ fi # Termux: https://github.com/termux/command-not-found if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then command_not_found_handler() { - /data/data/com.termux/files/usr/libexec/termux/command-not-found -- "$1" + /data/data/com.termux/files/usr/libexec/termux/command-not-found "$1" } fi From 1448d234d6d9c25f64a48b16379b34db28a36898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 11 Nov 2021 17:20:07 +0100 Subject: [PATCH 83/88] fix(dirhistory): fix Up/Down key bindings for Terminal.app Reference: https://github.com/ohmyzsh/ohmyzsh/commit/7f49494#commitcomment-60117011 --- plugins/dirhistory/dirhistory.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index 26ef07494..971eb6540 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -182,7 +182,7 @@ bindkey "\e\e[A" dirhistory_zle_dirhistory_up # Putty bindkey "\eO3A" dirhistory_zle_dirhistory_up # GNU screen case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2 -Apple_Terminal) bindkey "^[OA" dirhistory_zle_dirhistory_up ;; # Terminal.app +Apple_Terminal) bindkey "^[[A" dirhistory_zle_dirhistory_up ;; # Terminal.app esac if (( ${+terminfo[kcuu1]} )); then bindkey "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt @@ -195,7 +195,7 @@ bindkey "\e\e[B" dirhistory_zle_dirhistory_down # Putty bindkey "\eO3B" dirhistory_zle_dirhistory_down # GNU screen case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2 -Apple_Terminal) bindkey "^[OB" dirhistory_zle_dirhistory_down ;; # Terminal.app +Apple_Terminal) bindkey "^[[B" dirhistory_zle_dirhistory_down ;; # Terminal.app esac if (( ${+terminfo[kcud1]} )); then bindkey "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt From 6cb41b70a6d04301fd50cd5862ecd705ba226c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 8 Nov 2021 17:46:14 +0100 Subject: [PATCH 84/88] fix(lib): fix `omz_urldecode` unsafe eval bug The `omz_urldecode` function uses an eval to decode the input which can be exploited to inject commands. This is used only in the svn plugin and it requires a complex process to exploit, so it is highly unlikely to have been used by an attacker. --- lib/functions.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/functions.zsh b/lib/functions.zsh index fc53611b8..61f4dd49e 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -237,12 +237,11 @@ function omz_urldecode { tmp=${tmp:gs/\\/\\\\/} # Handle %-escapes by turning them into `\xXX` printf escapes tmp=${tmp:gs/%/\\x/} - local decoded - eval "decoded=\$'$tmp'" + local decoded="$(printf -- "$tmp")" # Now we have a UTF-8 encoded string in the variable. We need to re-encode # it if caller is in a non-UTF-8 locale. - local safe_encodings + local -a safe_encodings safe_encodings=(UTF-8 utf8 US-ASCII) if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding) From 06fc5fb12900d7ee5821a5f20b47be2c4b894ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 15:05:53 +0100 Subject: [PATCH 85/88] fix(dirhistory): fix unsafe eval bug in back and forward widgets The plugin unsafely processes directory paths in pop_past and pop_future. This commit fixes that. --- plugins/dirhistory/dirhistory.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index 971eb6540..e3f45ee99 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -19,14 +19,14 @@ export DIRHISTORY_SIZE=30 # Returns the element if the array was not empty, # otherwise returns empty string. function pop_past() { - eval "$1='$dirhistory_past[$#dirhistory_past]'" + eval "$1=${(q)dirhistory_past[$#dirhistory_past]}" if [[ $#dirhistory_past -gt 0 ]]; then dirhistory_past[$#dirhistory_past]=() fi } function pop_future() { - eval "$1='$dirhistory_future[$#dirhistory_future]'" + eval "$1=${(q)dirhistory_future[$#dirhistory_future]}" if [[ $#dirhistory_future -gt 0 ]]; then dirhistory_future[$#dirhistory_future]=() fi From a263cdac9c15de4003d3289a53cad1d19c8cfb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 09:08:18 +0100 Subject: [PATCH 86/88] fix(lib): fix potential command injection in `title` and `spectrum` functions The `title` function unsafely prints its input without sanitization, which if used with custom user code that calls it, it could trigger command injection. The `spectrum_ls` and `spectrum_bls` could similarly be exploited if a variable is changed in the user's shell environment with a carefully crafted value. This is highly unlikely to occur (and if possible, other methods would be used instead), but with this change the exploit of these two functions is now impossible. --- lib/spectrum.zsh | 6 ++++-- lib/termsupport.zsh | 13 ++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index d5c22a8c5..97f5c360a 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -20,16 +20,18 @@ done # Show all 256 colors with color number function spectrum_ls() { + setopt localoptions nopromptsubst local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: ${FG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}" done } # Show all 256 colors where the background is set to specific color function spectrum_bls() { + setopt localoptions nopromptsubst local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: ${BG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}" done } diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index ef0d78895..49f64400b 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -7,8 +7,7 @@ # (In screen, only short_tab_title is used) # Limited support for Apple Terminal (Terminal can't set window and tab separately) function title { - emulate -L zsh - setopt prompt_subst + setopt localoptions nopromptsubst # Don't set the title if inside emacs, unless using vterm [[ -n "$INSIDE_EMACS" && "$INSIDE_EMACS" != vterm ]] && return @@ -48,13 +47,13 @@ fi # Runs before showing the prompt function omz_termsupport_precmd { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE + [[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return + title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE" } # Runs before executing the command function omz_termsupport_preexec { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return + [[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return emulate -L zsh setopt extended_glob @@ -97,10 +96,10 @@ function omz_termsupport_preexec { fi # cmd name only, or if this is sudo or ssh, the next cmd - local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} + local CMD="${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}" local LINE="${2:gs/%/%%}" - title '$CMD' '%100>...>$LINE%<<' + title "$CMD" "%100>...>${LINE}%<<" } autoload -Uz add-zsh-hook From 72928432f1ddaa244e02067dd7fc14948a4a5ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 09:31:09 +0100 Subject: [PATCH 87/88] fix(plugins): fix potential command injection in `rand-quote` and `hitokoto` The `rand-quote` plugin uses quotationspage.com and prints part of its content to the shell without sanitization, which could trigger command injection. There is no evidence that this has been exploited, but this commit removes all possibility for exploit. Similarly, the `hitokoto` plugin uses the hitokoto.cn website to print quotes to the shell, also without sanitization. Furthermore, there is also no evidence that this has been exploited, but with this change it is now impossible. --- plugins/hitokoto/hitokoto.plugin.zsh | 18 +++++++++++------- plugins/rand-quote/rand-quote.plugin.zsh | 23 ++++++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/plugins/hitokoto/hitokoto.plugin.zsh b/plugins/hitokoto/hitokoto.plugin.zsh index 8646ebf3b..e346d18c5 100644 --- a/plugins/hitokoto/hitokoto.plugin.zsh +++ b/plugins/hitokoto/hitokoto.plugin.zsh @@ -1,14 +1,18 @@ if ! (( $+commands[curl] )); then - echo "hitokoto plugin needs curl to work" >&2 - return + echo "hitokoto plugin needs curl to work" >&2 + return fi function hitokoto { - emulate -L zsh - Q=$(curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | jq -j '.hitokoto+"\t"+.from') + setopt localoptions nopromptsubst - TXT=$(echo "$Q" | awk -F '\t' '{print $1}') - WHO=$(echo "$Q" | awk -F '\t' '{print $2}') + # Get hitokoto data + local -a data + data=("${(ps:\n:)"$(command curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | command jq -j '.hitokoto+"\n"+.from')"}") - [[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”" + # Exit if could not fetch hitokoto + [[ -n "$data" ]] || return 0 + + local quote="${data[1]}" author="${data[2]}" + print -P "%F{3}${author}%f: “%F{5}${quote}%f”" } diff --git a/plugins/rand-quote/rand-quote.plugin.zsh b/plugins/rand-quote/rand-quote.plugin.zsh index 371b997d3..23c21dc8f 100644 --- a/plugins/rand-quote/rand-quote.plugin.zsh +++ b/plugins/rand-quote/rand-quote.plugin.zsh @@ -1,14 +1,23 @@ if ! (( $+commands[curl] )); then - echo "rand-quote plugin needs curl to work" >&2 - return + echo "rand-quote plugin needs curl to work" >&2 + return fi function quote { - emulate -L zsh - Q=$(curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" | iconv -c -f ISO-8859-1 -t UTF-8 | grep -m 1 "dt ") + setopt localoptions nopromptsubst - TXT=$(echo "$Q" | sed -e 's/<\/dt>.*//g' -e 's/.*html//g' -e 's/^[^a-zA-Z]*//' -e 's/<\/a..*$//g') - WHO=$(echo "$Q" | sed -e 's/.*\/quotes\///g' -e 's/<.*//g' -e 's/.*">//g') + # Get random quote data + local data + data="$(command curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" \ + | iconv -c -f ISO-8859-1 -t UTF-8 \ + | command grep -a -m 1 'dt class="quote"')" - [[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”" + # Exit if could not fetch random quote + [[ -n "$data" ]] || return 0 + + local quote author + quote=$(sed -e 's|.*||g' -e 's|.*html||g' -e 's|^[^a-zA-Z]*||' -e 's|||g' <<< "$data") + + print -P "%F{3}${author}%f: “%F{5}${quote}%f”" } From b3ba9978cc42a5031c7b68e3cf917ec2e64643bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Nov 2021 09:54:21 +0100 Subject: [PATCH 88/88] fix(themes): fix potential command injection in `pygmalion`, `pygmalion-virtualenv` and `refined` The pygmalion and pygmalion-virtualenv themes unsafely handle git prompt information which results in a double evaluation of this information, so a malicious git repository could trigger a command injection if the user cloned and entered the repository. A similar method could be used in the refined theme. All themes have been patched against this vulnerability. --- themes/pygmalion-virtualenv.zsh-theme | 11 ++++++----- themes/pygmalion.zsh-theme | 6 +++--- themes/refined.zsh-theme | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/themes/pygmalion-virtualenv.zsh-theme b/themes/pygmalion-virtualenv.zsh-theme index 47b0b4fb1..c2ab7f4e6 100644 --- a/themes/pygmalion-virtualenv.zsh-theme +++ b/themes/pygmalion-virtualenv.zsh-theme @@ -35,19 +35,20 @@ prompt_setup_pygmalion(){ } prompt_pygmalion_precmd(){ - setopt localoptions extendedglob + setopt localoptions nopromptsubst extendedglob local gitinfo=$(git_prompt_info) local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}} - local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")" + local exp_nocolor="$(print -P \"${base_prompt_nocolor}${gitinfo_nocolor}${post_prompt_nocolor}\")" local prompt_length=${#exp_nocolor} + # add new line on prompt longer than 40 characters local nl="" - if [[ $prompt_length -gt 40 ]]; then - nl=$'\n%{\r%}'; + nl=$'\n%{\r%}' fi - PROMPT="$base_prompt$gitinfo$nl$post_prompt" + + PROMPT="${base_prompt}\$(git_prompt_info)${nl}${post_prompt}" } prompt_setup_pygmalion diff --git a/themes/pygmalion.zsh-theme b/themes/pygmalion.zsh-theme index b13adfd5f..be9ca3889 100644 --- a/themes/pygmalion.zsh-theme +++ b/themes/pygmalion.zsh-theme @@ -19,14 +19,14 @@ prompt_setup_pygmalion(){ } prompt_pygmalion_precmd(){ - setopt localoptions extendedglob + setopt localoptions nopromptsubst extendedglob local gitinfo=$(git_prompt_info) local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}} - local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")" + local exp_nocolor="$(print -P \"${base_prompt_nocolor}${gitinfo_nocolor}${post_prompt_nocolor}\")" local prompt_length=${#exp_nocolor} - PROMPT="${base_prompt}${gitinfo}${post_prompt}" + PROMPT="${base_prompt}\$(git_prompt_info)${post_prompt}" } prompt_setup_pygmalion diff --git a/themes/refined.zsh-theme b/themes/refined.zsh-theme index 5d39bd757..5e2de7a87 100644 --- a/themes/refined.zsh-theme +++ b/themes/refined.zsh-theme @@ -70,6 +70,7 @@ preexec() { # Output additional information about paths, repos and exec time # precmd() { + setopt localoptions nopromptsubst vcs_info # Get version control info before we start outputting stuff print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time)%f" unset cmd_timestamp #Reset cmd exec time.