Canop / broot

A new way to see and navigate directory trees : https://dystroy.org/broot
MIT License
10.57k stars 233 forks source link

Find and replace #635

Open fredcallaway opened 1 year ago

fredcallaway commented 1 year ago

Since I'm sure you want more work maintaining this already-amazing tool...

It occurred to me today that broot already has a lot of the features to support an incredible find/replace feature. It would basically look like the current content search workflow, but there would be a command to replace each occurrence of the search string with some other string (or a regex substitution). Naively, I think the implementation wouldn't be so hard; it would be just like the existing commands, except you'd need to be able to query the search string (this is not possible as far as I am aware).

As far as I know, there aren't any good unix tools for interactive find and replace in a directory(perhaps vim has something, but I doubt it would be as fast/easy as it could be with broot).

Canop commented 1 year ago

It makes sense but isn't totally trivial.

There are two specific difficulties with the current ergonomics:

  1. the preview of the replace (but it could replace the preview of the match)
  2. applying the command not to the selection but to the entire virtual set of matching files

The solution to 1 could probably be in place of the current match preview. The solution to 2 could be a specific verb handling and/or could involve the staging area

I'll think about this.

The reason I didn't really work on that is that I'm using neovim which is quite good already when you know how to use it. And there aren't so many cases where I want to replace in many files and don't want to preview all changes.

fredcallaway commented 1 year ago

For (1), I think it's most important that you can see the current match. Showing the replacement as well (in a style resembling a git word diff) would be nice, but not absolutely necessary. I definitely wouldn't want to only see the replacement.

For (2), based on your comment that you usually want to preview all changes, I think using the existing staging area mechanic makes the most sense here. As you say, you usually want to preview all changes, so a typical workflow might involving going through the files one at a time and staging them as you go (and you could always use the stage-all command if you want).

One issue that does arise is how to display three panes at once. The default settings might even disallow this. I think having the search panel and the staging area stacked on top of each other would be ideal here. FWIW, this stacking would also be useful for the case where you use two panes to move files from one to the other and want to preview. So I think it would make sense to by default have the preview panel on the right and to stack any other panels on the left when the preview panel is visible. This is probably not a trivial change though, so I feel that I may be asking too much.