[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: simple useful functions
From: |
Stefan Monnier |
Subject: |
Re: simple useful functions |
Date: |
Fri, 03 Dec 2010 21:36:31 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> (defun source (script &optional shell keep-current-directory)
> "Source the specified shell script.
> Source the shell SCRIPT and import the environment into this
> emacs. The optional SHELL specifies the shell other than the
> default `shell-file-name'. When KEEP-CURRENT-DIRECTORY is nil,
> which is the default, the current directory is temporarily
> changed to the directory where the script resides while sourcing
> the script."
> (interactive "fscript file: ")
> (if (null shell)
> (setq shell shell-file-name))
> (with-temp-buffer
> (unless keep-current-directory
> (setq default-directory (file-name-directory script)))
> (call-process shell nil t nil "-c" (concat "source " script "; printenv"))
> (while (re-search-backward "^\\([^=]+\\)=\\(.*\\)$" nil t)
> (setenv (match-string 1) (match-string 2)))))
Some problems I see with it, by order of decreasing importance:
- I fail to see in which circumstance(s) this is useful.
- What if the user uses scsh/emacs for his shell.
- Most scripts don't setup much of environment.
- AFAIC things like ~/.cshrc are not a scripts but a config files.
- The call-process needs to quote `script' (and should probably be
replaced by process-file).
- The prompt should start with a capital.
Stefan
- Re: simple useful functions, Tak Ota, 2010/12/03
- Re: simple useful functions,
Stefan Monnier <=
- Re: simple useful functions, Tak Ota, 2010/12/03
- Re: simple useful functions, Stefan Monnier, 2010/12/03
- Re: simple useful functions, David Kastrup, 2010/12/04
- Re: simple useful functions, Tak Ota, 2010/12/06
- Re: simple useful functions, Stefan Monnier, 2010/12/06
- Re: simple useful functions, Tak Ota, 2010/12/06
- Re: simple useful functions, Stefan Monnier, 2010/12/06
- Re: simple useful functions, René Kyllingstad, 2010/12/06
- Re: simple useful functions, Stefan Monnier, 2010/12/06