Fix customization type of `even-window-sizes'.
[emacs.git] / doc / misc / eshell.texi
blob60a1af0678dad79b34e44338908aa2d046a4bac6
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--2015 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 * Key Index::
88 @end menu
90 @node Introduction
91 @chapter Introduction
92 @section What is Eshell?
93 @cindex what is Eshell?
94 @cindex Eshell, what it is
96 Eshell is a @dfn{command shell} written in Emacs Lisp.  Everything it
97 does, it uses Emacs's facilities to do.  This means that Eshell is as
98 portable as Emacs itself.  It also means that cooperation with Lisp code
99 is natural and seamless.
101 What is a command shell?  To properly understand the role of a shell,
102 it's necessary to visualize what a computer does for you.  Basically, a
103 computer is a tool; in order to use that tool, you must tell it what to
104 do---or give it ``commands.''  These commands take many forms, such as
105 clicking with a mouse on certain parts of the screen.  But that is only
106 one form of command input.
108 By far the most versatile way to express what you want the computer to
109 do is by using an abbreviated language called @dfn{script}.  In
110 script, instead of telling the computer, ``list my files, please'',
111 one writes a standard abbreviated command word---@samp{ls}.  Typing
112 @samp{ls} in a command shell is a script way of telling the computer
113 to list your files.@footnote{This is comparable to viewing the
114 contents of a folder using a graphical display.}
116 The real flexibility of this approach is apparent only when you realize
117 that there are many, many different ways to list files.  Perhaps you
118 want them sorted by name, sorted by date, in reverse order, or grouped
119 by type.  Most graphical browsers have simple ways to express this.  But
120 what about showing only a few files, or only files that meet a certain
121 criteria?  In very complex and specific situations, the request becomes
122 too difficult to express using a mouse or pointing device.  It is just
123 these kinds of requests that are easily solved using a command shell.
125 For example, what if you want to list every Word file on your hard
126 drive, larger than 100 kilobytes in size, and which hasn't been looked
127 at in over six months?  That is a good candidate list for deletion, when
128 you go to clean up your hard drive.  But have you ever tried asking your
129 computer for such a list?  There is no way to do it!  At least, not
130 without using a command shell.
132 The role of a command shell is to give you more control over what your
133 computer does for you.  Not everyone needs this amount of control, and
134 it does come at a cost: Learning the necessary script commands to
135 express what you want done.  A complicated query, such as the example
136 above, takes time to learn.  But if you find yourself using your
137 computer frequently enough, it is more than worthwhile in the long run.
138 Any tool you use often deserves the time spent learning to master it.
139 @footnote{For the understandably curious, here is what that command
140 looks like: But don't let it fool you; once you know what's going on,
141 it's easier than it looks: @code{ls -lt **/*.doc(Lk+50aM+5)}.}
143 @section What Eshell is not
144 @cindex Eshell, what it is not
145 @cindex what Eshell is not
146 @cindex what isn't Eshell?
148 Eshell is @emph{not} a replacement for system shells such as
149 @command{bash} or @command{zsh}.  Use Eshell when you want to move
150 text between Emacs and external processes; if you only want to pipe
151 output from one external process to another (and then another, and so
152 on), use a system shell, because Emacs's IO system is buffer oriented,
153 not stream oriented, and is very inefficient at such tasks.  If you
154 want to write shell scripts in Eshell, don't; either write an elisp
155 library or use a system shell.
157 Some things Eshell just doesn't do well.  It fills the niche between
158 IELM and your system shell, where the peculiar use-cases lie, and it
159 is less than ideal outside that niche.
161 @menu
162 * Contributors to Eshell::      People who have helped out!
163 @end menu
165 @node Contributors to Eshell
166 @section Contributors to Eshell
167 @cindex contributors
168 @cindex authors
170 Contributions to Eshell are welcome.  I have limited time to work on
171 this project, but I will gladly add any code you contribute to me to
172 this package.
174 The following persons have made contributions to Eshell.
176 @itemize @bullet
177 @item
178 Eli Zaretskii made it possible for Eshell to run without requiring
179 asynchronous subprocess support.  This is important for MS-DOS, which
180 does not have such support.
182 @item
183 Miles Bader contributed many fixes during the port to Emacs 21.
185 @item
186 Stefan Monnier fixed the things which bothered him, which of course made
187 things better for all.
189 @item
190 Gerd Moellmann also helped to contribute bug fixes during the initial
191 integration with Emacs 21.
193 @item
194 Alex Schroeder contributed code for interactively querying the user
195 before overwriting files.
197 @item
198 Sudish Joseph helped with some XEmacs compatibility issues.
199 @end itemize
201 Apart from these, a lot of people have sent suggestions, ideas,
202 requests, bug reports and encouragement.  Thanks a lot!  Without you
203 there would be no new releases of Eshell.
205 @node Commands
206 @chapter Commands
208 In a command shell, everything is done by invoking commands.  This
209 chapter covers command invocations in Eshell, including the command
210 history and invoking commands in a script file.
212 @menu
213 * Invocation::
214 * Arguments::
215 * Built-ins::
216 * Variables::
217 * Aliases::
218 * History::
219 * Completion::
220 * for loop::
221 * Scripts::
222 @end menu
224 @node Invocation
225 @section Invocation
226 Unlike regular system shells, Eshell never invokes kernel functions
227 directly, such as @code{exec(3)}.  Instead, it uses the Lisp functions
228 available in the Emacs Lisp library.  It does this by transforming the
229 input line into a callable Lisp form.@footnote{To see the Lisp form that will be invoked, type: @samp{eshell-parse-command "echo hello"}}
231 The command can be either an Elisp function or an external command.
232 Eshell looks first for an @ref{Aliases, alias} with the same name as the
233 command, then a @ref{Built-ins, built-in command} or a function with the
234 same name; if there is no match, it then tries to execute it as an
235 external command.
237 The semicolon (@code{;}) can be used to separate multiple command
238 invocations on a single line.  A command invocation followed by an
239 ampersand (@code{&}) will be run in the background.  Eshell has no job
240 control, so you can not suspend or background the current process, or
241 bring a background process into the foreground.  That said, background
242 processes invoked from Eshell can be controlled the same way as any
243 other background process in Emacs.
245 @node Arguments
246 @section Arguments
247 Command arguments are passed to the functions as either strings or
248 numbers, depending on what the parser thinks they look like.  If you
249 need to use a function that takes some other data type, you will need to
250 call it in an Elisp expression (which can also be used with
251 @ref{Expansion, expansions}).  As with other shells, you can
252 escape special characters and spaces with the backslash (@code{\}) and
253 apostrophes (@code{''}) and double quotes (@code{""}).
255 @node Built-ins
257 @section Built-in commands
258 Several commands are built-in in Eshell.  In order to call the
259 external variant of a built-in command @code{foo}, you could call
260 @code{*foo}.  Usually, this should not be necessary.  You can check
261 what will be applied by the @code{which} command:
263 @example
264 ~ $ which ls
265 eshell/ls is a compiled Lisp function in `em-ls.el'
266 ~ $ which *ls
267 /bin/ls
268 @end example
270 If you want to discard a given built-in command, you could declare an
271 alias, @ref{Aliases}.  Example:
273 @example
274 ~ $ which sudo
275 eshell/sudo is a compiled Lisp function in `em-unix.el'
276 ~ $ alias sudo '*sudo $*'
277 ~ $ which sudo
278 sudo is an alias, defined as "*sudo $*"
279 @end example
281 @vindex eshell-prefer-lisp-functions
282 If you would prefer to use the built-in commands instead of the external
283 commands, set @code{eshell-prefer-lisp-functions} to @code{t}.
285 Some of the built-in commands have different behavior from their
286 external counterparts, and some have no external counterpart.  Most of
287 these will print a usage message when given the @code{--help} option.
289 @table @code
291 @item addpath
292 @cmindex addpath
293 Adds a given path or set of paths to the PATH environment variable, or,
294 with no arguments, prints the current paths in this variable.
296 @item alias
297 @cmindex alias
298 Define an alias (@pxref{Aliases}).  This does not add it to the aliases
299 file.
301 @item clear
302 @cmindex clear
303 Scrolls the contents of the eshell window out of sight, leaving a blank window.
304 If provided with an optional non-nil argument, the scrollback contents are
305 cleared instead.
307 @item date
308 @cmindex date
309 Similar to, but slightly different from, the GNU Coreutils
310 @command{date} command.
312 @item define
313 @cmindex define
314 Define a varalias.
315 @xref{Variable Aliases, , , elisp, The Emacs Lisp Reference Manual}.
317 @item diff
318 @cmindex diff
319 Use Emacs's internal @code{diff} (not to be confused with
320 @code{ediff}).  @xref{Comparing Files, , , emacs, The GNU Emacs Manual}.
322 @item grep
323 @cmindex grep
324 @itemx agrep
325 @cmindex agrep
326 @itemx egrep
327 @cmindex egrep
328 @itemx fgrep
329 @cmindex fgrep
330 @itemx glimpse
331 @cmindex glimpse
332 The @command{grep} commands are compatible with GNU @command{grep}, but
333 use Emacs's internal @code{grep} instead.
335 @item info
336 @cmindex info
337 Same as the external @command{info} command, but uses Emacs's internal
338 Info reader.
340 @item jobs
341 @cmindex jobs
342 List subprocesses of the Emacs process, if any, using the function
343 @code{list-processes}.
345 @item kill
346 @cmindex kill
347 Kill processes.  Takes a PID or a process object and an optional
348 signal specifier.
350 @item listify
351 @cmindex listify
352 Eshell version of @code{list}.  Allows you to create a list using Eshell
353 syntax, rather than Elisp syntax.  For example, @samp{listify foo bar}
354 and @code{("foo" "bar")} both evaluate to @code{("foo" "bar")}.
356 @item locate
357 @cmindex locate
358 Alias to Emacs's @code{locate} function, which simply runs the external
359 @command{locate} command and parses the results.
360 @xref{Dired and Find, , , emacs, The GNU Emacs Manual}.
362 @item make
363 @cmindex make
364 Run @command{make} through @code{compile}.
365 @xref{Compilation, , , emacs, The GNU Emacs Manual}.
367 @item occur
368 @cmindex occur
369 Alias to Emacs's @code{occur}.
370 @xref{Other Repeating Search, , , emacs, The GNU Emacs Manual}.
372 @item printnl
373 @cmindex printnl
374 Print the arguments separated by newlines.
376 @item cd
377 @cmindex cd
378 This command changes the current working directory.  Usually, it is
379 invoked as @samp{cd foo} where @file{foo} is the new working directory.
380 But @command{cd} knows about a few special arguments:
382 When it receives no argument at all, it changes to the home directory.
384 Giving the command @samp{cd -} changes back to the previous working
385 directory (this is the same as @samp{cd $-}).
387 The command @samp{cd =} shows the directory stack.  Each line is
388 numbered.
390 With @samp{cd =foo}, Eshell searches the directory stack for a directory
391 matching the regular expression @samp{foo} and changes to that
392 directory.
394 With @samp{cd -42}, you can access the directory stack by number.
396 @item su
397 @cmindex su
398 @itemx sudo
399 @cmindex sudo
400 Uses TRAMP's @command{su} or @command{sudo} method @pxref{Inline methods, , , tramp}
401 to run a command via @command{su} or @command{sudo}.  These commands
402 are in the eshell-tramp module, which is disabled by default.
404 @end table
406 @subsection Built-in variables
407 Eshell knows a few built-in variables:
409 @table @code
411 @item $+
412 @vindex $+
413 This variable always contains the current working directory.
415 @item $-
416 @vindex $-
417 This variable always contains the previous working directory (the
418 current working directory from before the last @code{cd} command).
420 @item $_
421 @vindex $_
422 It refers to the last argument of the last command.
424 @item $$
425 @vindex $$
426 This is the result of the last command.  In case of an external
427 command, it is @code{t} or @code{nil}.
429 @item $?
430 @vindex $?
431 This variable contains the exit code of the last command (0 or 1 for
432 Lisp functions, based on successful completion).
434 @end table
436 @node Variables
437 @section Variables
438 Since Eshell is just an Emacs REPL@footnote{Read-Eval-Print Loop}, it
439 does not have its own scope, and simply stores variables the same you
440 would in an Elisp program.  Eshell provides a command version of
441 @code{setq} for convenience.
443 @node Aliases
444 @section Aliases
446 Aliases are commands that expand to a longer input line.  For example,
447 @command{ll} is a common alias for @code{ls -l}, and would be defined
448 with the command invocation @samp{alias ll ls -l}; with this defined,
449 running @samp{ll foo} in Eshell will actually run @samp{ls -l foo}.
450 Aliases defined (or deleted) by the @command{alias} command are
451 automatically written to the file named by @code{eshell-aliases-file},
452 which you can also edit directly (although you will have to manually
453 reload it).
455 @node History
456 @section History
457 @cmindex history
458 The @samp{history} command shows all commands kept in the history ring
459 as numbered list.  If the history ring contains
460 @code{eshell-history-size} commands, those numbers change after every
461 command invocation, therefore the @samp{history} command shall be
462 applied before using the expansion mechanism with history numbers.
464 The n-th entry of the history ring can be applied with the @samp{!n}
465 command.  If @code{n} is negative, the entry is counted from the end
466 of the history ring.
468 @samp{!foo} expands to the last command beginning with @code{foo}, and
469 @samp{!?foo} to the last command containing @code{foo}.  The n-th
470 argument of the last command beginning with @code{foo} is accessible
471 by @code{!foo:n}.
473 The history ring is loaded from a file at the start of every session,
474 and written back to the file at the end of every session.  The file path
475 is specified in @code{eshell-history-file-name}.  Unlike other shells,
476 such as Bash, Eshell can not be configured to keep a history ring of a
477 different size than that of the history file.
479 Since the default buffer navigation and searching key-bindings are
480 still present in the Eshell buffer, the commands for history
481 navigation and searching are bound to different keys:
483 @table @kbd
484 @item M-r
485 @itemx M-s
486 History I-search.
488 @item M-p
489 @itemx M-n
490 Previous and next history line.  If there is anything on the input
491 line when you run these commands, they will instead jump to the
492 precious or next line that begins with that string.
493 @end table
495 @node Completion
496 @section Completion
497 Eshell uses the pcomplete package for programmable completion, similar
498 to that of other command shells.  Argument completion differs depending
499 on the preceding command: for example, possible completions for
500 @command{rmdir} are only directories, while @command{rm} completions can
501 be directories @emph{and} files.  Eshell provides predefined completions
502 for the built-in functions and some common external commands, and you
503 can define your own for any command.
505 Eshell completion also works for lisp forms and glob patterns. If the
506 point is on a lisp form, then @key{TAB} will behave similarly to completion
507 in @code{elisp-mode} and @code{lisp-interaction-mode}.  For glob
508 patterns, If there are few enough possible completions of the patterns,
509 they will be cycled when @key{TAB} is pressed, otherwise it will be removed
510 from the input line and the possible completions will be listed.
512 If you want to see the entire list of possible completions when it's
513 below the cycling threshold, press @kbd{M-?}.
515 @subsection pcomplete
516 Pcomplete, short for programmable completion, is the completion
517 library originally written for Eshell, but usable for command
518 completion@footnote{Command completion as opposed to code completion,
519 which is a beyond the scope of pcomplete.}  in other modes.
521 Completions are defined as functions (with @code{defun}) named
522 @code{pcomplete/COMMAND}, where @code{COMMAND} is the name of the
523 command for which this function provides completions; you can also name
524 the function @code{pcomplete/MAJOR-MODE/COMMAND} to define completions
525 for a specific major mode.
527 @node for loop
528 @section @code{for} loop
529 Because Eshell commands can not (easily) be combined with lisp forms,
530 Eshell provides a command-oriented @command{for}-loop for convenience.
531 The syntax is as follows:
533 @example
534 @code{for VAR in TOKENS @{ command invocation(s) @}}
535 @end example
537 where @samp{TOKENS} is a space-separated sequence of values of
538 @var{VAR} for each iteration.  This can even be the output of a
539 command if @samp{TOKENS} is replaced with @samp{@{ command invocation @}}.
541 @node Scripts
542 @section Scripts
543 @cmindex source
544 @fnindex eshell-source-file
545 You can run Eshell scripts much like scripts for other shells; the main
546 difference is that since Eshell is not a system command, you have to run
547 it from within Emacs.  An Eshell script is simply a file containing a
548 sequence of commands, as with almost any other shell script.  Scripts
549 are invoked from Eshell with @command{source}, or from anywhere in Emacs
550 with @code{eshell-source-file}.
552 @cmindex .
553 If you wish to load a script into your @emph{current} environment,
554 rather than in a subshell, use the @code{.} command.
556 @node Expansion
557 @chapter Expansion
558 Expansion in a command shell is somewhat like macro expansion in macro
559 parsers (such as @command{cpp} and @command{m4}), but in a command
560 shell, they are less often used for constants, and usually for using
561 variables and string manipulation.@footnote{Eshell has no
562 string-manipulation expansions because the Elisp library already
563 provides many functions for this.}  For example, @code{$var} on a line
564 expands to the value of the variable @code{var} when the line is
565 executed.  Expansions are usually passed as arguments, but may also be
566 used as commands.@footnote{E.g., entering just @samp{$var} at the prompt
567 is equivalent to entering the value of @code{var} at the prompt.}
569 @menu
570 * Dollars Expansion::
571 * Globbing::
572 @end menu
574 @node Dollars Expansion
575 @section Dollars Expansion
576 Eshell has different @code{$} expansion syntax from other shells.  There
577 are some similarities, but don't let these lull you into a false sense
578 of familiarity.
580 @table @code
582 @item $var
583 Expands to the value bound to @code{var}.  This is the main way to use
584 variables in command invocations.
586 @item $#var
587 Expands to the length of the value bound to @code{var}.  Raises an error
588 if the value is not a sequence
589 (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The Emacs Lisp Reference Manual}).
591 @item $(lisp)
592 Expands to the result of evaluating the S-expression @code{(lisp)}.  On
593 its own, this is identical to just @code{(lisp)}, but with the @code{$},
594 it can be used in a string, such as @samp{/some/path/$(lisp).txt}.
596 @item $@{command@}
597 Returns the output of @command{command}, which can be any valid Eshell
598 command invocation, and may even contain expansions.
600 @item $var[i]
601 Expands to the @code{i}th element of the value bound to @code{var}.  If
602 the value is a string, it will be split at whitespace to make it a list.
603 Again, raises an error if the value is not a sequence.
605 @item $var[: i]
606 As above, but now splitting occurs at the colon character.
608 @item $var[: i j]
609 As above, but instead of returning just a string, it now returns a list
610 of two strings.  If the result is being interpolated into a larger
611 string, this list will be flattened into one big string, with each
612 element separated by a space.
614 @item $var["\\\\" i]
615 Separate on backslash characters.  Actually, the first argument -- if it
616 doesn't have the form of a number, or a plain variable name -- can be
617 any regular expression.  So to split on numbers, use @samp{$var["[0-9]+" 10 20]}.
619 @item $var[hello]
620 Calls @code{assoc} on @code{var} with @code{"hello"}, expecting it to be
621 an alist (@pxref{Association List Type, Association Lists, , elisp,
622 The Emacs Lisp Reference Manual}).
624 @item $#var[hello]
625 Returns the length of the cdr of the element of @code{var} who car is equal
626 to @code{"hello"}.
628 @end table
630 @node Globbing
631 @section Globbing
632 Eshell's globbing syntax is very similar to that of Zsh.  Users coming
633 from Bash can still use Bash-style globbing, as there are no
634 incompatibilities.  Most globbing is pattern-based expansion, but there
635 is also predicate-based expansion.  See
636 @ref{Filename Generation, , , zsh, The Z Shell Manual}
637 for full syntax.  To customize the syntax and behavior of globbing in
638 Eshell see the Customize@footnote{@xref{Easy Customization, , , emacs,
639 The GNU Emacs Manual}.}
640 groups ``eshell-glob'' and ``eshell-pred''.
642 @node Input/Output
643 @chapter Input/Output
644 Since Eshell does not communicate with a terminal like most command
645 shells, IO is a little different.
647 @section Visual Commands
648 If you try to run programs from within Eshell that are not
649 line-oriented, such as programs that use ncurses, you will just get
650 garbage output, since the Eshell buffer is not a terminal emulator.
651 Eshell solves this problem by running such programs in Emacs's
652 terminal emulator.
654 Programs that need a terminal to display output properly are referred
655 to in this manual as ``visual commands,'' because they are not simply
656 line-oriented.  You must tell Eshell which commands are visual, by
657 adding them to @code{eshell-visual-commands}; for commands that are
658 visual for only certain @emph{sub}-commands -- e.g., @samp{git log} but
659 not @samp{git status} -- use @code{eshell-visual-subcommands}; and for
660 commands that are visual only when passed certain options, use
661 @code{eshell-visual-options}.
663 Caution: Some tools such as Git use the pager @samp{less} by default
664 to paginate their output but call it with its @samp{-F} option.  This
665 option causes @samp{less} to echo the output instead of paginating it
666 if the output is less than one page long.  This causes undesirable
667 behavior if, e.g., @samp{git diff}, is defined as a visual subcommand.
668 It'll work if the output is big enough and fail if it is less than one
669 page long.  If that occurs to you, search for configuration options
670 for calling @samp{less} without the @samp{-F} option.  For Git, you
671 can do that using @samp{git config --global core.pager 'less -+F'}.
673 @section Redirection
674 Redirection is mostly the same in Eshell as it is in other command
675 shells.  The output redirection operators @code{>} and @code{>>} as
676 well as pipes are supported, but there is not yet any support for
677 input redirection.  Output can also be redirected to buffers, using
678 the @code{>>>} redirection operator, and Elisp functions, using
679 virtual devices.
681 The buffer redirection operator, @code{>>>}, expects a buffer object
682 on the right-hand side, into which it inserts the output of the
683 left-hand side.  e.g., @samp{echo hello >>> #<buffer *scratch*>}
684 inserts the string @code{"hello"} into the @file{*scratch*} buffer.
686 @code{eshell-virtual-targets} is a list of mappings of virtual device
687 names to functions.  Eshell comes with two virtual devices:
688 @file{/dev/kill}, which sends the text to the kill ring, and
689 @file{/dev/clip}, which sends text to the clipboard.
691 You can, of course, define your own virtual targets.  They are defined
692 by adding a list of the form @samp{("/dev/name" @var{function} @var{mode})} to
693 @code{eshell-virtual-targets}.  The first element is the device name;
694 @var{function} may be either a lambda or a function name.  If
695 @var{mode} is @code{nil}, then the function is the output function; if it is
696 non-@code{nil}, then the function is passed the redirection mode as a
697 symbol--@code{overwrite} for @code{>}, @code{append} for @code{>>}, or
698 @code{insert} for @code{>>>}--and the function is expected to return
699 the output function.
701 The output function is called once on each line of output until
702 @code{nil} is passed, indicating end of output.
704 @node Extension modules
705 @chapter Extension modules
706 Eshell provides a facility for defining extension modules so that they
707 can be disabled and enabled without having to unload and reload them,
708 and to provide a common parent Customize group for the
709 modules.@footnote{ERC provides a similar module facility.}  An Eshell
710 module is defined the same as any other library but one requirement: the
711 module must define a Customize@footnote{@xref{Customization, , ,
712 elisp, The Emacs Lisp Reference Manual}.}
713 group using @code{eshell-defgroup} (in place of @code{defgroup}) with
714 @code{eshell-module} as the parent group.@footnote{If the module has
715 no user-customizable options, then there is no need to define it as an
716 Eshell module.}  You also need to load the following as shown:
718 @example
719 (eval-when-compile
720   (require 'cl-lib)
721   (require 'esh-mode)
722   (require 'eshell))
724 (require 'esh-util)
725 @end example
727 @menu
728 * Writing a module::
729 * Module testing::
730 * Directory handling::
731 * Key rebinding::
732 * Smart scrolling::
733 * Terminal emulation::
734 @end menu
736 @node Writing a module
737 @section Writing a module
739 @node Module testing
740 @section Module testing
742 @node Directory handling
743 @section Directory handling
745 @node Key rebinding
746 @section Key rebinding
748 @node Smart scrolling
749 @section Smart scrolling
751 @node Terminal emulation
752 @section Terminal emulation
754 @node Bugs and ideas
755 @chapter Bugs and ideas
756 @cindex reporting bugs and ideas
757 @cindex bugs, how to report them
758 @cindex author, how to reach
759 @cindex email to the author
760 @cindex FAQ
761 @cindex problems, list of common
762 @cindex known bugs
763 @cindex bugs, known
765 If you find a bug or misfeature, don't hesitate to report it, by
766 using @kbd{M-x report-emacs-bug}.  The same applies to feature requests.
767 It is best to discuss one thing at a time.  If you find several
768 unrelated bugs, please report them separately.
770 @ignore
771 If you have ideas for improvements, or if you have written some
772 extensions to this package, I would like to hear from you.  I hope you
773 find this package useful!
774 @end ignore
776 Below is a list of some known problems with Eshell version 2.4.2,
777 which is the version included with Emacs 22.
779 @table @asis
780 @item Documentation incomplete
782 @item Differentiate between aliases and functions
784 Allow for a Bash-compatible syntax, such as:
786 @example
787 alias arg=blah
788 function arg () @{ blah $* @}
789 @end example
791 @item @samp{for i in 1 2 3 @{ grep -q a b && *echo has it @} | wc -l} outputs result after prompt
793 In fact, piping to a process from a looping construct doesn't work in
794 general.  If I change the call to @code{eshell-copy-handles} in
795 @code{eshell-rewrite-for-command} to use @code{eshell-protect}, it seems
796 to work, but the output occurs after the prompt is displayed.  The whole
797 structured command thing is too complicated at present.
799 @item Error with @command{bc} in @code{eshell-test}
801 On some XEmacs system, the subprocess interaction test fails
802 inexplicably, although @command{bc} works fine at the command prompt.
804 @item Eshell does not delete @file{*Help*} buffers in XEmacs 21.1.8+
806 In XEmacs 21.1.8, the @file{*Help*} buffer has been renamed such that
807 multiple instances of the @file{*Help*} buffer can exist.
809 @item Pcomplete sometimes gets stuck
811 You press @key{TAB}, but no completions appear, even though the
812 directory has matching files.  This behavior is rare.
814 @item @samp{grep python $<rpm -qa>} doesn't work, but using @samp{*grep} does
816 This happens because the @code{grep} Lisp function returns immediately,
817 and then the asynchronous @command{grep} process expects to examine the
818 temporary file, which has since been deleted.
820 @item Problem with C-r repeating text
822 If the text @emph{before point} reads "./run", and you type @kbd{C-r r u
823 n}, it will repeat the line for every character typed.
825 @item Backspace doesn't scroll back after continuing (in smart mode)
827 Hitting space during a process invocation, such as @command{make}, will
828 cause it to track the bottom of the output; but backspace no longer
829 scrolls back.
831 @item It's not possible to fully @code{unload-feature} Eshell
833 @item Menu support was removed, but never put back
835 @item Using C-p and C-n with rebind gets into a locked state
837 This happened a few times in Emacs 21, but has been irreproducible
838 since.
840 @item If an interactive process is currently running, @kbd{M-!} doesn't work
842 @item Use a timer instead of @code{sleep-for} when killing child processes
844 @item Piping to a Lisp function is not supported
846 Make it so that the Lisp command on the right of the pipe is repeatedly
847 called with the input strings as arguments.  This will require changing
848 @code{eshell-do-pipeline} to handle non-process targets.
850 @item Input redirection is not supported
852 See the above entry.
854 @item Problem running @command{less} without arguments on Windows
856 The result in the Eshell buffer is:
858 @example
859 Spawning child process: invalid argument
860 @end example
862 Also a new @command{less} buffer was created with nothing in it@dots{}
863 (presumably this holds the output of @command{less}).
865 If @command{less.exe} is invoked from the Eshell command line, the
866 expected output is written to the buffer.
868 Note that this happens on NT-Emacs 20.6.1 on Windows 2000. The term.el
869 package and the supplied shell both use the @command{cmdproxy} program
870 for running shells.
872 @item Implement @samp{-r}, @samp{-n} and @samp{-s} switches for @command{cp}
874 @item Make @kbd{M-5 M-x eshell} switch to ``*eshell<5>*'', creating if need be
876 @item @samp{mv @var{dir} @var{file}.tar} does not remove directories
878 This is because the tar option --remove-files doesn't do so.  Should it
879 be Eshell's job?
881 @item Bind @code{standard-output} and @code{standard-error}
883 This would be so that if a Lisp function calls @code{print}, everything
884 will happen as it should (albeit slowly).
886 @item When an extension module fails to load, @samp{cd /} gives a Lisp error
888 @item If a globbing pattern returns one match, should it be a list?
890 @item Make sure syntax table is correct in Eshell mode
892 So that @kbd{M-DEL} acts in a predictable manner, etc.
894 @item Allow all Eshell buffers to share the same history and list-dir
896 @item There is a problem with script commands that output to @file{/dev/null}
898 If a script file, somewhere in the middle, uses @samp{> /dev/null},
899 output from all subsequent commands is swallowed.
901 @item Split up parsing of text after @samp{$} in @file{esh-var.el}
903 Make it similar to the way that @file{esh-arg.el} is structured.
904 Then add parsing of @samp{$[?\n]}.
906 @item After pressing @kbd{M-RET}, redisplay before running the next command
908 @item Argument predicates and modifiers should work anywhere in a path
910 @example
911 /usr/local/src/editors/vim $ vi **/CVS(/)/Root(.)
912 Invalid regexp: "Unmatched ( or \\("
913 @end example
915 With @command{zsh}, the glob above expands to all files named
916 @file{Root} in directories named @file{CVS}.
918 @item Typing @samp{echo $@{locate locate@}/bin<TAB>} results in a Lisp error
920 Perhaps it should interpolate all permutations, and make that the
921 globbing result, since otherwise hitting return here will result in
922 ``(list of filenames)/bin'', which is never valuable.  Thus, one could
923 @command{cat} only C backup files by using @samp{ls $@{identity *.c@}~}.
924 In that case, having an alias command name @command{glob} for
925 @command{identity} would be useful.
927 @item Once symbolic mode is supported for @command{umask}, implement @command{chmod} in Lisp
929 @item Create @code{eshell-expand-file-name}
931 This would use a data table to transform things such as @samp{~+},
932 @samp{...}, etc.
934 @item Abstract @file{em-smart.el} into @file{smart-scroll.el}
936 It only really needs: to be hooked onto the output filter and the
937 pre-command hook, and to have the input-end and input-start markers.
938 And to know whether the last output group was ``successful.''
940 @item Allow for fully persisting the state of Eshell
942 This would include: variables, history, buffer, input, dir stack, etc.
944 @item Implement D as an argument predicate
946 It means that files beginning with a dot should be included in the
947 glob match.
949 @item A comma in a predicate list should mean OR
951 At the moment, this is not supported.
953 @item Error if a glob doesn't expand due to a predicate
955 An error should be generated only if @code{eshell-error-if-no-glob} is
956 non-@code{nil}.
958 @item @samp{(+ RET SPC TAB} does not cause @code{indent-according-to-mode} to occur
960 @item Create @code{eshell-auto-accumulate-list}
962 This is a list of commands for which, if the user presses @kbd{RET}, the
963 text is staged as the next Eshell command, rather than being sent to the
964 current interactive process.
966 @item Display file and line number if an error occurs in a script
968 @item @command{wait} doesn't work with process ids at the moment
970 @item Enable the direct-to-process input code in @file{em-term.el}
972 @item Problem with repeating @samp{echo $@{find /tmp@}}
974 With smart display active, if @kbd{RET} is held down, after a while it
975 can't keep up anymore and starts outputting blank lines.  It only
976 happens if an asynchronous process is involved@dots{}
978 I think the problem is that @code{eshell-send-input} is resetting the
979 input target location, so that if the asynchronous process is not done
980 by the time the next @kbd{RET} is received, the input processor thinks
981 that the input is meant for the process; which, when smart display is
982 enabled, will be the text of the last command line!  That is a bug in
983 itself.
985 In holding down @kbd{RET} while an asynchronous process is running,
986 there will be a point in between termination of the process, and the
987 running of @code{eshell-post-command-hook}, which would cause
988 @code{eshell-send-input} to call @code{eshell-copy-old-input}, and then
989 process that text as a command to be run after the process.  Perhaps
990 there should be a way of killing pending input between the death of the
991 process, and the @code{post-command-hook}.
993 @item Allow for a more aggressive smart display mode
995 Perhaps toggled by a command, that makes each output block a smart
996 display block.
998 @item Create more meta variables
1000 @table @samp
1001 @item $!
1002 The reason for the failure of the last disk command, or the text of the
1003 last Lisp error.
1005 @item $=
1006 A special associate array, which can take references of the form
1007 @samp{$=[REGEXP]}.  It indexes into the directory ring.
1008 @end table
1010 @item Eshell scripts can't execute in the background
1012 @item Support zsh's ``Parameter Expansion'' syntax, i.e., @samp{$@{@var{name}:-@var{val}@}}
1014 @item Write an @command{info} alias that can take arguments
1016 So that the user can enter @samp{info chmod}, for example.
1018 @item Create a mode @code{eshell-browse}
1020 It would treat the Eshell buffer as a outline.  Collapsing the outline
1021 hides all of the output text.  Collapsing again would show only the
1022 first command run in each directory
1024 @item Allow other revisions of a file to be referenced using @samp{file@{rev@}}
1026 This would be expanded by @code{eshell-expand-file-name} (see above).
1028 @item Print ``You have new mail'' when the ``Mail'' icon is turned on
1030 @item Implement @kbd{M-|} for Eshell
1032 @item Implement input redirection
1034 If it's a Lisp function, input redirection implies @command{xargs} (in a
1035 way@dots{}).  If input redirection is added, also update the
1036 @code{file-name-quote-list}, and the delimiter list.
1038 @item Allow @samp{#<@var{word} @var{arg}>} as a generic syntax
1040 With the handling of @emph{word} specified by an
1041 @code{eshell-special-alist}.
1043 @item In @code{eshell-eval-using-options}, allow a @code{:complete} tag
1045 It would be used to provide completion rules for that command.  Then the
1046 macro will automagically define the completion function.
1048 @item For @code{eshell-command-on-region}, apply redirections to the result
1050 So that @samp{+ > 'blah} would cause the result of the @code{+} (using
1051 input from the current region) to be inserting into the symbol
1052 @code{blah}.
1054 If an external command is being invoked, the input is sent as standard
1055 input, as if a @samp{cat <region> |} had been invoked.
1057 If a Lisp command, or an alias, is invoked, then if the line has no
1058 newline characters, it is divided by whitespace and passed as arguments
1059 to the Lisp function.  Otherwise, it is divided at the newline
1060 characters.  Thus, invoking @code{+} on a series of numbers will add
1061 them; @code{min} would display the smallest figure, etc.
1063 @item Write @code{eshell-script-mode} as a minor mode
1065 It would provide syntax, abbrev, highlighting and indenting support like
1066 @code{emacs-lisp-mode} and @code{shell-mode}.
1068 @item In the history mechanism, finish the Bash-style support
1070 This means @samp{!n}, @samp{!#}, @samp{!:%}, and @samp{!:1-} as separate
1071 from @samp{!:1*}.
1073 @item Support the -n command line option for @command{history}
1075 @item Implement @command{fc} in Lisp
1077 @item Specifying a frame as a redirection target should imply the currently active window's buffer
1079 @item Implement @samp{>@var{func-or-func-list}}
1081 This would allow for an ``output translators'', that take a function to
1082 modify output with, and a target.  Devise a syntax that works well with
1083 pipes, and can accommodate multiple functions (i.e., @samp{>'(upcase
1084 regexp-quote)} or @samp{>'upcase}).
1086 @item Allow Eshell to read/write to/from standard input and output
1088 This would be optional, rather than always using the Eshell buffer.
1089 This would allow it to be run from the command line (perhaps).
1091 @item Write a @command{help} command
1093 It would call subcommands with @option{--help}, or @option{-h} or
1094 @option{/?}, as appropriate.
1096 @item Implement @command{stty} in Lisp
1098 @item Support @command{rc}'s matching operator, e.g., @samp{~ (@var{list}) @var{regexp}}
1100 @item Implement @command{bg} and @command{fg} as editors of @code{eshell-process-list}
1102 Using @command{bg} on a process that is already in the background does
1103 nothing.  Specifying redirection targets replaces (or adds) to the list
1104 current being used.
1106 @item Have @command{jobs} print only the processes for the current shell
1108 @item How can Eshell learn if a background process has requested input?
1110 @item Support @samp{2>&1} and @samp{>&} and @samp{2>} and @samp{|&}
1112 The syntax table for parsing these should be customizable, such that the
1113 user could change it to use rc syntax: @samp{>[2=1]}.
1115 @item Allow @samp{$_[-1]}, which would indicate the last element of the array
1117 @item Make @samp{$x[*]} equal to listing out the full contents of @samp{x}
1119 Return them as a list, so that @samp{$_[*]} is all the arguments of the
1120 last command.
1122 @item Copy ANSI code handling from @file{term.el} into @file{em-term.el}
1124 Make it possible for the user to send char-by-char to the underlying
1125 process.  Ultimately, I should be able to move away from using term.el
1126 altogether, since everything but the ANSI code handling is already part
1127 of Eshell.  Then, things would work correctly on MS-Windows as well
1128 (which doesn't have @file{/bin/sh}, although @file{term.el} tries to use
1129 it).
1131 @item Make the shell spawning commands be visual
1133 That is, make (@command{su}, @command{bash}, @command{telnet},
1134 @command{rlogin}, @command{rsh}, etc.)@: be part of
1135 @code{eshell-visual-commands}.  The only exception is if the shell is
1136 being used to invoke a single command.  Then, the behavior should be
1137 based on what that command is.
1139 @item Create a smart viewing command named @command{open}
1141 This would search for some way to open its argument (similar to opening
1142 a file in the Windows Explorer).
1144 @item Alias @command{read} to be the same as @command{open}, only read-only
1146 @item Write a @command{tail} command which uses @code{view-file}
1148 It would move point to the end of the buffer, and then turns on
1149 auto-revert mode in that buffer at frequent intervals---and a
1150 @command{head} alias which assumes an upper limit of
1151 @code{eshell-maximum-line-length} characters per line.
1153 @item Make @command{dgrep} load @code{dired}, mark everything, then invoke @code{dired-do-search}
1155 @item Write @file{mesh.c}
1157 This would run Emacs with the appropriate arguments to invoke Eshell
1158 only.  That way, it could be listed as a login shell.
1160 @item Use an intangible @code{PS2} string for multi-line input prompts
1162 @item Auto-detect when a command is visual, by checking @code{TERMCAP} usage
1164 @item The first keypress after @kbd{M-x watson} triggers
1165 @code{eshell-send-input}
1167 @item Make @kbd{/} electric
1169 So that it automatically expands and corrects pathnames.  Or make
1170 pathname completion for Pcomplete auto-expand @samp{/u/i/std<TAB>} to
1171 @samp{/usr/include/std<TAB>}.
1173 @item Write the @command{pushd} stack to disk along with @code{last-dir-ring}
1175 @item Add options to @code{eshell/cat} which would allow it to sort and uniq
1177 @item Implement @command{wc} in Lisp
1179 Add support for counting sentences, paragraphs, pages, etc.
1181 @item Once piping is added, implement @command{sort} and @command{uniq} in Lisp
1183 @item Implement @command{touch} in Lisp
1185 @item Implement @command{comm} in Lisp
1187 @item Implement an @command{epatch} command in Lisp
1189 This would call @code{ediff-patch-file}, or @code{ediff-patch-buffer},
1190 depending on its argument.
1192 @item Have an option such that @samp{ls -l} generates a dired buffer
1194 @item Write a version of @command{xargs} based on command rewriting
1196 That is, @samp{find X | xargs Y} would be indicated using @samp{Y
1197 $@{find X@}}.  Maybe @code{eshell-do-pipelines} could be changed to
1198 perform this on-thy-fly rewriting.
1200 @item Write an alias for @command{less} that brings up a @code{view-mode} buffer
1202 Such that the user can press @key{SPC} and @key{DEL}, and then @key{q}
1203 to return to Eshell.  It would be equivalent to:
1204 @samp{X > #<buffer Y>; view-buffer #<buffer Y>}.
1206 @item Make @code{eshell-mode} as much a full citizen as @code{shell-mode}
1208 Everywhere in Emacs where @code{shell-mode} is specially noticed, add
1209 @code{eshell-mode} there.
1211 @item Permit the umask to be selectively set on a @command{cp} target
1213 @item Problem using @kbd{M-x eshell} after using @code{eshell-command}
1215 If the first thing that I do after entering Emacs is to run
1216 @code{eshell-command} and invoke @command{ls}, and then use @kbd{M-x
1217 eshell}, it doesn't display anything.
1219 @item @kbd{M-RET} during a long command (using smart display) doesn't work
1221 Since it keeps the cursor up where the command was invoked.
1223 @end table
1225 @node GNU Free Documentation License
1226 @appendix GNU Free Documentation License
1227 @include doclicense.texi
1229 @node Concept Index
1230 @unnumbered Concept Index
1232 @printindex cp
1234 @node Function and Variable Index
1235 @unnumbered Function and Variable Index
1237 @printindex fn
1239 @node Command Index
1240 @unnumbered Command Index
1242 @printindex cm
1244 @node Key Index
1245 @unnumbered Key Index
1247 @printindex ky
1248 @bye