![如何在 Windows 10 中永久设置我的 cmd 提示符](https://linux22.com/image/1608124/%E5%A6%82%E4%BD%95%E5%9C%A8%20Windows%2010%20%E4%B8%AD%E6%B0%B8%E4%B9%85%E8%AE%BE%E7%BD%AE%E6%88%91%E7%9A%84%20cmd%20%E6%8F%90%E7%A4%BA%E7%AC%A6.png)
我知道我可以使用命令动态设置它PROMPT
,但是如何为每个控制台会话设置它?
答案1
我假设你指的是 Powershell 中的提示符,因为它是 Windows 10 中的默认 shell
提示是通过全局设置的
"%UserProfile%\Documents\WindowsPowerShell\profile.ps1"
无颜色:
Function set-prompt { "$ESC[$($executionContext.SessionState.Path.CurrentLocation)$('$' * ($nestedPromptLevel + 1)) $ESC[0m" }
带颜色:
switch ($Action) { "Default" { Function global:prompt { if (test-path variable:/PSDebugContext) { '[DBG]: ' } write-host " " write-host ("$ESC[48;2;40;40;40m$ESC[38;2;170;210;0m$(Get-Location) $ESC[0m $ESC[0m") if ( $host.UI.RawUI.WindowTitle -match "Administrator" ) { $Host.UI.RawUI.ForegroundColor = 'Red' $(if ($nestedpromptlevel -ge 1) { write-host ('PS $$ ') -ForegroundColor Red -NoNewLine } else { write-host ('PS $ ') -ForegroundColor Red -NoNewLine }) } else { $(if ($nestedpromptlevel -ge 1) { write-host ('PS $$ ') -ForegroundColor Blue -NoNewLine } else { write-host ('PS $ ') -ForegroundColor Blue -NoNewLine }) } return " " } } } set-prompt Default
- 向用户显示彩色文本提示,向管理员显示红色文本提示
- 允许即时切换配置文件:
- 复制/粘贴
Default
以下部分并进行相应编辑(包括名称,即Default
)set-prompt Default
. 通过||重新加载会话并切换提示符set-prompt <name>
- 复制/粘贴