sd
sd copied to clipboard
Interactive mode
sd can be useful in situations for typical search and replace. It would be nice to have an --interactive flag so that we can "yes" or "no" or "default" (== yes?) to a particular replacement.
@YodaEmbedding I definitely agree. Do you have any ideas on what the UI/UX would look like?
A very rough sketch is below. Some of the keystrokes are copied from git add -p (e.g. [A], [D]) to reduce the learning curve.
Preview:
Once upon a midknight dreary, while I pondered, weak and weary,
I ate some lovely [midknight] valencia oranges.
While I nodded, nearly napping, suddenly there came a tapping,
As of some one gently tapdapping while eating midknight valencia oranges.
-------------------------------------------------------------------------
filename.txt line 2 / 1024
From: midknight
To: midnight
[Y] yes
[N] no
[A] yes to rest of file
[D] no to rest of file
[J] next
[K] previous
[Q] quit, save changes
[!] abort, do not save file(s?)
An alternative format would be something like:
filename.txt:
Y 1: Once upon a [midnight] dreary, while I pondered, weak and weary,
> 2: I ate some lovely [midknight] valencia oranges. <== current line
N 4: As of some one gently tapdapping while eating [midknight] valencia oranges.
someotherfile.txt:
[...]
[Y] yes
[N] no
[A] yes to rest of file
[D] no to rest of file
[J] next
[K] previous
[Q] quit, save changes
[!] abort, do not save file(s?)
...with some colors to highlight replacements, search matches, the current line, etc.
Open questions:
- How much context does the user need? (a line? surrounding lines?)
- Word wrapping?
- Should the file be modified immediately upon a
[Y]? - Should the file be modified immediately after we have done all replacements?
- Should the output of the preview window be modified immediately upon a
[Y]?