GithubHelp home page GithubHelp logo

sdrave / fzf-bibtex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from msprev/fzf-bibtex

0.0 1.0 0.0 38 KB

a BibTeX source for fzf

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%

fzf-bibtex's Introduction

fzf-bibtex

A BibTeX source for fzf.

  • Blazingly fast, even with large BibTeX files
  • Caches results intelligently (hence the speed)
  • Uses a well-understood framework to parse BibTeX (bibtool)
  • Vim integration (via fzf.vim)
  • Supports multiple BibTeX files
  • Supports cross references (thanks to @cao)
  • Basic BibLaTeX support (thanks to @ashwinvis)

Example use

To select items using fzf from a .bib file (as in image above):

bibtex-ls references.bib | fzf --multi --ansi

To cite items (using the pandoc '@' format or LaTeX \cite command) from a .bib file:

bibtex-ls references.bib | fzf --multi --ansi | bibtex-cite

To pretty print items (in markdown) from a .bib file:

bibtex-ls references.bib | fzf --multi --ansi | bibtex-markdown references.bib

Installation

Requirements

On the Mac, these can be installed by homebrew:

brew install fzf
brew install bib-tool
brew install go

If you want vim integration:

Installation

go get github.com/msprev/fzf-bibtex/cmd/bibtex-ls
go install github.com/msprev/fzf-bibtex/cmd/bibtex-ls
go install github.com/msprev/fzf-bibtex/cmd/bibtex-markdown
go install github.com/msprev/fzf-bibtex/cmd/bibtex-cite

Vim integration

Assuming the executables installed above are available to Vim in your file path, add this to your vimrc file:

let $FZF_BIBTEX_CACHEDIR = 'PATH-TO-CACHE-DIR'
let $FZF_BIBTEX_SOURCES = 'PATH-TO-BIBTEX-FILE'

function! s:bibtex_cite_sink(lines)
    let r=system("bibtex-cite ", a:lines)
    execute ':normal! a' . r
endfunction

function! s:bibtex_markdown_sink(lines)
    let r=system("bibtex-markdown ", a:lines)
    execute ':normal! a' . r
endfunction

nnoremap <silent> <leader>c :call fzf#run({
                        \ 'source': 'bibtex-ls',
                        \ 'sink*': function('<sid>bibtex_cite_sink'),
                        \ 'up': '40%',
                        \ 'options': '--ansi --layout=reverse-list --multi --prompt "Cite> "'})<CR>

nnoremap <silent> <leader>m :call fzf#run({
                        \ 'source': 'bibtex-ls',
                        \ 'sink*': function('<sid>bibtex_markdown_sink'),
                        \ 'up': '40%',
                        \ 'options': '--ansi --layout=reverse-list --multi --prompt "Markdown> "'})<CR>

<leader>c will bring up fzf to insert citation to selected items.

<leader>m will bring up fzf to insert pretty markdown versions of selected items.

An insert mode mapping, typing '@@' brings up fzf to insert a citation:

function! s:bibtex_cite_sink_insert(lines)
    let r=system("bibtex-cite ", a:lines)
    execute ':normal! a' . r
    call feedkeys('a', 'n')
endfunction

inoremap <silent> @@ <c-g>u<c-o>:call fzf#run({
                        \ 'source': 'bibtex-ls',
                        \ 'sink*': function('<sid>bibtex_cite_sink_insert'),
                        \ 'up': '40%',
                        \ 'options': '--ansi --layout=reverse-list --multi --prompt "Cite> "'})<CR>

An alternative insert mode mapping that detects .bib files in parent, current or child directories (thanks to @ashwinvis):

function! Bibtex_ls()
  let bibfiles = (
      \ globpath('.', '*.bib', v:true, v:true) +
      \ globpath('..', '*.bib', v:true, v:true) +
      \ globpath('*/', '*.bib', v:true, v:true)
      \ )
  let bibfiles = join(bibfiles, ' ')
  let source_cmd = 'bibtex-ls '.bibfiles
  return source_cmd
endfunction

function! s:bibtex_cite_sink_insert(lines)
    let r=system("bibtex-cite ", a:lines)
    execute ':normal! a' . r
    call feedkeys('a', 'n')
endfunction

inoremap <silent> @@ <c-g>u<c-o>:call fzf#run({
                        \ 'source': Bibtex_ls(),
                        \ 'sink*': function('<sid>bibtex_cite_sink_insert'),
                        \ 'up': '40%',
                        \ 'options': '--ansi --layout=reverse-list --multi --prompt "Cite> "'})<CR>

Command line use

bibtex-ls [-cache=...] [file1.bib file2.bib ...]

Lists to stdout the content of .bib files, one record per line.

If the following environment variables are set, then these command line arguments can be omitted.

  • FZF_BIBTEX_CACHEDIR: path to a cache directory
  • FZF_BIBTEX_SOURCES: path to bibtex file; multiple items separated by a ':'

The cache directory should be a suitable directory for bibtex-ls temporary files. Parsing BibTeX databases is computationally intensive, so the command caches the results. The cache is updated if the underlying BibTeX file has been changed. If no cache directory is specified, the operating system's directory for temporary files is used.

(NB. If you are tinkering with fzf-bibtex's codebase, beware of outdated caches. Cache is only updated if the underlying BibTeX file has been changed. If you change the fzf-bibtex codebase, make sure to flush the cache by touching the BibTeX files, or deleting the cache, before you run new code on them).

bibtex-cite [-mode=pandoc|latex]

Pretty print citations in LaTeX \cite command or pandoc @ format for selected entries passed over stdin.

bibtex-markdown [-cache=...] [file1.bib file2.bib ...]

Pretty print items (in markdown) for selected .bib entries passed over stdin.

Cache directory may be set using the same environment variable as bibtex-ls.

Errors?

fzf-bibtex uses bibtool to parse BibTeX files. If there is an error, it is likely that your BibTeX file is not being parsed correctly. You can locate the cause, and correct it, by running bibtool directly on your BibTeX file from the command line. Look at any errors reported from:

bibtool references.bib -o parsed.bib

The BibTeX fields that fzf-bibtex asks bibtool to extract from your file can be seen by running bibtool with this rsc file:

expand.macros = On
expand.crossref = On
preserve.keys = On
preserve.key.case = On
print.line.length { 1000 }
keep.field { date }
keep.field { author }
keep.field { title }
keep.field { year }
keep.field { journal }
keep.field { booktitle }
keep.field { editor }
keep.field { publisher }
keep.field { address }
keep.field { pages }
keep.field { school }
keep.field { volume }
rename.field { year = date if year = ".+" }
add.field { year = "%-4.1d(date)" }
new.entry.type{Article}
new.entry.type{Book}
new.entry.type{MVBook}
new.entry.type{InBook}
new.entry.type{BookInBook}
new.entry.type{SuppBook}
new.entry.type{Booklet}
new.entry.type{Collection}
new.entry.type{MVCollection}
new.entry.type{InCollection}
new.entry.type{SuppCollection}
new.entry.type{Manual}
new.entry.type{Misc}
new.entry.type{Online}
new.entry.type{Patent}
new.entry.type{Periodical}
new.entry.type{SuppPeriodical}
new.entry.type{Proceedings}
new.entry.type{MVProceedings}
new.entry.type{Reference}
new.entry.type{MVReference}
new.entry.type{Inreference}
new.entry.type{Report}
new.entry.type{Set}
new.entry.type{Thesis}
new.entry.type{Unpublished}
new.entry.type{Cdata}
new.entry.type{CustomA}
new.entry.type{CustomB}
new.entry.type{CustomC}
new.entry.type{CustomD}
new.entry.type{CustomE}
new.entry.type{CustomF}
new.entry.type{Conference}
new.entry.type{Electronic}
new.entry.type{MasterThesis}
new.entry.type{PhdThesis}
new.entry.type{TechReport}
new.entry.type{WWW}
new.entry.type{Artwork}
new.entry.type{Audio}
new.entry.type{BibNote}
new.entry.type{Commentary}
new.entry.type{Image}
new.entry.type{Jurisdiction}
new.entry.type{Legislation}
new.entry.type{Legal}
new.entry.type{Letter}
new.entry.type{Movie}
new.entry.type{Music}
new.entry.type{Performance}
new.entry.type{Review}
new.entry.type{Software}
new.entry.type{Standard}
new.entry.type{Video}
new.entry.type{XData}

Release notes

  • 1.0 (4 November 2018)
    • first version

Similar

fzf-bibtex's People

Contributors

ashwinvis avatar cao avatar msprev avatar thehamsta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.