lastpass / lastpass-cli

LastPass command line interface tool
GNU General Public License v2.0
2.85k stars 292 forks source link

add support to output NoteType to lpass ls #581

Open knksmith57 opened 3 years ago

knksmith57 commented 3 years ago

Proposal to add NoteType as a supported format placeholder field to ls. This would enable users to grep results based on the NoteType field, which makes categorizing notes infinitely more valuable.

SSH keys are a good example use case. Without including "SSH" in the note name, or creating a dedicated group to hold SSH keys inside of, there's no way to know which notes contain SSH keys. NoteType adds no incremental value when accessing items via lpass CLI.

example usage

## where %nt is a new placeholder for the NoteType field
❯ lpass ls --format='%ai,%nt'
foobar@example.com
all
    888888888,Credit Card
    999999999,SSH Key
    000000000,Membership

workarounds

For those frustrated with the lack of JSON support for ls (which would also make this easier), it's possible to coerce show to behave like ls by combining a match-all basic regex via --basic-regexp with the --expand-multi option:

❯ lpass show --expand-multi --basic-regexp '.*'

Finally, adding --json will result in the desired output format:

❯ lpass show --expand-multi --basic-regexp '.*' --json

Or, shortened for brevity:

❯ lpass show -xjG '.*'

With this parseable JSON output, one can leverage jq to filter by NoteType (or any other field):

❯ lpass show -xjG '.*' | jq '.[]|select(.note|startswith("NoteType:SSH Key"))'