Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Neat hash -d trick



I came up with this just now:

for ((i = 1; i < 9; i++)); do
  hash -d .$i=${(j:/:)${(l:2::.:)${(s::)${(l:i::.:)}}}}
done

It allows you to write

cd ~.4/dir

which would cd to ../../../../dir, given that that directory exists.

If someone could come up with a simpler expansion that would be sweet.

What would be even sweeter is if someone would come up with a way to
do this with only one call to hash -d without writing out all the
expansions and can easily be parameterized.  I couldnât figure out a
way to include the loop in the expansion.



Messages sorted by: Reverse Date, Date, Thread, Author