feature request: save preview content to file from interactive mode
Title: feature request: save preview content to file from interactive mode
Use case
When exploring a large JSON document interactively, I often discover a subtree I want to save to a file — but I didn't know I'd need it when I launched fx, so I didn't set up stdout redirection upfront.
This is especially common when a subtree contains a nested JSON string (e.g. an escaped JSON payload inside a string field). I want to save it to a file so I can fx it again to explore the inner structure.
Currently the options are:
P— prints to stdout and exits fx, requiringfx data.json > output.jsonto have been set up beforehandytheny— copies to clipboard, which works for small values but is awkward for large subtrees (paste into a file externally)
Neither supports a "save and keep exploring" workflow.
Proposal
Add an s key binding in preview mode (p) that prompts for a file path and writes the current node's value to that file, without leaving fx.
Flow:
- Navigate to the desired node
- Press
pto enter preview mode - Press
s— asave to:prompt appears - Type a file path and press Enter
- See a confirmation message ("saved to output.json"), continue exploring
The s key doesn't conflict in preview mode since the "show sizes/line numbers" selector only applies in the main view.
I have a working implementation and would be happy to open a PR if this sounds useful.
Source: antonmedv/fx