Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Ignoring current directory with auto_cd
- X-seq: zsh-users 21882
- From: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Ignoring current directory with auto_cd
- Date: Mon, 12 Sep 2016 21:43:08 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=oRlZOydkBN4zq/hgilUrYEy/PmzExSst32lrQAoJwtc=; b=CaVwf9ULkVZceUfdY1Plhze84cF4lEt6WsaS8hTkhfBu61mLMvQVFb82TPqqPx/Ru2 BwIBQswke96L2mhce8p9uE14VDf4PbY1/gFSFYo5J0XfjMwOeKpFXosfr3ueFVlPRynw FmpXNbS49TP5O3sRKAIs9HbEWHPMuqgmKOEpVKWrF+A5nXLERH4+piEIeBAWJRhGNUzl 7MtMQRMBsVzHXqWiJQ6d5pFKUu+VQZWHRrunCU36Sde0J+Vu/AcWoRfy67pVx6ewEKAh bELNXIUcFDalCnZBx+ntvmkmht+leiwKNzQjYuDZoHgbxc9nqLGkGIEdev2MOKW+/nzF FYkw==
- In-reply-to: <160912102321.ZM24807@torch.brasslantern.com>
- 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
- References: <CABZhJg9se+WgA+tdvxKTd+UeHFLWibQpnqmOr=AAHBr4mz_DSg@mail.gmail.com> <160912102321.ZM24807@torch.brasslantern.com>
I am sorry, Bart. I realize now that my question was very badly worded.
I'll see if I can explain what I meant with an example:
Suppose I stand in a directory called "src". Since I have "zstyle
':completion:*:cd:*' ignore-parents parent pwd" set, if I type "cd
../s<tab>", I will not be offered "src" as a completion, since it gets
excluded by the zstyle setting.
However, if I only type "../s<tab>" (at the beginning of the command line),
"src" will be one of the alternatives offered by completion. I realize this
is because the completion system cannot know that it should exclude the
current directory.
So my question was: can I use something similar to the zstyle for cd
completion to always exclude the current directory in such a situation?
On Mon, Sep 12, 2016 at 7:23 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
wrote:
> On Sep 12, 2:32pm, Jesper Nygards wrote:
> }
> } Is there a way to make auto_cd also ignore the current directory, in the
> } same way cd does with this zstyle set? I tried this without success:
> }
> } zstyle ':completion::complete:-command-::' ignore-parents parent pwd
>
> Styles of this sort only apply to completion (as might be obvious from
> the word "completion" in the context) and only because there is a layer
> of user-defined functions implementing most of the completion system.
> There are no built-in shell operations that use zstyles values directly.
>
> This might mostly do what you want:
>
> autoload -Uz add-zsh-hook
>
> no-local-autocd() {
> set -- "${(z)2}"
> [[ $1 = */* ]] || unsetopt autocd
> }
>
> reset-autocd {
> setopt autocd
> }
>
> add-zsh-hook preexec no-local-autocd
> add-zsh-hook precmd reset-autocd
>
> I say "mostly" because if you do something like
>
> % echo foo ; /usr/bin
>
> the autocd to /usr/bin won't happen because "echo" caused the option to
> be turned off.
>
> You can do a similar thing by overloading the accept-line ZLE widget, or
> in more detail by using a DEBUG trap with the DEBUG_BEFORE_CMD option set,
> but either of those has its own problems.
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author