See also EshellFunctions for more elaborate examples.
The eshell aliases are stored in a file whose name is in the variable
eshell-aliases-file (this defaults to something like ~/.emacs.d/eshell/aliases). If you edit it by hand then (as the manual says), you’ll need to refresh eshell’s cache of the values. To do this, run the
eshell-read-aliases-list function (which, of course, you can do by typing its name in eshell!)
I used this in my .emacs so that I can simply open file instead of find-file. This has the added advantage that I can M-x open file when I can’t remember what C-x C-f does ;P
(defalias 'open 'find-file) (defalias 'openo 'find-file-other-window)
Make sure that the positional parameters are included:
~ $ alias ll 'ls -l $*'
~ $ alias emacs 'find-file $1'
Note that without the quotes, the positional parameter will get lost:
~ $ alias emacs find-file $1 ~ $ alias alias emacs find-file
Note also that $* will not work because
‘find-file’ expects exactly one parameter. Using $* instead of $1 will pass a list of parameters to find-file, and find-file will barf:
~ $ alias emacs 'find-file $*' ~ $ emacs test.txt Wrong type argument: stringp, ("test.txt")
Note, that $* will work with the following advice (put it into .emacs):
(defadvice find-file (around find-files activate) "Also find all files within a list of files. This even works recursively." (if (listp filename) (loop for f in filename do (find-file f wildcards)) ad-do-it))
The same idea is for checking html files. I generate a lot of html documentation using Doxygen and want to see the document without leaving emacs. If you have emacs-w3m and w3m installed; then you may want to alias w3m to w3m-find-file same as emacs to find-file:
~ $ alias w3m 'w3m-find-file $1'
~ $ alias clear recenter 0
The trick is that all aliases will be stored automatically, thus you do not need to edit anything equivalent to your
".bash_alias" manually. The variable
‘eshell-aliases-file’ defines the file in which aliases are stored. Refer to the comments in the source file
"em-alias.el" for details.
You also can define new eshell commands in your .emacs file. There is a simple example. To define ‘emacs’ command as ‘find-file’ as above you may write:
(defun eshell/emacs (file) (find-file file))
This way you can define pretty complicated functions using all emacs lisp power. From the other side, it may be just overkill for such simple definitions. See EshellFunctions for more information about this. --AntonKulchitsky
Many people have lines like this in their .bashrc file: alias ll=’ls -l’ Eshell needs a different syntax: alias ll ‘ls -l’ To integrate both, either:
I have used solution d: I use a line in .bashrc which, after all aliases have been defined, creates the alias file for eshell (eshell-aliases-file):
alias | sed -E "s/^alias ([^=]+)='(.*)'$/alias \1 \2 \$*/g; s/'\\\''/'/g;" >~/.emacs.d/eshell/alias
This takes care of allowing eventual parameters ($*) and allows single quotes as part of the expanded alias. That line takes only 0m0.007s so I don’t mind running it each time I open bash.
– 2.m7.2010 DanielClemente