3

I use eshell-parse-command 'ls -l' and I got this:

(progn (eshell-trap-errors
         (eshell-named-command "ls" (list "-l"))))

Then I write a alias in my .emacs file:

(defalias 'ls
  (progn ...))

But I doesn't work. I don't know why.

unionx
  • 437
  • 3
  • 15

2 Answers2

4

Add following code to your configuration file.

(require 'em-alias)
(add-to-list 'eshell-command-aliases-list (list "ls" "ls -l"))
syohex
  • 2,293
  • 17
  • 16
  • How to add multiple alias? Can I just add another list in this (add-to-list) expression? Or I have to add a new (add-to-list ...) each time I add something? – Nick Nov 27 '14 at 01:47
  • You can define aliases in file. Default alias file is ~/.emacs.d/eshell/alias(You can change alias file by variable eshell-aliases-file). Alias entry is like this 'alias ll ls -l $*'. See also http://www.gnu.org/software/emacs/manual/html_node/eshell/Aliases.html – syohex Nov 27 '14 at 03:28
  • Thank you very much for your explanation. I'm concerned on the elisp syntax to join multiple list here. In Clojure, I can `(conj '(1 2 3) '(4 5 6) '(7 8 9))` Is it possible to do it in elisp? – Nick Nov 27 '14 at 03:35
  • I suppose you can use `append` like this. `(append '(1 2 3) '(4 5 6) '(7 8 9))`. – syohex Nov 27 '14 at 04:23
  • Thank you. I found an easy way: just use `alias` within eshell. – Nick Nov 28 '14 at 02:35
0

The easiest way to add alias to eshell is:

Open eshell,

alias alias-name definition

Eshell will automatically write it into ~/emacs.d/eshell/alias (don't edit it yourself).

For example:

alias sau sudo aptitude update

Then you can type sau to launch sudo aptitude update.

Type alias (in eshll, of course) will list all the alias you've defined.


Some useful alias:

Map find-file to ff, then you can open a file in emacs with ff file:

alias ff 'find-file $1'

Map dired to d:

alias d 'dired $1'

Resources: Mastering Eshell

http://www.masteringemacs.org/article/complete-guide-mastering-eshell
Nick
  • 8,451
  • 13
  • 57
  • 106