back

by JNRowe·2y ago·view on hn ↗
The article spends a little time talking about the drawbacks of using CDPATH because it will break scripts, but the better answer is simply not to export it. CDPATH is a shell variable, not an environment variable, and should be treated that way.

Simply use "CDPATH=here:there" without the export, get the same functionality and no additional breakage.

Plus, on zsh you can use the tied variable cdpath instead of CDPATH(see typeset -T¹). cdpath is an array that accepts all the regular array operations. For bonus points you can even declare it with -U to remove the need to consider duplicates in your config. Other common -- and useful -- tied variables include path/PATH and fpath/FPATH².

¹ https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Command...

² https://zsh.sourceforge.io/Doc/Release/Parameters.html#Param...