Inside the ZSH completion system, a custom message upon mashing of tab for a particular argument of a command is possible via the _message function, as shown in this completion script (_foo) for a particular command (foo):
#compdef foo local curcontext="$curcontext" state _arguments -C -s \ '1: :->dofoo' \ && return 0 case "$state" in dofoo) _message -r " -- warning: lp0 on fire" _values "parameters" $(_call_program getparam echo aaa bbb) ;; esac
E.g.
% ls $fpath[*]/_foo 2>/dev/null /Users/jdoe/.zsh/functions/_foo % rm ~/.zcompdump && exec zsh % function foo () { echo "$@" } % foo █ -- warning: lp0 on fire aaa bbb
(When modifying $fpath to include a custom directory, always do that before the autoload -U compinit && compinit commands.)
However, given a command line of echo $(foo bar)█, the completion _foo is not involved when tab is mashed, as this is a command substitution, and not an autocompletion of foo.
During command substitution, the command being substituted has no indication whether it is being run directly or as a command substitution (there is a special ZSH_EVAL_CONTEXT variable though exporting that only indicates toplevel regardless), and writing to the terminal then restoring the cursor position will be complicated:
% cat awkward #!/bin/zsh echo -ne "\e7\n -- warning: lp0 on fire\e[F\e8" >/dev/tty; echo blat % ./awkward blat % echo $(./awkward)
... though that's hardly perfect, as if the prompt is down at the bottom of the screen, horrible buggy things happen:
% echo -ne "\e[$LINES;0H" ... % ./awkward blatwarning: lp0 on fire % echo $(./awkward ) -- warblat fire
A more complicated program would need to deal properly with being at the bottom of the terminal, or even use ncurses for portability, and will need to somehow indicate to zsh that any custom line(s) written (may) need to be cleared so the display does not risk being mucked up with the output of a subsequent command. But that's more work.
The zsh code in Src/exec.c does not look like it does anything special for a cmdsubst job, and the preexec hook function is not called for command substitution, either. So I'm really not seeing anything simple for custom below-the-prompt terminal messaging during the execution of a command substitution in zsh.