2

I know you can customize settings or set environmental variables to get emacs to use other shells in shell-mode (1, 2). Is it possible to simply start a shell specifying which shell you want to use interactively?

Like: M-x other-shell RET /path/to/csh RET

Or set up something in your init file to let you use other shells fairly easily without changing the default?

3

This appears to do the job:

(defun other-shell (explicit-shell-file-name)
  (interactive "f")
  (if (called-interactively-p)
      (call-interactively #'shell)
    (shell)))

This relies on shell using the variable explicit-shell-file-name as a first choice of the shell to be used.

It also relies on not using lexical scoping.

|improve this answer|||||
  • This works if you don't already have a shell running. But if you do, it switches you to the existing shell. – Tyler Apr 10 '16 at 20:09
  • @Tyler Use a prefix argument to avoid that. No different from the original shell command. – Harald Hanche-Olsen Apr 10 '16 at 20:10
  • To use a prefix when you have helm-M-x bound see this asnwer emacs.stackexchange.com/questions/20299/… – salotz Apr 12 '16 at 1:32
  • AFAIK lexical scoping does not matter here since explicit-shell-file-name is defined through defcustom in shell.el and that marks the variable as special. – Tobias Mar 5 at 0:51
0

Building on Harald's answer. If you want to specify the shell by name (interactive "s" option) rather than path and use the default shell-file-name instead of the explicit path:

(defun other-shell (shell-file-name)
  (interactive "s")
  (if (called-interactively-p)
      (call-interactively #'shell)
    (shell)))

I found this to be more useful when using a shell like xonsh where I just want to use the one in the virtualenv that started emacs, rather than specify long explicit paths.

|improve this answer|||||
  • FYI: Also for this version of other-shell lexical scoping does not matter since (special-variable-p 'shell-file-name) gives t. – Tobias Mar 5 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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