zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Ignoring current directory with auto_cd
Date: Mon, 12 Sep 2016 10:23:21 -0700	[thread overview]
Message-ID: <160912102321.ZM24807@torch.brasslantern.com> (raw)
In-Reply-To: <CABZhJg9se+WgA+tdvxKTd+UeHFLWibQpnqmOr=AAHBr4mz_DSg@mail.gmail.com>

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.


  reply	other threads:[~2016-09-12 17:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12 12:32 Jesper Nygårds
2016-09-12 17:23 ` Bart Schaefer [this message]
2016-09-12 19:43   ` Jesper Nygårds
2016-09-13  0:24     ` Bart Schaefer

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=160912102321.ZM24807@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).