From 15b30206dfd830beac77229ac6e59feca8d21d01 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Wed, 11 Mar 2020 01:58:40 +0530 Subject: [PATCH] Add 'z -' capability to bash and zsh --- src/main.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index dc3a617..44113b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -157,18 +157,20 @@ case "$PROMPT_COMMAND" in esac z() { - if [ $# -ne 0 ]; then + if [ "$#" -eq 0 ]; then + cd "$HOME" + elif [ "$#" -eq 1 ] && [ "$1" = "-" ]; then + cd "-" + else _Z_RESULT=$(zoxide query "$@") - case $_Z_RESULT in + case "$_Z_RESULT" in "query: "*) cd "${_Z_RESULT:7}" ;; *) - echo -n "${_Z_RESULT}" + echo -n "$_Z_RESULT" ;; esac - else - cd "${HOME}" fi } "#; @@ -220,18 +222,20 @@ _zoxide_precmd() { } z() { - if [ $# -ne 0 ]; then + if [ "$#" -eq 0 ]; then + cd "$HOME" + elif [ "$#" -eq 1 ] && [ "$1" = "-" ]; then + cd "-" + else _Z_RESULT=$(zoxide query "$@") - case $_Z_RESULT in + case "$_Z_RESULT" in "query: "*) cd "${_Z_RESULT:7}" ;; *) - echo -n "${_Z_RESULT}" + echo -n "$_Z_RESULT" ;; esac - else - cd "${HOME}" fi } "#;