yazz.com
yazz.com

Reputation: 58786

How can I reload the interactive shell and run some commands on emacs startup?

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

Upvotes: 1

Views: 308

Answers (3)

offby1
offby1

Reputation: 6983

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.

Upvotes: 1

Ivan Andrus
Ivan Andrus

Reputation: 5301

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

Upvotes: 1

Trey Jackson
Trey Jackson

Reputation: 74430

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)

Upvotes: 4

Related Questions