Shell Wrapper
The y shell wrapper is a function that launches Yazi and, on exit, changes your shell's working directory to wherever Yazi last visited. This is the single most impactful productivity feature of Yazi.
How it works
Yazi writes the last-visited directory path to --cwd-file when it exits. The shell wrapper reads that file and runs cd to that path.
Bash / Zsh
Add to ~/.bashrc or ~/.zshrc:
~/.bashrc or ~/.zshrc
function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd"
fi
rm -f -- "$tmp"
}
Fish
Add to ~/.config/fish/config.fish:
~/.config/fish/config.fish
function y
set tmp (mktemp -t "yazi-cwd.XXXXX")
yazi $argv --cwd-file=$tmp
if set cwd (cat -- $tmp); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
cd -- $cwd
end
rm -f -- $tmp
end
Nushell
Add to ~/.config/nushell/config.nu:
~/.config/nushell/config.nu
def --env y [...args] {
let tmp = (mktemp -t "yazi-cwd.XXXXX")
yazi ...$args --cwd-file=$tmp
let cwd = (open $tmp)
if $cwd != "" and $cwd != $env.PWD {
cd $cwd
}
rm -f $tmp
}
PowerShell
Add to $PROFILE (typically ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1):
$PROFILE
function y {
$tmp = [System.IO.Path]::GetTempFileName()
yazi @args --cwd-file $tmp
$cwd = Get-Content $tmp
if ($cwd -and $cwd -ne (Get-Location).Path) {
Set-Location $cwd
}
Remove-Item $tmp
}
Windows CMD
Save as y.cmd and place in a directory in your %PATH%:
y.cmd
@echo off
set tmp=%TEMP%\yazi-cwd.txt
yazi %* --cwd-file="%tmp%"
set /p cwd=<"%tmp%"
if defined cwd if not "%cwd%"=="%CD%" cd /d "%cwd%"
del "%tmp%" 2>nul
Verification
After adding the wrapper, restart your shell and run:
y
# navigate around, press q
pwd # should show the last directory you visited in Yazi
tip
Use y instead of yazi for normal use. Only use the yazi binary directly when you want to skip the directory-tracking behavior.