File: em-alias.el.html
Command aliases greatly simplify the definition of new commands.
They exist as an alternative to alias functions, which are otherwise quite superior, being more flexible and natural to the Emacs Lisp environment (if somewhat trickier to define; [Alias functions]).
;_* Creating aliases
The user interface is simple: type 'alias' followed by the command name followed by the definition. Argument references are made using '$1', '$2', etc., or '$*'. For example:
alias ll 'ls -l $*'
This will cause the command 'll NEWS' to be replaced by 'ls -l NEWS'. This is then passed back to the command parser for reparsing.{Only the command text specified in the alias definition will be reparsed. Argument references (such as '$*') are handled using variable values, which means that the expansion will not be reparsed, but used directly.}
To delete an alias, specify its name without a definition:
alias ll
Aliases are written to disk immediately after being defined or deleted. The filename in which they are kept is defined by the variable eshell-aliases-file.
The format of this file is quite basic. It specifies the alias
definitions in almost exactly the same way that the user entered
them, minus any argument quoting (since interpolation is not done
when the file is read). Hence, it is possible to add new aliases
to the alias file directly, using a text editor rather than the
alias command. Or, this method can be used for editing aliases
that have already defined.
Here is an example of a few different aliases, and they would appear in the aliases file:
alias clean rm -fr **/.#*~
alias commit cvs commit -m changes $*
alias ll ls -l $*
alias info (info)
alias reindex glimpseindex -o ~/Mail
alias compact for i in ~/Mail/**/*~*.bz2(Lk+50) { bzip2 -9v $i }
;_* Auto-correction of bad commands
When a user enters the same unknown command many times during a session, it is likely that they are experiencing a spelling difficulty associated with a certain command. To combat this, Eshell will offer to automatically define an alias for that misspelled command, once a given tolerance threshold has been reached.
Whenever the same bad command name is encountered
eshell-bad-command-tolerance times, the user will be prompted in
the minibuffer to provide an alias name. An alias definition will
then be created which will result in an equal call to the correct
name. In this way, Eshell gradually learns about the commands that
the user mistypes frequently, and will automatically correct them!
Note that a '$*' is automatically appended at the end of the alias definition, so that entering it is unnecessary when specifying the corrected command name.
Defined variables (5)
eshell-alias-load-hook | A hook that gets run when ‘eshell-alias’ is loaded. |
eshell-aliases-file | The file in which aliases are kept. |
eshell-bad-command-tolerance | The number of failed commands to ignore before creating an alias. |
eshell-command-aliases-list | A list of command aliases currently defined by the user. |
eshell-failed-commands-alist | An alist of command name failures. |
Defined functions (10)
eshell-alias-completions | (NAME) |
eshell-alias-initialize | () |
eshell-command-aliased-p | (NAME) |
eshell-fix-bad-commands | (NAME) |
eshell-lookup-alias | (NAME) |
eshell-maybe-replace-by-alias | (COMMAND ARGS) |
eshell-read-aliases-list | () |
eshell-write-aliases-list | () |
eshell/alias | (&optional ALIAS &rest DEFINITION) |
pcomplete/eshell-mode/alias | () |