* doc/misc/tramp.texi: Index more user options.
[emacs.git] / doc / misc / eshell.texi
blob43f8cd6381129e136fa9093c5ac1b789e86f80c9
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename ../../info/eshell.info
4 @settitle Eshell: The Emacs Shell
5 @include docstyle.texi
6 @defindex cm
7 @synindex vr fn
8 @c %**end of header
10 @copying
11 This manual is for Eshell, the Emacs shell.
13 Copyright @copyright{} 1999--2018 Free Software Foundation, Inc.
15 @quotation
16 Permission is granted to copy, distribute and/or modify this document
17 under the terms of the GNU Free Documentation License, Version 1.3 or
18 any later version published by the Free Software Foundation; with no
19 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
20 and with the Back-Cover Texts as in (a) below.  A copy of the license
21 is included in the section entitled ``GNU Free Documentation License''.
23 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
24 modify this GNU manual.''
25 @end quotation
26 @end copying
28 @dircategory Emacs misc features
29 @direntry
30 * Eshell: (eshell).             A command shell implemented in Emacs Lisp.
31 @end direntry
33 @titlepage
34 @sp 4
35 @c The title is printed in a large font.
36 @center @titlefont{User's Guide}
37 @sp 1
38 @center @titlefont{to}
39 @sp 1
40 @center @titlefont{Eshell: The Emacs Shell}
41 @ignore
42 @sp 2
43 @center release 2.4
44 @c -release-
45 @end ignore
46 @sp 3
47 @center John Wiegley & Aidan Gauland
48 @c -date-
50 @page
51 @vskip 0pt plus 1filll
52 @insertcopying
53 @end titlepage
55 @contents
57 @c ================================================================
58 @c                   The real text starts here
59 @c ================================================================
61 @ifnottex
62 @node Top
63 @top Eshell
65 Eshell is a shell-like command interpreter implemented in Emacs Lisp.
66 It invokes no external processes except for those requested by the
67 user.  It is intended to be an alternative to the IELM (@pxref{Lisp Interaction, Emacs Lisp Interaction, , emacs, The Emacs Editor})
68 REPL for Emacs @emph{and} with an interface similar to command shells
69 such as @command{bash}, @command{zsh}, @command{rc}, or
70 @command{4dos}.
71 @c This manual is updated to release 2.4 of Eshell.
73 @insertcopying
74 @end ifnottex
76 @menu
77 * Introduction::             A brief introduction to the Emacs Shell.
78 * Commands::
79 * Expansion::
80 * Input/Output::
81 * Extension modules::
82 * Bugs and ideas::              Known problems, and future ideas.
83 * GNU Free Documentation License:: The license for this documentation.
84 * Concept Index::
85 * Function and Variable Index::
86 * Command Index::
87 @ignore
88 * Key Index::
89 @end ignore
90 @end menu
92 @node Introduction
93 @chapter Introduction
94 @section What is Eshell?
95 @cindex what is Eshell?
96 @cindex Eshell, what it is
98 Eshell is a @dfn{command shell} written in Emacs Lisp.  Everything it
99 does, it uses Emacs's facilities to do.  This means that Eshell is as
100 portable as Emacs itself.  It also means that cooperation with Lisp code
101 is natural and seamless.
103 What is a command shell?  To properly understand the role of a shell,
104 it's necessary to visualize what a computer does for you.  Basically, a
105 computer is a tool; in order to use that tool, you must tell it what to
106 do---or give it ``commands.''  These commands take many forms, such as
107 clicking with a mouse on certain parts of the screen.  But that is only
108 one form of command input.
110 By far the most versatile way to express what you want the computer to
111 do is by using an abbreviated language called @dfn{script}.  In
112 script, instead of telling the computer, ``list my files, please'',
113 one writes a standard abbreviated command word---@samp{ls}.  Typing
114 @samp{ls} in a command shell is a script way of telling the computer
115 to list your files.@footnote{This is comparable to viewing the
116 contents of a folder using a graphical display.}
118 The real flexibility of this approach is apparent only when you realize
119 that there are many, many different ways to list files.  Perhaps you
120 want them sorted by name, sorted by date, in reverse order, or grouped
121 by type.  Most graphical browsers have simple ways to express this.  But
122 what about showing only a few files, or only files that meet a certain
123 criteria?  In very complex and specific situations, the request becomes
124 too difficult to express using a mouse or pointing device.  It is just
125 these kinds of requests that are easily solved using a command shell.
127 For example, what if you want to list every Word file on your hard
128 drive, larger than 100 kilobytes in size, and which hasn't been looked
129 at in over six months?  That is a good candidate list for deletion, when
130 you go to clean up your hard drive.  But have you ever tried asking your
131 computer for such a list?  There is no way to do it!  At least, not
132 without using a command shell.
134 The role of a command shell is to give you more control over what your
135 computer does for you.  Not everyone needs this amount of control, and
136 it does come at a cost: Learning the necessary script commands to
137 express what you want done.  A complicated query, such as the example
138 above, takes time to learn.  But if you find yourself using your
139 computer frequently enough, it is more than worthwhile in the long run.
140 Any tool you use often deserves the time spent learning to master it.
141 @footnote{For the understandably curious, here is what that command
142 looks like: But don't let it fool you; once you know what's going on,
143 it's easier than it looks: @code{ls -lt **/*.doc(Lk+50aM+5)}.}
145 @menu
146 * Contributors to Eshell::      People who have helped out!
147 @end menu
149 @node Contributors to Eshell
150 @section Contributors to Eshell
151 @cindex contributors
152 @cindex authors
154 Contributions to Eshell are welcome.  I have limited time to work on
155 this project, but I will gladly add any code you contribute to me to
156 this package.
158 The following persons have made contributions to Eshell.
160 @itemize @bullet
161 @item
162 Eli Zaretskii made it possible for Eshell to run without requiring
163 asynchronous subprocess support.  This is important for MS-DOS, which
164 does not have such support.
166 @item
167 Miles Bader contributed many fixes during the port to Emacs 21.
169 @item
170 Stefan Monnier fixed the things which bothered him, which of course made
171 things better for all.
173 @item
174 Gerd Moellmann also helped to contribute bug fixes during the initial
175 integration with Emacs 21.
177 @item
178 Alex Schroeder contributed code for interactively querying the user
179 before overwriting files.
181 @item
182 Sudish Joseph helped with some XEmacs compatibility issues.
183 @end itemize
185 Apart from these, a lot of people have sent suggestions, ideas,
186 requests, bug reports and encouragement.  Thanks a lot!  Without you
187 there would be no new releases of Eshell.
189 @node Commands
190 @chapter Commands
192 In a command shell, everything is done by invoking commands.  This
193 chapter covers command invocations in Eshell, including the command
194 history and invoking commands in a script file.
196 @menu
197 * Invocation::
198 * Arguments::
199 * Built-ins::
200 * Variables::
201 * Aliases::
202 * History::
203 * Completion::
204 * for loop::
205 * Scripts::
206 @end menu
208 @node Invocation
209 @section Invocation
210 Unlike regular system shells, Eshell never invokes kernel functions
211 directly, such as @code{exec(3)}.  Instead, it uses the Lisp functions
212 available in the Emacs Lisp library.  It does this by transforming the
213 input line into a callable Lisp form.@footnote{To see the Lisp form that will be invoked, type: @samp{eshell-parse-command "echo hello"}}
215 The command can be either an Elisp function or an external command.
216 Eshell looks first for an @ref{Aliases, alias} with the same name as the
217 command, then a @ref{Built-ins, built-in command} or a function with the
218 same name; if there is no match, it then tries to execute it as an
219 external command.
221 The semicolon (@code{;}) can be used to separate multiple command
222 invocations on a single line.  A command invocation followed by an
223 ampersand (@code{&}) will be run in the background.  Eshell has no job
224 control, so you can not suspend or background the current process, or
225 bring a background process into the foreground.  That said, background
226 processes invoked from Eshell can be controlled the same way as any
227 other background process in Emacs.
229 @node Arguments
230 @section Arguments
231 Command arguments are passed to the functions as either strings or
232 numbers, depending on what the parser thinks they look like.  If you
233 need to use a function that takes some other data type, you will need to
234 call it in an Elisp expression (which can also be used with
235 @ref{Expansion, expansions}).  As with other shells, you can
236 escape special characters and spaces with the backslash (@code{\}) and
237 apostrophes (@code{''}) and double quotes (@code{""}).  This is needed
238 especially for file names with special characters like pipe
239 (@code{|}), which could be part of remote file names.
241 @node Built-ins
242 @section Built-in commands
243 Several commands are built-in in Eshell.  In order to call the
244 external variant of a built-in command @code{foo}, you could call
245 @code{*foo}.  Usually, this should not be necessary.  You can check
246 what will be applied by the @code{which} command:
248 @example
249 ~ $ which ls
250 eshell/ls is a compiled Lisp function in `em-ls.el'
251 ~ $ which *ls
252 /bin/ls
253 @end example
255 If you want to discard a given built-in command, you could declare an
256 alias, @ref{Aliases}.  Example:
258 @example
259 ~ $ which sudo
260 eshell/sudo is a compiled Lisp function in `em-tramp.el'.
261 ~ $ alias sudo '*sudo $*'
262 ~ $ which sudo
263 sudo is an alias, defined as "*sudo $*"
264 @end example
266 @vindex eshell-prefer-lisp-functions
267 If you would prefer to use the built-in commands instead of the external
268 commands, set @code{eshell-prefer-lisp-functions} to @code{t}.
270 Some of the built-in commands have different behavior from their
271 external counterparts, and some have no external counterpart.  Most of
272 these will print a usage message when given the @code{--help} option.
274 @table @code
276 @item addpath
277 @cmindex addpath
278 Adds a given path or set of paths to the PATH environment variable, or,
279 with no arguments, prints the current paths in this variable.
281 @item alias
282 @cmindex alias
283 Define an alias (@pxref{Aliases}).  This does not add it to the aliases
284 file.
286 @item clear
287 @cmindex clear
288 Scrolls the contents of the eshell window out of sight, leaving a blank window.
289 If provided with an optional non-nil argument, the scrollback contents are
290 cleared instead.
292 @item date
293 @cmindex date
294 Similar to, but slightly different from, the GNU Coreutils
295 @command{date} command.
297 @item define
298 @cmindex define
299 Define a varalias.
300 @xref{Variable Aliases, , , elisp, The Emacs Lisp Reference Manual}.
302 @item diff
303 @cmindex diff
304 Use Emacs's internal @code{diff} (not to be confused with
305 @code{ediff}).  @xref{Comparing Files, , , emacs, The GNU Emacs Manual}.
307 @item grep
308 @cmindex grep
309 @itemx agrep
310 @cmindex agrep
311 @itemx egrep
312 @cmindex egrep
313 @itemx fgrep
314 @cmindex fgrep
315 @itemx glimpse
316 @cmindex glimpse
317 The @command{grep} commands are compatible with GNU @command{grep}, but
318 use Emacs's internal @code{grep} instead.
320 @item info
321 @cmindex info
322 Same as the external @command{info} command, but uses Emacs's internal
323 Info reader.
325 @item jobs
326 @cmindex jobs
327 List subprocesses of the Emacs process, if any, using the function
328 @code{list-processes}.
330 @item kill
331 @cmindex kill
332 Kill processes.  Takes a PID or a process object and an optional
333 signal specifier.
335 @item listify
336 @cmindex listify
337 Eshell version of @code{list}.  Allows you to create a list using Eshell
338 syntax, rather than Elisp syntax.  For example, @samp{listify foo bar}
339 and @code{("foo" "bar")} both evaluate to @code{("foo" "bar")}.
341 @item locate
342 @cmindex locate
343 Alias to Emacs's @code{locate} function, which simply runs the external
344 @command{locate} command and parses the results.
345 @xref{Dired and Find, , , emacs, The GNU Emacs Manual}.
347 @item make
348 @cmindex make
349 Run @command{make} through @code{compile}.
350 @xref{Compilation, , , emacs, The GNU Emacs Manual}.
352 @item occur
353 @cmindex occur
354 Alias to Emacs's @code{occur}.
355 @xref{Other Repeating Search, , , emacs, The GNU Emacs Manual}.
357 @item printnl
358 @cmindex printnl
359 Print the arguments separated by newlines.
361 @item cd
362 @cmindex cd
363 This command changes the current working directory.  Usually, it is
364 invoked as @samp{cd foo} where @file{foo} is the new working directory.
365 But @command{cd} knows about a few special arguments:
367 When it receives no argument at all, it changes to the home directory.
369 Giving the command @samp{cd -} changes back to the previous working
370 directory (this is the same as @samp{cd $-}).
372 The command @samp{cd =} shows the directory stack.  Each line is
373 numbered.
375 With @samp{cd =foo}, Eshell searches the directory stack for a directory
376 matching the regular expression @samp{foo} and changes to that
377 directory.
379 With @samp{cd -42}, you can access the directory stack by number.
381 @item su
382 @cmindex su
383 @itemx sudo
384 @cmindex sudo
385 Uses TRAMP's @command{su} or @command{sudo} method @pxref{Inline methods, , , tramp}
386 to run a command via @command{su} or @command{sudo}.  These commands
387 are in the eshell-tramp module, which is disabled by default.
389 @end table
391 @subsection Built-in variables
392 Eshell knows a few built-in variables:
394 @table @code
396 @item $+
397 @vindex $+
398 This variable always contains the current working directory.
400 @item $-
401 @vindex $-
402 This variable always contains the previous working directory (the
403 current working directory from before the last @code{cd} command).
405 @item $_
406 @vindex $_
407 It refers to the last argument of the last command.
409 @item $$
410 @vindex $$
411 This is the result of the last command.  In case of an external
412 command, it is @code{t} or @code{nil}.
414 @item $?
415 @vindex $?
416 This variable contains the exit code of the last command (0 or 1 for
417 Lisp functions, based on successful completion).
419 @end table
421 @ref{Aliases} for the built-in variables @samp{$*}, @samp{$1},
422 @samp{$2}, @dots{}, in alias definitions.
424 @node Variables
425 @section Variables
426 Since Eshell is just an Emacs REPL@footnote{Read-Eval-Print Loop}, it
427 does not have its own scope, and simply stores variables the same you
428 would in an Elisp program.  Eshell provides a command version of
429 @code{setq} for convenience.
431 @node Aliases
432 @section Aliases
434 @vindex $*
435 Aliases are commands that expand to a longer input line.  For example,
436 @command{ll} is a common alias for @code{ls -l}, and would be defined
437 with the command invocation @kbd{alias ll 'ls -l $*'}; with this defined,
438 running @samp{ll foo} in Eshell will actually run @samp{ls -l foo}.
439 Aliases defined (or deleted) by the @command{alias} command are
440 automatically written to the file named by @code{eshell-aliases-file},
441 which you can also edit directly (although you will have to manually
442 reload it).
444 @vindex $1, $2, @dots{}
445 Note that unlike aliases in Bash, arguments must be handled
446 explicitly.  Typically the alias definition would end in @samp{$*} to
447 pass all arguments along.  More selective use of arguments via
448 @samp{$1}, @samp{$2}, etc., is also possible.  For example,
449 @kbd{alias mcd 'mkdir $1 && cd $1'} would cause @kbd{mcd foo} to
450 create and switch to a directory called @samp{foo}.
452 @node History
453 @section History
454 @cmindex history
455 The @samp{history} command shows all commands kept in the history ring
456 as numbered list.  If the history ring contains
457 @code{eshell-history-size} commands, those numbers change after every
458 command invocation, therefore the @samp{history} command shall be
459 applied before using the expansion mechanism with history numbers.
461 The n-th entry of the history ring can be applied with the @samp{!n}
462 command.  If @code{n} is negative, the entry is counted from the end
463 of the history ring.
465 @samp{!foo} expands to the last command beginning with @code{foo}, and
466 @samp{!?foo} to the last command containing @code{foo}.  The n-th
467 argument of the last command beginning with @code{foo} is accessible
468 by @code{!foo:n}.
470 The history ring is loaded from a file at the start of every session,
471 and written back to the file at the end of every session.  The file path
472 is specified in @code{eshell-history-file-name}.  Unlike other shells,
473 such as Bash, Eshell can not be configured to keep a history ring of a
474 different size than that of the history file.
476 Since the default buffer navigation and searching key-bindings are
477 still present in the Eshell buffer, the commands for history
478 navigation and searching are bound to different keys:
480 @table @kbd
481 @item M-r
482 @itemx M-s
483 History I-search.
485 @item M-p
486 @itemx M-n
487 Previous and next history line.  If there is anything on the input
488 line when you run these commands, they will instead jump to the
489 previous or next line that begins with that string.
490 @end table
492 @node Completion
493 @section Completion
494 Eshell uses the pcomplete package for programmable completion, similar
495 to that of other command shells.  Argument completion differs depending
496 on the preceding command: for example, possible completions for
497 @command{rmdir} are only directories, while @command{rm} completions can
498 be directories @emph{and} files.  Eshell provides predefined completions
499 for the built-in functions and some common external commands, and you
500 can define your own for any command.
502 Eshell completion also works for lisp forms and glob patterns. If the
503 point is on a lisp form, then @key{TAB} will behave similarly to completion
504 in @code{elisp-mode} and @code{lisp-interaction-mode}.  For glob
505 patterns, If there are few enough possible completions of the patterns,
506 they will be cycled when @key{TAB} is pressed, otherwise it will be removed
507 from the input line and the possible completions will be listed.
509 If you want to see the entire list of possible completions when it's
510 below the cycling threshold, press @kbd{M-?}.
512 @subsection pcomplete
513 Pcomplete, short for programmable completion, is the completion
514 library originally written for Eshell, but usable for command
515 completion@footnote{Command completion as opposed to code completion,
516 which is a beyond the scope of pcomplete.}  in other modes.
518 Completions are defined as functions (with @code{defun}) named
519 @code{pcomplete/COMMAND}, where @code{COMMAND} is the name of the
520 command for which this function provides completions; you can also name
521 the function @code{pcomplete/MAJOR-MODE/COMMAND} to define completions
522 for a specific major mode.
524 @node for loop
525 @section @code{for} loop
526 Because Eshell commands can not (easily) be combined with lisp forms,
527 Eshell provides a command-oriented @command{for}-loop for convenience.
528 The syntax is as follows:
530 @example
531 @code{for VAR in TOKENS @{ command invocation(s) @}}
532 @end example
534 where @samp{TOKENS} is a space-separated sequence of values of
535 @var{VAR} for each iteration.  This can even be the output of a
536 command if @samp{TOKENS} is replaced with @samp{@{ command invocation @}}.
538 @node Scripts
539 @section Scripts
540 @cmindex source
541 @fnindex eshell-source-file
542 You can run Eshell scripts much like scripts for other shells; the main
543 difference is that since Eshell is not a system command, you have to run
544 it from within Emacs.  An Eshell script is simply a file containing a
545 sequence of commands, as with almost any other shell script.  Scripts
546 are invoked from Eshell with @command{source}, or from anywhere in Emacs
547 with @code{eshell-source-file}.
549 @cmindex .
550 If you wish to load a script into your @emph{current} environment,
551 rather than in a subshell, use the @code{.} command.
553 @node Expansion
554 @chapter Expansion
555 Expansion in a command shell is somewhat like macro expansion in macro
556 parsers (such as @command{cpp} and @command{m4}), but in a command
557 shell, they are less often used for constants, and usually for using
558 variables and string manipulation.@footnote{Eshell has no
559 string-manipulation expansions because the Elisp library already
560 provides many functions for this.}  For example, @code{$var} on a line
561 expands to the value of the variable @code{var} when the line is
562 executed.  Expansions are usually passed as arguments, but may also be
563 used as commands.@footnote{E.g., entering just @samp{$var} at the prompt
564 is equivalent to entering the value of @code{var} at the prompt.}
566 @menu
567 * Dollars Expansion::
568 * Globbing::
569 @end menu
571 @node Dollars Expansion
572 @section Dollars Expansion
573 Eshell has different @code{$} expansion syntax from other shells.  There
574 are some similarities, but don't let these lull you into a false sense
575 of familiarity.
577 @table @code
579 @item $var
580 Expands to the value bound to @code{var}.  This is the main way to use
581 variables in command invocations.
583 @item $#var
584 Expands to the length of the value bound to @code{var}.  Raises an error
585 if the value is not a sequence
586 (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The Emacs Lisp Reference Manual}).
588 @item $(lisp)
589 Expands to the result of evaluating the S-expression @code{(lisp)}.  On
590 its own, this is identical to just @code{(lisp)}, but with the @code{$},
591 it can be used in a string, such as @samp{/some/path/$(lisp).txt}.
593 @item $@{command@}
594 Returns the output of @command{command}, which can be any valid Eshell
595 command invocation, and may even contain expansions.
597 @item $var[i]
598 Expands to the @code{i}th element of the value bound to @code{var}.  If
599 the value is a string, it will be split at whitespace to make it a list.
600 Again, raises an error if the value is not a sequence.
602 @item $var[: i]
603 As above, but now splitting occurs at the colon character.
605 @item $var[: i j]
606 As above, but instead of returning just a string, it now returns a list
607 of two strings.  If the result is being interpolated into a larger
608 string, this list will be flattened into one big string, with each
609 element separated by a space.
611 @item $var["\\\\" i]
612 Separate on backslash characters.  Actually, the first argument -- if it
613 doesn't have the form of a number, or a plain variable name -- can be
614 any regular expression.  So to split on numbers, use @samp{$var["[0-9]+" 10 20]}.
616 @item $var[hello]
617 Calls @code{assoc} on @code{var} with @code{"hello"}, expecting it to be
618 an alist (@pxref{Association List Type, Association Lists, , elisp,
619 The Emacs Lisp Reference Manual}).
621 @item $#var[hello]
622 Returns the length of the cdr of the element of @code{var} who car is equal
623 to @code{"hello"}.
625 @end table
627 @node Globbing
628 @section Globbing
629 Eshell's globbing syntax is very similar to that of Zsh.  Users coming
630 from Bash can still use Bash-style globbing, as there are no
631 incompatibilities.  Most globbing is pattern-based expansion, but there
632 is also predicate-based expansion.  See
633 @ref{Filename Generation, , , zsh, The Z Shell Manual}
634 for full syntax.  To customize the syntax and behavior of globbing in
635 Eshell see the Customize@footnote{@xref{Easy Customization, , , emacs,
636 The GNU Emacs Manual}.}
637 groups ``eshell-glob'' and ``eshell-pred''.
639 @node Input/Output
640 @chapter Input/Output
641 Since Eshell does not communicate with a terminal like most command
642 shells, IO is a little different.
644 @section Visual Commands
645 If you try to run programs from within Eshell that are not
646 line-oriented, such as programs that use ncurses, you will just get
647 garbage output, since the Eshell buffer is not a terminal emulator.
648 Eshell solves this problem by running such programs in Emacs's
649 terminal emulator.
651 Programs that need a terminal to display output properly are referred
652 to in this manual as ``visual commands,'' because they are not simply
653 line-oriented.  You must tell Eshell which commands are visual, by
654 adding them to @code{eshell-visual-commands}; for commands that are
655 visual for only certain @emph{sub}-commands -- e.g., @samp{git log} but
656 not @samp{git status} -- use @code{eshell-visual-subcommands}; and for
657 commands that are visual only when passed certain options, use
658 @code{eshell-visual-options}.
660 Caution: Some tools such as Git use the pager @samp{less} by default
661 to paginate their output but call it with its @samp{-F} option.  This
662 option causes @samp{less} to echo the output instead of paginating it
663 if the output is less than one page long.  This causes undesirable
664 behavior if, e.g., @samp{git diff}, is defined as a visual subcommand.
665 It'll work if the output is big enough and fail if it is less than one
666 page long.  If that occurs to you, search for configuration options
667 for calling @samp{less} without the @samp{-F} option.  For Git, you
668 can do that using @samp{git config --global core.pager 'less -+F'}.
670 @vindex eshell-destroy-buffer-when-process-dies
671 If you want the buffers created by visual programs killed when the
672 program exits, customize the variable
673 @code{eshell-destroy-buffer-when-process-dies} to a non-@code{nil}
674 value; the default is @code{nil}.
676 @section Redirection
677 Redirection is mostly the same in Eshell as it is in other command
678 shells.  The output redirection operators @code{>} and @code{>>} as
679 well as pipes are supported, but there is not yet any support for
680 input redirection.  Output can also be redirected to buffers, using
681 the @code{>>>} redirection operator, and Elisp functions, using
682 virtual devices.
684 The buffer redirection operator, @code{>>>}, expects a buffer object
685 on the right-hand side, into which it inserts the output of the
686 left-hand side.  e.g., @samp{echo hello >>> #<buffer *scratch*>}
687 inserts the string @code{"hello"} into the @file{*scratch*} buffer.
688 The convenience shorthand variant @samp{#<@var{buffer-name}>}, as in
689 @samp{#<*scratch*>}, is also accepted.
691 @code{eshell-virtual-targets} is a list of mappings of virtual device
692 names to functions.  Eshell comes with two virtual devices:
693 @file{/dev/kill}, which sends the text to the kill ring, and
694 @file{/dev/clip}, which sends text to the clipboard.
696 You can, of course, define your own virtual targets.  They are defined
697 by adding a list of the form @samp{("/dev/name" @var{function} @var{mode})} to
698 @code{eshell-virtual-targets}.  The first element is the device name;
699 @var{function} may be either a lambda or a function name.  If
700 @var{mode} is @code{nil}, then the function is the output function; if it is
701 non-@code{nil}, then the function is passed the redirection mode as a
702 symbol--@code{overwrite} for @code{>}, @code{append} for @code{>>}, or
703 @code{insert} for @code{>>>}--and the function is expected to return
704 the output function.
706 The output function is called once on each line of output until
707 @code{nil} is passed, indicating end of output.
709 @node Extension modules
710 @chapter Extension modules
711 Eshell provides a facility for defining extension modules so that they
712 can be disabled and enabled without having to unload and reload them,
713 and to provide a common parent Customize group for the
714 modules.@footnote{ERC provides a similar module facility.}  An Eshell
715 module is defined the same as any other library but one requirement: the
716 module must define a Customize@footnote{@xref{Customization, , ,
717 elisp, The Emacs Lisp Reference Manual}.}
718 group using @code{eshell-defgroup} (in place of @code{defgroup}) with
719 @code{eshell-module} as the parent group.@footnote{If the module has
720 no user-customizable options, then there is no need to define it as an
721 Eshell module.}  You also need to load the following as shown:
723 @example
724 (eval-when-compile
725   (require 'cl-lib)
726   (require 'esh-mode)
727   (require 'eshell))
729 (require 'esh-util)
730 @end example
732 @menu
733 * Writing a module::
734 * Module testing::
735 * Directory handling::
736 * Key rebinding::
737 * Smart scrolling::
738 * Terminal emulation::
739 @end menu
741 @node Writing a module
742 @section Writing a module
744 @node Module testing
745 @section Module testing
747 @node Directory handling
748 @section Directory handling
750 @node Key rebinding
751 @section Key rebinding
753 @node Smart scrolling
754 @section Smart scrolling
756 @node Terminal emulation
757 @section Terminal emulation
759 @node Bugs and ideas
760 @chapter Bugs and ideas
761 @cindex reporting bugs and ideas
762 @cindex bugs, how to report them
763 @cindex author, how to reach
764 @cindex email to the author
765 @cindex FAQ
766 @cindex problems, list of common
767 @cindex known bugs
768 @cindex bugs, known
770 If you find a bug or misfeature, don't hesitate to report it, by
771 using @kbd{M-x report-emacs-bug}.  The same applies to feature requests.
772 It is best to discuss one thing at a time.  If you find several
773 unrelated bugs, please report them separately.
775 @ignore
776 If you have ideas for improvements, or if you have written some
777 extensions to this package, I would like to hear from you.  I hope you
778 find this package useful!
779 @end ignore
781 Below is a list of some known problems with Eshell version 2.4.2,
782 which is the version included with Emacs 22.
784 @table @asis
785 @item Documentation incomplete
787 @item Differentiate between aliases and functions
789 Allow for a Bash-compatible syntax, such as:
791 @example
792 alias arg=blah
793 function arg () @{ blah $* @}
794 @end example
796 @item @samp{for i in 1 2 3 @{ grep -q a b && *echo has it @} | wc -l} outputs result after prompt
798 In fact, piping to a process from a looping construct doesn't work in
799 general.  If I change the call to @code{eshell-copy-handles} in
800 @code{eshell-rewrite-for-command} to use @code{eshell-protect}, it seems
801 to work, but the output occurs after the prompt is displayed.  The whole
802 structured command thing is too complicated at present.
804 @item Error with @command{bc} in @code{eshell-test}
806 On some XEmacs system, the subprocess interaction test fails
807 inexplicably, although @command{bc} works fine at the command prompt.
809 @item Eshell does not delete @file{*Help*} buffers in XEmacs 21.1.8+
811 In XEmacs 21.1.8, the @file{*Help*} buffer has been renamed such that
812 multiple instances of the @file{*Help*} buffer can exist.
814 @item Pcomplete sometimes gets stuck
816 You press @key{TAB}, but no completions appear, even though the
817 directory has matching files.  This behavior is rare.
819 @item @samp{grep python $<rpm -qa>} doesn't work, but using @samp{*grep} does
821 This happens because the @code{grep} Lisp function returns immediately,
822 and then the asynchronous @command{grep} process expects to examine the
823 temporary file, which has since been deleted.
825 @item Problem with C-r repeating text
827 If the text @emph{before point} reads "./run", and you type @kbd{C-r r u
828 n}, it will repeat the line for every character typed.
830 @item Backspace doesn't scroll back after continuing (in smart mode)
832 Hitting space during a process invocation, such as @command{make}, will
833 cause it to track the bottom of the output; but backspace no longer
834 scrolls back.
836 @item It's not possible to fully @code{unload-feature} Eshell
838 @item Menu support was removed, but never put back
840 @item Using C-p and C-n with rebind gets into a locked state
842 This happened a few times in Emacs 21, but has been irreproducible
843 since.
845 @item If an interactive process is currently running, @kbd{M-!} doesn't work
847 @item Use a timer instead of @code{sleep-for} when killing child processes
849 @item Piping to a Lisp function is not supported
851 Make it so that the Lisp command on the right of the pipe is repeatedly
852 called with the input strings as arguments.  This will require changing
853 @code{eshell-do-pipeline} to handle non-process targets.
855 @item Input redirection is not supported
857 See the above entry.
859 @item Problem running @command{less} without arguments on Windows
861 The result in the Eshell buffer is:
863 @example
864 Spawning child process: invalid argument
865 @end example
867 Also a new @command{less} buffer was created with nothing in it@dots{}
868 (presumably this holds the output of @command{less}).
870 If @command{less.exe} is invoked from the Eshell command line, the
871 expected output is written to the buffer.
873 Note that this happens on NT-Emacs 20.6.1 on Windows 2000. The term.el
874 package and the supplied shell both use the @command{cmdproxy} program
875 for running shells.
877 @item Implement @samp{-r}, @samp{-n} and @samp{-s} switches for @command{cp}
879 @item Make @kbd{M-5 M-x eshell} switch to ``*eshell<5>*'', creating if need be
881 @item @samp{mv @var{dir} @var{file}.tar} does not remove directories
883 This is because the tar option --remove-files doesn't do so.  Should it
884 be Eshell's job?
886 @item Bind @code{standard-output} and @code{standard-error}
888 This would be so that if a Lisp function calls @code{print}, everything
889 will happen as it should (albeit slowly).
891 @item When an extension module fails to load, @samp{cd /} gives a Lisp error
893 @item If a globbing pattern returns one match, should it be a list?
895 @item Make sure syntax table is correct in Eshell mode
897 So that @kbd{M-DEL} acts in a predictable manner, etc.
899 @item Allow all Eshell buffers to share the same history and list-dir
901 @item There is a problem with script commands that output to @file{/dev/null}
903 If a script file, somewhere in the middle, uses @samp{> /dev/null},
904 output from all subsequent commands is swallowed.
906 @item Split up parsing of text after @samp{$} in @file{esh-var.el}
908 Make it similar to the way that @file{esh-arg.el} is structured.
909 Then add parsing of @samp{$[?\n]}.
911 @item After pressing @kbd{M-RET}, redisplay before running the next command
913 @item Argument predicates and modifiers should work anywhere in a path
915 @example
916 /usr/local/src/editors/vim $ vi **/CVS(/)/Root(.)
917 Invalid regexp: "Unmatched ( or \\("
918 @end example
920 With @command{zsh}, the glob above expands to all files named
921 @file{Root} in directories named @file{CVS}.
923 @item Typing @samp{echo $@{locate locate@}/bin<TAB>} results in a Lisp error
925 Perhaps it should interpolate all permutations, and make that the
926 globbing result, since otherwise hitting return here will result in
927 ``(list of filenames)/bin'', which is never valuable.  Thus, one could
928 @command{cat} only C backup files by using @samp{ls $@{identity *.c@}~}.
929 In that case, having an alias command name @command{glob} for
930 @command{identity} would be useful.
932 @item Once symbolic mode is supported for @command{umask}, implement @command{chmod} in Lisp
934 @item Create @code{eshell-expand-file-name}
936 This would use a data table to transform things such as @samp{~+},
937 @samp{...}, etc.
939 @item Abstract @file{em-smart.el} into @file{smart-scroll.el}
941 It only really needs: to be hooked onto the output filter and the
942 pre-command hook, and to have the input-end and input-start markers.
943 And to know whether the last output group was ``successful.''
945 @item Allow for fully persisting the state of Eshell
947 This would include: variables, history, buffer, input, dir stack, etc.
949 @item Implement D as an argument predicate
951 It means that files beginning with a dot should be included in the
952 glob match.
954 @item A comma in a predicate list should mean OR
956 At the moment, this is not supported.
958 @item Error if a glob doesn't expand due to a predicate
960 An error should be generated only if @code{eshell-error-if-no-glob} is
961 non-@code{nil}.
963 @item @samp{(+ RET SPC TAB} does not cause @code{indent-according-to-mode} to occur
965 @item Create @code{eshell-auto-accumulate-list}
967 This is a list of commands for which, if the user presses @kbd{RET}, the
968 text is staged as the next Eshell command, rather than being sent to the
969 current interactive process.
971 @item Display file and line number if an error occurs in a script
973 @item @command{wait} doesn't work with process ids at the moment
975 @item Enable the direct-to-process input code in @file{em-term.el}
977 @item Problem with repeating @samp{echo $@{find /tmp@}}
979 With smart display active, if @kbd{RET} is held down, after a while it
980 can't keep up anymore and starts outputting blank lines.  It only
981 happens if an asynchronous process is involved@dots{}
983 I think the problem is that @code{eshell-send-input} is resetting the
984 input target location, so that if the asynchronous process is not done
985 by the time the next @kbd{RET} is received, the input processor thinks
986 that the input is meant for the process; which, when smart display is
987 enabled, will be the text of the last command line!  That is a bug in
988 itself.
990 In holding down @kbd{RET} while an asynchronous process is running,
991 there will be a point in between termination of the process, and the
992 running of @code{eshell-post-command-hook}, which would cause
993 @code{eshell-send-input} to call @code{eshell-copy-old-input}, and then
994 process that text as a command to be run after the process.  Perhaps
995 there should be a way of killing pending input between the death of the
996 process, and the @code{post-command-hook}.
998 @item Allow for a more aggressive smart display mode
1000 Perhaps toggled by a command, that makes each output block a smart
1001 display block.
1003 @item Create more meta variables
1005 @table @samp
1006 @item $!
1007 The reason for the failure of the last disk command, or the text of the
1008 last Lisp error.
1010 @item $=
1011 A special associate array, which can take references of the form
1012 @samp{$=[REGEXP]}.  It indexes into the directory ring.
1013 @end table
1015 @item Eshell scripts can't execute in the background
1017 @item Support zsh's ``Parameter Expansion'' syntax, i.e., @samp{$@{@var{name}:-@var{val}@}}
1019 @item Write an @command{info} alias that can take arguments
1021 So that the user can enter @samp{info chmod}, for example.
1023 @item Create a mode @code{eshell-browse}
1025 It would treat the Eshell buffer as a outline.  Collapsing the outline
1026 hides all of the output text.  Collapsing again would show only the
1027 first command run in each directory
1029 @item Allow other revisions of a file to be referenced using @samp{file@{rev@}}
1031 This would be expanded by @code{eshell-expand-file-name} (see above).
1033 @item Print ``You have new mail'' when the ``Mail'' icon is turned on
1035 @item Implement @kbd{M-|} for Eshell
1037 @item Implement input redirection
1039 If it's a Lisp function, input redirection implies @command{xargs} (in a
1040 way@dots{}).  If input redirection is added, also update the
1041 @code{file-name-quote-list}, and the delimiter list.
1043 @item Allow @samp{#<@var{word} @var{arg}>} as a generic syntax
1045 With the handling of @emph{word} specified by an
1046 @code{eshell-special-alist}.
1048 @item In @code{eshell-eval-using-options}, allow a @code{:complete} tag
1050 It would be used to provide completion rules for that command.  Then the
1051 macro will automagically define the completion function.
1053 @item For @code{eshell-command-on-region}, apply redirections to the result
1055 So that @samp{+ > 'blah} would cause the result of the @code{+} (using
1056 input from the current region) to be inserting into the symbol
1057 @code{blah}.
1059 If an external command is being invoked, the input is sent as standard
1060 input, as if a @samp{cat <region> |} had been invoked.
1062 If a Lisp command, or an alias, is invoked, then if the line has no
1063 newline characters, it is divided by whitespace and passed as arguments
1064 to the Lisp function.  Otherwise, it is divided at the newline
1065 characters.  Thus, invoking @code{+} on a series of numbers will add
1066 them; @code{min} would display the smallest figure, etc.
1068 @item Write @code{eshell-script-mode} as a minor mode
1070 It would provide syntax, abbrev, highlighting and indenting support like
1071 @code{emacs-lisp-mode} and @code{shell-mode}.
1073 @item In the history mechanism, finish the Bash-style support
1075 This means @samp{!n}, @samp{!#}, @samp{!:%}, and @samp{!:1-} as separate
1076 from @samp{!:1*}.
1078 @item Support the -n command line option for @command{history}
1080 @item Implement @command{fc} in Lisp
1082 @item Specifying a frame as a redirection target should imply the currently active window's buffer
1084 @item Implement @samp{>@var{func-or-func-list}}
1086 This would allow for an ``output translators'', that take a function to
1087 modify output with, and a target.  Devise a syntax that works well with
1088 pipes, and can accommodate multiple functions (i.e., @samp{>'(upcase
1089 regexp-quote)} or @samp{>'upcase}).
1091 @item Allow Eshell to read/write to/from standard input and output
1093 This would be optional, rather than always using the Eshell buffer.
1094 This would allow it to be run from the command line (perhaps).
1096 @item Write a @command{help} command
1098 It would call subcommands with @option{--help}, or @option{-h} or
1099 @option{/?}, as appropriate.
1101 @item Implement @command{stty} in Lisp
1103 @item Support @command{rc}'s matching operator, e.g., @samp{~ (@var{list}) @var{regexp}}
1105 @item Implement @command{bg} and @command{fg} as editors of @code{eshell-process-list}
1107 Using @command{bg} on a process that is already in the background does
1108 nothing.  Specifying redirection targets replaces (or adds) to the list
1109 current being used.
1111 @item Have @command{jobs} print only the processes for the current shell
1113 @item How can Eshell learn if a background process has requested input?
1115 @item Support @samp{2>&1} and @samp{>&} and @samp{2>} and @samp{|&}
1117 The syntax table for parsing these should be customizable, such that the
1118 user could change it to use rc syntax: @samp{>[2=1]}.
1120 @item Allow @samp{$_[-1]}, which would indicate the last element of the array
1122 @item Make @samp{$x[*]} equal to listing out the full contents of @samp{x}
1124 Return them as a list, so that @samp{$_[*]} is all the arguments of the
1125 last command.
1127 @item Copy ANSI code handling from @file{term.el} into @file{em-term.el}
1129 Make it possible for the user to send char-by-char to the underlying
1130 process.  Ultimately, I should be able to move away from using term.el
1131 altogether, since everything but the ANSI code handling is already part
1132 of Eshell.  Then, things would work correctly on MS-Windows as well
1133 (which doesn't have @file{/bin/sh}, although @file{term.el} tries to use
1134 it).
1136 @item Make the shell spawning commands be visual
1138 That is, make (@command{su}, @command{bash}, @command{telnet},
1139 @command{rlogin}, @command{rsh}, etc.)@: be part of
1140 @code{eshell-visual-commands}.  The only exception is if the shell is
1141 being used to invoke a single command.  Then, the behavior should be
1142 based on what that command is.
1144 @item Create a smart viewing command named @command{open}
1146 This would search for some way to open its argument (similar to opening
1147 a file in the Windows Explorer).
1149 @item Alias @command{read} to be the same as @command{open}, only read-only
1151 @item Write a @command{tail} command which uses @code{view-file}
1153 It would move point to the end of the buffer, and then turns on
1154 auto-revert mode in that buffer at frequent intervals---and a
1155 @command{head} alias which assumes an upper limit of
1156 @code{eshell-maximum-line-length} characters per line.
1158 @item Make @command{dgrep} load @code{dired}, mark everything, then invoke @code{dired-do-search}
1160 @item Write @file{mesh.c}
1162 This would run Emacs with the appropriate arguments to invoke Eshell
1163 only.  That way, it could be listed as a login shell.
1165 @item Use an intangible @code{PS2} string for multi-line input prompts
1167 @item Auto-detect when a command is visual, by checking @code{TERMCAP} usage
1169 @item The first keypress after @kbd{M-x watson} triggers
1170 @code{eshell-send-input}
1172 @item Make @kbd{/} electric
1174 So that it automatically expands and corrects pathnames.  Or make
1175 pathname completion for Pcomplete auto-expand @samp{/u/i/std<TAB>} to
1176 @samp{/usr/include/std<TAB>}.
1178 @item Write the @command{pushd} stack to disk along with @code{last-dir-ring}
1180 @item Add options to @code{eshell/cat} which would allow it to sort and uniq
1182 @item Implement @command{wc} in Lisp
1184 Add support for counting sentences, paragraphs, pages, etc.
1186 @item Once piping is added, implement @command{sort} and @command{uniq} in Lisp
1188 @item Implement @command{touch} in Lisp
1190 @item Implement @command{comm} in Lisp
1192 @item Implement an @command{epatch} command in Lisp
1194 This would call @code{ediff-patch-file}, or @code{ediff-patch-buffer},
1195 depending on its argument.
1197 @item Have an option such that @samp{ls -l} generates a dired buffer
1199 @item Write a version of @command{xargs} based on command rewriting
1201 That is, @samp{find X | xargs Y} would be indicated using @samp{Y
1202 $@{find X@}}.  Maybe @code{eshell-do-pipelines} could be changed to
1203 perform this on-thy-fly rewriting.
1205 @item Write an alias for @command{less} that brings up a @code{view-mode} buffer
1207 Such that the user can press @key{SPC} and @key{DEL}, and then @key{q}
1208 to return to Eshell.  It would be equivalent to:
1209 @samp{X > #<buffer Y>; view-buffer #<buffer Y>}.
1211 @item Make @code{eshell-mode} as much a full citizen as @code{shell-mode}
1213 Everywhere in Emacs where @code{shell-mode} is specially noticed, add
1214 @code{eshell-mode} there.
1216 @item Permit the umask to be selectively set on a @command{cp} target
1218 @item Problem using @kbd{M-x eshell} after using @code{eshell-command}
1220 If the first thing that I do after entering Emacs is to run
1221 @code{eshell-command} and invoke @command{ls}, and then use @kbd{M-x
1222 eshell}, it doesn't display anything.
1224 @item @kbd{M-RET} during a long command (using smart display) doesn't work
1226 Since it keeps the cursor up where the command was invoked.
1228 @end table
1230 @node GNU Free Documentation License
1231 @appendix GNU Free Documentation License
1232 @include doclicense.texi
1234 @node Concept Index
1235 @unnumbered Concept Index
1237 @printindex cp
1239 @node Function and Variable Index
1240 @unnumbered Function and Variable Index
1242 @printindex fn
1244 @node Command Index
1245 @unnumbered Command Index
1247 @printindex cm
1249 @c There are no @kindex entries in this manual; avoid generating an
1250 @c empty menu.
1251 @ignore
1252 @node Key Index
1253 @unnumbered Key Index
1255 @printindex ky
1256 @end ignore
1258 @bye