The r
built-in utility in the zsh
shell, if used with no options, re-executes the most recent command in the command history.
The issue with this is that if you have a number of shell sessions sharing history (the SHARE_HISTORY
shell option is set), it's fairly easy to make the mistake of executing commands from a "non-local" shell session without intending to do so. This makes using r
potentially dangerous.
Question: How may one either change the behavior of r
to only consider history events local to the current shell session, or write a separate alias or function, rl
, that only considers local events?
Since r
is supposed to be the same as fc -e -
(recall the most recent command, don't edit it, then execute it), I thought maybe using r -L
or fc -e - -L
would do it, but for whatever reason, it only seems to work if the most recent global history event is from the current shell session. If this is not the case, the shell complains with an fc: no matching events found
error.
zsh
version 5.8 (zsh-5.8-0-g77d203f
) is in use here, from the zsh-5.8p0
package on OpenBSD 6.8.
Tangentially related question: