Add 'z -' capability to bash and zsh

This commit is contained in:
Ajeet D'Souza 2020-03-11 01:58:40 +05:30
parent 34ab8f3f8b
commit 15b30206df

View File

@ -157,18 +157,20 @@ case "$PROMPT_COMMAND" in
esac esac
z() { z() {
if [ $# -ne 0 ]; then if [ "$#" -eq 0 ]; then
cd "$HOME"
elif [ "$#" -eq 1 ] && [ "$1" = "-" ]; then
cd "-"
else
_Z_RESULT=$(zoxide query "$@") _Z_RESULT=$(zoxide query "$@")
case $_Z_RESULT in case "$_Z_RESULT" in
"query: "*) "query: "*)
cd "${_Z_RESULT:7}" cd "${_Z_RESULT:7}"
;; ;;
*) *)
echo -n "${_Z_RESULT}" echo -n "$_Z_RESULT"
;; ;;
esac esac
else
cd "${HOME}"
fi fi
} }
"#; "#;
@ -220,18 +222,20 @@ _zoxide_precmd() {
} }
z() { z() {
if [ $# -ne 0 ]; then if [ "$#" -eq 0 ]; then
cd "$HOME"
elif [ "$#" -eq 1 ] && [ "$1" = "-" ]; then
cd "-"
else
_Z_RESULT=$(zoxide query "$@") _Z_RESULT=$(zoxide query "$@")
case $_Z_RESULT in case "$_Z_RESULT" in
"query: "*) "query: "*)
cd "${_Z_RESULT:7}" cd "${_Z_RESULT:7}"
;; ;;
*) *)
echo -n "${_Z_RESULT}" echo -n "$_Z_RESULT"
;; ;;
esac esac
else
cd "${HOME}"
fi fi
} }
"#; "#;