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 :
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.
If you’ve multiple bar folders, you can specify multiple parts of the path, so that you match the right one:
z foo bar