URL:
  <https://savannah.gnu.org/bugs/?68814>

                 Summary: HISTCONTROL=erasedups breaks readline's
operate-and-get-next (\C-o)
                   Group: The GNU Bourne-Again SHell
               Submitter: cubernetes
               Submitted: Wed 21 Oct 2026 02:52:45 PM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Unlocked


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Wed 21 Oct 2026 02:52:45 PM UTC By: cubernetes <cubernetes>
Not sure whether this should be considered a bug worth fixing, or expected
behavior.

Readline's operate-and-get-next, as far as I know and without being familiar
with the source code, remembers the current history number, executes the
current line, increases the remembered history number by one, fetches that
command from the history, and replaces the new (empty) readline buffer with
that command.

That logic breaks when `erasedups` is turned on, because the line that was
just executed is guaranteed to be removed *before* readline fetches the next
command, if the line was not edited.

The effect is always that operate-and-get-next skips over at least one entry,
or N entries if N commands were deduplicated.

I tried to see if a user could implement a workaround, but failed because I
could not find a way to get the current history number of a command retrieved
from history:
- fc -lr|head -1|awk '{print $1}'
- : '\!'; echo "${_@P}"
- echo "$HISTCMD"
All those do not print the history number of the retrieved command when run in
a bind -x context before accept-line.


Since I use operate-and-get-next quite extensively, the only workaround I
currently have is something like this:
```
bind '"\C-o": "\e\C-ad\e\C-ao"'
bind -x '"\e\C-ad": HISTCONTROL=ignoreboth'
bind '"\e\C-ao": operate-and-get-next'

bind '"\C-m": "\e\C-ae\e\C-am"'
bind -x '"\e\C-ae": HISTCONTROL=ignoreboth:erasedups'
bind '"\e\C-am": accept-line'

bind '"\C-j": "\C-m"'
```
Not perfect, because obviously history entries are not deduplicated upon \C-o,
but it's the only temporary solution I can think of, without giving up on
erasedups.







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68814>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to