0

我想在 (Windows 10) powershell 中使用以下命令编辑服务:

> oc edit service helloworld -o json

这将打开记事本作为编辑器来编辑文件。但是,我确实想在带有语法突出显示的编辑器中打开它。我在文档中找到了以下内容: 文档片段

这将导致以下命令。我已将 sublime text 3 添加到我的路径中,但是当我运行命令时:

> OC_EDITOR="subl" oc edit service helloworld -o json

输出是:

OC_EDITOR=subl : The term 'OC_EDITOR=subl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

我尝试了所有类型的变体,例如带/不带引号、sublime_text,但它们似乎不起作用。

从命令行运行 subl 或 sublime_text 只会打开 sublime text 3。

4

1 回答 1

2

您发布的屏幕截图显示了如何oc通过设置仅适用于该命令的环境变量来覆盖 Bash (linux shell) cli 上的编辑器。

我对 Powershell 并不太熟悉,但我认为应该应用相同的逻辑。如果您在 Powershell 会话中创建OC_EDITOR环境变量,它应该允许oc edit您的 Sublime Text 编辑器使用。

Set-Item -Path Env:OC_EDITOR -Value subl

您可以确认这是通过

Get-ChildItem Env:OC_EDITOR

现在,我没有oc在 Windows 机器上安装我的工具来测试它,但它应该可以工作。


Powershell 参考:https ://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables

于 2019-02-05T15:40:42.950 回答