【发布时间】:2019-01-09 20:11:57
【问题描述】:
有没有办法在已运行的完成脚本和 VSCode 中的下一个命令行提示符之间添加换行符。在 powershell 的 ISE 控制台中,它跳过了几行以使其更易于阅读。我浏览网页寻找答案,但我认为我的搜索措辞不正确。任何想法都会有所帮助。
【问题讨论】:
-
见
get-help about_prompts -Full
标签: powershell visual-studio-code
有没有办法在已运行的完成脚本和 VSCode 中的下一个命令行提示符之间添加换行符。在 powershell 的 ISE 控制台中,它跳过了几行以使其更易于阅读。我浏览网页寻找答案,但我认为我的搜索措辞不正确。任何想法都会有所帮助。
【问题讨论】:
get-help about_prompts -Full
标签: powershell visual-studio-code
如果您阅读了 Kory Gill 记录的 about_prompts 帮助文件(通过运行 get-help about_prompts -Full),那么这里有很多关于更改默认提示行为的示例。
运行(Get-Command Prompt).ScriptBlock 以获取默认布局。我的默认Prompt函数:
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
# .Link
# https://go.microsoft.com/fwlink/?LinkID=225750
# .ExternalHelp System.Management.Automation.dll-help.xml
要在之前的代码输出后添加两个换行符,请运行:
Function Prompt {
"
PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
# .Link
# https://go.microsoft.com/fwlink/?LinkID=225750
# .ExternalHelp System.Management.Automation.dll-help.xml
}
要使这些设置保持不变,您需要将修改后的函数添加到您的 PowerShell 配置文件中。
复制上面的代码(或您喜欢的代码)并将其添加到 C:\Users\User\Documents\WindowsPowershell\Profile.ps1 中的配置文件脚本中,如 about_Profiles 中所述。这将使所需的提示行为持续存在,并且还将应用于 vscode 中的嵌入式 PowerShell 终端。这些是about_Profiles 中记录的配置文件脚本位置:
Description Path
----------- ----
Current User, Current Host $Home\[My ]Documents\WindowsPowerShell\Profile.ps1
Current User, All Hosts $Home\[My ]Documents\Profile.ps1
All Users, Current Host $PsHome\Microsoft.PowerShell_profile.ps1
All Users, All Hosts $PsHome\Profile.ps1
运行help about_Profiles -Full 以了解有关配置文件的更多信息。
【讨论】:
Function Prompt { $date = Get-Date -Format G "[$date]:$($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; # .Link # https://go.microsoft.com/fwlink/?LinkID=225750 # .ExternalHelp System.Management.Automation.dll-help.xml }