I can use
print -S "echo test"
to place the command echo test
into the history file, so that when I hit the UP-arrow, I get it into the zle buffer.
This does not seem to work from within a zsh startup file. For instance, I put at the last command in my .zshrc the line
print -S ": testing"
and started a subshell using
zsh
I would expect that, when I press now the up-arrow, I would get the command : testing
for execution, but instead I get the most recently, manually entered command.
My history is configured like this:
HISTFILE=~/.histfile.$TTY:t
HISTSIZE=500
SAVEHIST=$HISTSIZE
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt hist_no_store
setopt hist_reduce_blanks
setopt incappendhistory
setopt no_share_history
I have ensured that my .zshrc has indeed been sourced when I typed zsh
(i.e. the variable ZDOTDIR is not set), so the print -S
must have been executed.
My guess is that during sourcing of .zshrc, the history mechanism itself has not been set up yet, and therefore the print -S
does not take effect.
I was thinking to put the logic into the precmd
hook (and ensure that the command is only placed into the history the very first time the precmd is executed), but I wonder if there is a simpler way to implement this.