Fix exit codes in 'z' command

This commit is contained in:
Ajeet D'Souza 2020-03-16 14:26:59 +05:30
parent a5369beaa4
commit 146e5709fb

View File

@ -108,7 +108,13 @@ struct HookConfig {
const BASH_Z: &str = r#" const BASH_Z: &str = r#"
_z_cd() { _z_cd() {
cd "${@}" > /dev/null && test -n "$_ZO_ECHO" && echo "${PWD}" cd "${@}" > /dev/null
if [ "${?}" -eq 0 ]; then
if [ -n "$_ZO_ECHO" ]; then
echo "${PWD}"
fi
fi
} }
z() { z() {
@ -119,8 +125,14 @@ z() {
else else
local result=$(zoxide query "${@}") local result=$(zoxide query "${@}")
case "${result}" in case "${result}" in
"query: "*) _z_cd "${result:7}" ;; "query: "*)
*) [ -n "${result}" ] && echo "${result}" ;; _z_cd "${result:7}"
;;
*)
if [ -n "${result}" ]; then
echo "${result}"
fi
;;
esac esac
fi fi
} }
@ -129,9 +141,13 @@ z() {
const FISH_Z: &str = r#" const FISH_Z: &str = r#"
function _z_cd function _z_cd
cd "$argv" > /dev/null cd "$argv" > /dev/null
and commandline -f repaint
and [ -n "$_ZO_ECHO" ] if [ "$status" -eq 0 ]
and echo "$PWD" commandline -f repaint
if [ -n "$_ZO_ECHO" ]
echo "$PWD"
end
end
end end
function z function z
@ -150,8 +166,9 @@ function z
case 'query: *' case 'query: *'
_z_cd (string sub -s 8 "$result") _z_cd (string sub -s 8 "$result")
case '*' case '*'
[ -n "$result" ] if [ -n "$result" ]
and echo "$result" echo "$result"
end
end end
end end
end end