Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Z - Jump to directories that you actually use. (github.com/rupa)
101 points by snihalani on Sept 1, 2012 | hide | past | favorite | 32 comments


I use fasd, which is just like z, v, autojump, only much more powerful: https://github.com/clvv/fasd


you get + 100 karma for posting that. I can't believe I didn't come up with something similar in all these years


It's even based on Z, cool. You've reminded me to update my copy as the version I'm using is f.sh!


This looks like a serious productivity boost. Where has it been hiding all my life?

Thanks a million! :D


Seriously handy, thanks! I was about to dive into Z, but this looks even better.


No tricks, just regular cd:

  % pwd
  /home/aram
  % cd mstate
  /home/aram/src/launchpad.net/juju-core/mstate
  % cd go/src
  /home/aram/go/src
  % cd plan9
  /home/aram/plan9
  %
It uses the $CDPATH environment variable ($cdpath in rc(1)). $CDPATH is a list of places in which to search for the wanted directory. I put all the things I regularly use there, and my cds are almost always short, usually just a single name.

I don't maintain $CDPATH myself, my profile runs a one liner that descends into certain directories and constructs $CDPATH for me within the constrains of some rules (for example excludes leafs, excludes {bin,doc,pkg,test}, etc).

Finding about $CDPATH was a huge productivity boost to me, not only in time saved typing, but in allowing me to change the way I work. I now rarely care where things in the filesystem are (e.g. various source code for various software, where the build products are, etc). I used to do a lot of moving and symlinking around, to arrange stuff so I remember where I've put it and to keep paths short, but now I don't care. It could be wherever, it's just one name away. The namespace had become a big hash.


This is a pretty good solution, however there are a few things other programs add on:

- $CDPATH requires manual management. You're using a line in profile, but I imagine that's limited to specific directories and creates overhead when creating new shells. - What happens with namespace collision? First entry in $CDPATH wins? - Fuzzy searching for mistyped directory names. I don't find this feature that useful personally, but was requested quite a bit by others.

William (autojump maintainer)


Just tried this to see if tab-completion works. It does (only for cd of course). BTW: what is "rc(1)"?


Rc(1) is the Unix v10/Plan 9 shell[1] written by Tom Duff[2], of Duff's device[3] fame. Rc(1) is of course available in Unix as well, I use the port from plan9port[4].

[1] http://doc.cat-v.org/plan_9/4th_edition/papers/rc

[2] http://en.wikipedia.org/wiki/Tom_Duff

[3] http://en.wikipedia.org/wiki/Duff%27s_device

[4] http://swtch.com/plan9port/


|my profile runs a one liner... what's that one liner look like?


I lied, seems to be 5 lines total :-)

  export CDPATH=.:~
  cdpaths="$([ -d ~/src ] && find ~/src -mindepth 1 -type d | egrep -v '/(\.)|_[a-zA-Z0-9]' | egrep -v '(bin)|(cmd)|(doc)|(lib)|(pkg)|(test)' | xargs -n1 dirname | uniq)"
  for i in $cdpaths; do
  	CDPATH=$CDPATH:$i
  done


Fish-compatible version: https://github.com/sjl/z-fish


Thanks for that, added! It looks pretty promising.


I've been using a tool called autojump that does a similar thing and I love it.. https://github.com/joelthelion/autojump

Tools like Z and autojump are fantastic timesavers.


If you like his Z, check out his V (if you use Vim).

https://github.com/rupa/v


CDPATH, as desribed in man bash

'The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is ".:~:/usr".'


In case anyone else is wondering what "frecency" is:

Frecency is a portmantaeu of ’recent’ and ’frequency’. It is a weighted rank that depends on how often and how recently something occured. As far as I know, Mozilla came up with the term.


I have been using this--very handy. Is there a version that doesn't cd? It'd be nice for ls, etc.


just use an alias wrapper like:

  alias zls='z \!*;ls;cd -'
(with additional zll etc for ls -l or -a)


Is this good for zsh? Is there a preferred alternative?


It works just fine with zsh. If you're on a mac you can easily install z (and keep it up to date) with `brew install z`


FYI - The caveat for how to set up z for zsh were wrong in brew. I just submitted a pull request to fix this.

https://github.com/mxcl/homebrew/pull/14621


Great, updating brew asap!


Shameless plug: Bash function to jump back in path

https://gist.github.com/1119556


In bash, you can just cd - to pop back to the previous working directory, like popd without the pushd.

I also set .bash_profile aliases to quickly cd up the directory tree with just dots. It's silly, but surprising helpful.

  alias ..='cd ..'
  alias ...='cd ../..'
  alias ....='cd ../../..'


I did some Googling and was not satisfied with any of the solutions (pushd/popd, aliases, CDPATH etc.). That's why I wrote this. Works fine for me :)

PS: The whole story on my blog https://chanux.wordpress.com/2012/08/09/no-more-cd-dot-dot-s...


I like that idea, I could definitely see it being helpful. I've type cd.. too many times when I meant to say cd ..


me too. That's why I also:

  alias cd..='cd ..'
:)


At least '..' is defined by default in zsh.


Posz for Powershell - https://github.com/manojlds/posz


Does anyone know what the initial --add is for? I'm using z-fish and I'm wondering if I can elide it.


It's a wonderful little tool. I love it. Give it a try, you won't regret!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: