Skip to content

history: fix duplicate entries after "history -n" with HISTTIMEFORMAT - #721

Open
dfherr wants to merge 2 commits into
akinomyoga:masterfrom
dfherr:fix-history-rskip-line-count
Open

dfherr wants to merge 2 commits into
akinomyoga:masterfrom
dfherr:fix-history-rskip-line-count

Conversation

@dfherr

@dfherr dfherr commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

When enabling HISTTIMEFORMAT this check clamped the history. This caused ble.sh to re-read half of the history on the first history search. Removing the clamps removes the issue.

Use bleopt prompt_rps1='\q{history-index}/\q{history-percentile}' to make it obserable

Before the fix: Open a new tab. Check number. Press search. Number goes up by 50% to 100% (depending on size due to clamp).
After fix: no additional entries.

@akinomyoga

Copy link
Copy Markdown
Owner

Although I agree that the calculation of the rskip truncation has been wrong, why is it entirely removed? It will be broken and causes inconsistency between Bash's in-memory history and ble.sh's history records when HISTSIZE and HISTFILESIZE are different, etc.

@dfherr

dfherr commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

ah, i'm sorry. there are so many edge-cases here and I only tested against my setup and against a reduced HISTSIZE. I thought the clamp is unnecessary here, because even at HISTSIZE smaller than the HISTFILESIZE it was duplicated before but didn't add duplicates after removing the truncation.

but there seems to be cases it is necessary.

I'll push an updated try combining #723 and this together. However, you are certainly much more qualified to reason about this than I am.

@akinomyoga

Copy link
Copy Markdown
Owner

I'll push an updated try combining #723 and this together.

Yeah, that is easier as #723 and this are very much correlated.

@akinomyoga

akinomyoga commented Sep 5, 2026 •

Copy link
Copy Markdown
Owner

I don't remember the details when I introduced this in commit 7be255c, but you actually may be correct. Regardless of HISTTIMEFORMAT, the reading point of the history file should be at its end. I'll need to carefully confirm that.

@dfherr

dfherr commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Dropping it does break if the history grows before ble.sh reads the history. I'm working on a combined fix right now and will push it soon. It's a lot more code now though. I will leave a lot of comments so you have an easier time adapting to what i got wrong

@dfherr
dfherr force-pushed the fix-history-rskip-line-count branch from 394dd70 to 5af45bc Compare September 5, 2026 11:53
@dfherr

dfherr commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

New attempt with rskip now counting entries instead of lines, which should be consistent with wskip and with how bash handles this itself.

I added a test file. on master 29 of the 41 tests fail. with my fixes all 41 pass.

Disclaimer: this was written with claude code. I tried to verify what I can, but I'm not deep into bash or the ble.sh source. if you would rather throw it away, that's reasonable. it should at least give you an idea about what's wrong and could fix it.

@dfherr

dfherr commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

looks like i introduced a new bug. i'll push another update soon

@dfherr

dfherr commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

I tripped over #725 in testing, which happens on master too. this seems to work fine

@dfherr

dfherr commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

i found one more history bug. i build on top of this branch so i can't open it here yet:

dfherr#1

btw: thanks for this great project. i love it and recommend it to all colleagues! best way to get modern cli feeling while being bash compatible (by using bash 😆 ).

それから、大阪大学の助教をされていると知りました!すごいですね!実は私も大阪大学大学院情報科学研究科に交換留学で一学期間在籍していました。もし鬼塚先生にお会いする機会があれば、ドイツの Dennis がよろしく言っていたとお伝えください

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants