Powershell - 缩短了目录提示,但如何保存更改?

Dre*_*nai 4 powershell

在 Windows 10 中使用 Powershell。要更改提示:

PS C:\Users\b.HQ\Desktop\tsdev\my_folder> 
PS my_folder> tsc
Run Code Online (Sandbox Code Playgroud)

我在 Powershell 中使用了以下命令:

function prompt {'PS ' + $(Get-Location | Split-Path -Leaf) + ">"}
Run Code Online (Sandbox Code Playgroud)

但是,每次我重新启动 Powershell 时,我都必须重新输入。 有没有办法坚持这种变化?

PS我对Powershell的配置一无所知,我一直在寻找解决方案,但除了我使用的提示外,我没有看到保存它的方法。

Pli*_*kee 5

powershell管理员身份运行,然后运行以下命令:

Test-Path $Profile

如果它返回,false则不,您还没有配置文件,因此请创建它:

New-Item –Path $Profile –Type File –Force

(这将创建配置文件,或将覆盖现有的)

然后,编辑您的配置文件:

notepad $Profile

将您的功能放在文件中并保存。