Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use PowerShell in shell-mode for Emacs?

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

like image 736
Cheeso Avatar asked May 16 '09 14:05

Cheeso


People also ask

How do I open Emacs in PowerShell?

Starting Emacs in GUI mode (Normal Startup)Open the cmd / powershell and type runemacs at the prompt.

How do I run a PowerShell script from the shell?

In File Explorer (or Windows Explorer), right-click the script file name and then select "Run with PowerShell". The "Run with PowerShell" feature starts a PowerShell session that has an execution policy of Bypass, runs the script, and closes the session.

Can I run a PowerShell script from Linux server?

PowerShell can be installed on different Linux distributions. Most Linux platforms and distributions have a major release each year, and provide a package manager that is used to install PowerShell.


2 Answers

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)))
like image 144
kotchwane Avatar answered Oct 01 '22 20:10

kotchwane


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.

like image 36
Ray Avatar answered Oct 01 '22 20:10

Ray