当自定义 ZSH 完成器为 运行 时显示进度指示
Display progress indication while custom ZSH completer is running
我的一个工具有一个自定义的 ZSH tab 完成功能。它运行良好,但有时工具需要很长时间才能回答;有没有一种方法可以在工具 运行 期间(以及在完成 运行 之前)显示某种指示,表明正在发生某些事情?
例如,是否可以让它在当前行下方显示一条消息,例如:
prompt$ pypath /providers/conf<TAB>
Completing...
这里的挑战是,一旦完成候选可用,光标必须 return 到它之前的位置(我点击 'TAB' 的位置)。我知道 ZSH 可以做到这一点,但它可以在工具完成之前显示一条消息 运行?
这是我当前的完成脚本:
#compdef pypath
# This does not work; it is only added when the whole thing ends
# _message -r "Completing..."
IFS=$'\n' path_candidates=($(pypath "${PREFIX}*" | sed 's|.*/||' | sort -u))
compset -P '*/'
if [ -z "$path_candidates" ]; then
compadd -x "No matches found."
else
compadd -q -S '/' $path_candidates
fi
您可以尝试使用 zle -R "Completing..."
。
zle -R [ -c ] [ display-string ] [ string ... ]
...
-R [ -c ] [ display-string ] [ string ... ]
Redisplay the command line; this is to be called from within a user-defined widget to allow changes to become visible. If a display-string is given and not empty, this is shown in the status line (immediately below the line being edited).
If the optional strings are given they are listed below the prompt in the same way as completion lists are printed. If no strings are given but the -c option is used such a list is cleared.
Note that this option is only useful for widgets that do not exit immediately after using it because the strings displayed will be erased immediately after return from the widget.
This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the command has no effect. In this case there will usually be no other arguments.
-- zshzle(1): Zsh Line Editor, Zle Bulitins, zle -R
(I couldn't find a good anchor, so please find/search in the page with zle -R
)
我的一个工具有一个自定义的 ZSH tab 完成功能。它运行良好,但有时工具需要很长时间才能回答;有没有一种方法可以在工具 运行 期间(以及在完成 运行 之前)显示某种指示,表明正在发生某些事情?
例如,是否可以让它在当前行下方显示一条消息,例如:
prompt$ pypath /providers/conf<TAB>
Completing...
这里的挑战是,一旦完成候选可用,光标必须 return 到它之前的位置(我点击 'TAB' 的位置)。我知道 ZSH 可以做到这一点,但它可以在工具完成之前显示一条消息 运行?
这是我当前的完成脚本:
#compdef pypath
# This does not work; it is only added when the whole thing ends
# _message -r "Completing..."
IFS=$'\n' path_candidates=($(pypath "${PREFIX}*" | sed 's|.*/||' | sort -u))
compset -P '*/'
if [ -z "$path_candidates" ]; then
compadd -x "No matches found."
else
compadd -q -S '/' $path_candidates
fi
您可以尝试使用 zle -R "Completing..."
。
zle -R [ -c ] [ display-string ] [ string ... ]
...
-R [ -c ] [ display-string ] [ string ... ]
Redisplay the command line; this is to be called from within a user-defined widget to allow changes to become visible. If a display-string is given and not empty, this is shown in the status line (immediately below the line being edited).
If the optional strings are given they are listed below the prompt in the same way as completion lists are printed. If no strings are given but the -c option is used such a list is cleared.
Note that this option is only useful for widgets that do not exit immediately after using it because the strings displayed will be erased immediately after return from the widget.
This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the command has no effect. In this case there will usually be no other arguments.
--
zshzle(1): Zsh Line Editor, Zle Bulitins, zle -R
(I couldn't find a good anchor, so please find/search in the page withzle -R
)