zsh-users
 help / color / mirror / code / Atom feed
* Completion for cd
@ 2017-03-14 17:38 Jesper Nygårds
  2017-03-14 19:07 ` Bart Schaefer
  0 siblings, 1 reply; 27+ messages in thread
From: Jesper Nygårds @ 2017-03-14 17:38 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 2333 bytes --]

I am using zsh 5.3.1. For a long time I've had the following completion
configuration:

zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]}' '+l:|=*'
zstyle ':completion::*:::' completer _expand _complete _prefix _approximate
_ignored
cdpath=(. /opt)

The idea is of course that if something I write is the start of a
completion, I want it to be completed. If such match is _not_ found, I want
completion to the left (prefix completion?) to be attempted. It works well.
If I stand in a directory 'statistics' containing the directories
'stats-lib' and 'stats-web', I can write 'cd web<tab>' and have it
completed to 'stats-web'. That is what I want.

However, I have a slight problem with it. In my '/opt' directory, I have a
directory called 'webcert'. If I stand in the 'statistics' directory,
writing 'cd web<tab>' gives me 'webcert', since '/opt' is in the cdpath
array. This is as expected since I have configured matcher-list to prefer
what is a prefix to what is a suffix, so 'webcert' (in the cdpath) is
found, and therefore 'stats-web' (in the current directory) is never
offered.

I would like to keep the matcher-list configuration, but for the cmpletion
to prefer matches in the current directory over matches in cdpath. I
therefore added the following configuration:

zstyle ':completion:*:*:cd:*:*' completer _expand _complete
_complete:withpath _prefix _approximate _ignored
zstyle ':completion:*:complete:cd:*:*' tag-order local-directories -
zstyle ':completion:*:withpath:cd:*:*' tag-order path-directories

This works as intended: now 'stats-web' in the current directory is
preferred over 'webcert' in cdpath, so typing 'cd web<tab>' completes to
'stats-web'. If I want to go to 'webcert', I can type 'cd webc<tab>' and it
will complete to 'webcert'.

However, now I find a surprising side-effect of this change. I have also
this configuration:

zstyle ':completion:*:*:cd:*:*' ignore-parents parent pwd

But this is broken by my change! If I go to directory 'zsh' in
'/usr/local/Cellar', and then type 'cd ../z<tab>', I am offered 'zsh'
together with 'zsh-completion', whereas before the change, I would only be
offered 'zsh-completion', since I have configured cd to ignore the current
directory.

I can't figure out why my configuration change has caused the
'ignore-parents' style to stop working.

^ permalink raw reply	[flat|nested] 27+ messages in thread
* Completion for cd
@ 2004-03-28 10:42 Thorsten Haude
  2004-03-28 12:03 ` Thorsten Kampe
  2004-03-28 19:56 ` Bart Schaefer
  0 siblings, 2 replies; 27+ messages in thread
From: Thorsten Haude @ 2004-03-28 10:42 UTC (permalink / raw)
  To: Zsh User ML

[-- Attachment #1: Type: text/plain, Size: 2016 bytes --]

Hi,

one of the last upgrades of Zsh in Debian Sarge changed the way
directory names for cd are completed. With the current set of
functions, user's home directories are completed, which is a nuisance.

I think I have found the file to change:
/usr/share/zsh/4.1.1/functions/Completion/Zsh/_cd

Now, there are some problems:
1. I don't understand enough of the code to reliably remove user's
home directories from completion. I could fall back to an older
version of the file, but would loose completion of cdable vars.

The code in question is probably this part:
- - - Schnipp - - -
    # With cdablevars, we can complete foo as if ~foo/
    if [[ -o cdablevars && -n "$PREFIX" && "$PREFIX" != <-> ]]; then
      if [[ "$PREFIX" != */* ]]; then
        alt=( "$alt[@]" 'named-directories: : _tilde' )
      else
        local oipre="$IPREFIX" opre="$PREFIX" dirpre dir

        # Note we need a tilde because cdablevars also allows user home
        # directories, hence nonomatch (above) to suppress error messages.

        dirpre="${PREFIX%%/*}/"
        IPREFIX="$IPREFIX$dirpre"
        eval "dir=( ~$dirpre )"
        PREFIX="${PREFIX#*/}"

        [[ $#dir -eq 1 && "$dir[1]" != "~$dirpre" ]] &&
          _wanted named-directories expl 'directory after cdablevar' \
              _path_files -W dir -/ && ret=0

        PREFIX="$opre"
        IPREFIX="$oipre"
      fi
    fi
- - - Schnapp - - -

How to rip out home dir completion without affecting cdable vars?


2. I would like to do the change in a way that does not interfere with
future updates from Debian's package management system. Any ideas?


I'm not sure whether the change in behavior is the idea of the Zsh
team or of the Debian maintainer. I reported this as a bug to Debian,
but if someone here is closer to the source he might want to revert
this change in Zsh itself.


tia,

Thorsten
-- 
Don't let your sense of morals prevent you from doing what is right.
    - Isaac Asimov

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2017-03-15 20:33 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 17:38 Completion for cd Jesper Nygårds
2017-03-14 19:07 ` Bart Schaefer
2017-03-14 21:50   ` Jesper Nygårds
2017-03-15  3:56     ` Bart Schaefer
2017-03-15  7:22       ` Jesper Nygårds
2017-03-15 17:00         ` Bart Schaefer
2017-03-15 20:33           ` Jesper Nygårds
  -- strict thread matches above, loose matches on Subject: below --
2004-03-28 10:42 Thorsten Haude
2004-03-28 12:03 ` Thorsten Kampe
2004-03-28 20:34   ` Thorsten Haude
2004-03-30  1:15     ` Thorsten Kampe
2004-03-31 20:19       ` Thorsten Haude
2004-04-01 18:04         ` Bart Schaefer
2004-04-01 20:44           ` Thorsten Haude
2004-04-02  4:38             ` Bart Schaefer
2004-04-02  6:52               ` Thorsten Haude
2004-04-02 16:11                 ` Bart Schaefer
2004-04-04 14:43                   ` Thorsten Haude
2004-04-04 15:14                     ` Clint Adams
2004-04-04 15:26                       ` Thorsten Haude
2004-04-04 16:39                         ` Clint Adams
2004-04-05  0:04                           ` Bart Schaefer
2004-04-05  3:50                             ` Clint Adams
2004-03-28 19:56 ` Bart Schaefer
2004-03-31 20:22   ` Thorsten Haude
2004-04-01 18:24     ` Bart Schaefer
2004-04-01 20:52       ` Thorsten Haude

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).