0
del-prompt-accept-line() { OLD_PROMPT="$PROMPT" PROMPT="> " zle reset-prompt PROMPT="$OLD_PROMPT" zle accept-line } zle -N del-prompt-accept-line bindkey "^M" del-prompt-accept-line 

This breaks for multiline command lines like

> echo one\ > two 

I don't want it to change PROMPT until the command is actually run, not just when pressing enter in the command line.

del-prompt-accept-line() { OLD_PROMPT="$PROMPT" PROMPT="> " zle reset-prompt PROMPT="$OLD_PROMPT" zle accept-line } autoload -Uz add-zsh-hook add-zsh-hook preexec del-prompt-accept-line 

now this version (trying to use preexec, the only applicable hook I know about) causes the error

widgets can only be called when ZLE is active

So how can I make a prompt that looks like

directory % 

while I am editing the command line, then changes to

> 

when I run the command line?

When I scrollback, I want to only see > prompts

10
  • In your multiline case, if you accept-line the first line, then it edits a new line (and switches to the PS2 prompt). At that point, as far as ZLE is concerned the previous line is history, you can't get back to that and edit the prompt that was displayed for a previously edited line. Commented Nov 12 at 6:34
  • What you could do is bind return to a widget that only calls accept-line if the current buffer contains complete code (would not cause a PS2 prompt for additional lines) and inserts a newline character into the editing buffer otherwise like fish does. IIRC, that approach has already been answered here. Commented Nov 12 at 6:37
  • @StéphaneChazelas what about printing over the last few lines, recreating the command line and just replacing the prompt of the first line Commented Nov 12 at 6:44
  • That can't really work reliably and would mean a lot of work and special features not all terminal supports like reporting what's on their screen. The previous line(s) is(are) not even guaranteed to still be on the screen (may have been scrolled out) Commented Nov 12 at 6:48
  • See github.com/romkatv/zsh-no-ps2 about the approach I suggested above (I've not tested it myself). Commented Nov 12 at 6:51

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.