Skip to main content
as yet more fussing
Source Link
thrig
  • 35.9k
  • 4
  • 70
  • 88

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.:

% echocat $(awkward #!/bin/zsh echo -ne "\e7\n -- warning: lo0lp0 on fire\e8"fire\e[F\e8" >/dev/tty; echo blat % ./awkward blat % echo $(./awkward) 

... though that's the simple case of direct ZSH code running inside the shell itself (and it's buggyhardly perfect, as if the prompt is ondown at the last linebottom of the window); as a child process, wellscreen, good luckhorrible buggy things happen:

% cat awkward #!/bin/zsh echo -ne "\e7\n -- warning: lp0 on fire\e[F\e8" >/dev/tty; echo blat"\e[$LINES;0H" ... % ./awkward blatwarning: lp0 on fire % echo $(./awkward ) -- warblat█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 readily viablesimple for custom below-the-prompt terminal messaging during the execution of a command substitution in zsh.

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.

% echo $(echo -ne "\e7\n -- warning: lo0 on fire\e8" >/dev/tty; echo blat) 

... though that's the simple case of direct ZSH code running inside the shell itself (and it's buggy if the prompt is on the last line of the window); as a child process, well, good luck:

% cat awkward #!/bin/zsh echo -ne "\e7\n -- warning: lp0 on fire\e[F\e8" >/dev/tty; echo blat % ./awkward blatwarning: lp0 on fire % echo $(./awkward) -- warblat█ fire 

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 readily viable for custom terminal messaging during the execution of a command substitution.

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.

increased blathering involved with command substitution aspect of question
Source Link
thrig
  • 35.9k
  • 4
  • 70
  • 88

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 lsecho /aaa bbb) ;; esac 

However, given a command line of echo $(foo bar) with the cursor past the closing parenthesis 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 

(and _foo placed in aWhen modifying $fpath to include a custom directory and, always do that before the function foo ()autoload {-U echocompinit "$@"&& } to actualize foocompinit andcommands.)

However, given a command line of rm ~/.zcompdump &&echo exec$(foo zshbar)█ for a clean slate), the completion function _foo is notnot involved when tab is mashed, as this is a command substitution, and not an autocompletion of foo.

A simple write toDuring command substitution, the terminal device fromcommand being substituted has no indication whether it is being run directly or as a command substitution (there is a special fooZSH_EVAL_CONTEXT is also unsuitable, asvariable though exporting that moves the cursor position underonly indicates zshtoplevel following aregardless), and tab from after the closing paren:writing to the terminal then restoring the cursor position will be complicated.

% echo $(zshecho -cne 'echo"\e7\n -e- "\nwarn"warning: lo0 on fire\e8" >/dev/tty; echo foo'blat) warn foo 

... so no answer yet but batterythough that's the simple case of direct ZSH code running inside the shell itself (and it's buggy if the prompt is lowon the last line of the window); as a child process, well, good luck:

% cat awkward #!/bin/zsh echo -ne "\e7\n -- warning: lp0 on fire\e[F\e8" >/dev/tty; echo blat % ./awkward blatwarning: lp0 on fire % echo $(./awkward) -- warblat█ fire 

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 readily viable for custom terminal messaging during the execution of a command substitution.

Inside the ZSH completion system, a custom message upon mashing of tab for a particular argument is possible via the _message function:

#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 ls /) ;; esac 

However, given a command line of echo $(foo bar) with the cursor past the closing parenthesis (and _foo placed in a $fpath directory and function foo () { echo "$@" } to actualize foo and rm ~/.zcompdump && exec zsh for a clean slate), the completion function _foo is not involved when tab is mashed, as this is a command substitution.

A simple write to the terminal device from foo is also unsuitable, as that moves the cursor position under zsh following a tab from after the closing paren:

% echo $(zsh -c 'echo -e "\nwarn" >/dev/tty; echo foo') warn foo 

... so no answer yet but battery is low ...

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.

% echo $(echo -ne "\e7\n -- warning: lo0 on fire\e8" >/dev/tty; echo blat) 

... though that's the simple case of direct ZSH code running inside the shell itself (and it's buggy if the prompt is on the last line of the window); as a child process, well, good luck:

% cat awkward #!/bin/zsh echo -ne "\e7\n -- warning: lp0 on fire\e[F\e8" >/dev/tty; echo blat % ./awkward blatwarning: lp0 on fire % echo $(./awkward) -- warblat█ fire 

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 readily viable for custom terminal messaging during the execution of a command substitution.

Source Link
thrig
  • 35.9k
  • 4
  • 70
  • 88

Inside the ZSH completion system, a custom message upon mashing of tab for a particular argument is possible via the _message function:

#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 ls /) ;; esac 

However, given a command line of echo $(foo bar) with the cursor past the closing parenthesis (and _foo placed in a $fpath directory and function foo () { echo "$@" } to actualize foo and rm ~/.zcompdump && exec zsh for a clean slate), the completion function _foo is not involved when tab is mashed, as this is a command substitution.

A simple write to the terminal device from foo is also unsuitable, as that moves the cursor position under zsh following a tab from after the closing paren:

% echo $(zsh -c 'echo -e "\nwarn" >/dev/tty; echo foo') warn foo 

... so no answer yet but battery is low ...