tags:

views:

69

answers:

3

I relise that I have to add something like:

shell

: to my .emacs file. But then how can I get it to do shell commands like:

cd /mydirectory

: and other shell actions

+4  A: 

This is a function which does what you want. You can add it (customizing the actions), or just add the body:

(defun shell-and-stuff ()
  "run a shell, then do some extra stuff"
  (interactive)
  (let ((shell-buf (get-buffer-create "*shell*")))
    (shell shell-buf)
    (comint-send-string
     (get-buffer-process shell-buf)
     "cd some-directory
ls
touch frog
")))
(shell-and-stuff)
Trey Jackson
+1  A: 

The cd part is easy, just let bind the variable default-directory. See this question for some possible solutions.

Ivan Andrus
+1  A: 

Trey Jackson's idea looks good. Also note that the manual (info "(emacs) Interactive Shell") says

Emacs sends the new shell the contents of the file ~/.emacs_SHELLNAME as input, if it exists, where SHELLNAME is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is ~/.emacs_bash. If this file is not found, Emacs tries to fallback on ~/.emacs.d/init_SHELLNAME.sh.

So you could put your commands in that file.

offby1