lsd icon indicating copy to clipboard operation
lsd copied to clipboard

Draft: Add a --json flag to output json.

Open jorikvanveen opened this issue 1 year ago • 2 comments

This PR adds a --json flag which causes lsd to output the Metas as JSON.

It's a basic proof of concept I put together in an evening, so there are some .unwrap()s and rough edges. It's meant to show what I imagine this feature to look like so you can decide whether this is something you actually want implemented in lsd. If it is I can start working on a more serious implementation.

Why?

Combining this flag with something like nushell allows users to create ls aliases that output structured nu data but still look pretty.

For example, this alias:

def --wrapped ls [...rest] {
        lsd ...$rest --json --icon always --icon-theme fancy --color always
        | from json
        | get 0.content
        | select type display size date
        | update date {|row| $row.date | into datetime}
        | update size {|row| $row.size | into filesize}
      }

results in this output: image

and you can then use other nushell operations to do something with this data: image

TODO

  • [x] Use cargo fmt
  • [ ] Add necessary tests
  • [ ] Update default config/theme in README (if applicable)
  • [ ] Update man page at lsd/doc/lsd.md (if applicable)

jorikvanveen avatar Oct 13 '24 08:10 jorikvanveen

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jorikvanveen Once this PR has been reviewed and has the lgtm label, please assign zwpaper for approval by writing /assign @zwpaper in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

muniu-bot[bot] avatar Oct 13 '24 08:10 muniu-bot[bot]

Will this be merged? Another nushell user here

dolence avatar Apr 03 '25 18:04 dolence