Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when deleting the last item in a history delete --contains <text> command #10189

Closed
NethumL opened this issue Jan 4, 2024 · 0 comments
Closed
Labels
bug Something that's not working as intended
Milestone

Comments

@NethumL
Copy link
Contributor

NethumL commented Jan 4, 2024

How to reproduce (these are the commands to run and the outputs I get)

$ echo sometext
sometext

$ echo sometext hello
sometext hello

$ history delete --contains sometext
[1] echo sometext hello
[2] echo sometext

Enter nothing to cancel the delete, or
Enter one or more of the entry IDs or ranges like '5..12', separated by a space.
For example '7 10..15 35 788..812'.
Enter 'all' to delete all the matching entries.

Delete which entries? 2

Ignoring invalid history entry ID "2"

Deleting any other entry ID works, but not the last one.

I went through the code in share/functions/history.fish (locally), and with a little print-debugging, narrowed it down to line 177. It checks whether the ID entered is less than the count. But since these IDs are 1-indexed, that makes the last ID invalid. I think the fix is to change and test $i -lt $found_items_count to and test $i -le $found_items_count.

The bug seems to have been introduced in this commit where deleting ranges of history entries was implemented. Earlier, it was a > check, and if ID > count, then it shows the error message. In the current implementation, if ID < count, only then the ID is valid, which seems to be incorrect.

I have the (tiny) fix in a fork: NethumL/fish-shell.
I checked it locally, and the fix works (both in my system-wide installed fish and the one I compiled after implementing the fix).
PR: #10190

System details:

$ fish --version
fish, version 3.7.0
$ echo $version
3.7.0

OS: macOS Sonoma 14.1.1 (23B81)
Terminal: Alacritty

The problem can also be reproduced without third-party customisations (using sh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= fish')

@faho faho closed this as completed Jan 4, 2024
@faho faho added this to the fish next-3.x milestone Jan 4, 2024
@faho faho added the bug Something that's not working as intended label Jan 4, 2024
@faho faho modified the milestones: fish next-3.x, fish 3.7.1 Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants