Emacs: Get the path for current buffer from command-line

At work, I use Emacs (nowadays with the Spacemacs configuration). My favorite Git history browser is tig. When I want to see the git history or blame for the file I’m currently editing, what do I do?

There are many possible solutions, but here’s mine: a small script called cur that returns the path to the buffer currently active in Emacs.

emacsclient -e '(buffer-file-name (window-buffer))' | \
    sed -e 's/^"//' -e 's/"$//'

It’s easy to use with tig – or any other command-line tool you might need:

tig blame $(cur)

Comments or questions? Send me an e-mail.