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