From 1306fba4acaf970909f4fe635b04f1474270a51d Mon Sep 17 00:00:00 2001 From: Mark Keisler Date: Tue, 26 Jul 2022 02:56:42 -0500 Subject: [PATCH] zsh: allow `z` to navigate dirstack via `+n` and `-n` --- CHANGELOG.md | 1 + templates/zsh.txt | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a48c035..750b81c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Fish: change fuzzy completion prefix to `z!`. +- Zsh: allow `z` to navigate dirstack via `+n` and `-n`. ## [0.8.2] - 2022-06-26 diff --git a/templates/zsh.txt b/templates/zsh.txt index 11b69ed..3abb781 100644 --- a/templates/zsh.txt +++ b/templates/zsh.txt @@ -19,7 +19,7 @@ function __zoxide_pwd() { # cd + custom logic based on the value of _ZO_ECHO. function __zoxide_cd() { # shellcheck disable=SC2164 - \builtin cd -- "$@" {%- if echo %} && __zoxide_pwd {%- endif %} + \builtin cd -- "$@" >/dev/null {%- if echo %} && __zoxide_pwd {%- endif %} } {{ section }} @@ -59,15 +59,7 @@ function __zoxide_z() { # shellcheck disable=SC2199 if [[ "$#" -eq 0 ]]; then __zoxide_cd ~ - elif [[ "$#" -eq 1 ]] && [[ "$1" = '-' ]]; then - if [[ -n "${OLDPWD}" ]]; then - __zoxide_cd "${OLDPWD}" - else - # shellcheck disable=SC2016 - \builtin printf 'zoxide: $OLDPWD is not set' - return 1 - fi - elif [[ "$#" -eq 1 ]] && [[ -d "$1" ]]; then + elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then __zoxide_cd "$1" elif [[ "$@[-1]" == "${__zoxide_z_prefix}"* ]]; then # shellcheck disable=SC2124