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 Request: Press a key for "path" to current element #10

Closed
klei22 opened this issue Feb 10, 2022 · 6 comments
Closed

Feature Request: Press a key for "path" to current element #10

klei22 opened this issue Feb 10, 2022 · 6 comments

Comments

@klei22
Copy link

klei22 commented Feb 10, 2022

Just tried jless after seeing on hacker news -- would it be possible to add a way to output the path to a given element?

e.g.

This would be super helpful when inspecting through highly nested json packets.

@PaulJuliusMartinez
Copy link
Owner

The path to the currently focused node is displayed in the bottom status bar, relative to the input, e.g., input.foo.bar[2].qux.

By default it formats object keys using .key, unless the key is not a valid JavaScript identifier (matches the regular expression "^[_$a-zA-Z][_$a-zA-Z0-9]*$), in which case it renders it as ["key with space"]. I can imagine a scenario where you always want the ["key"] syntax, even for valid identifiers. That's probably makes sense for "line" mode (press m to see the input as actual JSON).

Is there some functionality you're looking for that's different that that?

You mention deeply nested packets, and the path is truncated when longer than the width of the screen, which, if you need the whole path, is a problem. You could try making your screen wider in that case, but obviously that solution has its limits, and is inconvenient.

I have also considered adding support for copying things to the clipboard, but there are a lot of different things you could want to copy, so I've thought of using two key commands starting with y for different things:

  • yy: copy the current value, pretty printed
  • yo: copy the current value, pretty printed on one-line
  • yd: copy the current value, printed as compactly as possible
  • yp: copy the simplified path to the current node, e.g., .foo.bar[2].qux
  • yj: copy the "pure" path to the current node, e.g., .["foo"]["bar"][2]["qux"]
  • yq: copy a jq style path that includes the current node, e.g., .foo.bar[].qux

@klei22
Copy link
Author

klei22 commented Feb 11, 2022

The support for copying to the clipboard sounds fantastic!

@deoxykev
Copy link

I would love support for copying to the clipboard. When I first installed the tool, I actually tried those exact shortcuts to see if worked that way.

Great work on this tool, now I can finally ditch fx.

@bew
Copy link

bew commented Feb 11, 2022

What about the ability to quit the UI and print that path, for consumption by other cli tools?

@AP2008
Copy link
Contributor

AP2008 commented Feb 11, 2022

@PaulJuliusMartinez I added the support for yy, yo, yp and yj in this PR: #18 . What should the behaviour be for yq. How should yd be implemented ?

@PaulJuliusMartinez
Copy link
Owner

Support for copying paths is now available in the v0.8.0 release by using yp (normal path), yb (path but always uses square brackets for object keys) or yq (jq style path). Copying values can be done with yy (pretty printed) or yv (not pretty printed), and yk copies object keys.

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

5 participants