2

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:

1 Answer 1

0

The fact that r -L was not working as expected was recognized as a bug when I asked about it on the zsh-users mailing list.

The bug was corrected on the 18th of February 2021, on the shell's Git development branch:

commit 6bef719302d6db33c63fb6f2636986dff1941ac2
Author: Peter Stephenson <retracted>
Date:   Thu Feb 18 21:37:08 2021 +0000

    users/26509: fix for r -L

    fc with the -L option should ignore remote entires, rather than
    reading them and treating them as an error.

You must log in to answer this question.

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