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

Allow more complex interactive search of history, history command with regex #3136

Open
rocketraman opened this issue Jun 10, 2016 · 7 comments

Comments

@rocketraman
Copy link
Contributor

It would be nice if when doing a history search, I could start from a regex. For example, if my history contained:

foo bar baz

I should be able to type:

foo.*baz with an Alt-Up [1] and find foo bar baz.

On a related note, even history --search doesn't seem to work with regexes -- one has to grep it for equivalent behavior.

[1] I'm not sure if this should be the default behavior or gated behind a separate key combo from a regular history traversal. Perhaps Ctrl-Alt-Up or something like that.

@krader1961 krader1961 added this to the fish-future milestone Jun 10, 2016
@krader1961
Copy link
Contributor

I can see a strong argument for supporting regex searching via the history command. I'm ambivalent about complicating the interactive history searching with that capability. What happens when someone enters foo*baz thinking that globs rather than regexes are recognized? In fact, if we do implement this, I think the simpler glob syntax is preferable. As your example illustrates, what people normally want to do is limit the matches to sequences of strings separated by arbitrary characters. I would be very surprised if anyone would ever enter something like abc[0-9]+ .*(def|ghi) and press [up-arrow] to find history entries matching that pattern.

@rocketraman
Copy link
Contributor Author

rocketraman commented Jun 10, 2016

As your example illustrates, what people normally want to do is limit the matches to sequences of strings separated by arbitrary characters.

Agreed. An alternate approach that makes this particular use case possible on the interactive history search is really what I was looking for, especially if the more general regex-based search is possible on the history command. I generalized unnecessarily from my simple requirement to an interactive regex search.

@rocketraman rocketraman changed the title Allow search of history with regex argument Allow more complex interactive search of history, history command with regex Jun 10, 2016
@sollidsnake
Copy link
Contributor

I also like regexp searches, so I use this along with fish: https://github.com/junegunn/fzf
It brings to fish the ctrl-r hotkey with a nice interface.

@rocketraman
Copy link
Contributor Author

I also like regexp searches, so I use this along with fish: https://github.com/junegunn/fzf

Thanks for the pointer. Indeed, it seems quite useful. It has some issues integrating properly with fish, however. Example: junegunn/fzf#436

Regardless, some basic interactive history improvements directly in fish would still be useful.

@krader1961
Copy link
Contributor

FWIW, I don't believe we should ever implement glob or regex matching for auto-suggestions. That is, what you see when you type some characters and press [up-arrow], [ctrl-P], or otherwise invoke the up-or-search function. I do, on the other hand, believe we should support globs and PCREs for the history search command.

@krader1961
Copy link
Contributor

In the past couple of months I've merged changes to the history subsystem to implement case-insensitive searching, display the timestamp, and support interactively deleting multiline commands. All of those should make it into the 2.4.0 release. So now I'm interested in resolving this issue.

What do people think about making history search "term" treat term as a glob by default rather than a literal string? We would also add -r and --regex flags to treat the search term as a PCRE pattern (same as string match -r)? Making glob matching the default is consistent with string match without -r. I don't think this will cause any problems in practice because it is pretty unlikely anyone is currently typing something like history search 'abc*def' expecting it to literally match that string.

@krader1961 krader1961 self-assigned this Oct 18, 2016
@krader1961
Copy link
Contributor

I've implemented the history search glob behavior in commit e1315dc. Feel free to use or not as you see fit. TBD is history search PCRE behavior but I'm going to make that a separate issue in my fork since I think that is far less useful than simply allowing someone to type history search 'abc*def' to find every command containing those strings separated by some other strings.

@krader1961 krader1961 removed their assignment Aug 29, 2017
@zanchey zanchey modified the milestones: fish-future, fish-3.0 Oct 31, 2017
@ridiculousfish ridiculousfish modified the milestones: fish-3.0, fish-future Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants