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

Re: Ignoring current directory with auto_cd



On Sep 12,  9:43pm, Jesper Nygards wrote:
}
} [...] I have "zstyle ':completion:*:cd:*' ignore-parents parent pwd" set
} [...]
} 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.

Actually it's not because the system doesn't know it should exclude the
current directory -- it's because the system doesn't know if you're
intending to type the name of a directory, or if you are intending to
type the path to a command file that happens to be inside some ../s*
directory.  In that word position, it has to complete both directory
names and command names, and the latter might include a relative path
as a prefix.

} 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?

If you never want to complete the path prefixes of non-absolute command
name paths, you can do this:

zstyle -e ':completion::complete:-command-::' tag-order \
    '[[ $words[CURRENT] = */* && $words[CURRENT] != /* ]] && reply=(
        commands executables builtins functions aliases
        suffix-aliases reserved-words jobs parameters -
	)'

This will complete all the usual things in command position except
that commands and executables are normally further subdivided by _files
into globbed-files, directories, and all-files, which the trailing "-"
will force to be excluded.

You can get fancier with the conditional expression, e.g., check for
$words[CURRENT]*/**/*(*) finding something, or some such.



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