7

I'd like to use a zsh script to append a command to the command history so that it appears when I hit the up arrow. I've been appending a line to ${HISTFILE}, and it shows up there as the last line, but the up arrow action appears to ignore it.

I see that zsh maintains a session history in parallel to the history file, but I haven't yet seen a way to add to it, or to otherwise accomplish what I'm setting out to do. Is there a way to do it?

1

1 Answer 1

8

You can use print -s or print -S for this:

-s
Place the results in the history list instead of on the standard output. Each argument to the print command is treated as a single word in the history, regardless of its content.
-S
Place the results in the history list instead of on the standard output. In this case only a single argument is allowed; it will be split into words as if it were a full shell command line. The effect is similar to reading the line from a history file with the HIST_LEX_WORDS option active.

See https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html#index-print

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .