The other day I was curious if I could add the current timestamp to my eshell
prompt. After some Kagi‘ing I found this
page and started writing my own
prompt! (Using the example under “A fancy prompt” as a starting point.)
Before
After
My Config
Here’s what my config ended up looking like [note: see below for an updated version]:
Note about the format
Note that if you want eshell-previous-prompt and eshell-next-prompt (which
the author suggests binding to M-{ and M-}) to keep working, you need a
space before the $ symbol in your prompt.
If you want to change this format, you can still edit the regex that eshell uses
to find the prompts. The helpdoc for eshell-prompt-function says as much:
Make sure to update ‘eshell-prompt-regexp’ so that it will match your prompt.
Dec 2022 Update
Recently I found this StackOverflow
post and got some useful
improvements from it, including:
Make all prompt components read-only, so that the prompt cannot be deleted as
regular text.
Try to abbreviate-file-name of current directory as per eshell defaults,
e.g. display ~ instead of /path/to/user/home.
Choose between prompts # and $ depending on user privileges, as per Bourne and
eshell defaults.
My updated custom-eshell-prompt function is:
Bonus
As I was writing this post I found out about this
project. Looks like it doesn’t
support timestamps though, and not sure if it gives you much fine-grained
customization.