zsh tips: Changing directories

We all know how to change directories via cd , but zsh has some really neat features implemented to support us in changing directories the smart way.

Changing directories without cd

Because we all like productivity, let’s make cd  itself needless, by enabling auto_cd :

setopt auto_cd

Now as you’ve enabled auto_cd , you can change directories without even typing  cd :

# the old fashioned way
cd ../foo/bar

# the new way, with auto_cd enabled
../foo/bar

Changing directories with string replacement

Let’s say you change into a complicated path. Then you need to change into a similar path, with a somewhat different substring:

# change into ../example/foo/subdir
cd ../example/foo/subdir

# now change into ../example/bar/subdir
cd foo bar

Changing directories with auto completion

I already mentioned it in the last post, auto completion is really helpful in long / complicated directory paths:

# while this is a lot of typing
cd ~/Documents/business/git/check42

# this is much more comfy
cd ~/D/b/g/42<tab>

Changing to recent directories with z

There’s a project on github called z. This is the absolute “pro-way” to change to most recent used directories.

Basically it will replace / alias your cd command, and then it starts learning. After it has learned about your cd behaviour, you can use z  to jump to your most frequent used directories. And if this isn’t enough, it also support regex.

Let’s say you’ve to move to /some/complicated/path/with/foo/bar  all the time. Instead of cd  into it, you can now z  into it.

z bar

If you’ve multiple bar folders, you can specify multiple parts of the path, so that you match the right one:

z foo bar

Awesome, isn’t it? And when you’re using oh-my-zsh like suggested in the zsh: A shell on steroids post, then you just can load the z plugin.

10 Comments

  • ruya yorumu

    At this time it appears like WordPress is the best blogging
    platform out there right now. (from what I’ve read) Is that what you are using on your blog?

    • Dominique Barton

      Hi. Yeah, we’re using WordPress for our blog and I really like it, as it has a huge user base and there are a lot of plugins available. Cheers Domi

  • Canada Kratom

    Vous n’êtes jamais aussi bon que sous la pression ?

    • Dominique Barton

      What? 🙂

  • happy wheels

    Thanks for sharing insightful information

  • Lou

    thanks for sharing the module.

  • offshore25

    Thanks for sharing this usefull information.

  • skribbl io

    We don’t promise, you don’t know tomorrow again. But I really mean only these words (I like you). Don’t ask anything, I can’t answer.