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