我开始尝试使用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
>"
}
但是我还没有成功复制其余部分......非常感谢您提供的技巧,这些对我很有帮助!