Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add ability to output selection when exiting #209

Closed
ditsuke opened this issue May 29, 2022 · 8 comments
Closed

[feature] Add ability to output selection when exiting #209

ditsuke opened this issue May 29, 2022 · 8 comments

Comments

@ditsuke
Copy link

ditsuke commented May 29, 2022

What

When exiting, we could use either an entry flag or a keyboard shortcut to output selected value to standard output.

Why

This would make fx useful as part of interactive pipelines.

History

Previously implemented in the NodeJS version, but not yet in the rewritten-in-Go version. Previous request: #132.

@sinux-l5d
Copy link

I came across fx seeking this exact feature. I'm using AWS a lot currently, and when I manually run commands it would be useful to pipe into interactive fx to choose the property I want.

So I would just have to do $VALUABLE_INFO=$(aws <whichever> | fx) to store for example an IP address (I never remember the path to the value...)

@antonmedv
Copy link
Owner

I think a fx -select or something will be ok.

@sinux-l5d
Copy link

So is it a feature you're still considering?

@antonmedv
Copy link
Owner

Yes, for sure. Don’t know when I gonna find time to implement it, unless someone decides to support this feature development)

sinux-l5d added a commit to sinux-l5d/fx that referenced this issue Nov 23, 2022
sinux-l5d added a commit to sinux-l5d/fx that referenced this issue Nov 23, 2022
@sinux-l5d
Copy link

sinux-l5d commented Nov 23, 2022

Hi again, I have a prototype.
This works really simply: when the --select/-s flag is passed, the program outputs the value of the selected level/property (model.cursorPath()) when exiting.

To make the program interactive when stdout is piped (aka not a tty), I use stderr.
It works, but as I think it might not be a good practice I have a second commit that use stderr only then the select flag is passed and output is not a tty.
Bubble Tea seams to work perfectly using stderr.
Otherwise, I'd need to dig into how programs like vipe works to ask for user input while piping to other command.

You can try this feature with something like curl -s https://dummyjson.com/products/1 | go run . -s or curl -s https://dummyjson.com/products/1 | go run . -s | cat, and going into the document to select a property: it will output its value.

I'll open a pull request if you're interested :)

@pyhedgehog
Copy link

pyhedgehog commented Apr 16, 2023

I propose extension to this feature: Three options:

  1. Print value in JSON format.
  2. Print value in raw format (if string)
  3. Print path to selected element (like .x[123]["some strange key"].key.a.b.c[0].d) to be used with fx or jq.

@antonmedv
Copy link
Owner

Now js has yank support.

@pyhedgehog
Copy link

pyhedgehog commented Oct 14, 2023

@antonmedv

Now js has yank support.

It's good, but there are two drawbacks:

  1. How to customize what console program think clipboard is? I.e. I'm using windows and connecting to linux via several ssh hops... you understand.
  2. How to use this (as was planned from start) as a dialog-like selector in script? I.e. I've planned to write curl http://example.com/something.json|fx --select-value|jq -c 'to_entries[]'|sponge entries.jsonl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants