Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: completion of filenames
On Fri, Dec 13, 2019 at 9:07 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Or not. Anyway for now I don't even know where to look.
Let's take this all the way back to the beginning for a moment ...
On Tue, Dec 10, 2019 at 8:19 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> As I have it now TAB only completes filenames after some leading
> command. If I hit TAB at the beginning of a line it seems to want to
> find commands. Can I have filename completion active right from the
> start?
When there is nothing at all on the command line, completion starts
out in the special "-command-" context. If you start from "zsh -f"
and load the completion system (compinit) and then type ^x h (as
previously suggested by PWS -- note, you have to let go of the ctrl
key before hitting h) you will find this (apologies for any extraneous
line wrapping):
%
tags in context :completion::complete:-command-::
commands builtins functions aliases suffix-aliases reserved-words
jobs parameters parameters (_command_names _autocd)
commands
(_path_commands _path_commands
_command_names _autocd)
jobs
(_jobs _command_names _autocd)
parameters
(_parameters _command_names _autocd)
You'll notice that "files" are not in that description anywhere.
If we add your "zstyle ':completion:*' completer _expand _complete
_files" setting:
%
tags in context :completion::complete:-command-::
commands builtins functions aliases suffix-aliases reserved-words
jobs parameters parameters (_command_names _autocd)
commands
(_path_commands _command_names _autocd)
jobs
(_jobs _command_names _autocd)
parameters
(_parameters _command_names _autocd)
tags in context :completion::files:::
globbed-files (_files)
Now we have files, but they're still going to be tried only after all
the more specific context has failed to locate anything. If you want
files to be tried along with all of those other options, you need to
put _files BEFORE _complete in the zstyle, and if you want that to
happen only at an empty prompt, you need to use the specific -command-
context.
zstyle :completion::complete:-command-:: completer _expand _files _complete
zstyle :completion::complete:-command-:: insert-tab false
Note that when you form a list of completers, the implication is that
if an earlier entry in the list finds ANY possible completion, then
the later entries will not be tried. So at an empty prompt you are
going to get either the default stuff from _complete, or the local
files from _files, depending on which order those appear in the style.
If you want both all the time, a different formulation would be
needed.
You've got one more issue, I think, based on your subsequent question:
> Where is 'expand-or-complete' defined?
You shouldn't be using both expand-or-complete and the _expand
completer. If you invoke expand-or-complete, it's going to try to do
expansion on the word and if that succeeds it will never proceed into
attempting completion. To use _expand, you should be re-binding the
TAB key:
bindkey "^I" complete-word
Usually compinit will take care of this for you, but only if the
zstyle definitions appear in your .zshrc (et al) BEFORE you invoke
compinit. This is in the doc:
To initialize the system, the function compinit should be in a direc-
tory mentioned in the fpath parameter ... If completion styles (see
below) are set up to perform expansion as well as completion by
default, and the TAB key is bound to expand-or-complete, compinit will
rebind it to complete-word; this is necessary to use the correct form
of expansion.
Does any of this help with your situation?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author