TIL: Fish Shell Directory History

Last updated: Thu Jan 11 2024

fish shell has two built-in functions, nextd and prevd, that let you jump between recently visited directories in a stack-like manner.

cd ~/Developer
cd ~/Documents
nextd # Working directory is now ~/Developer
prevd # Working directory is now ~/Documents

You can also use dirh to print the directory stack and cdh for an interactive navigator (which doesn’t work that well, in my experience).

However, an extra neat fact is that nextd and prevd have default keybindings! With an empty command line, press Alt+← (Option+← on Macs) for prevd and Alt+→ (Option+→ on Macs) for nextd.

References