1 ;;; em-script.el --- Eshell script files
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009 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/>.
30 (eshell-defgroup eshell-script nil
31 "This module allows for the execution of files containing Eshell
32 commands, as a script file."
33 :tag
"Running script files."
34 :group
'eshell-module
)
38 (defcustom eshell-script-load-hook
'(eshell-script-initialize)
39 "*A list of functions to call when loading `eshell-script'."
41 :group
'eshell-script
)
43 (defcustom eshell-login-script
(concat eshell-directory-name
"login")
44 "*If non-nil, a file to invoke when starting up Eshell interactively.
45 This file should be a file containing Eshell commands, where comment
46 lines begin with '#'."
48 :group
'eshell-script
)
50 (defcustom eshell-rc-script
(concat eshell-directory-name
"profile")
51 "*If non-nil, a file to invoke whenever Eshell is started.
52 This includes when running `eshell-command'."
54 :group
'eshell-script
)
58 (defun eshell-script-initialize ()
59 "Initialize the script parsing code."
60 (make-local-variable 'eshell-interpreter-alist
)
61 (setq eshell-interpreter-alist
62 (cons '((lambda (file)
63 (string= (file-name-nondirectory file
)
64 "eshell")) . eshell
/source
)
65 eshell-interpreter-alist
))
66 (make-local-variable 'eshell-complex-commands
)
67 (setq eshell-complex-commands
68 (append '("source" ".") eshell-complex-commands
))
69 ;; these two variables are changed through usage, but we don't want
70 ;; to ruin it for other modules
71 (let (eshell-inside-quote-regexp
72 eshell-outside-quote-regexp
)
73 (and (not eshell-non-interactive-p
)
75 (file-readable-p eshell-login-script
)
77 (list 'eshell-commands
78 (catch 'eshell-replace-command
79 (eshell-source-file eshell-login-script
))) t
))
81 (file-readable-p eshell-rc-script
)
83 (list 'eshell-commands
84 (catch 'eshell-replace-command
85 (eshell-source-file eshell-rc-script
))) t
))))
87 (defun eshell-source-file (file &optional args subcommand-p
)
88 "Execute a series of Eshell commands in FILE, passing ARGS.
89 Comments begin with '#'."
93 (inhibit-point-motion-hooks t
)
94 after-change-functions
)
95 (goto-char (point-max))
96 (insert-file-contents file
)
97 (goto-char (point-max))
98 (throw 'eshell-replace-command
101 (list (list 'eshell-command-name
(list 'quote file
))
102 (list 'eshell-command-arguments
104 (let ((cmd (eshell-parse-command (cons here
(point)))))
106 (setq cmd
(list 'eshell-as-subcommand cmd
)))
108 (delete-region here
(point))
111 (defun eshell/source
(&rest args
)
112 "Source a file in a subshell environment."
113 (eshell-eval-using-options
115 '((?h
"help" nil nil
"show this usage screen")
118 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1,
120 (eshell-source-file (car args
) (cdr args
) t
)))
122 (put 'eshell
/source
'eshell-no-numeric-conversions t
)
124 (defun eshell/.
(&rest args
)
125 "Source a file in the current environment."
126 (eshell-eval-using-options
128 '((?h
"help" nil nil
"show this usage screen")
131 Invoke the Eshell commands in FILE within the current shell
132 environment, binding ARGS to $1, $2, etc.")
133 (eshell-source-file (car args
) (cdr args
))))
135 (put 'eshell
/.
'eshell-no-numeric-conversions t
)
140 ;; generated-autoload-file: "esh-groups.el"
143 ;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647
144 ;;; em-script.el ends here