Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Neat hash -d trick
- X-seq: zsh-users 15467
- From: Nikolai Weibull <now@xxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Neat hash -d trick
- Date: Fri, 22 Oct 2010 00:34:09 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=ODYN+mW1zHYHsoLaj1214KizXcFOTdbyObonQeb/LAI=; b=wyaSB3O16cPnD7Tewk+w/8jHDJuJLpKJcy+jl9+W7GJaD67F41bwGmGfFSuxAwAO2s 1iyehpJ+AmivqNYh/yROZPes6c/CnWDGEjbL2rzJ3Yjoxj8o+Sz+xr7GUBlUaeEKksyO trorkdsLmrn31qMjIHDjWydMlHqw/L1rn/VCY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; b=gZ20fHH5cnWVNvUolqSoQ+gnrUnM4cyx7VZ8MV/cXsqw0OpAUUCM3opYt6JYRTsckS WPvAXyLSYT+Ayfo+M4vY9KqRMbk08KTrOq37m65PcLpf0E+YQ6bPFc6WiUvqC2PegbzD FM60cEiRU84EUZEyDVDhCnaDN5Cx9UPzwV5kQ=
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Sender: nikolai.weibull@xxxxxxxxx
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