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

Re: How to do a simple find-replace autocomplete?



On 2007-07-15 at 19:33 -0700, Peter Mawhorter wrote:
> There may be a better way to do this tha's Zsh specific, but I've
> always just stuck a couple of variable declarations in my .zprofile:
> 
> export $p=/home/pmawhorter/media/pictures
> 
> and the like. When I type:
> 
> cd $p<Tab>
> 
> It completes to /home/pmawhorter/media/pictures.
> What is anoying is that I can't type '$p/a<Tab>' and complete directly
> to /home/pmawhorter/media/pictures/arrivals... I have to hit tab
> twice. Still, it's one way to "shortcut" directories.

% hash -d foo=~/bin/common
% less ~foo/<tab>
[shows completions]

Without the / before the <tab>, the ~foo is expanded first.

This is just adding entries to the directory hash table, the same one
that by default auto-populates with users' home directories.  (Which is
unwieldy when there's tens of thousands of users via LDAP and NFS
homedir automounts, so there's some hoops to jump through if you want to
artificially restrict it to a limited subset of users who are of
interest, but that's a whole different story).


Now, you can keep all the existing variables by just doing:
% setopt cdablevars

which will let you use ~p/ to mean the contents of $d/ but tying more
nicely into things like tab-completion.

-Phil



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