lemoony / snipkit

Snippet CLI manager for quickly accessing shell snippets without leaving the terminal.
Apache License 2.0
88 stars 5 forks source link

Feature Request: Expose Snippets Via JSON #202

Closed vkhitrin closed 2 months ago

vkhitrin commented 1 year ago

Hey @lemoony, I enjoy snipkit a lot since this is a great aggregator of snippets.

I was wondering if it is part of the scope of this project to have the ability to expose available snippets via JSON in addition to the TUI. If we can access all the snippets as a JSON, we can leverage snipkit and use this info for various GUI/front ends.

For example, I would like to have an Alfred workflow or a Raycast extension to act as the front end.

lemoony commented 1 year ago

Hi @vkhitrin ,

sure, i'm open that. As a matter of fact, i thought about this too a while back but didn't follow up on it.

What requirements do have in mind? Just exposing the snippets via REST (or, alternatively, gRPC)? Remote execution via a HTTP interface probably has some limitations (and security issues).

vkhitrin commented 1 year ago

@lemoony,

We should do local only. As you mentioned, exposing it via remote-compatible protocols will require a lot of attention.
The idea is to have the output be printed to shell or any stdout stream (locally).

What I had in mind is something like this (pseudo commands):

# Current implementation of TUI browsing
snipkit browse

# New mechanism to output snippets as a JSON/other format(s) to stdout
snipkit dump <ARGUMENTS>
vkhitrin commented 1 year ago

@lemoony, I am slowly trying to get familiar with the code base (as seen in #203). If this is something you don't wish to work on, I will try my best to propose a draft in the future.

lemoony commented 1 year ago

@vkhitrin Sorry for the delayed replay, right now I'm drowning in work. I will look at the MR in the next couple of days! I really appreciate the contribution :)

lemoony commented 1 year ago

Ok, I think I now understand your proposal. However, the JSON could potentially be quite large.

Is it enough for your use to dump all snippets managed by snipkit to stdout or do you want to pass some filter parameter?

vkhitrin commented 1 year ago

Ok, I think I now understand your proposal. However, the JSON could potentially be quite large.

True, it all depends on the amount of snippets a user has. I don't have many snippets right now, so I was not too concerned about fetching all snippets.

Is it enough for your use to dump all snippets managed by snipkit to stdout or do you want to pass some filter parameter?

This is a good question, thinking about it more, since this issue was inspired by SnippetLab Alfred Workflow, I guess a good approach is not to dump all snippets but to ask the user to filter.

SnippetLabs ships with an Alfred Workflow that packages a binary that lets you query its database, but it doesn't appear to let you dump all of the snippets:

unzip /Applications/SnippetsLab.app/Contents/SharedSupport/Integrations/SnippetsLabAlfred.alfredworkflow -d /tmp/
/tmp/SnippetsLabAlfredWorkflow --action=search --query="OpenStack"

This will return a plist (XML formatted) of Snippets IDs tagged with #OpenStack.

For `snipkit', I think a similar behavior makes sense.

lemoony commented 2 months ago

At long last, the next release will contain a new sub-command to export all snippets as JSON (implemented in https://github.com/lemoony/snipkit/pull/258 ). This goes hand-in-hand with feature request https://github.com/lemoony/snipkit/issues/233.

lemoony commented 2 months ago

Released with v1.5.0 👍

There's also an example of how to customize snipkit for alternative workflows:

https://lemoony.github.io/snipkit/v1.5.0/getting-started/fzf/