From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Neat hash -d trick
Date: Thu, 21 Oct 2010 21:05:13 -0700 [thread overview]
Message-ID: <101021210513.ZM30802@torch.brasslantern.com> (raw)
In-Reply-To: <AANLkTikBOSBNfBHXDFdfiCkijVt5G5+-1UVFz_VqY3wZ@mail.gmail.com>
[Aside to -workers: This reminds me about Mikael Magnusson's thread
for his proposed HASH_LOOKUP option, which sort of died out without
resolution after a discussion of findcmd() behaving oddly.]
On Oct 22, 12:34am, Nikolai Weibull wrote:
}
} for ((i = 1; i < 9; i++)); do
You probably mean <= 9 there? Or just
for i in {1..9}
} hash -d .$i=${(j:/:)${(l:2::.:)${(s::)${(l:i::.:)}}}}
hash -d .$i=${${(l:i*3::../:)}%/}
} done
}
} cd ~.4/dir
A generic word of caution about using "hash -d": if you for any reason
change the value of $PATH or $path after this, all your custom hash
entries are lost when the table is rebuilt for the new searchpath.
A similar trick:
dotdot() {
if (( NUMERIC > 0 ))
then LBUFFER+=..; repeat $((NUMERIC-1)) LBUFFER+=/..
else LBUFFER+=.
fi
}
zle -N dotdot
bindkey . dotdot
Now you can type ESC 4 . to insert ../../../.. (or ESC 9 ESC 9 . to
insert 99 levels, if for some insane reason you need that many).
} 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
Because the counter has to be referenced twice in the expansion, I
don't think there's any way of avoiding the "for" loop that's worth
the effort to figure out. However,
for i in {1..9}; h+=(.$i=${${(l:i*3::../:)}%/}); hash -d $h
Or to avoid leaving $i and $h with a value at the end,
hash -d $( for i in {1..9}; print .$i=${${(l:i*3::../:)}%/} )
next prev parent reply other threads:[~2010-10-22 4:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-21 22:34 Nikolai Weibull
2010-10-22 4:05 ` Bart Schaefer [this message]
2010-10-22 7:28 ` Mikael Magnusson
2010-10-22 8:09 ` Julien Nicoulaud
2010-10-22 8:39 ` Jérémie Roquet
2010-10-22 10:29 ` Nikolai Weibull
2010-10-22 14:24 ` Oliver Kiddle
2010-10-27 15:45 ` Jean-Rene David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=101021210513.ZM30802@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).