CC-by-SA Richard Bartz, Munich Makro Freak https://commons.wikimedia.org/wiki/File:A_Taraxacum_Ruderalia_dandelion_clock.jpg

Making git and Emacs’ eshell work together

tl;dr

I often end up in eshell.

Sometimes, because I’m running Emacs on Windows (where shells work, but it’s a pain), and sometimes just because.  The problem, until today, was that anytime I would invoke a git command that wanted to call the pager (say, diff), I would see the following annoying message from less:

WARNING: terminal is not fully functional
-  (press RETURN)

This happens because eshell sets $TERM to “dumb”.  It doesn’t try to fool anyone.  It’s dumb.

But, since I’m stubborn and lazy, I just put up with it the stupidity of eshell and the annoyance of git’s invocation of less.  Till today.

Some would say the answer is “Don’t use git in emacs — use magit!” And they’d be right. I do use magit, but commands should work, too.

So, after a spree of productivity yesterday, I woke up today and hit that annoying message again.  I decided to track it down.

I came across this StackOverflow thread. There is a hint there — I didn’t know less could be told to only page in certain cases — but not anything that says “only sometimes use less”.

So I managed to hack something together:

git config --global core.pager '`test "$TERM" = "dumb" && echo cat || echo less`'

I haven’t tried this under Windows, yet, but I’m hoping it works.

Image CC-by-SA: Richard Bartz, Munich Makro Freak

10 thoughts on “Making git and Emacs’ eshell work together”

  1. You could use (setenv “GIT_PAGER” “”) to disable git paging from emacs initiated commands only.

    1. And maybe that is what I’ll end up using on Windows. That or the other eshell-visual-options that someone else pointed to here.

    1. See, but that requires reading the documentation. It’s better to post this and then see what happens. Look at the replies I’ve gotten (like yours 😉 ).

    2. Except in the case of “git log -1” when the *git* buffer is created for a few seconds and then disappears. The answer in that case is to change the flags using the LESS environment variable (explained in the StakeOverflow answer above).

      But, in any case, the output then goes to a different buffer, but the user may want the output in the *eshell* buffer.

Leave a Reply

Your email address will not be published. Required fields are marked *