I've found that file names with dates before the title are difficult to tab-completion. I'd like to write custom completion functions for these directories. How do I specify that the completer should be used instead of the default?

  • What exactly is difficult about them to tab-complete? And how would you want the tab completion to work for these? – Marlon Richert Aug 13 '20 at 12:15

There's no way to specify it, but you can patch the _path_files completion function to achieve this:

# Load the `functions` table.
zmodload -Fa zsh/parameter p:functions

# Load the definition of _path_files.
autoload +X -Uz _path_files

# Make a copy of it.

# Replace the original.
_path_files() {
  # `$words[CURRENT]` is the current word under completion.
  # `:a` turns it into an absolute path.
  if [[ $words[CURRENT]:a == <pattern that matches the dirs in question>/* ]]; then
    <your special completion function> "$@"
    _original_path_files "$@"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.