rupa / z

z - jump around
Do What The F*ck You Want To Public License
16.39k stars 1.17k forks source link

How to force it to cd to a directory if it exists #206

Open nikitavoloboev opened 7 years ago

nikitavoloboev commented 7 years ago

For example I maybe in a folder ~/projects/something

And in there there maybe a folder files like ~/projects/something/files

If I do z files it actually goes to some other folder 'files'. I want to make it so that z will always work like 'cd' command if the path is given and the folder exists in the current place where I am.

Can I do this?

johnfb commented 7 years ago

The simplest way I can think of to do something like that would be:

_cz() { cd "$@" > /dev/null 2>&1 || _z "$@" 2>&1; }
alias cz=_cz

Then you can do: cz path if path exists as a dir then it will go there, if not it will invoke z

rupa commented 7 years ago

-c argument restricts matches to current dir, but IMHO the way to deal with getting unexpected result, or getting to something that isn't the top match, is to adjust the mnemonic so it matches something unique, maybe use a couple of args, eg z so files or z pro files