Skip to content

Instantly share code, notes, and snippets.

@dsanson
Created September 8, 2011 16:57
Show Gist options
  • Save dsanson/1203906 to your computer and use it in GitHub Desktop.
Save dsanson/1203906 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'bibtex'
match=ARGV[0]
bibfile = '/Users/david/.pandoc/default.bib'
smallbib = `bibtool -i #{bibfile} -- 'select{$key title booktitle author editor "#{match}"}'`
bib = BibTeX.parse(smallbib)
bib.delete('@comment') #Avoid false hits in comments
entries = []
bib.each do |hit|
key = hit.key
sep = ", "
begin
author = hit.author.map(&:last)[0]
rescue
begin
author = hit.editor.map(&:last)[0]
rescue
author = ""
sep = ""
end
end
begin
title = hit.title[0]
title.delete!("\{\}\n\'")
title.gsub!(/\s+/, " ")
rescue
begin
title = hit.booktitle[0]
rescue
title = ""
sep = ""
end
end
entries.push("{ 'word': '#{key}', 'menu': '#{author}#{sep}#{title}' }")
end
#puts "[" + entries.join(", ") + "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment