Add $_ZO_ECHO to echo match before navigating

This commit is contained in:
Ajeet D'Souza 2020-03-15 17:44:23 +05:30
parent f31fcf2d1f
commit f4cd1159c5
1 changed files with 17 additions and 9 deletions

View File

@ -107,15 +107,19 @@ struct HookConfig {
} }
const BASH_Z: &str = r#" const BASH_Z: &str = r#"
_z_cd() {
cd "${@}" > /dev/null && test -n "$_ZO_ECHO" && echo "${PWD}"
}
z() { z() {
if [ "${#}" -eq 0 ]; then if [ "${#}" -eq 0 ]; then
cd "${HOME}" _z_cd "${HOME}"
elif [ "${#}" -eq 1 ] && [ "${1}" = '-' ]; then elif [ "${#}" -eq 1 ] && [ "${1}" = '-' ]; then
cd '-' _z_cd '-'
else else
local result=$(zoxide query "${@}") local result=$(zoxide query "${@}")
case "${result}" in case "${result}" in
"query: "*) cd "${result:7}" ;; "query: "*) _z_cd "${result:7}" ;;
*) [ -n "${result}" ] && echo "${result}" ;; *) [ -n "${result}" ] && echo "${result}" ;;
esac esac
fi fi
@ -123,15 +127,20 @@ z() {
"#; "#;
const FISH_Z: &str = r#" const FISH_Z: &str = r#"
function _z_cd
cd "$argv" > /dev/null
and commandline -f repaint
and [ -n "$_ZO_ECHO" ]
and echo "$PWD"
end
function z function z
set -l argc (count "$argv") set -l argc (count "$argv")
if [ "$argc" -eq 0 ] if [ "$argc" -eq 0 ]
cd "$HOME" _z_cd "$HOME"
and commandline -f repaint
else if [ "$argc" -eq 1 ] else if [ "$argc" -eq 1 ]
and [ "$argv[1]" = '-' ] and [ "$argv[1]" = '-' ]
cd '-' _z_cd '-'
and commandline -f repaint
else else
# TODO: use string-collect from fish 3.1.0 once it has wider adoption # TODO: use string-collect from fish 3.1.0 once it has wider adoption
set -l IFS '' set -l IFS ''
@ -139,8 +148,7 @@ function z
switch "$result" switch "$result"
case 'query: *' case 'query: *'
cd (string sub -s 8 "$result") _z_cd (string sub -s 8 "$result")
and commandline -f repaint
case '*' case '*'
[ -n "$result" ] [ -n "$result" ]
and echo "$result" and echo "$result"