The script itself can be found here: https://gist.github.com/zverhope/1d4d77 ... e049623738
Rather than using a separate index of citekeys to determine what keys to add and/or remove, this script derives its citekeys from the bib file itself, using pandoc-citeproc to provide the list that the script then compares against the citekeys from your open Bookends library. If a citekey is present in Bookends but not in the bib file, it will add the record in BibTeX format to the end of your bibfile.
Two things: to make this work, you need to have both pandoc-citeproc and jq installed. This will usually be done via homebrew. You also need to specify the paths to these functions in the script. You'll notice that both of these are located in /usr/local/bin/ on my system. To find out where they are on yours (if installed) type
Code: Select all
Code: Select all
Finally and perhaps most importantly: the most difficult part of making the script was actually figuring out how to make Bookends print newlines in the output so that these could be read by grep in a shell script. This was necessary to figure out where a citekey was in order to remove it from the bib file if no longer present in your Bookends library. I also didn't want to have to include a custom BibTeX.fmt file with this, which would unnecessarily complicate things. So, as it is currently working (for me), each new entry in the bib file constitutes a single line. This means that the remove function searches for the citekey, returns the line, and then removes the line, which is actually the entire bib entry for that record. BUT if your current bib file doesn't have one line for each entry, this won't work properly on your end. In that case, you might also try regenerating the bib file from scratch (which this script will do) or turning off the remove function. You can also try it out to see what happens. The script should backup your bib file to "your.bib.bak" before attempting to remove anything, but do your own backup as well before using this for the first time. Perhaps someone else can come up with a more elegant solution for the removal function, but this works for me right now.
Hope others find this useful. Enjoy!
(Also, credit to iandol and kseggleton for a few of the bones -- particularly iterations by counts of 25 -- of the current script.)