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

Re: Completion does not work with hidden files/directories



Oliver,

Thank you for your reply.

Le dim. 30 mai 2021 à 14:53, Oliver Kiddle <opk@xxxxxxx> a écrit :
Fran?ois RONVAUX wrote:
> In my home directory, there are currently only hidden files/directories and the
> completion mechanism does not see them :-(

The main way to control which files are included in file completion is
via the file-patterns style. So if you always want to see hidden files,
it would be something like:

  zstyle ':completion:*' file-patterns '%p(D):globbed-files *(D-/):directories' '*(D):all-files'

(D) is a glob qualifier that includes hidden files and you might use it
from the command-line as, e.g. *.png(D)

I was going to suggest something like the following which adds the (D)
to the all-files fallback:

  zstyle ':completion:*' file-patterns '%p:globbed-files *(-/):directories' '*(D):all-files'

Unfortunately, _files has some sort of shortcut where it does:

  [[ "$pat" = '*' ]] && return ret

So it never tried all-files if globbed-files was using * as a glob. This
should perhaps be looked into and discussed on -workers.

What you can do, however is add a second run of the _complete completer
with the separate file-patterns style:

  zstyle ':completion:*::::' completer _complete _complete:-hidden
  zstyle ':completion:*:complete-hidden:*' file-patterns '%p(D):globbed-files' '*(D):all-files'

Note, however that you likely already have a completer style with other
functions like _expand listed and you should only add _complete:-hidden
to the list somewhere after _complete.

> Same issue when I want to change of directory :

cd doesn't use files so file-patterns may not help there.

> zstyle ':completion:*' cache-path ${ZDOTDIR}/zsh_cache
> zstyle ':completion:*' use-cache true #on

> Second issue (less important) : the section "Create a cache" in the above file
> does not work.

Only some completion functions need to create a cache. Note that those
lines do not create a cache, they only tell completion where to put cache
files. Is ${ZDOTDIR} definitely set to something. If not, it could be
trying /zsh_cache. The directory you specify should already exist and should be a writable directory.

Oliver


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