3 ms·
You can get part way to this sort of experience in standard bash/sh by setting up a thoughtful 'CDPATH' and also making use of 'cd -'. In fact I have the latter
by frou_dh 11y ago
You can get part way to this sort of experience in standard bash/sh by setting up a thoughtful 'CDPATH' and also making use of 'cd -'. In fact I have the latter aliased as z because it's like Undo.
- 6502nerdface 11y agoAlso by using the `pushd' and `popd' built-ins.
- michaelhoffman 11y agoI alias `cd` to a function that includes `pushd` so I don't have to remember.
- mtdewcmu 11y agoI have Page Up and Page Down set to cycle through the directory stack, so they are similar to the back and forward buttons in a web browser. Except that mine is circular. I can't take credit; I found the idea on the web somewhere and made refinements. I can't remember anymore which parts were mine and which were from the web.
- vram22 11y agoRight, was going to mention CDPATH but searched the thread first to see if anyone already had. Also, as you have said, 'cd -' is useful; more so if you often toggle between two dirs, such as a src and a corresponding bin dir (e.g. doing C dev), or src and doc, etc. Then you only need to keep doing 'cd -' to toggle between them, as long as you are not going to any other dir in between. For long dir paths that I cd to often, I sometimes define them as shorter shell env. vars. and add them to my .profile or equivalent startup file. Then I just do: cd $short_dir_name_1 # or 2, etc.
- mtdewcmu 11y agoCDPATH is kind of obnoxious. It's confusing to have phantom subdirectories no matter where you are, which interact with auto-completion, and they can alias real subdirectories, which is always surprising and annoying when it happens. Furthermore, the autocomplete support for CDPATH directories didn't work satisfactorily. I found a somewhat better way to use CDPATH. I made the only thing in my CDPATH a special directory into which I placed symlinks, and all of the symlinks were prefixed with an underscore. So if I wanted to jump to one of these "bookmarks," I'd start with the underscore prefix; this reduced the likelihood of them aliasing subdirectories in $PWD. I wrote shell functions to automate adding and deleting links, which automatically enforced the underscore rule. I eventually got sick of even this system and stopped using it. My final conclusion was that CDPATH is not useful. When I want quick access to a directory, I just make a symlink in $HOME. It's not that hard to type `cd ~/symlink`, and it always does what you expect.