在PowerShell中使用title命令

在Powershell中无法像在cmd内一样愉快的使用title命令来更改标题而是使用如下命令

1
$host.ui.RawUI.WindowTitle="自定义标题"

使用这条命令来更改属实是有点麻烦,很难记,所以我们使用alias来让title命令可以在Powershell内使用

1
test-path $profile

如果返回值为false则执行如下命令

1
New-Item -path $profile -type file -force

如果返回值为true则执行如下命令

注:在执行此命令前需要电脑内安装了Visual Studio Code

1
code $profile 

运行完之后会打开一个profile文件,在该文件内输入以下代码

1
2
3
4
function Set-WindowTitle {
$host.UI.RawUI.WindowTitle = [string]::Join(" ", $args)
}
Set-Alias -name "title" -value Set-WindowTitle

重启Powershell可以发现我们在PowerShell内可以使用title命令改更改窗口标题了

1
title A Minecraft Server