我可以在Emacs的shell模式下使用PowerShell吗?

13

我可以在Emacs的shell模式下使用PowerShell作为默认的shell吗?
如何实现?


3
有这篇博客文章(http://blogs.msdn.com/powershell/archive/2008/04/15/powershell-running-inside-of-emacs.aspx)以及这些指示(http://blogs.msdn.com/dotnetinterop/archive/2008/04/10/run-powershell-as-a-shell-within-emacs.aspx)。 - Matthew Flaschen
4个回答

8

9
一个更有用的链接是 http://blogs.msdn.com/dotnetinterop/archive/2008/04/10/run-powershell-as-a-shell-within-emacs.aspx。 - Chris Conway
2
这两个链接对我来说都无法访问 :( - ucsky
1
内容已移动,这是当前链接 - chaorace

7

基于博客文章在Emacs中作为shell运行PowerShell(2008年4月)和Emacs Wiki上关于PowerShell的部分,称为将PowerShell作为次要shell(更新于2010年5月):

  • powershell.el保存在Emacs安装目录下的.\share\emacs\site-lisp或任何其他load-path中的目录中。(powershell.el太长了,无法包含在此答案中。如博客文章所述,当标准输入和输出被重定向时,没有办法强制PowerShell以交互模式运行,因此需要相当多的粘合代码来将其用作较低级别的shell。)

  • 将以下内容添加到你的.emacs文件中:

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

完成后,使用M-x powershell打开并交互使用PS shell缓冲区。


4

与其使用一整个包,我想出了一个只有五行代码的方案,它已经满足我的需求。你可能想要快速地调整它来适应自己的需求。

(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)))

这在 Windows 10 上使用 emacs-26.3-x86_64-no-deps 运行良好。 - ucsky

2

最快的方法是运行shell模式,然后从命令行运行powershell。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接