3 ms·
Why is this better than CDPATH that is already built into my shell?
by riddley 3y ago
Why is this better than CDPATH that is already built into my shell?
- keerthiko 3y agofor one, it is not built into either of my shells: Windows gitbash, or OSX terminal.
- semanticist 3y agoOS X Terminal isn't your shell, by default zsh is your shell on Mac OS, and it does support cdpath: https://zsh.sourceforge.io/Intro/intro_13.html https://zsh.sourceforge.io/Intro/intro_13.html I assume Windows Linux thing uses Bash? It works even more simply, exactly like $PATH.
- BeetleB 3y agoThink of this as an auto-CDPATH. With CDPATH you have to explicitly add the directories. And even with CDPATH, it won't work if you need to go deep down. As an example, say I have ~/Programs/Firefox/Profiles/kdskdj/Cache. Most people would put just ~/Programs or ~/Programs/Firefox into CDPATH. If you want to get to the Cache directory, you still need to know "Profiles/kdskdj/Cache". With z, if you're lucky, you'll just do "z Cache". Worst case, "z Fire Cache"
- kazinator 3y agoDo you know of completion for the cd command that works with CDPATH? So that when you type "cd prefix[Tab]" it will give completions from CDPATH?
- kazinator 3y agoCDPATH is kind of flawed. It wants to be a mapping feature. So that is to say, when I type "cd foo", I want foo to be "cd alias" for some "/path/to/foo" or possibly even "/path/to/bar". I know where I want to go; I don't need a search to find it! Fortunately, there is a way to get that with CDPATH. You can make some directory, say /home/yourself/.cdfarm. Inside .cdfarm/, you have symlinks to various directories foo -> /path/to/foo bar -> /path/to/elsewhere/bar and you put this .cdfarm into your CDPATH: CDPATH=:~/.cdfarm and that's it, all other management is via ~/.cdfarm. Unfortunately, the symlinks appear in the PWD, unless you use "cd -P"; for that you can "alias cd='cd -P". Even if you use -P, when Bash's cd resolves something via CDPATH, it prints the target path name with the /home/yourself/.cdpath/... in it, as it appears before -P resolution. That's not necessarily a bad thing; it reminds you of how you are getting to where you are.