Bike command line piped into jq – e.g. listing highlit terms

I have a couple of Bike outlines here in which I have been highlighting terms of interest, and now I want to list those terms.

We can start by filtering in the Bike app GUI (⇧⌘F) with an outline path:

//*/run::@mark/..

Also, the new bike command line (Bike > Install Command Line Tool ...) can harvest matching lines as text, markdown, json, bike, or opml

Lets start with text:

bike get outline --refs '//*/run::@mark/..' -o txt

If we only want the highlit words themselves, without the line containing them, then we can first switch to json (the default, so we don’t need the -o switch now)

bike get outline --refs '//*/run::@mark/..'

and then pipe the result into a jq query (jqlang can be installed via brew)

which pulls out just the highlit strings themselves:

.root.children[].text[] | select(.attrs.mark).string

Putting it together for the command line, specifying -r for text output without double quotes:

bike get outline --refs '//*/run::@mark/..' | jq -r '.root.children[].text[] | select(.attrs.mark).string'
1 Like

Neat, I just gave it a try and success!

1 Like

You could re-wrap the stream as an Array,
and tag on a jq sort_by,
before making it a stream again with []

[.root.children[].text[] |
    select(.attrs.mark).string] |
    sort_by(ascii_downcase)[]

but just piping onwards to the shell’s | sort -f seems lighter :slight_smile:

1 Like

A post was split to a new topic: List of All Links in Outline (via bike command line tool)

With jq’s recurse, we can get things even without a Bike outline path.

For the flat listing of all highlit strings, at any depth of the outline, this time skipping the outline path:

.root | recurse(.children[]?) |
    .text[]? | select(.attrs.mark) | .string

i.e. at the command line:

bike get outline | jq -r '.root | recurse(.children[]?) |
    .text[]? | select(.attrs.mark) | .string'