我已经开始“玩弄” PowerShell,并试图让它“表现”。
我想做的一件事是将 PROMPT 自定义为与 MS-Dos 上的 "$M$P$_$+$G" 所做的“相似”:
这些功能的快速概述:
性格| 说明
$m 与当前驱动器号关联的远程名称,如果当前驱动器不是网络驱动器,则为空字符串。
$p 当前驱动器和路径
$_ ENTER-LINEFEED
$+ 零个或多个加号 (+) 字符取决于推送目录堆栈的深度,每个推送的级别一个字符
$g >(大于号)
所以最终的输出是这样的:
\\spma1fp1\JARAVJ$ H:\temp
++>
我已经能够将$M
and$_
功能(和一个漂亮的历史功能)添加到我的提示中,如下所示:
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
>"
}
但其余的还不是我设法复制的东西......
非常感谢您肯定会提供的提示!