I have a custom ZSH tab-completion function for one of my tools. It works well, however sometimes it takes a long time for the tool to answer; is there a way to display some sort of indication that something is happening while the tool is running (and before it completes running)?
For example, is it possible to make it show a message below the current line, like:
prompt$ pypath /providers/conf<TAB>
Completing...
The challenge here is that the cursor must return to its previous position (where I hit 'TAB') once completion candidates are available. I know ZSH can do this, but can it display a message BEFORE the tool finishes running?
Here's my current completion script:
#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
You could try to use 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
)