out-of-cheese-error / the-way

A code snippets manager for your terminal.
MIT License
352 stars 16 forks source link

Search within snippet contents #115

Closed fhill2 closed 2 years ago

fhill2 commented 2 years ago

As a pet user, searching snippet contents/body & descriptions at the same time in the same fzf pane interactively helps me find the snippet I'm looking for faster. Sometimes I remember a part of the snippet contents and not the description, and vice versa.

So far I have been using (PR #68 that searches contents and descriptions, but it is not interactive. (afaik) there is no feature to perform an interactive grep on snippet contents.

What are your thoughts about adding such a feature?

Ninjani commented 2 years ago

Nice idea and would be really useful!

This ended up being not that hard to implement at a basic level - PR #116 lets you search also within snippet contents but it doesn't highlight the matching text within the code preview. To add this I think the only way at the moment would be to run the search again within the code and redo the highlighting - I need to see how much this would impact performance since it adds an extra search and highlight step at each keypress. Maybe there's a workaround.

Also, I noticed that fuzzy search isn't that great for this purpose (returns a lot of false positives) so the PR has exact mode on - I'll make fuzzy an optional argument instead

EDIT: added the code match highlight now, would you like to test this out and check if performance has degraded? It's pretty snappy on my side.

fhill2 commented 2 years ago

Thank you for implementing this feature.

I'm trying to test and having some issues.

git clone https://github.com/out-of-cheese-error/the-way
git checkout -b search_code
cargo build
./target/debug/the-way search
# <enter phrase contained within a snippet>

Tried with cargo build --release, and the master branch.

To confirm, this change is implemented inside the-way search skim UI? Not sure why I'm not seeing the expected changes you have described.

Ninjani commented 2 years ago

I think the command would be git clone -b search_code https://github.com/out-of-cheese-error/the-way, git checkout would make a new local branch instead.

Also, I've added the -e option for exact matching and kept fuzzy as default, just to keep as close as possible to people's current workflow.

fhill2 commented 2 years ago

Aah haha yeah my bad, been a long day. All working now on my system.

This is awesome, search is within body and description language tag now with the same result highlighting.

It is snappy however I only have around 10 snippets.

Ninjani commented 2 years ago

Great to hear, thanks! I'll test it out tomorrow with 100 random gists and then push a new version.