bear icon indicating copy to clipboard operation
bear copied to clipboard

Document example use cases

Open sloansparger opened this issue 4 years ago • 2 comments

It would be useful to have some visual documentation on how to utilize this CLI for people wanting to start and build custom workflows using the CLI. Please leave a comment of something you'd like to see documented below, or upvote existing ideas!

sloansparger avatar Jun 12 '20 18:06 sloansparger

Perhaps how to interact with the CLI via Applescript? I have been trying to do so, but apparently that is not very simple since do shell script uses sh instead of zsh. Any help would be appreciated.

(My end goal is to set up some sort of sync with an external folder. The python script available did not work out very well for me)

bcdavasconcelos avatar Jun 13 '20 00:06 bcdavasconcelos

@bcdavasconcelos apologies for the slow reply. I'm not familiar with applescript at all, so I'm not able to help there.

If you were to use the CLI in bash/zsh I would do something like this: bear search " " | awk 'BEGIN {FS="\t"}; {print "bear open-note " $1 " | head"}' | xargs -0 bash -c

  1. bear search " " gets all notes with a space (best way I know to find all of them).
  2. Pipe result into awk. Bear search results an {id}\t{title} for each note. We just want the id for each note. Awk will let us do that for each line by setting FS=\t (I suggest reading learn awk in 20 minutes if you're unfamiliar awk). We then build a string "bear open-note " $1 " | head" Which lets us grab the first 10 lines of every single note in bear. You can replace head with any command, in your case you may want to echo the contents into a file.
  3. Pipe the resulting string from awk back into bash using xargs. This allows us to run a command for each line of our awk output, which is a single bash script.

Maybe fetching all notes and doing something with their contents might be a common enough use case I should create an example for...

sloansparger avatar Jun 20 '20 20:06 sloansparger