Skip to content

Instantly share code, notes, and snippets.

@dsanson
Created September 15, 2010 15:14
Show Gist options
  • Save dsanson/580866 to your computer and use it in GitHub Desktop.
Save dsanson/580866 to your computer and use it in GitHub Desktop.
extract bibtex keys
#!/usr/bin/ruby
## get a sorted list of cite keys that match an array of strings
##
## Usage:
##
## $ bibkey citekey1 [citekey2 ...]
## $ bibkey path-to-bibtex citekey1 [citekey2 ...]
##
## if the first argument is a path to a readable file, then the
## the script tries to use it as the bibtex file. Otherwise,
## the script searches defaultbib:
defaultbib="/Users/david/Documents/Dropbox/smallbib/smallbib.bib"
## Extract the citekeys
def extractcitekeys(somestrings,text)
keys = []
somestrings.each { |match|
match.chomp
keys = keys + text.scan(/@.*?\{(#{match}.*?),/i)
}
keys.uniq!
keys.sort!
return keys
end
## parse the command line
strings=ARGV
## is the first argument a readable file?
maybebib=strings.shift
if File.readable?(maybebib) then
bib=maybebib
else
bib=defaultbib
strings.unshift(maybebib)
end
File.open(bib) { |file|
mytext = file.read
mykeys = extractcitekeys(strings,mytext)
puts mykeys
}
@andrewheiss
Copy link

In your post on the pandoc Google Group you mention that the fastest group refresh time available in TextExpander is one day. I just found out from TextExpander support that it's possible to set the refresh time to whatever you want with AppleScript. Check this script out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment