set tempfile (mktemp -t "yazi-cwd.XXX") command yazi $argv --cwd-file=$tempfile if read -z cwd < "$tempfile"; and [ "$cwd" != "$PWD" ]; and test -d "$cwd" builtin cd -- "$cwd" end command rm -f -- "$tempfile"