Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: !!$ unitialized at first prompt

On Sep 24,  1:39pm, Peter Stephenson wrote:
} The shell doesn't split words in the same way when importing history.
} In normal operation it relies on the lines having been passed through
} the lexical analyser to generate the words, which doesn't happen when
} history is read from a file.  Instead it just blindly splits on
} whitespace.

... and at the time this was designed, it would make history import an
agonizingly slow process if the entire history file had to be passed
through the lexical analyzer.

Nowadays that's probably not so much a concern for most people.  There's
probably an argument to be made that SHARE_HISTORY should force use of
the lexical analyzer, because (although no one has ever complained) the
current implementation means that history words referenced from shared
history behave differently than those from the local history.

You can load your own history something like this provided that you
*don't* use shared or extended history:

    readhistfile() {
	emulate -LR zsh
	local histline
	local -a histwords
	while read -r histline
	    if [[ $histline = *\\ ]]
		histwords+=( ${(z)histline}$'\n' )
		histwords+=( ${(z)histline} )
		print -s $histwords

That's not perfect, as it does things like insert a space at the front
of every continuation line in a multi-line command, but it's passable.
Note the function as written expects the history to be standard input.


Messages sorted by: Reverse Date, Date, Thread, Author