Closed psiska closed 3 years ago
Hey, thanks for the PR. This seems like an useful feature in general (even though I'm not familiar with the telescope plugin), however I'm not sure if it is worth baking into neuron itself? Especially as you can achieve this using a tool like jq
❯ neuron query 2> /dev/null | jq '.[]' | jq -c | tail -3
{"ID":"ghcid","Meta":{"slug":"ghcid","tags":[]},"Path":"./ghcid.md","Slug":"ghcid","Title":"ghcid"}
{"ID":"index","Meta":{"tags":[]},"Path":"./index.md","Slug":"index","Title":"Sridhar Ratnakumar"}
{"ID":"ka Project","Meta":{"slug":"ka","tags":[]},"Path":"./ka Project.md","Slug":"ka","Title":"ka Project"}
❯ neuron query --id index 2> /dev/null | jq -c
{"ID":"index","Meta":{"tags":[]},"Path":"./index.md","Slug":"index","Title":"Sridhar Ratnakumar"}
I can see your point, in keeping neuron as small as possible (correct me if I am wrong, but I have an impression this is a goal).
You are right that I can achieve that with some other external tools like 'jq'. No problem in here. On the other hand this change is quite small, contained and does not add other dependencies.
The 'jq' path requires pipe-ing output from one command to another which implies either shell or handling stream by myself (telescope is in lua so no shell is involved). Another factor is that it requires to have 'jq' installed.
So my point is that this change make it easier for me and hopefully for other who will wish to integrate the neuron into their pipelines. ( I am thinking about something like pandoc but for information manipulation)
If it helps to get this feature in I can redesign the flag to be more future-proof.
Okay, then let's consider these:
maybeToList
(from relude), instead of writing your own (m2s)bool printPrettyJson (printJsonLine . maybeToList) jsonl $ result
putTextLn . decodeUtf8
in printPrettyJson with putLBSLn
for consistencyBy the way, could you share your neovim telescope config? I'm curious about that plugin.
So I got back to the patch. Hopefully I got your comments rights. Let's see :)
When it comes to my telescope config. There is nothing special atm. Just binding of default pickers to shortcuts. What I am trying to achieve is to integrate neuron into it (even if I am aware of neuron2.vim).
@psiska Looks perfect! Just one last change: could increment the version (to 1.9.30.0) in neuron.cabal and add an entry (referencing this PR) in CHANGELOG.md?
(Make sure to merge with master if you haven't already)
I've added the entry in the Changelog and rebase against upstream/master.
To support querying by tools which expects whole information on one line. E.g. Neovim telescope plugin where I need to query neuron DB returns result split on multiple lines. Which is nice for human, however impose burden on program interaction.
This PR introduces the --jsonl flag to 'query' sub-command. If this flag is active one entry will be printed at each line. Which is super convenient format for command line processing.
Example
After