Open tramzee opened 5 years ago
Thanks for the contribution :+1:
I need to do more research to see how the directory stack works in other shells, but from the top of my mind they usually also have popd
and pushd
built-ins. I will get to a deeper review hopefully during the weekend.
When reading more about directory stack in other shells I also learned that cd
sets the OLDPWD
environment variable, which is currently notimplemented. So in case of switching to last directory we could just swap PWD
and OLDPWD
to enable the functionality. Supporting cd -
seems useful to me.
I have a question, do you just use cd to jump to last directory or do you use the functionality to jump to a directory deeper in the stack? I try not to blindly copy every feature and personally have never used the directory stack.
Comments to the proposed implementation:
dh
for more compatibilitydirs
just returned the sequence to make it more composable. You could then do for example dirs | (first)
or dirs | (count)
cd ~4
works to change directory, but you can also use it with any other command like ls ~4
.
-No unit tests.I see two options:
1) To support flipping back and forth between two directories with cd -
we can add OLDPWD
and flip it with PWD
.
2) To add proper implementation of the directory stack would require more work, and I am not sure if it is that useful.
@tramzee Would 1) be enough to cover your usage?
Sources:
@dundalek I use the directory stack deeper than just one. However, I would say that 90% of my usage is cd -
. Having said that I can certainly live without any stack whatsoever. Completion makes changing directories easy enough without excessive amounts of typing.
Also, I would be willing to tale a cut at doing the full directory stack implementation (pushd, popd, and dirs).
@tramzee Cool, that makes sense. I am also interested in having the full dir stack implementation, so that would be great.
FYI I refactored the built-ins a bit so that they are now defined with defcmd
which is cleaner than being hardcoded. Also it should be now possible to implement more customizations in user space in ~/.closhrc
. For example I think it could be an interesting experiment to try to implement the whole dir stack functionality via defcmd
s in ~/.closhrc
.
I like to use
cd -
to flip back and forth between two directories.This implements a very rudimentary directory stack that allows an easy way to return to a previous directory. It also adds a
dh
command that allows one to view the stack.