function y
    set tmp (mktemp -t "yazi-cwd.XXXXXX")

    # In Zellij + Alacritty, force Yazi away from graphical adapters and into Chafa.
    # This gives text/blocks previews instead of broken/blank image panes.
    if set -q ZELLIJ
        env -u DISPLAY -u WAYLAND_DISPLAY -u SWAYSOCK -u HYPRLAND_INSTANCE_SIGNATURE -u WAYFIRE_SOCKET TERM=xterm-256color yazi $argv --cwd-file="$tmp"
    else
        yazi $argv --cwd-file="$tmp"
    end

    if set cwd (command cat -- "$tmp"); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
        builtin cd -- "$cwd"
    end

    rm -f -- "$tmp"
end
