-
Notifications
You must be signed in to change notification settings - Fork 152
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
Add History::delete
for FileBackedHistory
#736
base: main
Are you sure you want to change the base?
Conversation
- Add `History::delete` for `FileBackedHistory` - Adapt `history` to print id rather than just consecutive numbers - Add `history delete <id>` to demo See also nushell/nushell#11629
Trying this out. It looks like D:\reedline〉history
... others not listed
46 ls
47 ls -r
48 hello another very large option for hello word that will force one column
49 history
D:\reedline〉history delete-item 48 01/31/2024 07:52:21 AM
D:\reedline〉history 01/31/2024 07:52:27 AM
... others not listed
45 ls
46 ls -r
47 hello another very large option for hello word that will force one column
48 history delete-item 48
49 history |
Ids are not preserved with the file-based history. |
Right, i understand that the ids are not preserved but if it's counting from 1 to 50 they should always be the same numbers unless something was deleted from within right? |
Yes, looking at your example again, it looks indeed like a one-off error.
|
diffing the two history outputs, when I said |
Will have another look later on. Thanks for the careful check @fdncred! |
@fdncred I had another look (with a different machine on a different OS) and it still just works for me... First, I run
I can't seem to manage to get it into the broken state you had |
And what happens when you delete something other than |
Also, that just works:
|
Could you maybe try one more time? And double check that you run the correct command and have the correct branch checked out? |
Sure, no worries. Clearly I'm using the right PR and the right command, otherwise it would echo the command to the string as if I typed "history blah". Also, I'm doing
i want to delete 47 which is that long one
Notice that 47 is now 46 and 0 is different. I'm testing on Windows. I wonder if that makes a difference due to line endings or something like that? One other thing that I noticed. If I open the history.txt file in a text editor, the Also, for fun, here is my history.txt file from Windows. Not sure if gh will change line endings or what. |
I just tested on WSL Ubuntu and it works there. Must be a Windows thing? |
I tested on both Windows and Fedora, so I don't think it's a Windows thing. Two guesses:
|
That worked. Here's my guess. My history is old so I had items in history with leading spaces. Leading spaces aren't permitted anymore. So, maybe we should trim the history items somewhere to prevent this from happening. |
Good to hear that this fixed it. Would be good to have a reproducer though to make sure that this is indeed the reason. |
I'm not really sure what it is. I can reproduce it every time with that history file I attached above. |
1a4692c
to
9aad030
Compare
Your guess is correct. I was able to reproduce the behavior with your history file and can confirm that the leading whitespace is to blame. I also found another bug in my implementation, will convert this to a draft for now. |
It should be fine now. Here's what I changed:
|
I tested this PR this morning with this history.txt and couldn't get it to work. It just deleted item 0 off the history. |
I just checked, and the problem is that your history file is at capacity (50). At this point, I see only these ways forward:
|
Seems like it's good that we caught this but bad because it means more changes are due. I'm not really a fan of any option but the first one. Seems like this is close to being what we need but not quite. Sorry I found so many problems. It's not my intent to have continual criticisms of your PR. :( |
I very much appreciate that you found these bugs.
I don't think it's super close. We would have to introduce the concept of explicit indexes. But just thinking about all the edge cases makes not want to go further into this direction. Especially since I don't care too much about the file backed history, and would much rather have nushell switch completely to sqlite :D |
for what it's worth, i'd rather have nushell just be sqlite. i just think there would be outrage if that happened. |
Just for context, I meant changing the default to sqlite, not removing the file-based backend (at least for now :P) |
Anyway, my suggestion would be to merge nushell/nushell#11629 and leave this PR open for now. Agreed @fdncred? |
History::delete
forFileBackedHistory
history
to print id rather than just consecutive numbershistory remove-item <id>
to demoSee also nushell/nushell#11629