Rename option to shell-command-dont-erase-buffer
[emacs.git] / doc / misc / eshell.texi
bloba7a3840aa5f426a06fde2c5849273c941314e9f2
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--2016 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 @section What Eshell is not
146 @cindex Eshell, what it is not
147 @cindex what Eshell is not
148 @cindex what isn't Eshell?
150 Eshell is @emph{not} a replacement for system shells such as
151 @command{bash} or @command{zsh}.  Use Eshell when you want to move
152 text between Emacs and external processes; if you only want to pipe
153 output from one external process to another (and then another, and so
154 on), use a system shell, because Emacs's IO system is buffer oriented,
155 not stream oriented, and is very inefficient at such tasks.  If you
156 want to write shell scripts in Eshell, don't; either write an elisp
157 library or use a system shell.
159 Some things Eshell just doesn't do well.  It fills the niche between
160 IELM and your system shell, where the peculiar use-cases lie, and it
161 is less than ideal outside that niche.
163 @menu
164 * Contributors to Eshell::      People who have helped out!
165 @end menu
167 @node Contributors to Eshell
168 @section Contributors to Eshell
169 @cindex contributors
170 @cindex authors
172 Contributions to Eshell are welcome.  I have limited time to work on
173 this project, but I will gladly add any code you contribute to me to
174 this package.
176 The following persons have made contributions to Eshell.
178 @itemize @bullet
179 @item
180 Eli Zaretskii made it possible for Eshell to run without requiring
181 asynchronous subprocess support.  This is important for MS-DOS, which
182 does not have such support.
184 @item
185 Miles Bader contributed many fixes during the port to Emacs 21.
187 @item
188 Stefan Monnier fixed the things which bothered him, which of course made
189 things better for all.
191 @item
192 Gerd Moellmann also helped to contribute bug fixes during the initial
193 integration with Emacs 21.
195 @item
196 Alex Schroeder contributed code for interactively querying the user
197 before overwriting files.
199 @item
200 Sudish Joseph helped with some XEmacs compatibility issues.
201 @end itemize
203 Apart from these, a lot of people have sent suggestions, ideas,
204 requests, bug reports and encouragement.  Thanks a lot!  Without you
205 there would be no new releases of Eshell.
207 @node Commands
208 @chapter Commands
210 In a command shell, everything is done by invoking commands.  This
211 chapter covers command invocations in Eshell, including the command
212 history and invoking commands in a script file.
214 @menu
215 * Invocation::
216 * Arguments::
217 * Built-ins::
218 * Variables::
219 * Aliases::
220 * History::
221 * Completion::
222 * for loop::
223 * Scripts::
224 @end menu
226 @node Invocation
227 @section Invocation
228 Unlike regular system shells, Eshell never invokes kernel functions
229 directly, such as @code{exec(3)}.  Instead, it uses the Lisp functions
230 available in the Emacs Lisp library.  It does this by transforming the
231 input line into a callable Lisp form.@footnote{To see the Lisp form that will be invoked, type: @samp{eshell-parse-command "echo hello"}}
233 The command can be either an Elisp function or an external command.
234 Eshell looks first for an @ref{Aliases, alias} with the same name as the
235 command, then a @ref{Built-ins, built-in command} or a function with the
236 same name; if there is no match, it then tries to execute it as an
237 external command.
239 The semicolon (@code{;}) can be used to separate multiple command
240 invocations on a single line.  A command invocation followed by an
241 ampersand (@code{&}) will be run in the background.  Eshell has no job
242 control, so you can not suspend or background the current process, or
243 bring a background process into the foreground.  That said, background
244 processes invoked from Eshell can be controlled the same way as any
245 other background process in Emacs.
247 @node Arguments
248 @section Arguments
249 Command arguments are passed to the functions as either strings or
250 numbers, depending on what the parser thinks they look like.  If you
251 need to use a function that takes some other data type, you will need to
252 call it in an Elisp expression (which can also be used with
253 @ref{Expansion, expansions}).  As with other shells, you can
254 escape special characters and spaces with the backslash (@code{\}) and
255 apostrophes (@code{''}) and double quotes (@code{""}).  This is needed
256 especially for file names with special characters like pipe
257 (@code{|}), which could be part of remote file names.
259 @node Built-ins
261 @section Built-in commands
262 Several commands are built-in in Eshell.  In order to call the
263 external variant of a built-in command @code{foo}, you could call
264 @code{*foo}.  Usually, this should not be necessary.  You can check
265 what will be applied by the @code{which} command:
267 @example
268 ~ $ which ls
269 eshell/ls is a compiled Lisp function in `em-ls.el'
270 ~ $ which *ls
271 /bin/ls
272 @end example
274 If you want to discard a given built-in command, you could declare an
275 alias, @ref{Aliases}.  Example:
277 @example
278 ~ $ which sudo
279 eshell/sudo is a compiled Lisp function in `em-unix.el'
280 ~ $ alias sudo '*sudo $*'
281 ~ $ which sudo
282 sudo is an alias, defined as "*sudo $*"
283 @end example
285 @vindex eshell-prefer-lisp-functions
286 If you would prefer to use the built-in commands instead of the external
287 commands, set @code{eshell-prefer-lisp-functions} to @code{t}.
289 Some of the built-in commands have different behavior from their
290 external counterparts, and some have no external counterpart.  Most of
291 these will print a usage message when given the @code{--help} option.
293 @table @code
295 @item addpath
296 @cmindex addpath
297 Adds a given path or set of paths to the PATH environment variable, or,
298 with no arguments, prints the current paths in this variable.
300 @item alias
301 @cmindex alias
302 Define an alias (@pxref{Aliases}).  This does not add it to the aliases
303 file.
305 @item clear
306 @cmindex clear
307 Scrolls the contents of the eshell window out of sight, leaving a blank window.
308 If provided with an optional non-nil argument, the scrollback contents are
309 cleared instead.
311 @item date
312 @cmindex date
313 Similar to, but slightly different from, the GNU Coreutils
314 @command{date} command.
316 @item define
317 @cmindex define
318 Define a varalias.
319 @xref{Variable Aliases, , , elisp, The Emacs Lisp Reference Manual}.
321 @item diff
322 @cmindex diff
323 Use Emacs's internal @code{diff} (not to be confused with
324 @code{ediff}).  @xref{Comparing Files, , , emacs, The GNU Emacs Manual}.
326 @item grep
327 @cmindex grep
328 @itemx agrep
329 @cmindex agrep
330 @itemx egrep
331 @cmindex egrep
332 @itemx fgrep
333 @cmindex fgrep
334 @itemx glimpse
335 @cmindex glimpse
336 The @command{grep} commands are compatible with GNU @command{grep}, but
337 use Emacs's internal @code{grep} instead.
339 @item info
340 @cmindex info
341 Same as the external @command{info} command, but uses Emacs's internal
342 Info reader.
344 @item jobs
345 @cmindex jobs
346 List subprocesses of the Emacs process, if any, using the function
347 @code{list-processes}.
349 @item kill
350 @cmindex kill
351 Kill processes.  Takes a PID or a process object and an optional
352 signal specifier.
354 @item listify
355 @cmindex listify
356 Eshell version of @code{list}.  Allows you to create a list using Eshell
357 syntax, rather than Elisp syntax.  For example, @samp{listify foo bar}
358 and @code{("foo" "bar")} both evaluate to @code{("foo" "bar")}.
360 @item locate
361 @cmindex locate
362 Alias to Emacs's @code{locate} function, which simply runs the external
363 @command{locate} command and parses the results.
364 @xref{Dired and Find, , , emacs, The GNU Emacs Manual}.
366 @item make
367 @cmindex make
368 Run @command{make} through @code{compile}.
369 @xref{Compilation, , , emacs, The GNU Emacs Manual}.
371 @item occur
372 @cmindex occur
373 Alias to Emacs's @code{occur}.
374 @xref{Other Repeating Search, , , emacs, The GNU Emacs Manual}.
376 @item printnl
377 @cmindex printnl
378 Print the arguments separated by newlines.
380 @item cd
381 @cmindex cd
382 This command changes the current working directory.  Usually, it is
383 invoked as @samp{cd foo} where @file{foo} is the new working directory.
384 But @command{cd} knows about a few special arguments:
386 When it receives no argument at all, it changes to the home directory.
388 Giving the command @samp{cd -} changes back to the previous working
389 directory (this is the same as @samp{cd $-}).
391 The command @samp{cd =} shows the directory stack.  Each line is
392 numbered.
394 With @samp{cd =foo}, Eshell searches the directory stack for a directory
395 matching the regular expression @samp{foo} and changes to that
396 directory.
398 With @samp{cd -42}, you can access the directory stack by number.
400 @item su
401 @cmindex su
402 @itemx sudo
403 @cmindex sudo
404 Uses TRAMP's @command{su} or @command{sudo} method @pxref{Inline methods, , , tramp}
405 to run a command via @command{su} or @command{sudo}.  These commands
406 are in the eshell-tramp module, which is disabled by default.
408 @end table
410 @subsection Built-in variables
411 Eshell knows a few built-in variables:
413 @table @code
415 @item $+
416 @vindex $+
417 This variable always contains the current working directory.
419 @item $-
420 @vindex $-
421 This variable always contains the previous working directory (the
422 current working directory from before the last @code{cd} command).
424 @item $_
425 @vindex $_
426 It refers to the last argument of the last command.
428 @item $$
429 @vindex $$
430 This is the result of the last command.  In case of an external
431 command, it is @code{t} or @code{nil}.
433 @item $?
434 @vindex $?
435 This variable contains the exit code of the last command (0 or 1 for
436 Lisp functions, based on successful completion).
438 @end table
440 @node Variables
441 @section Variables
442 Since Eshell is just an Emacs REPL@footnote{Read-Eval-Print Loop}, it
443 does not have its own scope, and simply stores variables the same you
444 would in an Elisp program.  Eshell provides a command version of
445 @code{setq} for convenience.
447 @node Aliases
448 @section Aliases
450 Aliases are commands that expand to a longer input line.  For example,
451 @command{ll} is a common alias for @code{ls -l}, and would be defined
452 with the command invocation @samp{alias ll ls -l}; with this defined,
453 running @samp{ll foo} in Eshell will actually run @samp{ls -l foo}.
454 Aliases defined (or deleted) by the @command{alias} command are
455 automatically written to the file named by @code{eshell-aliases-file},
456 which you can also edit directly (although you will have to manually
457 reload it).
459 @node History
460 @section History
461 @cmindex history
462 The @samp{history} command shows all commands kept in the history ring
463 as numbered list.  If the history ring contains
464 @code{eshell-history-size} commands, those numbers change after every
465 command invocation, therefore the @samp{history} command shall be
466 applied before using the expansion mechanism with history numbers.
468 The n-th entry of the history ring can be applied with the @samp{!n}
469 command.  If @code{n} is negative, the entry is counted from the end
470 of the history ring.
472 @samp{!foo} expands to the last command beginning with @code{foo}, and
473 @samp{!?foo} to the last command containing @code{foo}.  The n-th
474 argument of the last command beginning with @code{foo} is accessible
475 by @code{!foo:n}.
477 The history ring is loaded from a file at the start of every session,
478 and written back to the file at the end of every session.  The file path
479 is specified in @code{eshell-history-file-name}.  Unlike other shells,
480 such as Bash, Eshell can not be configured to keep a history ring of a
481 different size than that of the history file.
483 Since the default buffer navigation and searching key-bindings are
484 still present in the Eshell buffer, the commands for history
485 navigation and searching are bound to different keys:
487 @table @kbd
488 @item M-r
489 @itemx M-s
490 History I-search.
492 @item M-p
493 @itemx M-n
494 Previous and next history line.  If there is anything on the input
495 line when you run these commands, they will instead jump to the
496 precious or next line that begins with that string.
497 @end table
499 @node Completion
500 @section Completion
501 Eshell uses the pcomplete package for programmable completion, similar
502 to that of other command shells.  Argument completion differs depending
503 on the preceding command: for example, possible completions for
504 @command{rmdir} are only directories, while @command{rm} completions can
505 be directories @emph{and} files.  Eshell provides predefined completions
506 for the built-in functions and some common external commands, and you
507 can define your own for any command.
509 Eshell completion also works for lisp forms and glob patterns. If the
510 point is on a lisp form, then @key{TAB} will behave similarly to completion
511 in @code{elisp-mode} and @code{lisp-interaction-mode}.  For glob
512 patterns, If there are few enough possible completions of the patterns,
513 they will be cycled when @key{TAB} is pressed, otherwise it will be removed
514 from the input line and the possible completions will be listed.
516 If you want to see the entire list of possible completions when it's
517 below the cycling threshold, press @kbd{M-?}.
519 @subsection pcomplete
520 Pcomplete, short for programmable completion, is the completion
521 library originally written for Eshell, but usable for command
522 completion@footnote{Command completion as opposed to code completion,
523 which is a beyond the scope of pcomplete.}  in other modes.
525 Completions are defined as functions (with @code{defun}) named
526 @code{pcomplete/COMMAND}, where @code{COMMAND} is the name of the
527 command for which this function provides completions; you can also name
528 the function @code{pcomplete/MAJOR-MODE/COMMAND} to define completions
529 for a specific major mode.
531 @node for loop
532 @section @code{for} loop
533 Because Eshell commands can not (easily) be combined with lisp forms,
534 Eshell provides a command-oriented @command{for}-loop for convenience.
535 The syntax is as follows:
537 @example
538 @code{for VAR in TOKENS @{ command invocation(s) @}}
539 @end example
541 where @samp{TOKENS} is a space-separated sequence of values of
542 @var{VAR} for each iteration.  This can even be the output of a
543 command if @samp{TOKENS} is replaced with @samp{@{ command invocation @}}.
545 @node Scripts
546 @section Scripts
547 @cmindex source
548 @fnindex eshell-source-file
549 You can run Eshell scripts much like scripts for other shells; the main
550 difference is that since Eshell is not a system command, you have to run
551 it from within Emacs.  An Eshell script is simply a file containing a
552 sequence of commands, as with almost any other shell script.  Scripts
553 are invoked from Eshell with @command{source}, or from anywhere in Emacs
554 with @code{eshell-source-file}.
556 @cmindex .
557 If you wish to load a script into your @emph{current} environment,
558 rather than in a subshell, use the @code{.} command.
560 @node Expansion
561 @chapter Expansion
562 Expansion in a command shell is somewhat like macro expansion in macro
563 parsers (such as @command{cpp} and @command{m4}), but in a command
564 shell, they are less often used for constants, and usually for using
565 variables and string manipulation.@footnote{Eshell has no
566 string-manipulation expansions because the Elisp library already
567 provides many functions for this.}  For example, @code{$var} on a line
568 expands to the value of the variable @code{var} when the line is
569 executed.  Expansions are usually passed as arguments, but may also be
570 used as commands.@footnote{E.g., entering just @samp{$var} at the prompt
571 is equivalent to entering the value of @code{var} at the prompt.}
573 @menu
574 * Dollars Expansion::
575 * Globbing::
576 @end menu
578 @node Dollars Expansion
579 @section Dollars Expansion
580 Eshell has different @code{$} expansion syntax from other shells.  There
581 are some similarities, but don't let these lull you into a false sense
582 of familiarity.
584 @table @code
586 @item $var
587 Expands to the value bound to @code{var}.  This is the main way to use
588 variables in command invocations.
590 @item $#var
591 Expands to the length of the value bound to @code{var}.  Raises an error
592 if the value is not a sequence
593 (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The Emacs Lisp Reference Manual}).
595 @item $(lisp)
596 Expands to the result of evaluating the S-expression @code{(lisp)}.  On
597 its own, this is identical to just @code{(lisp)}, but with the @code{$},
598 it can be used in a string, such as @samp{/some/path/$(lisp).txt}.
600 @item $@{command@}
601 Returns the output of @command{command}, which can be any valid Eshell
602 command invocation, and may even contain expansions.
604 @item $var[i]
605 Expands to the @code{i}th element of the value bound to @code{var}.  If
606 the value is a string, it will be split at whitespace to make it a list.
607 Again, raises an error if the value is not a sequence.
609 @item $var[: i]
610 As above, but now splitting occurs at the colon character.
612 @item $var[: i j]
613 As above, but instead of returning just a string, it now returns a list
614 of two strings.  If the result is being interpolated into a larger
615 string, this list will be flattened into one big string, with each
616 element separated by a space.
618 @item $var["\\\\" i]
619 Separate on backslash characters.  Actually, the first argument -- if it
620 doesn't have the form of a number, or a plain variable name -- can be
621 any regular expression.  So to split on numbers, use @samp{$var["[0-9]+" 10 20]}.
623 @item $var[hello]
624 Calls @code{assoc} on @code{var} with @code{"hello"}, expecting it to be
625 an alist (@pxref{Association List Type, Association Lists, , elisp,
626 The Emacs Lisp Reference Manual}).
628 @item $#var[hello]
629 Returns the length of the cdr of the element of @code{var} who car is equal
630 to @code{"hello"}.
632 @end table
634 @node Globbing
635 @section Globbing
636 Eshell's globbing syntax is very similar to that of Zsh.  Users coming
637 from Bash can still use Bash-style globbing, as there are no
638 incompatibilities.  Most globbing is pattern-based expansion, but there
639 is also predicate-based expansion.  See
640 @ref{Filename Generation, , , zsh, The Z Shell Manual}
641 for full syntax.  To customize the syntax and behavior of globbing in
642 Eshell see the Customize@footnote{@xref{Easy Customization, , , emacs,
643 The GNU Emacs Manual}.}
644 groups ``eshell-glob'' and ``eshell-pred''.
646 @node Input/Output
647 @chapter Input/Output
648 Since Eshell does not communicate with a terminal like most command
649 shells, IO is a little different.
651 @section Visual Commands
652 If you try to run programs from within Eshell that are not
653 line-oriented, such as programs that use ncurses, you will just get
654 garbage output, since the Eshell buffer is not a terminal emulator.
655 Eshell solves this problem by running such programs in Emacs's
656 terminal emulator.
658 Programs that need a terminal to display output properly are referred
659 to in this manual as ``visual commands,'' because they are not simply
660 line-oriented.  You must tell Eshell which commands are visual, by
661 adding them to @code{eshell-visual-commands}; for commands that are
662 visual for only certain @emph{sub}-commands -- e.g., @samp{git log} but
663 not @samp{git status} -- use @code{eshell-visual-subcommands}; and for
664 commands that are visual only when passed certain options, use
665 @code{eshell-visual-options}.
667 Caution: Some tools such as Git use the pager @samp{less} by default
668 to paginate their output but call it with its @samp{-F} option.  This
669 option causes @samp{less} to echo the output instead of paginating it
670 if the output is less than one page long.  This causes undesirable
671 behavior if, e.g., @samp{git diff}, is defined as a visual subcommand.
672 It'll work if the output is big enough and fail if it is less than one
673 page long.  If that occurs to you, search for configuration options
674 for calling @samp{less} without the @samp{-F} option.  For Git, you
675 can do that using @samp{git config --global core.pager 'less -+F'}.
677 @vindex eshell-destroy-buffer-when-process-dies
678 If you want the buffers created by visual programs killed when the
679 program exits, customize the variable
680 @code{eshell-destroy-buffer-when-process-dies} to a non-@code{nil}
681 value; the default is @code{nil}.
683 @section Redirection
684 Redirection is mostly the same in Eshell as it is in other command
685 shells.  The output redirection operators @code{>} and @code{>>} as
686 well as pipes are supported, but there is not yet any support for
687 input redirection.  Output can also be redirected to buffers, using
688 the @code{>>>} redirection operator, and Elisp functions, using
689 virtual devices.
691 The buffer redirection operator, @code{>>>}, expects a buffer object
692 on the right-hand side, into which it inserts the output of the
693 left-hand side.  e.g., @samp{echo hello >>> #<buffer *scratch*>}
694 inserts the string @code{"hello"} into the @file{*scratch*} buffer.
695 The convenience shorthand variant @samp{#<@var{buffer-name}>}, as in
696 @samp{#<*scratch*>}, is also accepted.
698 @code{eshell-virtual-targets} is a list of mappings of virtual device
699 names to functions.  Eshell comes with two virtual devices:
700 @file{/dev/kill}, which sends the text to the kill ring, and
701 @file{/dev/clip}, which sends text to the clipboard.
703 You can, of course, define your own virtual targets.  They are defined
704 by adding a list of the form @samp{("/dev/name" @var{function} @var{mode})} to
705 @code{eshell-virtual-targets}.  The first element is the device name;
706 @var{function} may be either a lambda or a function name.  If
707 @var{mode} is @code{nil}, then the function is the output function; if it is
708 non-@code{nil}, then the function is passed the redirection mode as a
709 symbol--@code{overwrite} for @code{>}, @code{append} for @code{>>}, or
710 @code{insert} for @code{>>>}--and the function is expected to return
711 the output function.
713 The output function is called once on each line of output until
714 @code{nil} is passed, indicating end of output.
716 @node Extension modules
717 @chapter Extension modules
718 Eshell provides a facility for defining extension modules so that they
719 can be disabled and enabled without having to unload and reload them,
720 and to provide a common parent Customize group for the
721 modules.@footnote{ERC provides a similar module facility.}  An Eshell
722 module is defined the same as any other library but one requirement: the
723 module must define a Customize@footnote{@xref{Customization, , ,
724 elisp, The Emacs Lisp Reference Manual}.}
725 group using @code{eshell-defgroup} (in place of @code{defgroup}) with
726 @code{eshell-module} as the parent group.@footnote{If the module has
727 no user-customizable options, then there is no need to define it as an
728 Eshell module.}  You also need to load the following as shown:
730 @example
731 (eval-when-compile
732   (require 'cl-lib)
733   (require 'esh-mode)
734   (require 'eshell))
736 (require 'esh-util)
737 @end example
739 @menu
740 * Writing a module::
741 * Module testing::
742 * Directory handling::
743 * Key rebinding::
744 * Smart scrolling::
745 * Terminal emulation::
746 @end menu
748 @node Writing a module
749 @section Writing a module
751 @node Module testing
752 @section Module testing
754 @node Directory handling
755 @section Directory handling
757 @node Key rebinding
758 @section Key rebinding
760 @node Smart scrolling
761 @section Smart scrolling
763 @node Terminal emulation
764 @section Terminal emulation
766 @node Bugs and ideas
767 @chapter Bugs and ideas
768 @cindex reporting bugs and ideas
769 @cindex bugs, how to report them
770 @cindex author, how to reach
771 @cindex email to the author
772 @cindex FAQ
773 @cindex problems, list of common
774 @cindex known bugs
775 @cindex bugs, known
777 If you find a bug or misfeature, don't hesitate to report it, by
778 using @kbd{M-x report-emacs-bug}.  The same applies to feature requests.
779 It is best to discuss one thing at a time.  If you find several
780 unrelated bugs, please report them separately.
782 @ignore
783 If you have ideas for improvements, or if you have written some
784 extensions to this package, I would like to hear from you.  I hope you
785 find this package useful!
786 @end ignore
788 Below is a list of some known problems with Eshell version 2.4.2,
789 which is the version included with Emacs 22.
791 @table @asis
792 @item Documentation incomplete
794 @item Differentiate between aliases and functions
796 Allow for a Bash-compatible syntax, such as:
798 @example
799 alias arg=blah
800 function arg () @{ blah $* @}
801 @end example
803 @item @samp{for i in 1 2 3 @{ grep -q a b && *echo has it @} | wc -l} outputs result after prompt
805 In fact, piping to a process from a looping construct doesn't work in
806 general.  If I change the call to @code{eshell-copy-handles} in
807 @code{eshell-rewrite-for-command} to use @code{eshell-protect}, it seems
808 to work, but the output occurs after the prompt is displayed.  The whole
809 structured command thing is too complicated at present.
811 @item Error with @command{bc} in @code{eshell-test}
813 On some XEmacs system, the subprocess interaction test fails
814 inexplicably, although @command{bc} works fine at the command prompt.
816 @item Eshell does not delete @file{*Help*} buffers in XEmacs 21.1.8+
818 In XEmacs 21.1.8, the @file{*Help*} buffer has been renamed such that
819 multiple instances of the @file{*Help*} buffer can exist.
821 @item Pcomplete sometimes gets stuck
823 You press @key{TAB}, but no completions appear, even though the
824 directory has matching files.  This behavior is rare.
826 @item @samp{grep python $<rpm -qa>} doesn't work, but using @samp{*grep} does
828 This happens because the @code{grep} Lisp function returns immediately,
829 and then the asynchronous @command{grep} process expects to examine the
830 temporary file, which has since been deleted.
832 @item Problem with C-r repeating text
834 If the text @emph{before point} reads "./run", and you type @kbd{C-r r u
835 n}, it will repeat the line for every character typed.
837 @item Backspace doesn't scroll back after continuing (in smart mode)
839 Hitting space during a process invocation, such as @command{make}, will
840 cause it to track the bottom of the output; but backspace no longer
841 scrolls back.
843 @item It's not possible to fully @code{unload-feature} Eshell
845 @item Menu support was removed, but never put back
847 @item Using C-p and C-n with rebind gets into a locked state
849 This happened a few times in Emacs 21, but has been irreproducible
850 since.
852 @item If an interactive process is currently running, @kbd{M-!} doesn't work
854 @item Use a timer instead of @code{sleep-for} when killing child processes
856 @item Piping to a Lisp function is not supported
858 Make it so that the Lisp command on the right of the pipe is repeatedly
859 called with the input strings as arguments.  This will require changing
860 @code{eshell-do-pipeline} to handle non-process targets.
862 @item Input redirection is not supported
864 See the above entry.
866 @item Problem running @command{less} without arguments on Windows
868 The result in the Eshell buffer is:
870 @example
871 Spawning child process: invalid argument
872 @end example
874 Also a new @command{less} buffer was created with nothing in it@dots{}
875 (presumably this holds the output of @command{less}).
877 If @command{less.exe} is invoked from the Eshell command line, the
878 expected output is written to the buffer.
880 Note that this happens on NT-Emacs 20.6.1 on Windows 2000. The term.el
881 package and the supplied shell both use the @command{cmdproxy} program
882 for running shells.
884 @item Implement @samp{-r}, @samp{-n} and @samp{-s} switches for @command{cp}
886 @item Make @kbd{M-5 M-x eshell} switch to ``*eshell<5>*'', creating if need be
888 @item @samp{mv @var{dir} @var{file}.tar} does not remove directories
890 This is because the tar option --remove-files doesn't do so.  Should it
891 be Eshell's job?
893 @item Bind @code{standard-output} and @code{standard-error}
895 This would be so that if a Lisp function calls @code{print}, everything
896 will happen as it should (albeit slowly).
898 @item When an extension module fails to load, @samp{cd /} gives a Lisp error
900 @item If a globbing pattern returns one match, should it be a list?
902 @item Make sure syntax table is correct in Eshell mode
904 So that @kbd{M-DEL} acts in a predictable manner, etc.
906 @item Allow all Eshell buffers to share the same history and list-dir
908 @item There is a problem with script commands that output to @file{/dev/null}
910 If a script file, somewhere in the middle, uses @samp{> /dev/null},
911 output from all subsequent commands is swallowed.
913 @item Split up parsing of text after @samp{$} in @file{esh-var.el}
915 Make it similar to the way that @file{esh-arg.el} is structured.
916 Then add parsing of @samp{$[?\n]}.
918 @item After pressing @kbd{M-RET}, redisplay before running the next command
920 @item Argument predicates and modifiers should work anywhere in a path
922 @example
923 /usr/local/src/editors/vim $ vi **/CVS(/)/Root(.)
924 Invalid regexp: "Unmatched ( or \\("
925 @end example
927 With @command{zsh}, the glob above expands to all files named
928 @file{Root} in directories named @file{CVS}.
930 @item Typing @samp{echo $@{locate locate@}/bin<TAB>} results in a Lisp error
932 Perhaps it should interpolate all permutations, and make that the
933 globbing result, since otherwise hitting return here will result in
934 ``(list of filenames)/bin'', which is never valuable.  Thus, one could
935 @command{cat} only C backup files by using @samp{ls $@{identity *.c@}~}.
936 In that case, having an alias command name @command{glob} for
937 @command{identity} would be useful.
939 @item Once symbolic mode is supported for @command{umask}, implement @command{chmod} in Lisp
941 @item Create @code{eshell-expand-file-name}
943 This would use a data table to transform things such as @samp{~+},
944 @samp{...}, etc.
946 @item Abstract @file{em-smart.el} into @file{smart-scroll.el}
948 It only really needs: to be hooked onto the output filter and the
949 pre-command hook, and to have the input-end and input-start markers.
950 And to know whether the last output group was ``successful.''
952 @item Allow for fully persisting the state of Eshell
954 This would include: variables, history, buffer, input, dir stack, etc.
956 @item Implement D as an argument predicate
958 It means that files beginning with a dot should be included in the
959 glob match.
961 @item A comma in a predicate list should mean OR
963 At the moment, this is not supported.
965 @item Error if a glob doesn't expand due to a predicate
967 An error should be generated only if @code{eshell-error-if-no-glob} is
968 non-@code{nil}.
970 @item @samp{(+ RET SPC TAB} does not cause @code{indent-according-to-mode} to occur
972 @item Create @code{eshell-auto-accumulate-list}
974 This is a list of commands for which, if the user presses @kbd{RET}, the
975 text is staged as the next Eshell command, rather than being sent to the
976 current interactive process.
978 @item Display file and line number if an error occurs in a script
980 @item @command{wait} doesn't work with process ids at the moment
982 @item Enable the direct-to-process input code in @file{em-term.el}
984 @item Problem with repeating @samp{echo $@{find /tmp@}}
986 With smart display active, if @kbd{RET} is held down, after a while it
987 can't keep up anymore and starts outputting blank lines.  It only
988 happens if an asynchronous process is involved@dots{}
990 I think the problem is that @code{eshell-send-input} is resetting the
991 input target location, so that if the asynchronous process is not done
992 by the time the next @kbd{RET} is received, the input processor thinks
993 that the input is meant for the process; which, when smart display is
994 enabled, will be the text of the last command line!  That is a bug in
995 itself.
997 In holding down @kbd{RET} while an asynchronous process is running,
998 there will be a point in between termination of the process, and the
999 running of @code{eshell-post-command-hook}, which would cause
1000 @code{eshell-send-input} to call @code{eshell-copy-old-input}, and then
1001 process that text as a command to be run after the process.  Perhaps
1002 there should be a way of killing pending input between the death of the
1003 process, and the @code{post-command-hook}.
1005 @item Allow for a more aggressive smart display mode
1007 Perhaps toggled by a command, that makes each output block a smart
1008 display block.
1010 @item Create more meta variables
1012 @table @samp
1013 @item $!
1014 The reason for the failure of the last disk command, or the text of the
1015 last Lisp error.
1017 @item $=
1018 A special associate array, which can take references of the form
1019 @samp{$=[REGEXP]}.  It indexes into the directory ring.
1020 @end table
1022 @item Eshell scripts can't execute in the background
1024 @item Support zsh's ``Parameter Expansion'' syntax, i.e., @samp{$@{@var{name}:-@var{val}@}}
1026 @item Write an @command{info} alias that can take arguments
1028 So that the user can enter @samp{info chmod}, for example.
1030 @item Create a mode @code{eshell-browse}
1032 It would treat the Eshell buffer as a outline.  Collapsing the outline
1033 hides all of the output text.  Collapsing again would show only the
1034 first command run in each directory
1036 @item Allow other revisions of a file to be referenced using @samp{file@{rev@}}
1038 This would be expanded by @code{eshell-expand-file-name} (see above).
1040 @item Print ``You have new mail'' when the ``Mail'' icon is turned on
1042 @item Implement @kbd{M-|} for Eshell
1044 @item Implement input redirection
1046 If it's a Lisp function, input redirection implies @command{xargs} (in a
1047 way@dots{}).  If input redirection is added, also update the
1048 @code{file-name-quote-list}, and the delimiter list.
1050 @item Allow @samp{#<@var{word} @var{arg}>} as a generic syntax
1052 With the handling of @emph{word} specified by an
1053 @code{eshell-special-alist}.
1055 @item In @code{eshell-eval-using-options}, allow a @code{:complete} tag
1057 It would be used to provide completion rules for that command.  Then the
1058 macro will automagically define the completion function.
1060 @item For @code{eshell-command-on-region}, apply redirections to the result
1062 So that @samp{+ > 'blah} would cause the result of the @code{+} (using
1063 input from the current region) to be inserting into the symbol
1064 @code{blah}.
1066 If an external command is being invoked, the input is sent as standard
1067 input, as if a @samp{cat <region> |} had been invoked.
1069 If a Lisp command, or an alias, is invoked, then if the line has no
1070 newline characters, it is divided by whitespace and passed as arguments
1071 to the Lisp function.  Otherwise, it is divided at the newline
1072 characters.  Thus, invoking @code{+} on a series of numbers will add
1073 them; @code{min} would display the smallest figure, etc.
1075 @item Write @code{eshell-script-mode} as a minor mode
1077 It would provide syntax, abbrev, highlighting and indenting support like
1078 @code{emacs-lisp-mode} and @code{shell-mode}.
1080 @item In the history mechanism, finish the Bash-style support
1082 This means @samp{!n}, @samp{!#}, @samp{!:%}, and @samp{!:1-} as separate
1083 from @samp{!:1*}.
1085 @item Support the -n command line option for @command{history}
1087 @item Implement @command{fc} in Lisp
1089 @item Specifying a frame as a redirection target should imply the currently active window's buffer
1091 @item Implement @samp{>@var{func-or-func-list}}
1093 This would allow for an ``output translators'', that take a function to
1094 modify output with, and a target.  Devise a syntax that works well with
1095 pipes, and can accommodate multiple functions (i.e., @samp{>'(upcase
1096 regexp-quote)} or @samp{>'upcase}).
1098 @item Allow Eshell to read/write to/from standard input and output
1100 This would be optional, rather than always using the Eshell buffer.
1101 This would allow it to be run from the command line (perhaps).
1103 @item Write a @command{help} command
1105 It would call subcommands with @option{--help}, or @option{-h} or
1106 @option{/?}, as appropriate.
1108 @item Implement @command{stty} in Lisp
1110 @item Support @command{rc}'s matching operator, e.g., @samp{~ (@var{list}) @var{regexp}}
1112 @item Implement @command{bg} and @command{fg} as editors of @code{eshell-process-list}
1114 Using @command{bg} on a process that is already in the background does
1115 nothing.  Specifying redirection targets replaces (or adds) to the list
1116 current being used.
1118 @item Have @command{jobs} print only the processes for the current shell
1120 @item How can Eshell learn if a background process has requested input?
1122 @item Support @samp{2>&1} and @samp{>&} and @samp{2>} and @samp{|&}
1124 The syntax table for parsing these should be customizable, such that the
1125 user could change it to use rc syntax: @samp{>[2=1]}.
1127 @item Allow @samp{$_[-1]}, which would indicate the last element of the array
1129 @item Make @samp{$x[*]} equal to listing out the full contents of @samp{x}
1131 Return them as a list, so that @samp{$_[*]} is all the arguments of the
1132 last command.
1134 @item Copy ANSI code handling from @file{term.el} into @file{em-term.el}
1136 Make it possible for the user to send char-by-char to the underlying
1137 process.  Ultimately, I should be able to move away from using term.el
1138 altogether, since everything but the ANSI code handling is already part
1139 of Eshell.  Then, things would work correctly on MS-Windows as well
1140 (which doesn't have @file{/bin/sh}, although @file{term.el} tries to use
1141 it).
1143 @item Make the shell spawning commands be visual
1145 That is, make (@command{su}, @command{bash}, @command{telnet},
1146 @command{rlogin}, @command{rsh}, etc.)@: be part of
1147 @code{eshell-visual-commands}.  The only exception is if the shell is
1148 being used to invoke a single command.  Then, the behavior should be
1149 based on what that command is.
1151 @item Create a smart viewing command named @command{open}
1153 This would search for some way to open its argument (similar to opening
1154 a file in the Windows Explorer).
1156 @item Alias @command{read} to be the same as @command{open}, only read-only
1158 @item Write a @command{tail} command which uses @code{view-file}
1160 It would move point to the end of the buffer, and then turns on
1161 auto-revert mode in that buffer at frequent intervals---and a
1162 @command{head} alias which assumes an upper limit of
1163 @code{eshell-maximum-line-length} characters per line.
1165 @item Make @command{dgrep} load @code{dired}, mark everything, then invoke @code{dired-do-search}
1167 @item Write @file{mesh.c}
1169 This would run Emacs with the appropriate arguments to invoke Eshell
1170 only.  That way, it could be listed as a login shell.
1172 @item Use an intangible @code{PS2} string for multi-line input prompts
1174 @item Auto-detect when a command is visual, by checking @code{TERMCAP} usage
1176 @item The first keypress after @kbd{M-x watson} triggers
1177 @code{eshell-send-input}
1179 @item Make @kbd{/} electric
1181 So that it automatically expands and corrects pathnames.  Or make
1182 pathname completion for Pcomplete auto-expand @samp{/u/i/std<TAB>} to
1183 @samp{/usr/include/std<TAB>}.
1185 @item Write the @command{pushd} stack to disk along with @code{last-dir-ring}
1187 @item Add options to @code{eshell/cat} which would allow it to sort and uniq
1189 @item Implement @command{wc} in Lisp
1191 Add support for counting sentences, paragraphs, pages, etc.
1193 @item Once piping is added, implement @command{sort} and @command{uniq} in Lisp
1195 @item Implement @command{touch} in Lisp
1197 @item Implement @command{comm} in Lisp
1199 @item Implement an @command{epatch} command in Lisp
1201 This would call @code{ediff-patch-file}, or @code{ediff-patch-buffer},
1202 depending on its argument.
1204 @item Have an option such that @samp{ls -l} generates a dired buffer
1206 @item Write a version of @command{xargs} based on command rewriting
1208 That is, @samp{find X | xargs Y} would be indicated using @samp{Y
1209 $@{find X@}}.  Maybe @code{eshell-do-pipelines} could be changed to
1210 perform this on-thy-fly rewriting.
1212 @item Write an alias for @command{less} that brings up a @code{view-mode} buffer
1214 Such that the user can press @key{SPC} and @key{DEL}, and then @key{q}
1215 to return to Eshell.  It would be equivalent to:
1216 @samp{X > #<buffer Y>; view-buffer #<buffer Y>}.
1218 @item Make @code{eshell-mode} as much a full citizen as @code{shell-mode}
1220 Everywhere in Emacs where @code{shell-mode} is specially noticed, add
1221 @code{eshell-mode} there.
1223 @item Permit the umask to be selectively set on a @command{cp} target
1225 @item Problem using @kbd{M-x eshell} after using @code{eshell-command}
1227 If the first thing that I do after entering Emacs is to run
1228 @code{eshell-command} and invoke @command{ls}, and then use @kbd{M-x
1229 eshell}, it doesn't display anything.
1231 @item @kbd{M-RET} during a long command (using smart display) doesn't work
1233 Since it keeps the cursor up where the command was invoked.
1235 @end table
1237 @node GNU Free Documentation License
1238 @appendix GNU Free Documentation License
1239 @include doclicense.texi
1241 @node Concept Index
1242 @unnumbered Concept Index
1244 @printindex cp
1246 @node Function and Variable Index
1247 @unnumbered Function and Variable Index
1249 @printindex fn
1251 @node Command Index
1252 @unnumbered Command Index
1254 @printindex cm
1256 @c There are no @kindex entries in this manual; avoid generating an
1257 @c empty menu.
1258 @ignore
1259 @node Key Index
1260 @unnumbered Key Index
1262 @printindex ky
1263 @end ignore
1265 @bye