13

Can I use powershell as the shell, in shell mode for emacs?
How?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • 3
    There's this blog post (http://blogs.msdn.com/powershell/archive/2008/04/15/powershell-running-inside-of-emacs.aspx) and these instructions (http://blogs.msdn.com/dotnetinterop/archive/2008/04/10/run-powershell-as-a-shell-within-emacs.aspx) – Matthew Flaschen May 16 '09 at 14:26

4 Answers4

8

See Jeffrey Snover's blog post PowerShell running inside of Emacs

John D. Cook
  • 29,517
  • 10
  • 67
  • 94
  • 9
    A more useful link would be http://blogs.msdn.com/dotnetinterop/archive/2008/04/10/run-powershell-as-a-shell-within-emacs.aspx – Chris Conway May 16 '09 at 17:26
  • 2
    boths links look dead to me :( – ucsky Apr 07 '19 at 06:38
  • 1
    The content has been moved, here's [the current link](https://blogs.msdn.microsoft.com/dotnetinterop/2008/04/10/run-powershell-as-a-shell-within-emacs/) – chaorace Jul 02 '20 at 13:28
7

Based on the blog post Run PowerShell as a shell within Emacs (April 2008), and the section of the Emacs Wiki article on PowerShell called PowerShell as an inferior shell (updated May 2010):

  • Save powershell.el in .\share\emacs\site-lisp under the Emacs install directory, or any other directory in your load-path. (powershell.el is too long to be included in this answer. As explained in the blog post, there is no way to force PowerShell to run in interactive mode when standard input and output are redirected, so a fair bit of glue code is needed to use it as an inferior shell.)

  • Add the following to your .emacs file:

    (autoload 'powershell "powershell" "Run powershell as a shell within emacs." t)

Once done, use M-x powershell to open and interactively use a PS shell buffer.

sjy
  • 2,702
  • 1
  • 21
  • 22
Ray
  • 187,153
  • 97
  • 222
  • 204
4

Instead of a whole package, I came up with a five-liner that works well enough for my needs. You might want to adapt it quickly.

(defun powershell (&optional buffer)
  "Launches a powershell in buffer *powershell* and switches to it."
  (interactive)
  (let ((buffer (or buffer "*powershell*"))
    (powershell-prog "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"))
    (make-comint-in-buffer "shell" "*powershell*" powershell-prog)
    (switch-to-buffer buffer)))
kotchwane
  • 2,082
  • 1
  • 19
  • 24
2

The quickest way to find out would be to run shell-mode, and then run powershell from the command line.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263