Defining Eshell Commands

It’s a commonplace in the Emacs community that you never stop learning Emacs. No matter how long you’ve been using it, there’s always something new to discover. The truth of that maxim was brought home to me today when I came across an Emacs subreddit post from rvc09 asking how he could run a predetermined set of commands in Eshell as with a script in other shells.

I’ve never needed to do that so I hadn’t thought about how I would go about it. It turns out that the answer is simple but not at all obvious. Scroot had the answer. It turns out that you can define an Elisp function eshell/some-command and run it in Eshell by calling some-command.

But wait, there’s more. Within such a function you can use eshell-command1 to call any Eshell command. Those two facts allow you to essentially define a script that you can run from within Eshell.

As I said, I had no idea about this. It’s just another point on the never ending arc of my Emacs journey of discovery.

Footnotes:

1

Scroot says it’s eshell-run-command but that function doesn’t exist in my Emacs 29.3 installation, so I’m pretty sure he meant eshell-command.

This entry was posted in General and tagged . Bookmark the permalink.