zsh-workers
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: Greg Klanderman <gak@klanderman.net>
Cc: zsh-workers@sunsite.dk
Subject: Re: completing automounts with fake-files setting hangs zsh
Date: Sun, 25 Jan 2009 22:11:18 -0800	[thread overview]
Message-ID: <20090126061118.GA54012@redoubt.spodhuis.org> (raw)
In-Reply-To: <m3k58jjjud.fsf@klanderman.net>

On 2009-01-25 at 13:56 -0500, Greg Klanderman wrote:
> 
> >>>>> Greg Klanderman <gak@klanderman.net> writes:
> 
> > So maybe the right thing is to modify the compfiles builtin to treat
> > fake files ending in '/' as directories without stat'ing them?  I'll
> > poke at that some more if you agree it's reasonable..
> 
> Well, I now see that the problem is not in compfiles.. it handles the
> fake files, and returns them in the result array back to _path_files.
> I'm gonna move on to something else for a bit..

Bear in mind that tab-completion often looks for spelling mistakes in
previous components of the path.  Some knobs I have tuned at work:

----------------------------8< cut here >8------------------------------
# Prevent reading in parent directories for tab-expansion:
zstyle ':completion:*' preserve-prefix '(/home/*|/auto/*)/'
# Or: zstyle ':completion:*' preserve-prefix '*/'
# Post-4.3.6 flag which does things 'properly'; any prefix component
# which matches an existing dir should be directly accepted, instead of
# being subject to expansion:
zstyle ':completion:*' accept-exact-dirs true
----------------------------8< cut here >8------------------------------

We also have /home/ as an automount for some number of thousands of
users (>10); for me, I only see those entries for which I've already
populated the directory, so readdir() only returns items which have been
pulled into the local host.  Mind, /etc/auto.home is a flat-file being
distributed, rather than LDAP or NIS or whatever.

The other part is that the userdirs variable, for ~<user> expansion,
will by default walk getpwent(), which can get rather tiresome when the
network is congested; userdirs is exposed by zsh/parameter but as a
read-only variable.

Here's how I get around it; zfilter_comments is another function, which
is just a "cat without comment lines, internal to shell" which I'll
include at the botton, since it's not relevant to the core
functionality.
----------------------------8< cut here >8------------------------------
function reset_userdirs {
# There is a zsh internal map, userdirs, exposed by zsh/parameter;
# it's read-only though.
        [[ -f ~/.userdirs ]] || return
        local _u
        local -a _ud
        _ud=( $(zfilter_comments ~/.userdirs) )
        for _u in $_ud; do hash -d $_u="/home/$_u"; done
        hash -d desktop="$HOME/Desktop"
#...
}
 Hack to turn off userdirs completion by overriding userdirs.
# This overrides userdirs as a local variable inside the completion
# system, not touching the global variable.  We don't need to load
# zsh/parameter to achieve this.
#zmodload -i zsh/parameter
_comp_setup+=$'\ntypeset -a userdirs\nreset_userdirs'
reset_userdirs
----------------------------8< cut here >8------------------------------

Other completion system tags you can look at defining include:
  accounts my-accounts other-accounts users


There is in zsh room for improvement in a few areas to deal with large
maps loaded in by the OS slowly in large user environments or slow
filesystems; a way to explore might be adding a couple of zstyle tags
which activate more cautious lookup and adjust the relevant completion
functions to use those, as needed.  After all, that's what 'users',
'accounts', etc do already.  Perhaps with setting those and
preserve-prefix or accept-exact-dirs, you'll be okay; for me, the above
has made things work cleanly and smoothly enough that I haven't been
motivated to come up with decent improvements to feed back into zsh
(since it's only a problem at work and I have higher priorities when
there).

Regards,
-Phil

----------------------------8< cut here >8------------------------------
function zfilter_comments {
        local f infile="$1"
        while read f; do
                [[ -n ${f%%[$' \t']*\#*} && ${f#[#;]} == $f ]] || continue
                print -r -- ${f%%[$' \t']*\#*}
        done < "$infile"
}
----------------------------8< cut here >8------------------------------


      reply	other threads:[~2009-01-26  6:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-24 22:47 Greg Klanderman
2009-01-25  3:45 ` Greg Klanderman
2009-01-25 12:20   ` Bart Schaefer
2009-01-25 16:40     ` Greg Klanderman
2009-01-25 18:56       ` Greg Klanderman
2009-01-26  6:11         ` Phil Pennock [this message]

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=20090126061118.GA54012@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=gak@klanderman.net \
    --cc=zsh-workers@sunsite.dk \
    /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).