From e9991c6aa09ed5b0a2ac3eeb095364bc3c06953e Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 25 Dec 2020 19:39:42 +0100 Subject: chore: update git-lfs maintainer handle --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b091f5d89..bdd680b47 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,7 +1,7 @@ # Plugin owners plugins/aws/ @maksyms plugins/genpass/ @atoponce -plugins/git-lfs/ @vietduc01100001 +plugins/git-lfs/ @hellovietduc plugins/gitfast/ @felipec plugins/sdk/ @rgoldberg plugins/wp-cli/ @joshmedeski -- cgit v1.2.3-70-g09d2 From 90ffda7ed28dd8273b80bd262c6a28be65e4da71 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 27 Dec 2020 20:51:39 +0100 Subject: fix(genpass): use `log()` instead of `log2()` for zsh < 5.6 (#9548) Fixes #9548 --- plugins/genpass/genpass-xkcd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/genpass/genpass-xkcd b/plugins/genpass/genpass-xkcd index a486ccb40..ed0397138 100755 --- a/plugins/genpass/genpass-xkcd +++ b/plugins/genpass/genpass-xkcd @@ -43,7 +43,7 @@ fi # Figure out how many words we need for 128 bits of security margin. # Each word adds log2($#words) bits. -local -i n=$((ceil(128. / log2($#words)))) +local -i n=$((ceil(128. / (log($#words) / log(2))))) { local c -- cgit v1.2.3-70-g09d2 From 4b2431e8b1c08a2dc14fe31bf07a5e5f08eaa87e Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 28 Dec 2020 19:35:43 +0100 Subject: fix(updater): don't pipe changelog to less when updating Fixes #9509 --- tools/upgrade.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 4df7eb184..358242d0f 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -75,14 +75,10 @@ if git pull --rebase --stat origin master; then # Display changelog with less if available, otherwise just print it to the terminal if [[ "$1" = --interactive ]]; then - if (( $+commands[less] )); then - "$ZSH/tools/changelog.sh" HEAD "$last_commit" --text | LESS= command less -R - else - "$ZSH/tools/changelog.sh" HEAD "$last_commit" - fi + "$ZSH/tools/changelog.sh" HEAD "$last_commit" fi - printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog again with" "omz changelog" + printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog" fi printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET -- cgit v1.2.3-70-g09d2 From a251233bec17829eb46825157258219474b79c5c Mon Sep 17 00:00:00 2001 From: "Josh E. Roberts" Date: Wed, 30 Dec 2020 13:56:56 -0500 Subject: fix(brew)!: update `bcubc` alias to use `brew upgrade --cask` (#9501) BREAKING CHANGE: changes deprecated `brew cask reinstall $(...)` alias to use `brew upgrade --cask` instead. If you don't have this command, run `brew update` to get the latest Homebrew CLI version. Co-authored-by: jakepez --- plugins/brew/README.md | 22 +++++++++++----------- plugins/brew/brew.plugin.zsh | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/brew/README.md b/plugins/brew/README.md index b714b7ac0..bf952bf01 100644 --- a/plugins/brew/README.md +++ b/plugins/brew/README.md @@ -10,17 +10,17 @@ plugins=(... brew) ## Aliases -| Alias | Command | Description | -|----------|------------------------------------------------------------- |---------------------------------------------------------------------| -| `brewp` | `brew pin` | Pin a specified formula so that it's not upgraded. | -| `brews` | `brew list -1` | List installed formulae or the installed files for a given formula. | -| `brewsp` | `brew list --pinned` | List pinned formulae, or show the version of a given formula. | -| `bubo` | `brew update && brew outdated` | Update Homebrew data, then list outdated formulae and casks. | -| `bubc` | `brew upgrade && brew cleanup` | Upgrade outdated formulae and casks, then run cleanup. | -| `bubu` | `bubo && bubc` | Do the last two operations above. | -| `buf` | `brew upgrade --formula` | Upgrade only formulas (not casks). | -| `bcubo` | `brew update && brew outdated --cask` | Update Homebrew data, then list outdated casks. | -| `bcubc` | `brew cask reinstall $(brew outdated --cask) && brew cleanup` | Update outdated casks, then run cleanup. | +| Alias | Command | Description | +|----------|---------------------------------------|---------------------------------------------------------------------| +| `brewp` | `brew pin` | Pin a specified formula so that it's not upgraded. | +| `brews` | `brew list -1` | List installed formulae or the installed files for a given formula. | +| `brewsp` | `brew list --pinned` | List pinned formulae, or show the version of a given formula. | +| `bubo` | `brew update && brew outdated` | Update Homebrew data, then list outdated formulae and casks. | +| `bubc` | `brew upgrade && brew cleanup` | Upgrade outdated formulae and casks, then run cleanup. | +| `bubu` | `bubo && bubc` | Do the last two operations above. | +| `buf` | `brew upgrade --formula` | Upgrade only formulas (not casks). | +| `bcubo` | `brew update && brew outdated --cask` | Update Homebrew data, then list outdated casks. | +| `bcubc` | `brew upgrade --cask && brew cleanup` | Update outdated casks, then run cleanup. | ## Completion diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh index 30eb135bb..532dd9be7 100644 --- a/plugins/brew/brew.plugin.zsh +++ b/plugins/brew/brew.plugin.zsh @@ -6,4 +6,4 @@ alias bubc='brew upgrade && brew cleanup' alias bubu='bubo && bubc' alias buf='brew upgrade --formula' alias bcubo='brew update && brew outdated --cask' -alias bcubc='brew cask reinstall $(brew outdated --cask) && brew cleanup' +alias bcubc='brew upgrade --cask && brew cleanup' -- cgit v1.2.3-70-g09d2 From a4a79eaa8cdf39f35dcd1753b973e830ff7b00b8 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 30 Dec 2020 20:02:24 +0100 Subject: fix(changelog): remove CR characters in breaking change messages The GitHub UI might not remove CR characters from commit description forms filled from a Windows browser. --- tools/changelog.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/changelog.sh b/tools/changelog.sh index 8753212e9..634b61d01 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -91,6 +91,8 @@ function parse-commit { if [[ "$body" =~ "BREAKING CHANGE: (.*)" || \ "$subject" =~ '^[^ :\)]+\)?!: (.*)$' ]]; then message="${match[1]}" + # remove CR characters (might be inserted in GitHub UI commit description form) + message="${message//$'\r'/}" # skip next paragraphs (separated by two newlines or more) message="${message%%$'\n\n'*}" # ... and replace newlines with spaces -- cgit v1.2.3-70-g09d2 From 0e7c81316cab30d28d362f69ddc72be83029ac34 Mon Sep 17 00:00:00 2001 From: hjpotter92 Date: Thu, 31 Dec 2020 15:37:28 +0530 Subject: feat(grc): source `grc.zsh` instead of hard-coding its content (#9553) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/grc/README.md | 28 +++----------------------- plugins/grc/grc.plugin.zsh | 49 +++++++++++----------------------------------- 2 files changed, 14 insertions(+), 63 deletions(-) diff --git a/plugins/grc/README.md b/plugins/grc/README.md index dfda41466..515e87640 100644 --- a/plugins/grc/README.md +++ b/plugins/grc/README.md @@ -10,28 +10,6 @@ plugins=(... grc) ## Commands -The following commands are wrapped by `grc` so that their output is automatically colored: - -- `cc` -- `configure` -- `cvs` -- `df` -- `diff` -- `dig` -- `gcc` -- `gmake` -- `ifconfig` -- `iwconfig` -- `last` -- `ldap` -- `make` -- `mount` -- `mtr` -- `netstat` -- `ping` -- `ping6` -- `ps` -- `traceroute` -- `traceroute6` -- `wdiff` -- `whois` +The plugin sources the bundled alias generator from the installation, available at `/etc/grc.zsh`. +The complete list of wrapped commands may vary depending on the installed version of `grc`, look +at the file mentioned above (`/etc/grc.zsh`) to see which commands are wrapped. diff --git a/plugins/grc/grc.plugin.zsh b/plugins/grc/grc.plugin.zsh index 6a52ec568..b709b9e02 100644 --- a/plugins/grc/grc.plugin.zsh +++ b/plugins/grc/grc.plugin.zsh @@ -1,44 +1,17 @@ -# Adapted from: https://github.com/garabik/grc/blob/master/grc.zsh +#!/usr/bin/env zsh -if [[ "$TERM" = dumb ]] || (( ! $+commands[grc] )); then - return -fi - -# Supported commands -cmds=( - cc - configure - cvs - df - diff - dig - gcc - gmake - ifconfig - iwconfig - last - ldap - make - mount - mtr - netstat - ping - ping6 - ps - traceroute - traceroute6 - wdiff - whois +# common grc.zsh paths +files=( + /etc/grc.zsh # default + /usr/local/etc/grc.zsh # homebrew ) -# Set alias for supported commands -for cmd in $cmds; do - if (( $+commands[$cmd] )); then - eval "function $cmd { - grc --colour=auto \"${commands[$cmd]}\" \"\$@\" - }" +# verify the file is readable and source it +for file in $files; do + if [[ -r "$file" ]]; then + source "$file" + break fi done -# Clean up variables -unset cmds cmd +unset file files -- cgit v1.2.3-70-g09d2 From 0f6836701d82a2ee024153c7f781bb72c2e9a8ac Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 31 Dec 2020 23:20:24 +0100 Subject: fix(CLI): properly get zsh command in `omz update` (#9558) Zsh versions older than 5.3 don't have ZSH_ARGZERO, so use an alternative method to get the zsh command. Fixes #9558 --- lib/cli.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 92d447a8e..6fcffdf87 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -391,7 +391,9 @@ function _omz::update { # Restart the zsh session if [[ $ret -eq 0 && "$1" != --unattended ]]; then + # Old zsh versions don't have ZSH_ARGZERO + local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}" # Check whether to run a login shell - [[ "$ZSH_ARGZERO" = -* ]] && exec -l "${ZSH_ARGZERO#-}" || exec "$ZSH_ARGZERO" + [[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh" fi } -- cgit v1.2.3-70-g09d2 From 3d6db3261082d8f8c2c7dc7d5b94dbcc4ff0b00e Mon Sep 17 00:00:00 2001 From: YantaoZhao Date: Fri, 1 Jan 2021 11:11:01 -0600 Subject: feat(docker): update completion to upstream version (#9470) --- plugins/docker/_docker | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/docker/_docker b/plugins/docker/_docker index 10c19e233..7fe204313 100644 --- a/plugins/docker/_docker +++ b/plugins/docker/_docker @@ -624,7 +624,8 @@ __docker_container_subcommand() { "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " "($help)*--env-file=[Read environment variables from a file]:environment file:_files" "($help)*--expose=[Expose a port from the container without publishing it]: " - "($help)*--group=[Set one or more supplementary user groups for the container]:group:_groups" + "($help)*--gpus=[GPU devices to add to the container ('all' to pass all GPUs)]:device: " + "($help)*--group-add=[Set one or more supplementary user groups for the container]:group:_groups" "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" "($help)--init[Run an init inside the container that forwards signals and reaps processes]" @@ -750,6 +751,7 @@ __docker_container_subcommand() { $opts_attach_exec_run_start \ "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ "($help)--privileged[Give extended Linux capabilities to the command]" \ "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ @@ -791,7 +793,7 @@ __docker_container_subcommand() { "($help -f --follow)"{-f,--follow}"[Follow log output]" \ "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ - "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ "($help -)*:containers:__docker_complete_containers" && ret=0 ;; (ls|list) @@ -1018,6 +1020,7 @@ __docker_image_subcommand() { "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ "($help)--squash[Squash newly built layers into a single new layer]" \ "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ + "($help)--target=[Set the target build stage to build.]" \ "($help)*--ulimit=[ulimit options]:ulimit: " \ "($help)--userns=[Container user namespace]:user namespace:(host)" \ "($help -):path or URL:_directories" && ret=0 @@ -1958,6 +1961,8 @@ __docker_service_subcommand() { opts_help=("(: -)--help[Print usage]") opts_create_update=( + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " "($help)*--constraint=[Placement constraints]:constraint: " "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" "($help)*"{-e=,--env=}"[Set environment variables]:env: " @@ -1970,6 +1975,7 @@ __docker_service_subcommand() { "($help)*--label=[Service labels]:label: " "($help)--limit-cpu=[Limit CPUs]:value: " "($help)--limit-memory=[Limit Memory]:value: " + "($help)--limit-pids[Limit maximum number of processes (default 0 = unlimited)]" "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" "($help)*--mount=[Attach a filesystem mount to the service]:mount: " @@ -2012,6 +2018,7 @@ __docker_service_subcommand() { "($help)*--dns-option=[Set DNS options]:DNS option: " \ "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ + "($help)*--group=[Set one or more supplementary user groups for the container]:group: _groups " \ "($help)--mode=[Service Mode]:mode:(global replicated)" \ "($help)--name=[Service name]:name: " \ "($help)*--placement-pref=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ @@ -2035,7 +2042,7 @@ __docker_service_subcommand() { "($help)--no-task-ids[Do not include task IDs]" \ "($help)--no-trunc[Do not truncate output]" \ "($help)--since=[Show logs since timestamp]:timestamp: " \ - "($help)--tail=[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ "($help -)1:service:__docker_complete_services" && ret=0 ;; @@ -2639,6 +2646,8 @@ __docker_subcommand() { "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \ "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ + "($help)--containerd-namespace=[Containerd namespace to use]:containerd namespace:" \ + "($help)--containerd-plugins-namespace=[Containerd namespace to use for plugins]:containerd namespace:" \ "($help)--data-root=[Root directory of persisted Docker data]:path:_directories" \ "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ -- cgit v1.2.3-70-g09d2 From 0f6aa0182c8d13a2ff909b650d790f83373dc412 Mon Sep 17 00:00:00 2001 From: Peter Babič Date: Fri, 15 May 2020 11:01:18 +0200 Subject: feat(git): add grst alias for `git restore --staged` (#8932) Closes #8932 --- plugins/git/README.md | 1 + plugins/git/git.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index b7f216813..029386267 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -136,6 +136,7 @@ plugins=(... git) | grs | git restore | | grset | git remote set-url | | grss | git restore --source | +| grst | git restore --staged | | grt | cd "$(git rev-parse --show-toplevel \|\| echo .)" | | gru | git reset -- | | grup | git remote update | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index e32136f15..2f97dbc92 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -236,6 +236,7 @@ alias grrm='git remote remove' alias grs='git restore' alias grset='git remote set-url' alias grss='git restore --source' +alias grst='git restore --staged' alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' alias gru='git reset --' alias grup='git remote update' -- cgit v1.2.3-70-g09d2 From 88ffc2f6666fe1196ae57cc75b559b08e08cb616 Mon Sep 17 00:00:00 2001 From: Seamile Date: Sat, 2 Jan 2021 18:57:06 +0800 Subject: fix(lib): mark changes as MODIFIED on 'MM' in `git_prompt_status` (#9552) In the output of `git status -sb`, 'MM' indicates there are both added and modified changes. This change marks that case as MODIFIED instead of ADDED. --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 157c85062..34ffc7ab7 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -170,7 +170,7 @@ function git_prompt_status() { '\?\? ' 'UNTRACKED' 'A ' 'ADDED' 'M ' 'ADDED' - 'MM ' 'ADDED' + 'MM ' 'MODIFIED' ' M ' 'MODIFIED' 'AM ' 'MODIFIED' ' T ' 'MODIFIED' -- cgit v1.2.3-70-g09d2 From 4298e89b4b0a4090e2ff5a1e2014d5a6d04fc25c Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Sat, 2 Jan 2021 13:04:34 +0000 Subject: docs(nvm): clarify how to enable settings (#9542) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It wasn’t clear where I should set the `NVM_AUTOLOAD` variable. The clue was to be found in [the docs for another plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/fzf). It seems setting values need to come before Oh My Zsh is sourced. Updated read me to reflect this, and the fact that one of the settings mentioned is specific to nvm, not this plugin. --- plugins/nvm/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index 749a43403..700613085 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -11,9 +11,11 @@ plugins=(... nvm) ## Settings -- **`NVM_DIR`**: if you have installed nvm in a directory other than `$HOME/.nvm`, set and export `NVM_DIR` - to be the directory where you installed nvm. - +If you installed nvm in a directory other than `$HOME/.nvm`, set and export `NVM_DIR` to be the directory +where you installed nvm. + +These settings should go in your zshrc file, before Oh My Zsh is sourced: + - **`NVM_HOMEBREW`**: if you installed nvm via Homebrew, in a directory other than `/usr/local/opt/nvm`, you can set `NVM_HOMEBREW` to be the directory where you installed it. -- cgit v1.2.3-70-g09d2 From 98762faa0762e1f0ede05149c1f6b3a9db93e074 Mon Sep 17 00:00:00 2001 From: Robert Estelle Date: Sat, 2 Jan 2021 13:41:57 -0800 Subject: fix(vi-mode): control cursor, restore and use visual mode and speed up mode changes (#8004) --- plugins/vi-mode/vi-mode.plugin.zsh | 149 ++++++++++++++++++++++++++++++++----- 1 file changed, 130 insertions(+), 19 deletions(-) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index c91ba05ba..7ff826ea3 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -1,33 +1,61 @@ +# Control whether to force a redraw on each mode change. +# +# Resetting the prompt on every mode change can cause lag when switching modes. +# This is especially true if the prompt does things like checking git status. +# +# Set to "true" to force the prompt to reset on each mode change. +# Set to "false" to force the prompt *not* to reset on each mode change. +# +# (The default is not to reset, unless we're showing the mode in RPS1). +typeset -g VI_MODE_RESET_PROMPT_ON_MODE_CHANGE +typeset -g VI_KEYMAP=main + +function _vi-mode-set-cursor-shape-for-keymap() { + # https://vt100.net/docs/vt510-rm/DECSCUSR + local _shape=0 + case "${1:-${VI_KEYMAP:-main}}" in + main) _shape=6 ;; # vi insert: line + viins) _shape=6 ;; # vi insert: line + isearch) _shape=6 ;; # inc search: line + command) _shape=6 ;; # read a command name + vicmd) _shape=2 ;; # vi cmd: block + visual) _shape=2 ;; # vi visual mode: block + viopp) _shape=0 ;; # vi operation pending: blinking block + *) _shape=0 ;; + esac + printf $'\e[%d q' "${_shape}" +} + # Updates editor information when the keymap changes. function zle-keymap-select() { # update keymap variable for the prompt - VI_KEYMAP=$KEYMAP + typeset -g VI_KEYMAP=$KEYMAP - zle reset-prompt - zle -R + if [ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]; then + zle reset-prompt + zle -R + fi + _vi-mode-set-cursor-shape-for-keymap "${VI_KEYMAP}" } - zle -N zle-keymap-select -function vi-accept-line() { - VI_KEYMAP=main - zle accept-line +# These "echoti" statements were originally set in lib/key-bindings.zsh +# Not sure the best way to extend without overriding. +function zle-line-init() { + typeset -g VI_KEYMAP=main + (( ! ${+terminfo[smkx]} )) || echoti smkx + _vi-mode-set-cursor-shape-for-keymap "${VI_KEYMAP}" } +zle -N zle-line-init -zle -N vi-accept-line - +function zle-line-finish() { + (( ! ${+terminfo[rmkx]} )) || echoti rmkx + _vi-mode-set-cursor-shape-for-keymap default +} +zle -N zle-line-finish bindkey -v -# use custom accept-line widget to update $VI_KEYMAP -bindkey -M vicmd '^J' vi-accept-line -bindkey -M vicmd '^M' vi-accept-line - -# allow v to edit the command line (standard behaviour) -autoload -Uz edit-command-line -zle -N edit-command-line -bindkey -M vicmd 'v' edit-command-line - # allow ctrl-p, ctrl-n for navigate history (standard behaviour) bindkey '^P' up-history bindkey '^N' down-history @@ -45,12 +73,95 @@ bindkey '^s' history-incremental-search-forward bindkey '^a' beginning-of-line bindkey '^e' end-of-line +if [[ "${terminfo[kpp]}" != "" ]]; then + bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history +fi +if [[ "${terminfo[knp]}" != "" ]]; then + bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history +fi + +# start typing + [Up-Arrow] - fuzzy find history forward +if [[ "${terminfo[kcuu1]}" != "" ]]; then + autoload -U up-line-or-beginning-search + zle -N up-line-or-beginning-search + bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search +fi +# start typing + [Down-Arrow] - fuzzy find history backward +if [[ "${terminfo[kcud1]}" != "" ]]; then + autoload -U down-line-or-beginning-search + zle -N down-line-or-beginning-search + bindkey "${terminfo[kcud1]}" down-line-or-beginning-search +fi + +if [[ "${terminfo[khome]}" != "" ]]; then + bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line +fi +if [[ "${terminfo[kend]}" != "" ]]; then + bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line +fi + +if [[ "${terminfo[kcbt]}" != "" ]]; then + bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards +fi + +bindkey '^?' backward-delete-char # [Backspace] - delete backward +if [[ "${terminfo[kdch1]}" != "" ]]; then + bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward +else + bindkey "^[[3~" delete-char + bindkey "^[3;5~" delete-char + bindkey "\e[3~" delete-char +fi + +() { + local wrap_clipboard_widgets + function wrap_clipboard_widgets() { + # NB: Assume we are the first wrapper and that we only wrap native widgets + # See zsh-autosuggestions.zsh for a more generic and more robust wrapper + local verb="$1" + shift + + local widget + local wrapped_name + for widget in "$@"; do + wrapped_name="_zsh-vi-${verb}-${widget}" + if [ "${verb}" = copy ]; then + eval " + function ${wrapped_name}() { + zle .${widget} + printf %s \"\${CUTBUFFER}\" | clipcopy + } + " + else + eval " + function ${wrapped_name}() { + CUTBUFFER=\"\$(clippaste)\" + zle .${widget} + } + " + fi + zle -N "${widget}" "${wrapped_name}" + done + } + + wrap_clipboard_widgets copy vi-yank vi-yank-eol vi-backward-kill-word vi-change-whole-line vi-delete + wrap_clipboard_widgets paste vi-put-{before,after} + unfunction wrap_clipboard_widgets +} + # if mode indicator wasn't setup by theme, define default if [[ "$MODE_INDICATOR" == "" ]]; then - MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}" + MODE_INDICATOR='%B%F{red}<%b<<%f' fi function vi_mode_prompt_info() { + # If we're using the prompt to display mode info, and we haven't explicitly + # disabled "reset prompt on mode change", then set it here. + # + # We do that here instead of the `if` statement below because the user may + # set RPS1/RPROMPT to something else in their custom config. + : "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:=true}" + echo "${${VI_KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}" } -- cgit v1.2.3-70-g09d2 From 0e833b622ba43d38bd62227244d831f3c0e4a325 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 2 Jan 2021 23:59:55 +0100 Subject: refactor(vi-mode): remove duplicate bindkey logic and fix syntax --- plugins/vi-mode/vi-mode.plugin.zsh | 111 ++++++++++++------------------------- 1 file changed, 34 insertions(+), 77 deletions(-) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 7ff826ea3..f83ea7696 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -31,7 +31,7 @@ function zle-keymap-select() { # update keymap variable for the prompt typeset -g VI_KEYMAP=$KEYMAP - if [ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]; then + if [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]]; then zle reset-prompt zle -R fi @@ -73,84 +73,41 @@ bindkey '^s' history-incremental-search-forward bindkey '^a' beginning-of-line bindkey '^e' end-of-line -if [[ "${terminfo[kpp]}" != "" ]]; then - bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history -fi -if [[ "${terminfo[knp]}" != "" ]]; then - bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history -fi - -# start typing + [Up-Arrow] - fuzzy find history forward -if [[ "${terminfo[kcuu1]}" != "" ]]; then - autoload -U up-line-or-beginning-search - zle -N up-line-or-beginning-search - bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search -fi -# start typing + [Down-Arrow] - fuzzy find history backward -if [[ "${terminfo[kcud1]}" != "" ]]; then - autoload -U down-line-or-beginning-search - zle -N down-line-or-beginning-search - bindkey "${terminfo[kcud1]}" down-line-or-beginning-search -fi - -if [[ "${terminfo[khome]}" != "" ]]; then - bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line -fi -if [[ "${terminfo[kend]}" != "" ]]; then - bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line -fi - -if [[ "${terminfo[kcbt]}" != "" ]]; then - bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards -fi - -bindkey '^?' backward-delete-char # [Backspace] - delete backward -if [[ "${terminfo[kdch1]}" != "" ]]; then - bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward -else - bindkey "^[[3~" delete-char - bindkey "^[3;5~" delete-char - bindkey "\e[3~" delete-char -fi - -() { - local wrap_clipboard_widgets - function wrap_clipboard_widgets() { - # NB: Assume we are the first wrapper and that we only wrap native widgets - # See zsh-autosuggestions.zsh for a more generic and more robust wrapper - local verb="$1" - shift - - local widget - local wrapped_name - for widget in "$@"; do - wrapped_name="_zsh-vi-${verb}-${widget}" - if [ "${verb}" = copy ]; then - eval " - function ${wrapped_name}() { - zle .${widget} - printf %s \"\${CUTBUFFER}\" | clipcopy - } - " - else - eval " - function ${wrapped_name}() { - CUTBUFFER=\"\$(clippaste)\" - zle .${widget} - } - " - fi - zle -N "${widget}" "${wrapped_name}" - done - } - - wrap_clipboard_widgets copy vi-yank vi-yank-eol vi-backward-kill-word vi-change-whole-line vi-delete - wrap_clipboard_widgets paste vi-put-{before,after} - unfunction wrap_clipboard_widgets +function wrap_clipboard_widgets() { + # NB: Assume we are the first wrapper and that we only wrap native widgets + # See zsh-autosuggestions.zsh for a more generic and more robust wrapper + local verb="$1" + shift + + local widget + local wrapped_name + for widget in "$@"; do + wrapped_name="_zsh-vi-${verb}-${widget}" + if [ "${verb}" = copy ]; then + eval " + function ${wrapped_name}() { + zle .${widget} + printf %s \"\${CUTBUFFER}\" | clipcopy + } + " + else + eval " + function ${wrapped_name}() { + CUTBUFFER=\"\$(clippaste)\" + zle .${widget} + } + " + fi + zle -N "${widget}" "${wrapped_name}" + done } +wrap_clipboard_widgets copy vi-yank vi-yank-eol vi-backward-kill-word vi-change-whole-line vi-delete +wrap_clipboard_widgets paste vi-put-{before,after} +unfunction wrap_clipboard_widgets + # if mode indicator wasn't setup by theme, define default -if [[ "$MODE_INDICATOR" == "" ]]; then +if [[ -z "$MODE_INDICATOR" ]]; then MODE_INDICATOR='%B%F{red}<%b<<%f' fi @@ -166,6 +123,6 @@ function vi_mode_prompt_info() { } # define right prompt, if it wasn't defined by a theme -if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then +if [[ -z "$RPS1" && -z "$RPROMPT" ]]; then RPS1='$(vi_mode_prompt_info)' fi -- cgit v1.2.3-70-g09d2 From 9e5f280f87f2c127896c20edcdd8cd023b5b1893 Mon Sep 17 00:00:00 2001 From: Fernando Crespo Date: Sun, 3 Jan 2021 09:55:57 -0300 Subject: feat(CLI): add `plugin info` subcommand (#9452) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fernando Crespo Co-authored-by: Marc Cornellà --- lib/cli.zsh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 6fcffdf87..86a0ed3c4 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -37,7 +37,7 @@ function _omz { changelog) local -a refs refs=("${(@f)$(command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}") _describe 'command' refs ;; - plugin) subcmds=('list:List plugins') + plugin) subcmds=('info:Get plugin information' 'list:List plugins') _describe 'command' subcmds ;; pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches') _describe 'command' subcmds ;; @@ -46,6 +46,8 @@ function _omz { esac elif (( CURRENT == 4 )); then case "$words[2]::$words[3]" in + plugin::info) compadd "$ZSH"/plugins/*/README.md(.N:h:t) \ + "$ZSH_CUSTOM"/plugins/*/README.md(.N:h:t) ;; theme::use) compadd "$ZSH"/themes/*.zsh-theme(.N:t:r) \ "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::) ;; esac @@ -143,6 +145,7 @@ Usage: omz plugin [options] Available commands: + info Get information of a plugin list List all available Oh My Zsh plugins EOF @@ -155,6 +158,29 @@ EOF _omz::plugin::$command "$@" } +function _omz::plugin::info { + if [[ -z "$1" ]]; then + echo >&2 "Usage: omz plugin info " + return 1 + fi + + local readme + for readme in "$ZSH_CUSTOM/plugins/$1/README.md" "$ZSH/plugins/$1/README.md"; do + if [[ -f "$readme" ]]; then + (( ${+commands[less]} )) && less "$readme" || cat "$readme" + return 0 + fi + done + + if [[ -d "$ZSH_CUSTOM/plugins/$1" || -d "$ZSH/plugins/$1" ]]; then + _omz::log error "the '$1' plugin doesn't have a README file" + else + _omz::log error "'$1' plugin not found" + fi + + return 1 +} + function _omz::plugin::list { local -a custom_plugins builtin_plugins custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t)) -- cgit v1.2.3-70-g09d2 From 66e0438d4788d0a0cdc107b3975418f1a572e354 Mon Sep 17 00:00:00 2001 From: Gabriel Corral Date: Sun, 3 Jan 2021 06:58:52 -0600 Subject: fix(archlinux): update URL and key server in `pacmanallkeys` (#9569) - Added follow redirects curl flag to fix the 301 response - Updated trusted users URL format - Changed from `pgp.mit.edu` keyserver to `keyserver.ubuntu.com` keyserver --- plugins/archlinux/archlinux.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index c72e06dc2..32f09cef9 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -188,8 +188,8 @@ function pacdisowned() { } function pacmanallkeys() { - curl -s https://www.archlinux.org/people/{developers,trustedusers}/ | \ - awk -F\" '(/pgp.mit.edu/) { sub(/.*search=0x/,""); print $1}' | \ + curl -sL https://www.archlinux.org/people/{developers,trusted-users}/ | \ + awk -F\" '(/keyserver.ubuntu.com/) { sub(/.*search=0x/,""); print $1}' | \ xargs sudo pacman-key --recv-keys } -- cgit v1.2.3-70-g09d2 From 94ce46d48b901ed9e581ccad22d9192c25507acd Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 4 Jan 2021 16:38:36 +0100 Subject: docs(vi-mode): revamp README and document settings --- plugins/vi-mode/README.md | 73 +++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 8519a5592..fdf3ede73 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -1,34 +1,59 @@ -vi-mode -======= +# vi-mode plugin + This plugin increase `vi-like` zsh functionality. -Use `ESC` or `CTRL-[` to enter `Normal mode`. +To use it, add `vi-mode` to the plugins array in your zshrc file: +```zsh +plugins=(... vi-mode) +``` -History -------- +## Settings -- `ctrl-p` : Previous command in history -- `ctrl-n` : Next command in history -- `/` : Search backward in history -- `n` : Repeat the last `/` +- `VI_MODE_RESET_PROMPT_ON_MODE_CHANGE`: controls whether the prompt is redrawn when + switching to a different input mode. If this is unset, the mode indicator will not + be updated when changing to a different mode. + Set it to `true` to enable it. For example: + ```zsh + VI_MODE_RESET_PROMPT_ON_MODE_CHANGE=true + ``` -Mode indicators ---------------- + The default value is unset, unless `vi_mode_prompt_info` is used, in which case it'll + automatically be set to `true`. -*Normal mode* is indicated with red `<<<` mark at the right prompt, when it -wasn't defined by theme. +- `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode. + See [Mode indicator](#mode-indicator) for details. +## Mode indicator -Vim edition ------------ +*Normal mode* is indicated with a red `<<<` mark at the right prompt, when it +hasn't been defined by theme. -- `v` : Edit current command line in Vim +You can change this indicator by setting the `MODE_INDICATOR` variable. This setting +supports Prompt Expansion sequences. For example: + +```zsh +MODE_INDICATOR="%F{yellow}+%f" +``` + +You can also use the `vi_mode_prompt_info` function in your prompt, which will display +this mode indicator. + +## Key bindings + +Use `ESC` or `CTRL-[` to enter `Normal mode`. +NOTE: some of these key bindings are set by zsh by default when using a vi-mode keymap. -Movement --------- +### History + +- `ctrl-p` : Previous command in history +- `ctrl-n` : Next command in history +- `/` : Search backward in history +- `n` : Repeat the last `/` + +### Movement - `$` : To the end of the line - `^` : To the first non-blank character of the line @@ -46,9 +71,7 @@ Movement - `;` : Repeat latest f, t, F or T [count] times - `,` : Repeat latest f, t, F or T in opposite direction - -Insertion ---------- +### Insertion - `i` : Insert text before the cursor - `I` : Insert text before the first character in the line @@ -57,9 +80,7 @@ Insertion - `o` : Insert new command line below the current one - `O` : Insert new command line above the current one - -Delete and Insert ------------------ +### Delete and Insert - `ctrl-h` : While in *Insert mode*: delete character before the cursor - `ctrl-w` : While in *Insert mode*: delete word before the cursor @@ -73,3 +94,7 @@ Delete and Insert - `R` : Enter replace mode: Each character replaces existing one - `x` : Delete [count] characters under and after the cursor - `X` : Delete [count] characters before the cursor + +### Removed key bindings + +- `v` : Edit current command line in Vim -- cgit v1.2.3-70-g09d2 From 79980b00fb146437231c2a110ea49032b842c92c Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 4 Jan 2021 16:41:59 +0100 Subject: fix(vi-mode): hide cursor-change logic behind `VI_MODE_SET_CURSOR` setting Fixes #9570 --- plugins/vi-mode/README.md | 7 +++++++ plugins/vi-mode/vi-mode.plugin.zsh | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index fdf3ede73..41faf2de0 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -22,6 +22,13 @@ plugins=(... vi-mode) The default value is unset, unless `vi_mode_prompt_info` is used, in which case it'll automatically be set to `true`. +- `VI_MODE_SET_CURSOR`: controls whether the cursor style is changed when switching + to a different input mode. Set it to `true` to enable it (default: unset): + + ```zsh + VI_MODE_SET_CURSOR=true + ``` + - `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode. See [Mode indicator](#mode-indicator) for details. diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index f83ea7696..e5b252d83 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -4,13 +4,21 @@ # This is especially true if the prompt does things like checking git status. # # Set to "true" to force the prompt to reset on each mode change. -# Set to "false" to force the prompt *not* to reset on each mode change. +# Unset or set to any other value to do the opposite. # -# (The default is not to reset, unless we're showing the mode in RPS1). +# The default is not to reset, unless we're showing the mode in RPS1. typeset -g VI_MODE_RESET_PROMPT_ON_MODE_CHANGE +# Control whether to change the cursor style on mode change. +# +# Set to "true" to change the cursor on each mode change. +# Unset or set to any other value to do the opposite. +typeset -g VI_MODE_SET_CURSOR + typeset -g VI_KEYMAP=main function _vi-mode-set-cursor-shape-for-keymap() { + [[ "$VI_MODE_SET_CURSOR" = true ]] || return + # https://vt100.net/docs/vt510-rm/DECSCUSR local _shape=0 case "${1:-${VI_KEYMAP:-main}}" in -- cgit v1.2.3-70-g09d2 From 2118d35e017eb8c599f3c25863c8263aca307541 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 4 Jan 2021 21:41:11 +0100 Subject: fix(vi-mode)!: add back edit-command-line key binding as 'vv' (#9573) BREAKING CHANGE: the key binding to open an editor to edit the command line has been moved from being `v` (press v once) to being `vv` (press v twice). Now, the action for `v` is the default `visual-mode`, as is in Vim. Fixes #9573 --- plugins/vi-mode/README.md | 14 ++++++++------ plugins/vi-mode/vi-mode.plugin.zsh | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 41faf2de0..b59d5f279 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -60,6 +60,12 @@ NOTE: some of these key bindings are set by zsh by default when using a vi-mode - `/` : Search backward in history - `n` : Repeat the last `/` +### Vim edition + +- `vv` : Edit current command line in Vim + +NOTE: this used to be bound to `v`. That is now the default (`visual-mode`) + ### Movement - `$` : To the end of the line @@ -99,9 +105,5 @@ NOTE: some of these key bindings are set by zsh by default when using a vi-mode - `C` : Delete to the end of the line and start insert - `r{char}` : Replace the character under the cursor with {char} - `R` : Enter replace mode: Each character replaces existing one -- `x` : Delete [count] characters under and after the cursor -- `X` : Delete [count] characters before the cursor - -### Removed key bindings - -- `v` : Edit current command line in Vim +- `x` : Delete `count` characters under and after the cursor +- `X` : Delete `count` characters before the cursor diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index e5b252d83..0b11a6a7f 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -64,6 +64,11 @@ zle -N zle-line-finish bindkey -v +# allow vv to edit the command line (standard behaviour) +autoload -Uz edit-command-line +zle -N edit-command-line +bindkey -M vicmd 'vv' edit-command-line + # allow ctrl-p, ctrl-n for navigate history (standard behaviour) bindkey '^P' up-history bindkey '^N' down-history -- cgit v1.2.3-70-g09d2 From 492f712df281e96d6d1aa9ebb53b1304284b19a0 Mon Sep 17 00:00:00 2001 From: Konfekt Date: Tue, 5 Jan 2021 18:53:29 +0100 Subject: feat(plugins): add `universalarchive` plugin to conveniently compress files (#6846) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/universalarchive/README.md | 46 ++++++++++++++ plugins/universalarchive/_universalarchive | 6 ++ .../universalarchive/universalarchive.plugin.zsh | 70 ++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 plugins/universalarchive/README.md create mode 100644 plugins/universalarchive/_universalarchive create mode 100644 plugins/universalarchive/universalarchive.plugin.zsh diff --git a/plugins/universalarchive/README.md b/plugins/universalarchive/README.md new file mode 100644 index 000000000..93a1bd9fc --- /dev/null +++ b/plugins/universalarchive/README.md @@ -0,0 +1,46 @@ +# universalarchive plugin + +Lets you compress files by a command `ua `, supporting various +compression formats (e.g. 7z, tar.gz, lzma, ...). + +To enable it, add `universalarchive` to the plugins array in your zshrc file: + +```zsh +plugins=(... universalarchive) +``` + +## Usage + +Run `ua ` to compress `` into an archive file using ``. +For example: + +```sh +ua xz *.html +``` + +this command will compress all `.html` files in directory `folder` into `folder.xz`. + +This plugin saves you from having to remember which command line arguments compress a file. + +## Supported compression formats + +| Extension | Description | +|:-----------------|:-------------------------------| +| `7z` | 7zip file | +| `bz2` | Bzip2 file | +| `gz` | Gzip file | +| `lzma` | LZMA archive | +| `lzo` | LZO archive | +| `rar` | WinRAR archive | +| `tar` | Tarball | +| `tbz`/`tar.bz2` | Tarball with bzip2 compression | +| `tgz`/`tar.gz` | Tarball with gzip compression | +| `tlz`/`tar.lzma` | Tarball with lzma compression | +| `txz`/`tar.xz` | Tarball with lzma2 compression | +| `tZ`/`tar.Z` | Tarball with LZW compression | +| `xz` | LZMA2 archive | +| `Z` | Z archive (LZW) | +| `zip` | Zip archive | +| `zst` | Zstd archive | + +See [list of archive formats](https://en.wikipedia.org/wiki/List_of_archive_formats) for more information regarding the archive formats. diff --git a/plugins/universalarchive/_universalarchive b/plugins/universalarchive/_universalarchive new file mode 100644 index 000000000..17cfd782e --- /dev/null +++ b/plugins/universalarchive/_universalarchive @@ -0,0 +1,6 @@ +#compdef ua + +_arguments \ + "1:archive format:(7z bz2 gz lzma lzo rar tar tar.bz2 tar.gz tar.lzma tar.xz tar.Z tbz tgz tlz txz tZ xz Z zip zst)" \ + "*:input files:_files" \ +&& return 0 diff --git a/plugins/universalarchive/universalarchive.plugin.zsh b/plugins/universalarchive/universalarchive.plugin.zsh new file mode 100644 index 000000000..5a661a5b0 --- /dev/null +++ b/plugins/universalarchive/universalarchive.plugin.zsh @@ -0,0 +1,70 @@ +function ua() { + local usage=\ +"Archive files and directories using a given compression algorithm. + +Usage: $0 +Example: $0 tbz PKGBUILD + +Supported archive formats are: +7z, bz2, gz, lzma, lzo, rar, tar, tbz (tar.bz2), tgz (tar.gz), +tlz (tar.lzma), txz (tar.xz), tZ (tar.Z), xz, Z, zip, and zst." + + if [[ $# -lt 2 ]]; then + echo >&2 "$usage" + return 1 + fi + + local ext="$1" + local input="$(realpath "$2")" + + shift + + if [[ ! -e "$input" ]]; then + echo >&2 "$input not found" + return 1 + fi + + # generate output file name + local output + if [[ $# -gt 1 ]]; then + output="$(basename "${input%/*}")" + elif [[ -f "$input" ]]; then + output="$(basename "${input%.[^.]*}")" + elif [[ -d "$input" ]]; then + output="$(basename "${input}")" + fi + + # if output file exists, generate a random name + if [[ -f "${output}.${ext}" ]]; then + output=$(mktemp "${output}_XXX") && rm "$output" || return 1 + fi + + # add extension + output="${output}.${ext}" + + # safety check + if [[ -f "$output" ]]; then + echo >&2 "output file '$output' already exists. Aborting" + return 1 + fi + + case "$ext" in + 7z) 7z u "${output}" "${@}" ;; + bz2) bzip2 -vcf "${@}" > "${output}" ;; + gz) gzip -vcf "${@}" > "${output}" ;; + lzma) lzma -vc -T0 "${@}" > "${output}" ;; + lzo) lzop -vc "${@}" > "${output}" ;; + rar) rar a "${output}" "${@}" ;; + tar) tar -cvf "${output}" "${@}" ;; + tbz|tar.bz2) tar -cvjf "${output}" "${@}" ;; + tgz|tar.gz) tar -cvzf "${output}" "${@}" ;; + tlz|tar.lzma) XZ_OPT=-T0 tar --lzma -cvf "${output}" "${@}" ;; + txz|tar.xz) XZ_OPT=-T0 tar -cvJf "${output}" "${@}" ;; + tZ|tar.Z) tar -cvZf "${output}" "${@}" ;; + xz) xz -vc -T0 "${@}" > "${output}" ;; + Z) compress -vcf "${@}" > "${output}" ;; + zip) zip -rull "${output}" "${@}" ;; + zst) zstd -c -T0 "${@}" > "${output}" ;; + *) echo >&2 "$usage"; return 1 ;; + esac +} -- cgit v1.2.3-70-g09d2 From 64cb153084d2817f1c14691ffca1f23ebc3e8c48 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 5 Jan 2021 18:58:23 +0100 Subject: chore: add Konfekt as universalarchive maintainer --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index bdd680b47..e307e4be8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,4 +4,5 @@ plugins/genpass/ @atoponce plugins/git-lfs/ @hellovietduc plugins/gitfast/ @felipec plugins/sdk/ @rgoldberg +plugins/universalarchive/ @Konfekt plugins/wp-cli/ @joshmedeski -- cgit v1.2.3-70-g09d2 From 6b57839292025d17d97410d1627228f3ec730a62 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 5 Jan 2021 19:09:57 +0100 Subject: fix(CLI): show symlinked themes in `omz theme list` --- lib/cli.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 86a0ed3c4..3346d3973 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -359,8 +359,8 @@ EOF function _omz::theme::list { local -a custom_themes builtin_themes - custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)) - builtin_themes=("$ZSH"/themes/*.zsh-theme(.N:t:r)) + custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)) + builtin_themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r)) # If the command is being piped, print all found line by line if [[ ! -t 1 ]]; then -- cgit v1.2.3-70-g09d2 From 86f805280f6a8cf65d8d0a9380489aae4b72f767 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 5 Jan 2021 19:17:27 +0100 Subject: fix(changelog): display scope in breaking change messages --- tools/changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 634b61d01..7275db53a 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -286,7 +286,7 @@ function display-release { local hash subject for hash message in ${(kv)breaking}; do - echo " - $(fmt:hash) $(fmt:subject "${message}")" + echo " - $(fmt:hash) $(fmt:scope) $(fmt:subject "${message}")" done | sort echo } -- cgit v1.2.3-70-g09d2 From c9bf8b4a84d4ae392cf1bdd6a4a7c7c4f7710b92 Mon Sep 17 00:00:00 2001 From: Kyle Gerard Felker Date: Thu, 7 Jan 2021 13:55:18 -0600 Subject: fix(lib): update Emacs terminal detection in `title` function (#9577) Environment variable EMACS was replaced by INSIDE_EMACS --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 778f12bca..33451ef1f 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -10,7 +10,7 @@ function title { emulate -L zsh setopt prompt_subst - [[ "$EMACS" == *term* ]] && return + [[ "$INSIDE_EMACS" == *term* ]] && return # if $2 is unset use $1 as default # if it is set and empty, leave it as is -- cgit v1.2.3-70-g09d2 From 3635d7cf7e300b5ba746c384fc3e87a35561e62d Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 10 Jan 2021 17:22:52 +0100 Subject: fix(universalarchive): make plugin zsh-only to fix `realpath` not found error Fixes #9586 --- plugins/universalarchive/universalarchive.plugin.zsh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/universalarchive/universalarchive.plugin.zsh b/plugins/universalarchive/universalarchive.plugin.zsh index 5a661a5b0..b287c22b2 100644 --- a/plugins/universalarchive/universalarchive.plugin.zsh +++ b/plugins/universalarchive/universalarchive.plugin.zsh @@ -10,28 +10,28 @@ Supported archive formats are: tlz (tar.lzma), txz (tar.xz), tZ (tar.Z), xz, Z, zip, and zst." if [[ $# -lt 2 ]]; then - echo >&2 "$usage" + print -u2 -- "$usage" return 1 fi local ext="$1" - local input="$(realpath "$2")" + local input="${2:a}" shift if [[ ! -e "$input" ]]; then - echo >&2 "$input not found" + print -u2 -- "$input not found" return 1 fi # generate output file name local output if [[ $# -gt 1 ]]; then - output="$(basename "${input%/*}")" + output="${input:h:t}" elif [[ -f "$input" ]]; then - output="$(basename "${input%.[^.]*}")" + output="${input:r:t}" elif [[ -d "$input" ]]; then - output="$(basename "${input}")" + output="${input:t}" fi # if output file exists, generate a random name @@ -44,7 +44,7 @@ tlz (tar.lzma), txz (tar.xz), tZ (tar.Z), xz, Z, zip, and zst." # safety check if [[ -f "$output" ]]; then - echo >&2 "output file '$output' already exists. Aborting" + print -u2 -- "output file '$output' already exists. Aborting" return 1 fi @@ -65,6 +65,6 @@ tlz (tar.lzma), txz (tar.xz), tZ (tar.Z), xz, Z, zip, and zst." Z) compress -vcf "${@}" > "${output}" ;; zip) zip -rull "${output}" "${@}" ;; zst) zstd -c -T0 "${@}" > "${output}" ;; - *) echo >&2 "$usage"; return 1 ;; + *) print -u2 -- "$usage"; return 1 ;; esac } -- cgit v1.2.3-70-g09d2 From 3d51d6307791cf49c2ef28f2c05a542e521d85d7 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 10 Jan 2021 20:43:32 +0100 Subject: fix(changelog): fix spacing in breaking changes message --- tools/changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index 7275db53a..836afef14 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -286,7 +286,7 @@ function display-release { local hash subject for hash message in ${(kv)breaking}; do - echo " - $(fmt:hash) $(fmt:scope) $(fmt:subject "${message}")" + echo " - $(fmt:hash) $(fmt:scope)$(fmt:subject "${message}")" done | sort echo } -- cgit v1.2.3-70-g09d2 From 6b8b6253d229357ebb759ea2f96dec30633acc6f Mon Sep 17 00:00:00 2001 From: TIT Date: Mon, 11 Jan 2021 21:53:12 +0300 Subject: fix(jake-node): support all Jakefile filenames in `jake` completion (#9589) --- plugins/jake-node/jake-node.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/jake-node/jake-node.plugin.zsh b/plugins/jake-node/jake-node.plugin.zsh index 3b692f899..c2dad28af 100644 --- a/plugins/jake-node/jake-node.plugin.zsh +++ b/plugins/jake-node/jake-node.plugin.zsh @@ -6,7 +6,7 @@ # Inspiration : https://weblog.rubyonrails.org/2006/3/9/fast-rake-task-completion-for-zsh function _jake () { - if [ -f Jakefile ]||[ -f jakefile ]; then + if [ -f Jakefile ] || [ -f jakefile ] || [ -f Jakefile.js ] || [ -f jakefile.js ]; then compadd `jake -T | cut -d " " -f 2 | sed -E "s/.\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"` fi } -- cgit v1.2.3-70-g09d2 From fae34b383d6432f7118c2ad082224f6d27d51221 Mon Sep 17 00:00:00 2001 From: Søren Nielsen Date: Mon, 11 Jan 2021 20:26:37 +0100 Subject: feat(macports): add 'reclaim' to completion list for Macports (#9521) The sub-command `reclaim` is quite useful for freeing up disk space. `reclaim` is a useful command that is missing from the list of completions in the plugin. The description is for the `reclaim` sub-command is: "port reclaim will find files that can be removed to reclaim disk space by uninstalling inactive ports on your system as well as unnecessary unrequested ports, and removing unneeded or unused installation files. The user is then provided interactive options for files to remove. No files are removed initially, until the user selects them from the provided list." For all the details use this command on a system with Macports installed: `port help reclaim` --- plugins/macports/_port | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/macports/_port b/plugins/macports/_port index 6a9ebe0c6..897598a46 100644 --- a/plugins/macports/_port +++ b/plugins/macports/_port @@ -43,6 +43,7 @@ subcmds=( 'provides' 'rdependents' 'rdeps' +'reclaim' 'rpmpackage' 'search' 'selfupdate' -- cgit v1.2.3-70-g09d2 From 869eb2091389eabd919c32b2ca98ed1b0af851e6 Mon Sep 17 00:00:00 2001 From: wilkis Date: Tue, 12 Jan 2021 20:40:27 +0100 Subject: feat(last-working-dir): log separate `lwd`s for different SSH keys on the same user account (#9534) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/last-working-dir/README.md | 28 ++++++++++++++++++---- .../last-working-dir/last-working-dir.plugin.zsh | 14 ++++++----- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/plugins/last-working-dir/README.md b/plugins/last-working-dir/README.md index ced9e0370..b5cc55828 100644 --- a/plugins/last-working-dir/README.md +++ b/plugins/last-working-dir/README.md @@ -1,15 +1,33 @@ # last-working-dir plugin Keeps track of the last used working directory and automatically jumps into it -for new shells, unless: +for new shells, unless the starting directory is not `$HOME`. -- The plugin is already loaded. -- The current `$PWD` is not `$HOME`. - -Also adds `lwd` function to jump to the last working directory. +Also adds a `lwd` function to jump to the last working directory. To use it, add `last-working-dir` to the plugins array in your zshrc file: ```zsh plugins=(... last-working-dir) ``` + +## Features + +### Use separate last-working-dir files with different SSH keys + +If the same user account is used by multiple users connecting via different SSH keys, you can +configure SSH to map them to different `SSH_USER`s and the plugin will use separate lwd files +for each one. + +Make sure that your SSH server allows environment variables. You can enable this feature +within the `/etc/sshd/sshd_config` file: + +``` +PermitUserEnvironment yes +``` + +Then, add `environment="SSH_USER="` before the SSH keys in your `authorized_keys` file: + +``` +environment="SSH_USER=a.test@example.com" ssh-ed25519 AAAAC3Nz... +``` diff --git a/plugins/last-working-dir/last-working-dir.plugin.zsh b/plugins/last-working-dir/last-working-dir.plugin.zsh index fd21705ae..905a02a70 100644 --- a/plugins/last-working-dir/last-working-dir.plugin.zsh +++ b/plugins/last-working-dir/last-working-dir.plugin.zsh @@ -5,16 +5,18 @@ typeset -g ZSH_LAST_WORKING_DIRECTORY autoload -U add-zsh-hook add-zsh-hook chpwd chpwd_last_working_dir chpwd_last_working_dir() { - if [ "$ZSH_SUBSHELL" = 0 ]; then - local cache_file="$ZSH_CACHE_DIR/last-working-dir" - pwd >| "$cache_file" - fi + # Don't run in subshells + [[ "$ZSH_SUBSHELL" -eq 0 ]] || return 0 + # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty + local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}" + pwd >| "$cache_file" } # Changes directory to the last working directory lwd() { - local cache_file="$ZSH_CACHE_DIR/last-working-dir" - [[ -r "$cache_file" ]] && cd "$(cat "$cache_file")" + # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty + local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}" + [[ -r "$cache_file" ]] && cd "$(cat "$cache_file")" } # Jump to last directory automatically unless: -- cgit v1.2.3-70-g09d2 From a3bdff694a388c9bede63afec3c4a0a78bffa1ba Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Thu, 14 Jan 2021 17:26:40 +0000 Subject: fix(colorize): bypass less aliases in `colorize_less` (#9593) --- plugins/colorize/colorize.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/colorize/colorize.plugin.zsh b/plugins/colorize/colorize.plugin.zsh index cb5ac36f5..8ea98f80a 100644 --- a/plugins/colorize/colorize.plugin.zsh +++ b/plugins/colorize/colorize.plugin.zsh @@ -96,7 +96,7 @@ colorize_less() { # which assumes that his LESSOPEN has been executed. local LESSCLOSE="" - LESS="$LESS" LESSOPEN="$LESSOPEN" LESSCLOSE="$LESSCLOSE" less "$@" + LESS="$LESS" LESSOPEN="$LESSOPEN" LESSCLOSE="$LESSCLOSE" command less "$@" } if [ -t 0 ]; then -- cgit v1.2.3-70-g09d2 From 5db205908e9b5c43b74106c313712200c08fa79c Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Fri, 15 Jan 2021 21:19:46 +0530 Subject: chore: caution against `COMPLETION_WAITING_DOTS` in template (#8352) --- templates/zshrc.zsh-template | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index 307618104..65d5ea65b 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -45,6 +45,8 @@ ZSH_THEME="robbyrussell" # ENABLE_CORRECTION="true" # Uncomment the following line to display red dots whilst waiting for completion. +# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work) +# See https://github.com/ohmyzsh/ohmyzsh/issues/5765 # COMPLETION_WAITING_DOTS="true" # Uncomment the following line if you want to disable marking untracked files -- cgit v1.2.3-70-g09d2 From 63477411eb073ec3ddaa925f6e88bfa94db1e596 Mon Sep 17 00:00:00 2001 From: Arnaud Thimel Date: Thu, 25 Feb 2016 16:29:51 +0100 Subject: feat(git-prompt): display untracked files count Closes #8435 Closes #4880 --- plugins/git-prompt/git-prompt.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh index da674af98..43a327ab0 100644 --- a/plugins/git-prompt/git-prompt.plugin.zsh +++ b/plugins/git-prompt/git-prompt.plugin.zsh @@ -63,7 +63,7 @@ git_super_status() { STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_CHANGED$GIT_CHANGED%{${reset_color}%}" fi if [ "$GIT_UNTRACKED" -ne "0" ]; then - STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED%{${reset_color}%}" + STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED$GIT_UNTRACKED%{${reset_color}%}" fi if [ "$GIT_CHANGED" -eq "0" ] && [ "$GIT_CONFLICTS" -eq "0" ] && [ "$GIT_STAGED" -eq "0" ] && [ "$GIT_UNTRACKED" -eq "0" ]; then STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_CLEAN" @@ -83,7 +83,7 @@ ZSH_THEME_GIT_PROMPT_CONFLICTS="%{$fg[red]%}%{✖%G%}" ZSH_THEME_GIT_PROMPT_CHANGED="%{$fg[blue]%}%{✚%G%}" ZSH_THEME_GIT_PROMPT_BEHIND="%{↓%G%}" ZSH_THEME_GIT_PROMPT_AHEAD="%{↑%G%}" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{…%G%}" +ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%}%{…%G%}" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}" # Set the prompt. -- cgit v1.2.3-70-g09d2 From 47c04d921ebb3fe4916eb131ae11557650aa1ae3 Mon Sep 17 00:00:00 2001 From: Arnaud Thimel Date: Thu, 25 Feb 2016 16:36:31 +0100 Subject: feat(git-prompt): display stash count in prompt --- plugins/git-prompt/git-prompt.plugin.zsh | 8 +++++++- plugins/git-prompt/gitstatus.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh index 43a327ab0..a4c952471 100644 --- a/plugins/git-prompt/git-prompt.plugin.zsh +++ b/plugins/git-prompt/git-prompt.plugin.zsh @@ -40,6 +40,8 @@ function update_current_git_vars() { GIT_CONFLICTS=$__CURRENT_GIT_STATUS[5] GIT_CHANGED=$__CURRENT_GIT_STATUS[6] GIT_UNTRACKED=$__CURRENT_GIT_STATUS[7] + GIT_STASHED=$__CURRENT_GIT_STATUS[8] + GIT_CLEAN=$__CURRENT_GIT_STATUS[9] } git_super_status() { @@ -65,7 +67,10 @@ git_super_status() { if [ "$GIT_UNTRACKED" -ne "0" ]; then STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED$GIT_UNTRACKED%{${reset_color}%}" fi - if [ "$GIT_CHANGED" -eq "0" ] && [ "$GIT_CONFLICTS" -eq "0" ] && [ "$GIT_STAGED" -eq "0" ] && [ "$GIT_UNTRACKED" -eq "0" ]; then + if [ "$GIT_STASHED" -ne "0" ]; then + STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STASHED$GIT_STASHED%{${reset_color}%}" + fi + if [ "$GIT_CLEAN" -eq "1" ]; then STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_CLEAN" fi STATUS="$STATUS%{${reset_color}%}$ZSH_THEME_GIT_PROMPT_SUFFIX" @@ -84,6 +89,7 @@ ZSH_THEME_GIT_PROMPT_CHANGED="%{$fg[blue]%}%{✚%G%}" ZSH_THEME_GIT_PROMPT_BEHIND="%{↓%G%}" ZSH_THEME_GIT_PROMPT_AHEAD="%{↑%G%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%}%{…%G%}" +ZSH_THEME_GIT_PROMPT_STASHED="%{$fg_bold[blue]%}%{⚑%G%}" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}" # Set the prompt. diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py index bf3173614..786274a71 100644 --- a/plugins/git-prompt/gitstatus.py +++ b/plugins/git-prompt/gitstatus.py @@ -23,6 +23,18 @@ def get_tagname_or_hash(): return hash_ return None +# Re-use method from https://github.com/magicmonty/bash-git-prompt to get stashs count +def get_stash(): + cmd = Popen(['git', 'rev-parse', '--git-dir'], stdout=PIPE, stderr=PIPE) + so, se = cmd.communicate() + stash_file = '%s%s' % (so.decode('utf-8').rstrip(), '/logs/refs/stash') + + try: + with open(stash_file) as f: + return sum(1 for _ in f) + except IOError: + return 0 + # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind @@ -68,6 +80,12 @@ for st in status: elif st[0] != ' ': staged.append(st) +stashed = get_stash() +if not changed and not staged and not conflicts and not untracked and not stashed: + clean = 1 +else: + clean = 0 + out = ' '.join([ branch, str(ahead), @@ -76,5 +94,7 @@ out = ' '.join([ str(len(conflicts)), str(len(changed)), str(len(untracked)), + str(stashed), + str(clean) ]) print(out, end='') -- cgit v1.2.3-70-g09d2 From 8b37f817c29715873b91c8a8e7f883eccc240895 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 16 Jan 2021 18:59:24 +0100 Subject: fix(lib): use -N syntax in `head` and `tail` to support Solaris (#6391) Closes #6391 Co-authored-by: Sergey Mashkov --- lib/functions.zsh | 2 +- lib/git.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/functions.zsh b/lib/functions.zsh index 7beb62ad9..c4340f16c 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 -n20 | column -c3 -s " " -t | nl + | grep -v "./" | sort -nr | head -20 | column -c3 -s " " -t | nl } function uninstall_oh_my_zsh() { diff --git a/lib/git.zsh b/lib/git.zsh index 34ffc7ab7..c9363274c 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 -n1) + STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -1) fi if [[ -n $STATUS ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" -- cgit v1.2.3-70-g09d2 From f484f88b4208b6624af1d3572d31edabc73041bf Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 16 Jan 2021 19:58:29 +0100 Subject: fix(debian): add quotes to `kclean` alias (#3066) Co-authored-by: la-magra --- plugins/debian/debian.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index 68c6df1ae..108396784 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -66,7 +66,7 @@ if [[ $use_sudo -eq 1 ]]; then alias di="sudo dpkg -i" # Remove ALL kernel images and headers EXCEPT the one in use - alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))' + alias kclean='sudo aptitude remove -P "?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))"' # commands using su ######### @@ -105,7 +105,7 @@ else alias di='su -lc "dpkg -i" root' # Remove ALL kernel images and headers EXCEPT the one in use - alias kclean='su -lc "aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))" root' + alias kclean='su -lc "aptitude remove -P \"?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))\"" root' fi # Completion ################################################################ -- cgit v1.2.3-70-g09d2 From 6b0557afe84f671705029bf2a21002dfe9d07be5 Mon Sep 17 00:00:00 2001 From: deathjest3r Date: Sat, 16 Jan 2021 21:27:32 +0100 Subject: feat(plugins): add `term_tab` plugin to complete other zsh sessions' directories (#3018) --- plugins/term_tab/README | 16 ++++++++++++++ plugins/term_tab/term_tab.plugin.zsh | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 plugins/term_tab/README create mode 100644 plugins/term_tab/term_tab.plugin.zsh diff --git a/plugins/term_tab/README b/plugins/term_tab/README new file mode 100644 index 000000000..316062e73 --- /dev/null +++ b/plugins/term_tab/README @@ -0,0 +1,16 @@ + +term_tab - 'cwd' for all open zsh sessions +****************************************** + +What it does: +************* +This plugin allows to complete the 'cwd' of other Zsh sessions. Sounds +complicated but is rather simple. E.g. if you have three zsh sessions open, in +each session you are in a different folder, you can hit Ctrl+v in one session +to show you the current working directory of the other open zsh sessions. + +How it works: +************* +* It uses 'pidof zsh' to determine all zsh PIDs +* It reads procfs to get the current working directory of this session +* Everything is fed into zsh's completion magic diff --git a/plugins/term_tab/term_tab.plugin.zsh b/plugins/term_tab/term_tab.plugin.zsh new file mode 100644 index 000000000..1b612df68 --- /dev/null +++ b/plugins/term_tab/term_tab.plugin.zsh @@ -0,0 +1,41 @@ +# Copyright (C) 2014 Julian Vetter +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +function _term_list(){ + local -a expl + local -au dirs + + PREFIX="$IPREFIX$PREFIX" + IPREFIX= + SUFFIX="$SUFFIX$ISUFFIX" + ISUFFIX= + + [[ -o magicequalsubst ]] && compset -P '*=' + + case $OSTYPE in + solaris*) dirs=( ${(M)${${(f)"$(pgrep -U $UID -x zsh|xargs pwdx)"}:#$$:*}%%/*} ) ;; + linux*) dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) ) ;; + esac + dirs=( ${(D)dirs} ) + + compstate[pattern_match]='*' + _wanted directories expl 'current directory from other shell' \ + compadd -Q -M "r:|/=* r:|=*" -f -a dirs +} + +zle -C term_list menu-complete _generic +bindkey "^v" term_list +zstyle ':completion:term_list::::' completer _term_list -- cgit v1.2.3-70-g09d2 From 53aefc52e27afaeca83546f12f1dcbb78d733149 Mon Sep 17 00:00:00 2001 From: bullno1 Date: Sun, 17 Aug 2014 17:22:06 +0800 Subject: feat(plugins): add `zbell` plugin to notify when commands end (#3034) Closes #3034 --- plugins/zbell/README.md | 30 +++++++++++++++ plugins/zbell/zbell.plugin.zsh | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 plugins/zbell/README.md create mode 100644 plugins/zbell/zbell.plugin.zsh diff --git a/plugins/zbell/README.md b/plugins/zbell/README.md new file mode 100644 index 000000000..1c1c13546 --- /dev/null +++ b/plugins/zbell/README.md @@ -0,0 +1,30 @@ +# zbell plugin + +This plugin prints a bell character when a command finishes if it has been +running for longer than a specified duration. + +To use it, add `zbell` to the plugins array in your zshrc file: + +```zsh +plugins=(... zbell) +``` + +## Settings + +These settings need to be set in your zshrc file, before Oh My Zsh is sourced. + +- `zbell_duration`: duration in seconds after which to consider notifying + the end of a command. Default: 15 seconds. + +- `zbell_ignore`: if there are programs that you know run long that you + don't want to bell after, then add them to the `zbell_ignore` array. + By default, `$EDITOR` and `$PAGER` are ignored: + + ```zsh + zbell_ignore=($EDITOR $PAGER) + ``` + +## Author + +Adapted from an original version by [Jean-Philippe Ouellet](https://github.com/jpouellet). +Made available under the ISC license. diff --git a/plugins/zbell/zbell.plugin.zsh b/plugins/zbell/zbell.plugin.zsh new file mode 100644 index 000000000..6d0416502 --- /dev/null +++ b/plugins/zbell/zbell.plugin.zsh @@ -0,0 +1,83 @@ +#!/usr/bin/env zsh + +# This script prints a bell character when a command finishes +# if it has been running for longer than $zbell_duration seconds. +# If there are programs that you know run long that you don't +# want to bell after, then add them to $zbell_ignore. +# +# This script uses only zsh builtins so its fast, there's no needless +# forking, and its only dependency is zsh and its standard modules +# +# Written by Jean-Philippe Ouellet +# Made available under the ISC license. + +# only do this if we're in an interactive shell +[[ -o interactive ]] || return + +# get $EPOCHSECONDS. builtins are faster than date(1) +zmodload zsh/datetime || return + +# make sure we can register hooks +autoload -Uz add-zsh-hook || return + +# make sure we can do regexp replace +autoload -Uz regexp-replace || return + +# initialize zbell_duration if not set +(( ${+zbell_duration} )) || zbell_duration=15 + +# initialize zbell_ignore if not set +(( ${+zbell_ignore} )) || zbell_ignore=($EDITOR $PAGER) + +# initialize it because otherwise we compare a date and an empty string +# the first time we see the prompt. it's fine to have lastcmd empty on the +# initial run because it evaluates to an empty string, and splitting an +# empty string just results in an empty array. +zbell_timestamp=$EPOCHSECONDS + +# default notification function +# $1: command +# $2: duration in seconds +zbell_notify() { + type notify-send > /dev/null && \ + notify-send -i terminal "Command completed in ${2}s:" $1 + print -n "\a" +} + +# right before we begin to execute something, store the time it started at +zbell_begin() { + zbell_timestamp=$EPOCHSECONDS + zbell_lastcmd=$1 +} + +# when it finishes, if it's been running longer than $zbell_duration, +# and we dont have an ignored command in the line, then print a bell. +zbell_end() { + local cmd_duration=$(( $EPOCHSECONDS - $zbell_timestamp )) + local ran_long=$(( $cmd_duration >= $zbell_duration )) + + local zbell_lastcmd_tmp="$zbell_lastcmd" + regexp-replace zbell_lastcmd_tmp '^sudo ' '' + + [[ $zbell_last_timestamp == $zbell_timestamp ]] && return + + [[ $zbell_lastcmd_tmp == "" ]] && return + + zbell_last_timestamp=$zbell_timestamp + + local has_ignored_cmd=0 + for cmd in ${(s:;:)zbell_lastcmd_tmp//|/;}; do + words=(${(z)cmd}) + util=${words[1]} + if (( ${zbell_ignore[(i)$util]} <= ${#zbell_ignore} )); then + has_ignored_cmd=1 + break + fi + done + + (( ! $has_ignored_cmd && ran_long )) && zbell_notify $zbell_lastcmd $cmd_duration +} + +# register the functions as hooks +add-zsh-hook preexec zbell_begin +add-zsh-hook precmd zbell_end -- cgit v1.2.3-70-g09d2 From 172b32c90dadf09bcc1e9b562a68c1c282bf514e Mon Sep 17 00:00:00 2001 From: Sébastien MB Date: Sat, 16 Jan 2021 21:52:11 +0100 Subject: feat(essembeh): update theme with new features (#9595) - single line - quite simple by default: user@host:$PWD - green for local shell as non root - red for ssh shell as non root - magenta for root sessions - prefix with remote address for ssh shells - prefix to detect docker containers or chroot - git plugin to display current branch and status --- themes/essembeh.zsh-theme | 60 +++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/themes/essembeh.zsh-theme b/themes/essembeh.zsh-theme index 939bb7a4c..f34f36f8a 100644 --- a/themes/essembeh.zsh-theme +++ b/themes/essembeh.zsh-theme @@ -1,24 +1,14 @@ -# Theme with full path names and hostname -# Handy if you work on different servers all the time; - -local return_code="%(?..%{$fg_bold[red]%}%? ↵%{$reset_color%})" - -function my_git_prompt_info() { - ref=$(git symbolic-ref HEAD 2> /dev/null) || return - GIT_STATUS=$(git_prompt_status) - [[ -n $GIT_STATUS ]] && GIT_STATUS=" $GIT_STATUS" - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX" -} - -# Colored prompt -ZSH_THEME_COLOR_USER="green" -ZSH_THEME_COLOR_HOST="green" -ZSH_THEME_COLOR_PWD="yellow" -test -n "$SSH_CONNECTION" && ZSH_THEME_COLOR_USER="red" && ZSH_THEME_COLOR_HOST="red" -test `id -u` = 0 && ZSH_THEME_COLOR_USER="magenta" && ZSH_THEME_COLOR_HOST="magenta" -PROMPT='%{$fg_bold[$ZSH_THEME_COLOR_USER]%}%n@%{$fg_bold[$ZSH_THEME_COLOR_HOST]%}%M%{$reset_color%}:%{$fg_bold[$ZSH_THEME_COLOR_PWD]%}%~%{$reset_color%} $(my_git_prompt_info)%(!.#.$) ' -RPS1="${return_code}" +# My custom theme: +# - single line +# - quite simple by default: user@host:$PWD +# - green for local shell as non root +# - red for ssh shell as non root +# - magenta for root sessions +# - prefix with remote address for ssh shells +# - prefix to detect docker containers or chroot +# - git plugin to display current branch and status +# git plugin ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}(" ZSH_THEME_GIT_PROMPT_SUFFIX=") %{$reset_color%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%%" @@ -28,3 +18,33 @@ ZSH_THEME_GIT_PROMPT_RENAMED="~" ZSH_THEME_GIT_PROMPT_DELETED="!" ZSH_THEME_GIT_PROMPT_UNMERGED="?" +function zsh_essembeh_gitstatus { + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + GIT_STATUS=$(git_prompt_status) + if [[ -n $GIT_STATUS ]]; then + GIT_STATUS=" $GIT_STATUS" + fi + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX" +} + +# by default, use green for user@host and no prefix +local ZSH_ESSEMBEH_COLOR="green" +local ZSH_ESSEMBEH_PREFIX="" +if [[ -n "$SSH_CONNECTION" ]]; then + # display the source address if connected via ssh + ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[$(echo $SSH_CONNECTION | awk '{print $1}')]%{$reset_color%} " + # use red color to highlight a remote connection + ZSH_ESSEMBEH_COLOR="red" +elif [[ -r /etc/debian_chroot ]]; then + # prefix prompt in case of chroot + ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[chroot:$(cat /etc/debian_chroot)]%{$reset_color%} " +elif [[ -r /.dockerenv ]]; then + # also prefix prompt inside a docker contrainer + ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[docker]%{$reset_color%} " +fi +if [[ $UID = 0 ]]; then + # always use magenta for root sessions, even in ssh + ZSH_ESSEMBEH_COLOR="magenta" +fi +PROMPT='${ZSH_ESSEMBEH_PREFIX}%{$fg[$ZSH_ESSEMBEH_COLOR]%}%n@%M%{$reset_color%}:%{%B$fg[yellow]%}%~%{$reset_color%b%} $(zsh_essembeh_gitstatus)%(!.#.$) ' +RPROMPT="%(?..%{$fg[red]%}%?%{$reset_color%})" -- cgit v1.2.3-70-g09d2 From efcbd9f3480a28ec69c607c46adcbfd8d230ac9f Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 16 Jan 2021 22:55:17 +0100 Subject: fix(vi-mode): ignore `clip*` function errors in yank and put widgets Fixes #9605 --- plugins/vi-mode/vi-mode.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 0b11a6a7f..7f14961ad 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -100,13 +100,13 @@ function wrap_clipboard_widgets() { eval " function ${wrapped_name}() { zle .${widget} - printf %s \"\${CUTBUFFER}\" | clipcopy + printf %s \"\${CUTBUFFER}\" | clipcopy 2>/dev/null || true } " else eval " function ${wrapped_name}() { - CUTBUFFER=\"\$(clippaste)\" + CUTBUFFER=\"\$(clippaste 2>/dev/null || echo \$CUTBUFFER)\" zle .${widget} } " -- cgit v1.2.3-70-g09d2