sas*_*ang 78 windows powershell
使用Windows PowerShell,如何更改命令提示符?
例如,默认提示符说
PS C:\Documents and Settings\govendes\My Documents>
Run Code Online (Sandbox Code Playgroud)
我想自定义该字符串.
Oca*_*tal 95
只需将该函数prompt放入PowerShell配置文件(notepad $PROFILE)中,例如:
function prompt {"PS: $(get-date)>"}
Run Code Online (Sandbox Code Playgroud)
或有色:
function prompt
{
Write-Host ("PS " + $(get-date) +">") -nonewline -foregroundcolor White
return " "
}
Run Code Online (Sandbox Code Playgroud)
War*_*ens 20
与Ocaso Protal的回答相关,Windows Server 2012以及Windows 7(在PowerShell窗口中)需要以下内容:
new-item -itemtype file -path $profile -force
notepad $PROFILE
Run Code Online (Sandbox Code Playgroud)
如果你运行多个用户名(例如你自己+一个生产登录),我会建议以下作为提示:
function Global:prompt {"PS [$Env:username]$PWD`n>"}
Run Code Online (Sandbox Code Playgroud)
(此信息归功于David I. McIntosh.)
如果你想自己做,那么Ocaso Protal的答案是要走的路.但是,如果你像我一样懒,只是想为你做点什么,那么我强烈推荐Luke Sampson的Pshazz套餐.
只是为了告诉你你有多懒,我会提供一个快速的教程.
scoop install pshazz)pshazz use msys)Pshazz还允许您创建自己的主题,这与配置JSON文件一样简单.查看我的看看它有多容易!
小智 7
在提示符下,我喜欢当前的时间戳和已解析的网络驱动器的驱动器号。为了使其更具可读性,我将其分成两行,并使用了一些颜色。
有了CMD,我最终得到了
PROMPT=$E[33m$D$T$H$H$H$S$E[37m$M$_$E[1m$P$G
Run Code Online (Sandbox Code Playgroud)
对于PowerShell,我得到了与以下相同的结果:
function prompt {
$dateTime = get-date -Format "dd.MM.yyyy HH:mm:ss"
$currentDirectory = $(Get-Location)
$UncRoot = $currentDirectory.Drive.DisplayRoot
write-host "$dateTime" -NoNewline -ForegroundColor White
write-host " $UncRoot" -ForegroundColor Gray
# Convert-Path needed for pure UNC-locations
write-host "PS $(Convert-Path $currentDirectory)>" -NoNewline -ForegroundColor Yellow
return " "
}
Run Code Online (Sandbox Code Playgroud)
可读性更高:-)
顺便说一句:
powershell_ise.exe $PROFILE(哑)记事本。如果您要共享网络,此版本的沃伦·史蒂文斯(Warren Stevens)的答案避免了路径中嘈杂的“ Microsoft.PowerShell.Core \ FileSystem” Set-Location。
function prompt {"PS [$Env:username@$Env:computername]$($PWD.ProviderPath)`n> "}
Run Code Online (Sandbox Code Playgroud)
小智 5
仅显示驱动器号,我使用:
function prompt {(get-location).drive.name+"\...>"}
Run Code Online (Sandbox Code Playgroud)
然后返回到我使用的路径:
function prompt {"$pwd>"}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45889 次 |
| 最近记录: |