Artificial intelligent assistant

How to sort (by whatever key) BibTex entries in `.bib` file? I work with LaTeX and do versioning with Git. For bibliography management I use Mendeley. The problem is that each time Mendeley synchronizes it's `.bib` exports, they are in different order, what makes bibliography versioning much harder. My idea is to sort BibTex entries in `.bib` file, each time before commit. Could you help me, how to do this in smart (short&sweet) way ? :) P.S. I can run this routine manually. I do not need git integration. I just want program/script to sort `.bib` file.

How about `bibsort`?


NAME
bibsort - sort a BibTeX bibliography file

SYNOPSIS
bibsort [optional sort(1) switches] < infile >outfile

DESCRIPTION
bibsort filters a BibTeX bibliography, or bibliography frag-
ment, on its standard input, printing on standard output a
sorted bibliography.


It's a shell script wrapping `nawk` (and `tr`, `sort` and `grep`) and includes two warnings you might have to pay attention to (see the source).

( **Edit** There're also a lot of bibtex-related Perl modules...)

**Edit2** I just recognized you'd like to sort for _any_ key, while `bibsort` apparently sorts by _the bibtex tags_ only -- but maybe its source (it's not too long) is still helpful...?

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy ea971df3e7e5f11d0eedbee47cbeae3c