DEV Community

Cover image for Creating a smart alternative to 'cd' command

Creating a smart alternative to 'cd' command

Bhupesh Varshney ๐Ÿ‘พ on August 03, 2020

Do you sometimes forget the actual location of directories & have to juggle through cd & ls to know the right path? In this short post, we ...
Collapse
ย 
jonrandy profile image
Jon Randy ๐ŸŽ–๏ธ โ€ข โ€ข Edited

Install z - it's awesome - github.com/rupa/z

Collapse
ย 
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ โ€ข

Did you mean the Z Shell ?. It actually is great but it's limited compared to features available in bash

Collapse
ย 
jonrandy profile image
Jon Randy ๐ŸŽ–๏ธ โ€ข

Nope - check out the GitHub link

Collapse
ย 
vonheikemen profile image
Heiker โ€ข

I want to hear about these bash features that zsh doesn't have.

Thread Thread
ย 
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ โ€ข โ€ข Edited

mapfile/readarray for example is a very handy thing in bash which is not in zsh
Another one which I like read -p "Enter Password" doesn't work in zsh

Collapse
ย 
juniordevforlife profile image
Jason F โ€ข

Thanks for this Bhupesh. My team lead at my previous job introduced me to Bash aliases. I created a few aliases to help me with navigating to files and directories that I used every day. I'd never thought to go beyond that, but after seeing your post I may have to tinker with it. Thanks again!

Collapse
ย 
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ โ€ข

Thanks a lot (you are probably the first reader ๐Ÿ™ˆ), glad it helped ๐Ÿ”ฅ
I am still amazed by how much we can customize our shell

Collapse
ย 
taikedz profile image
TaiKedz โ€ข

That's pretty neat !

The only thing is.... why cd "$1" || exit ? If for some reason there's, say, a permission issue on that folder, or a broken symlink, exit will actually terminate your current shell session... surely not the effect you want from a function? Likely this should be return

Collapse
ย 
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ โ€ข

Yes, I absolutely agree (the thing is I it realized sometime later after I first published the blog)
I have updated it now
thanks for pointing it out ๐Ÿ‘

Collapse
ย 
idrisrampurawala profile image
Idris Rampurawala โ€ข

You have opened up a new array of ideas with this post. Thanks. Keep it up bro! ๐Ÿ˜Š

Collapse
ย 
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ โ€ข

๐ŸคŸ๐Ÿผ thanks

Collapse
ย 
delta456 profile image
Swastik Baranwal โ€ข

Thanks for this!