3

I'm very new to emacs and am currently using it to edit files on mac os x. How do I open instances of the shell from inside emacs so that I can execute the code I'm working on?

2
  • Welcome to Emacs.SE! Please have a look at this search for "emacs shell" for links to the manual and tutorials on using a shell within Emacs.
    – Dan
    Commented Aug 25, 2016 at 12:30
  • Press the escape key, then press the letter x, then type the word shell, then press the return key. Try that out and see if you like it. Then, instead of typing the word shell, you can type the word eshell in the above example. Then instead of typing the words shell or eshell, you can type the word term in the above example. None are as good as Terminal.app, but you can do most things inside of Emacs once you learn a few tricks like configuring the $PATH variable to your liking.
    – lawlist
    Commented Aug 25, 2016 at 13:40

3 Answers 3

2

I wrote this terminal command to open a terminal in the current working directory:

(defun terminal ()
  (interactive)
  (shell-command
   (format "open -b com.apple.terminal \"%s\""
       (if (buffer-file-name)
           (file-name-directory (buffer-file-name))
         (expand-file-name default-directory)))))

its not an emacs shell, but it is convenient for me.

2
  • what's the difference between this and M-x RET term ? Commented Nov 21, 2016 at 13:27
  • It opens the native Mac Terminal program in a separate window. Commented Nov 23, 2016 at 0:25
2

M-x eshell works. If you have helm M-x will show a list of possible completions when you start typing.

1
  • 2
    What's the link between helm and eshell?
    – JeanPierre
    Commented Sep 20, 2016 at 14:56
1

This is a really nice overview of various shell options in emacs. Which shell you use depends on what you need. Sane term is a nice basic terminal emulator. You can also look at the various settings I use if you like. I tend to use eshell for most things, but occasionally use sane term for more computation heavy tasks.

And here is another way to call a terminal, if you use iterm (which you should) on OS X.

     (defun open-dir-in-iterm ()
    "Open the current directory of the buffer in iTerm."
    (interactive)
    (let* ((iterm-app-path "/Applications/iTerm.app")
           (iterm-brew-path "/opt/homebrew-cask/Caskroom/iterm2/2.1.4/iTerm.app")
           (iterm-path (if (file-directory-p iterm-app-path)
                           iterm-app-path
                         iterm-brew-path)))
      (shell-command (concat "open -a " iterm-path " ."))))
      (global-set-key (kbd "C-x t") 'open-dir-in-iterm)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.