1 ;;; em-script.el --- Eshell script files
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: John Wiegley <johnw@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 (defgroup eshell-script nil
30 "This module allows for the execution of files containing Eshell
31 commands, as a script file."
32 :tag "Running script files."
33 :group 'eshell-module)
37 (defcustom eshell-script-load-hook '(eshell-script-initialize)
38 "*A list of functions to call when loading `eshell-script'."
40 :group 'eshell-script)
42 (defcustom eshell-login-script (concat eshell-directory-name "login")
43 "*If non-nil, a file to invoke when starting up Eshell interactively.
44 This file should be a file containing Eshell commands, where comment
45 lines begin with '#'."
47 :group 'eshell-script)
49 (defcustom eshell-rc-script (concat eshell-directory-name "profile")
50 "*If non-nil, a file to invoke whenever Eshell is started.
51 This includes when running `eshell-command'."
53 :group 'eshell-script)
57 (defun eshell-script-initialize ()
58 "Initialize the script parsing code."
59 (make-local-variable 'eshell-interpreter-alist)
60 (setq eshell-interpreter-alist
61 (cons '((lambda (file)
62 (string= (file-name-nondirectory file)
63 "eshell")) . eshell/source)
64 eshell-interpreter-alist))
65 (make-local-variable 'eshell-complex-commands)
66 (setq eshell-complex-commands
67 (append '("source" ".") eshell-complex-commands))
68 ;; these two variables are changed through usage, but we don't want
69 ;; to ruin it for other modules
70 (let (eshell-inside-quote-regexp
71 eshell-outside-quote-regexp)
72 (and (not eshell-non-interactive-p)
74 (file-readable-p eshell-login-script)
76 (list 'eshell-commands
77 (catch 'eshell-replace-command
78 (eshell-source-file eshell-login-script))) t))
80 (file-readable-p eshell-rc-script)
82 (list 'eshell-commands
83 (catch 'eshell-replace-command
84 (eshell-source-file eshell-rc-script))) t))))
86 (defun eshell-source-file (file &optional args subcommand-p)
87 "Execute a series of Eshell commands in FILE, passing ARGS.
88 Comments begin with '#'."
92 (inhibit-point-motion-hooks t)
93 after-change-functions)
94 (goto-char (point-max))
95 (insert-file-contents file)
96 (goto-char (point-max))
97 (throw 'eshell-replace-command
100 (list (list 'eshell-command-name (list 'quote file))
101 (list 'eshell-command-arguments
103 (let ((cmd (eshell-parse-command (cons here (point)))))
105 (setq cmd (list 'eshell-as-subcommand cmd)))
107 (delete-region here (point))
110 (defun eshell/source (&rest args)
111 "Source a file in a subshell environment."
112 (eshell-eval-using-options
114 '((?h "help" nil nil "show this usage screen")
117 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1,
119 (eshell-source-file (car args) (cdr args) t)))
121 (put 'eshell/source 'eshell-no-numeric-conversions t)
123 (defun eshell/. (&rest args)
124 "Source a file in the current environment."
125 (eshell-eval-using-options
127 '((?h "help" nil nil "show this usage screen")
130 Invoke the Eshell commands in FILE within the current shell
131 environment, binding ARGS to $1, $2, etc.")
132 (eshell-source-file (car args) (cdr args))))
134 (put 'eshell/. 'eshell-no-numeric-conversions t)
138 ;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647
139 ;;; em-script.el ends here