The ealias command is in effect a wrapper around emacsclient for the
Bash shell. It’s a simple way of defining a shell function, which
will in turn call a specific Emacs function with a number of given
arguments. It gives a little bit of eshell feeling and is
especially useful for mapping terminal-loving commands like man
to
their Emacs equivalents when using an M-x shell.
Somehow download the file ealias
in some directory and source it
either from your ~/.bashrc, for access in any shell, or your
~/.emacs_bash, if you prefer it only being active in the M-x shell.
After proper installation you should have access to a new command
called ealias
. See the output of
$ ealias --help
for a complete description and the Examples section below.
There are a couple of variables which influence the behavior of
the ealias
command. They are listed in the following table and
further described below.
Variable | Default | Description |
---|---|---|
EALIAS_RC | ~/.config/ealiasrc | Filename to use for the -w/-r/-e options |
EALIAS_CLIENT | emacsclient | Program to use as emacsclient |
For convenience the ealias
options -w
, -r
and -e
let you
write, resp. read, resp. edit the file EALIAS_RC
. This is just
an easy way to write your possibly interactively defined aliases to
a file and read them back in later.
A ealias
definition looks pretty much like a normal alias, except
it
- may contain a number of special format codes and
- it is called much like a function, i.e. it accepts parameter.
Let’s start with a simple example and redefine the man
command,
which is pretty useless in an M-x shell.
$ ealias man='man %*'
The %*
construct takes the remaining arguments (in this case all)
and concatenates them into a single string. We can examine what
would be executed with the -n
option.
$ man -n 3 printf
emacsclient --eval (man "3 printf")
$ man 3 printf
#<buffer *Man 3 printf*>
The next alias utilizes the diff
command, which takes 3 arguments,
namely the 2 files to find the differences for and which options to
use.
$ ealias ediff='diff %^ %^ %*'
The %^
code pops an argument and wraps it, like all
%
-constructs, in double-quotes, thereby transforming the shell
word into a Lisp string.
$ ediff -n file1 file2 -w -c
emacsclient --eval (diff "file1" "file2" "-w -c")
The last example finds a file and edits it as the root user.
$ ealias redit='find-file-other-window \"/sudo::$(readlink -f "$1")\"'
Note, that this alias uses regular parameters only. Since the whole expression is evaluated, we need to escape the quotes.
$ redit -n /etc/bashrc
emacsclient --eval (find-file-other-window "/sudo::/etc/bashrc")
See the file ealiasrc.example
for more examples.