File: esh-cmd.el.html
;_* Invoking external commands
External commands cause processes to be created, by loading external executables into memory. This is what most normal shells do, most of the time. For more information, see [External commands].
;_* Invoking Lisp functions
A Lisp function can be invoked using Lisp syntax, or command shell
syntax. For example, to run dired to edit the current directory:
/tmp $ (dired ".")
Or:
/tmp $ dired .
The latter form is preferable, but the former is more precise, since it involves no translations. See [Argument parsing], to learn more about how arguments are transformed before passing them to commands.
Ordinarily, if 'dired' were also available as an external command,
the external version would be called in preference to any Lisp
function of the same name. To change this behavior so that Lisp
functions always take precedence, set
eshell-prefer-lisp-functions to t.
;_* Alias functions
Whenever a command is specified using a simple name, such as 'ls',
Eshell will first look for a Lisp function of the name eshell/ls.
If it exists, it will be called in preference to any other command
which might have matched the name 'ls' (such as command aliases,
external commands, Lisp functions of that name, etc).
This is the most flexible mechanism for creating new commands, since it does not pollute the global namespace, yet allows you to use all of Lisp's facilities to define that piece of functionality. Most of Eshell's "builtin" commands are defined as alias functions.
;_* Lisp arguments
It is possible to invoke a Lisp form as an argument. This can be done either by specifying the form as you might in Lisp, or by using the '$' character to introduce a value-interpolation:
echo (+ 1 2)
Or
echo $(+ 1 2)
The two forms are equivalent. The second is required only if the form being interpolated is within a string, or is a subexpression of a larger argument:
echo x$(+ 1 2) "String $(+ 1 2)"
To pass a Lisp symbol as an argument, use the alternate quoting syntax, since the single quote character is far too overused in shell syntax:
echo #'lisp-symbol
Backquote can also be used:
echo (list ,lisp-symbol)
Lisp arguments are identified using the following regexp:
;_* Command hooks
There are several hooks involved with command execution, which can
be used either to change or augment Eshells behavior.
Defined variables (24)
eshell--local-vars | List of locally bound vars that should take precedence over env-vars. |
eshell-allow-commands | If non-nil, allow evaluating command forms (including Lisp forms). |
eshell-background-commands | A list of currently-running deferred commands. |
eshell-cmd-load-hook | A hook that gets run when ‘eshell-cmd’ is loaded. |
eshell-complex-commands | A list of commands names or functions, that determine complexity. |
eshell-current-command | The currently-running foreground command, if any. |
eshell-deferrable-commands | A list of functions which might return a deferrable process. |
eshell-foreground-command | The currently-running foreground command, if any. |
eshell-in-pipeline-p | Internal Eshell variable, non-nil inside a pipeline. |
eshell-last-async-procs | The currently-running foreground command, if any. |
eshell-last-command-result | The result of the last command. Not related to success. |
eshell-last-command-status | The exit code from the last command. 0 if successful. |
eshell-lisp-form-nil-is-failure | If non-nil, Lisp forms like (COMMAND ARGS) treat a nil result as failure. |
eshell-lisp-regexp | A regexp which, if matched at beginning of an argument, means Lisp. |
eshell-named-command-hook | A set of functions called before a named command is invoked. |
eshell-post-command-hook | A hook run after each interactive command is invoked. |
eshell-post-rewrite-command-function | Function run after command rewriting is finished. |
eshell-post-rewrite-command-hook | A hook run after command rewriting is finished. |
eshell-pre-command-hook | A hook run before each interactive command is invoked. |
eshell-pre-rewrite-command-hook | A hook run before command rewriting begins. |
eshell-prefer-lisp-functions | If non-nil, prefer Lisp functions to external commands. |
eshell-prepare-command-hook | A set of functions called to prepare a named command. |
eshell-rewrite-command-hook | A set of functions used to rewrite the command argument. |
eshell-subcommand-bindings | A list of ‘let’ bindings for subcommand environments. |