我已经开始“玩弄”PowerShell 并试图让它“正常运行”。
我想做的一件事是将 PROMPT 自定义为“类似于”MS-Dos 上的“$M$P$_$+$G”:
这些功能的简要概述:
字符|说明
$m 与当前驱动器盘符关联的远程名称,如果当前驱动器不是网络驱动器,则为空字符串。
$p 当前驱动器和路径
$_ 输入换行
$+ 零个或多个加号 (+) 字符,具体取决于 pushd 目录堆栈的深度,每个插入的级别一个字符
$g >(大于号)
所以最终的输出是这样的:
\\spma1fp1\JARAVJ$ H:\temp
++>
我已经能够将 $M
和 $_
功能(以及一个漂亮的历史记录功能)添加到我的提示中,如下所示:
function prompt
{
## Get the history. Since the history may be either empty,
## a single item or an array, the @() syntax ensures
## that PowerShell treats it as an array
$history = @(get-history)
## If there are any items in the history, find out the
## Id of the final one.
## PowerShell defaults the $lastId variable to '0' if this
## code doesn't execute.
if($history.Count -gt 0)
{
$lastItem = $history[$history.Count - 1]
$lastId = $lastItem.Id
}
## The command that we're currently entering on the prompt
## will be next in the history. Because of that, we'll
## take the last history Id and add one to it.
$nextCommand = $lastId + 1
## Get the current location
$currentDirectory = get-location
## Set the Windows Title to the current location
$host.ui.RawUI.WindowTitle = "PS: " + $currentDirectory
## And create a prompt that shows the command number,
## and current location
"PS:$nextCommand $currentDirectory
>"
}
但其余的还不是我设法复制的东西......
非常感谢您一定会提供的提示!
最佳答案
看看这是否符合您的要求:
function prompt
{
## Get the history. Since the history may be either empty,
## a single item or an array, the @() syntax ensures
## that PowerShell treats it as an array
$history = @(get-history)
## If there are any items in the history, find out the
## Id of the final one.
## PowerShell defaults the $lastId variable to '0' if this
## code doesn't execute.
if($history.Count -gt 0)
{
$lastItem = $history[$history.Count - 1]
$lastId = $lastItem.Id
}
## The command that we're currently entering on the prompt
## will be next in the history. Because of that, we'll
## take the last history Id and add one to it.
$nextCommand = $lastId + 1
## Get the current location
$currentDirectory = get-location
## Set the Windows Title to the current location
$host.ui.RawUI.WindowTitle = "PS: " + $currentDirectory
##pushd info
$pushdCount = $(get-location -stack).count
$pushPrompt = ""
for ($i=0; $i -lt $pushdCount; $i++)
{
$pushPrompt += "+"
}
## And create a prompt that shows the command number,
## and current location
"PS:$nextCommand $currentDirectory `n$($pushPrompt)>"
}
关于c# - 自定义 PowerShell 提示符 - 相当于 CMD 的 $M$P$_$+$G?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/157923/