Repository navigation
Conversation
3e97a27 to
cabd84a
Compare
ncw
left a comment
There was a problem hiding this comment.
This is a fun idea :-)
I pulled it locally and had a play.
Some immediate thoughts for discussion
- Needs help - I expect
?orhto bring up the help, likewise CTRL-L to refresh the screen. - I'd like to be able to edit the include file and see what happens to the files in real time (maybe too hard!). So press TAB say to move to editing the left hand side and TAB to move back again. Or press
eto edit the include file in your default editor (like the waygit commitworks). - I thought the default output to a file, then opening that file wasn't very unixy! Printing the result to stdout would probably be a more unixy default
- If you provide an output file, then it should use that file as the default input I think, so genfilters effectively edits a filter file for you. Having to supply two flags is non optimal. Maybe the one flag should be called
--edit, so yourclone genfilters --edit myfilters remote:path - I think we should try to make it as consistent with ncdu as possible so left, right should be enter exit directory and we should use RETURN or SPACE maybe to toggle the selection (might be worth studying some other text ui progs to see what they use).
- Perhaps ncdu should export some things genfilters should use or we factor ncdu parts into a lib.
Thanks! 😃
Sounds good to me.
That might be difficult! But also sounds like a fun challenge. 🙂 I'll look into this! Aside from the challenges of the text editor part, there's also the question of how to handle unexpected input -- syntax errors, non-existent paths, duplicated rules, etc. Error? Ignore? Fix? Also,
Haha, fair point! There is a
What if the input file doesn't exist though? (In other words, you have no file to start from and you want My first draft of this actually had no
In addition to my above question about non-existent input, what if you want to "Save as" the output to a different path than the input? Perhaps the input and output flags should stay but an
Sure, that makes sense to me. (Although we don't really "enter" directories the way
That would be helpful! 🙂 I frequently find myself wanting to reuse code from other rclone packages, but often they are in private functions so it becomes a question of whether to start making intrusive changes outside the package I'm working on... I sometimes wish more things were exported by default, but I also understand why they're not! I'll play around with these ideas and work on a revised version! |
|
X-Reply-Style: better-late-than-never
Good thought. If there is an error in the input file we should just print the error nicely and stop. If the user enters something incorrectly in the editor then we should display an error and make them edit it again or cancel.
The unix way would be to pipe the input file on stdin and pipe it to separate output file, or have an
That works for me. (You should preserve the old file with
Yes we should try to be deliberate about which bits are exported otherwise the codebase will degenerate into a tangled mess!
:-) How did you get on? |
I haven't had a chance to play around with it yet, but I do still plan to! 😅 |
Before this change, the helpers `ncdu` used to draw text, popup boxes and menus, and to keep log output off the screen, were private to `cmd/ncdu`. After this change, they live in a new `lib/tui` package, so other text based user interfaces can share them. `ncdu` uses them unchanged.
Before this change, code making filter rules for a name had to escape the glob special characters itself, keeping its own copy of the list in `globToRegexp`. After this change, `filter.GlobEscape` returns a glob matching a name literally. Its test checks every punctuation character against `GlobPathToRegexp` and `GlobStringToRegexp`, so a new special character fails it.
cabd84a to
c49ce29
Compare
@ncw Better late than never, part 2 😅 -- I finally got back to this. It's rebased onto master and reworked based on your feedback:
The other big change is that it doesn't use On rules it can't represent: it reads exactly what it could have written (anchored file or For bisync, |
c49ce29 to
d58540d
Compare
Before this change, filter rules for `--filter-from` or bisync's `--filters-file` had to be written by hand, where a small mistake can include or exclude far more than intended. After this change, `rclone genfilters remote:path` shows the remote as a tree in which files and directories are included or excluded with a key press. The rules are checked with rclone's own filters as they change, so the tree shows what rclone will include, and they can also be edited as text with the tree updating as you type. `--edit FILE` edits a filter file in place, keeping the old version as `FILE.bak`; otherwise the rules are read from standard input and written to standard output. `--exclude-others` starts with everything excluded (`- **`).
Before this change, a bisync `--filters-file` had to be written by hand, where a small mistake could make bisync include or exclude far more than intended. After this change, `--edit-filters` opens the `--filters-file` in `rclone genfilters` before the run, showing Path1 (or Path2 with `--edit-filters-path2`). If the filters change, bisync offers to do the `--resync` they need, and syncs nothing if declined. The flags are interactive, so the rc rejects them.
d58540d to
0806024
Compare
What is the purpose of this change?
This adds
rclone genfilters, a text based user interface for making filter rules. It shows the remote as a tree in which you include and exclude files and directories with a key press, and checks the rules with rclone's own filters as they change, so what you see is what rclone will include. The rules can also be edited as text (TAB), with the tree updating as you type.--edit FILEedits a filter file in place (keeping the old version asFILE.bak); otherwise the rules are read from stdin and written to stdout.--exclude-othersstarts with everything excluded.It also adds
--edit-filtersto bisync, which opens the--filters-filein genfilters before the run and offers to do the--resyncthat changed filters need.Demo: https://asciinema.org/a/ynXSjMcBUc8Gfg9V
Four commits:
lib/tui: ncdu's drawing helpers (text, popup box and menu, log redirect) moved into a package so genfilters can share them. No change to ncdu.filter: a smallGlobEscape, so genfilters doesn't keep its own copy of the glob special characters. Its test checks every punctuation character against rclone's glob compiler.genfilters: the command.bisync:--edit-filtersand--edit-filters-path2.Tested on macOS and Windows 11.
Was the change discussed in an issue or in the forum before?
Checklist