eshell.texi 44 KB

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