1

I'm a big fan of using bash's pushd, popd, and dirs program set. However, I tend to use it so much, that the list of directories becomes too hard to read through.

It would be nice if I could get the dirs operation to use aliases in addition to the default home directory ~. For example, if I move around a lot in the subdirectories of ~/Documents/MyBaseDir/MyCodeCheckout, then instead of...

user1> dirs
~/Documents/MyBaseDir/MyCodeCheckout/src/main/resource, ~/Documents/MyBaseDir/MyCodeCheckout/src/test/java/testdir1

...I'd like to get dirs (and pushd and popd) to display something like:

user1> dirs
~code1/src/main/resource, ~code1/src/test/java/testdir1

Notice in this post, that the latter output doesn't even need a scroll bar. In the typical command prompt window, it would cut down significantly on wrapping, which is a pain to decipher.

I've recently found the -v flag to the dirs command, which makes the above output look like this:

user1> dirs -v
0  ~/Documents/MyBaseDir/MyCodeCheckout/src/main/resource
1  ~/Documents/MyBaseDir/MyCodeCheckout/src/test/java/testdir1

This would be sufficient, and I can get this behavior by default by using:

alias dirs='dirs -v'

The only downside to that is that I can't find a way to get pushd or popd to use the same format when they display the same list. Despite bash documentation saying that a dirs operation is performed upon successful completion of both commands, it seems that the alias above does not expand into their realm.

Any further ideas would be appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.