我发现标题前带有日期的文件名很难用制表符完成。我想为这些目录编写自定义完成函数。如何指定应使用完成者而不是默认值?
无法指定它,但您可以修补_path_files
补全函数来实现此目的:
# 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.
functions[_original_path_files]=$functions[_path_files]
# 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> "$@"
else
_original_path_files "$@"
fi
}
Run Code Online (Sandbox Code Playgroud)
文档: