As I've read, eshell commands are just wrappers around actual elisp expressions. If true, everything I do in eshell I could do in an elisp REPL, right? Is it therefore possible to see what actual elisp is being invoked when we type in an eshell command?

The reason I ask is that I want to use org-mode's Babel. You can put elisp code in blocks and get results inserted after the block just fine. This is also true for regular shell (sh), but there is no way I know of running eshell commands as Babel "code blocks." So I'd like to have the actual elisp, which org-mode Babel handles in blocks well.

  • Creating new command in elisp for eshell is somehow like creating shell function/script for bash, for example, create a hello command, (defun eshell/hello () (message "hello")) (bash: function hello { echo hello }), then you can invoke hello command in eshell. Your question is unclear to me. – xuchunyang Aug 23 '15 at 2:07
  • Invoke the eshell. Type "ls". It returns the contents of the directory. But supposedly there is an elisp expression behind this "ls". What is the elisp that lists the directory contents? Can I find all the elisp expressions invoked by eshell -- is what I'm basically asking? – 147pm Aug 23 '15 at 2:21
  • I also found orgmode.org/worg/org-contrib/babel/languages/ob-doc-eshell.html but haven't tried it. – Günter Zöchbauer Jan 16 at 10:37

Is it therefore possible to see what actual elisp is being invoked...

Yes. They are all located in the eshell folder under Resources/elisp in the Emacs app folder. See screenshot of files on my computer. screenshot of that list on my local computer

So I'd like to have the actual elisp...

Open any of those files to see the actual elisp code. For example, ls command with its normal switches is implemented in em-ls.el file by John Wiegley and its core uses expand-file-name function.

How to find which lisp file provides what shell command? Open eshell prompt and then type, say you want to know where kill is in elisp:

which kill

will tell you that

eshell/kill is a compiled Lisp function in `esh-proc.el'

What other commands are available in eshell?

see the [manual][2]

there is no way I know of running eshell commands as Babel "code blocks."

There are no special eshell commands per se. Eshell mimics standard unix shell commands using existing lisp functions. You can invoke those same functions in org-babel lisp blocks without any mediating functions implemented in eshell.

| improve this answer | |

e.g.: M-x find-function RET eshell/ls RET

I like having find-function bound to C-hC-f as a variant on the standard describe-function binding (via which you can also indirectly get to the code, FYI).

You could also use the following:

(defun eshell/goto (name)
  "Visit the source code for the specified eshell command."
  (let ((func (eshell-find-alias-function name)))
    (if func
        (find-function func)
      (error "%s is not an elisp function" name))))

$ goto ls

If you want to know what's implemented in elisp and what isn't, you could just ask Emacs to complete on eshell/

e.g.: C-uC-ha eshell/ RET

| improve this answer | |
  • 2
    Both of these answers hit the nail on the head. I want to use elisp as a sort of systems scripting tool. Why? Because org-mode has excellent literal (Babel) support for elisp, and now I can capture/record everything I do in an org buffer. And unless you make a point to save it, your typical command line session gets lost. Being able to keep life inside an org buffer is beguiling to me. – 147pm Aug 23 '15 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.