How I enter citekey references in Obsidian using the terminal

Disclaimer: This was created on macOS with iTerm2 and is certainly easy to replicate on Linux, but I’m not sure how to do it on Windows. It requires a certain familiarity with terminal applications and might only come in handy if you anyway always have a terminal open. So it is certainly not a solution for everyone, but some people might get some use out of it:

I’m using Obsidian to write my Master thesis. Therefore I want to enter citekeys (to be used as bibtex or biblatex references later) directly into my notes. For my references I use a plain .bib file, which I edit in vim (using snippets to add new entries). When writing text in vim, I can use fzf-bibtex to quickly fuzzy search for a citekey through my bibliography file (entering all kinds of data: (parts of) author names, titles, publishers, years etc.) and enter it into the text. I wanted to be able to do the same in Obsidian. Hopefully there will be a plugin someday, where you can just enter the path to your bibliography file and set a shortcut to open a fuzzy search window in Obsidian to enter citekeys directly. But for now I hacked together a custom solution using dropdown terminal windows.

  1. I installed fzf-bibtex which provides the terminal commands bibtex-ls, bibtex-cite and bibtex-markdown (here only the first two are relevant). In order to set up fzf-bibtex, you can refer to the GitHub page linked above.[^1]
  2. I created the following aliases in my .zshrc (or .bashrc):
alias cit="bibtex-ls | fzf --multi --ansi | bibtex-cite -prefix='[@' -postfix=', ]' -separator='; @' | pbcopy && exit"
alias citcf="bibtex-ls | fzf --multi --ansi | bibtex-cite -prefix='[Cf. @' -postfix=', ]' -separator='; @' | pbcopy && exit"

The first one will open a fuzzy search window where I can select the entry I want, formating it correctly as [@citekey, ] and sending it to the system clipboard. The second one will do the same, but add “Cf.” at the beginning.

  1. I created a profile for each use case in iTerm2, entering the command under the “Send at start” setting, which will execute the command automatically whenever a window of that profile is opened. Then I defined a hotkey for each profile: double-press Shift and double-press Cmd in the “Keys” section in iTerm2.
  2. When in Obsidian, I just have to press the hotkey and a terminal window will open. I then enter my term and press enter to copy the citekey. The terminal window is closed automatically and I just paste the key into the text. (Since I use vim mode, I can press Esc and i to get the cursor to the position of the page, so I can enter it relatively effortlessly: [@citekey, 123]. Without vim mode you just have to press <-.) You can also select multiple entries at once by marking them with Shift which will give you [@citekey1; @citekey2 …].
  3. In addition, you could use a clipboard manager to quickly access previously used citekeys. Personally, I use Maccy which allows to open it’s window via a shortcut and paste previous entrys with Cmd-1, Cmd-2 etc.

In use:

citekeys-showcase

Edit: Now the terminal window closes automatically, so you don’t even have to press Cmd-w after selecting the key. This is not reflected in the gif above, but here you can see a video with the change and also an example of selecting multiple keys.

[^1]: It requires brew, fzf, bibtool and go, which might be a lot of dependencies for some users. But as I said, that’s not a solution for everyone.

4 Likes

This is fantastic! You might want to cross-post this to the zotero threads in #plugins and #knowledge-management!

Thanks! I cross-posted the link in the two relevant threads.

1 Like

That is cool. That is pretty much what I would like to have: Atom, Zettlr (and I think sublime) have plugins where you point to a bibTex file and the search window pops up when you type in ‘[@‘; you pick a reference that you need and the bibTex code gets inserted into your text.

1 Like

I use Zotero to collect references and to collect and manage PDFs; and a better bibTex plugin to automatically export all bibliographical data into bibTex format.

1 Like

Hey thanks for developing and sharing this! :smiley: Will try it out. Currently writing my Master’s Thesis as well, and til this resolved to use Zettlr and Obsidian interchange-ably, since Zettlr supports Bibtex. Will see how it goes :smiley:

1 Like