简体   繁体   中英

How to Permanently change PowerShell and CMD prompts

PowerShell prompt can be changed by calling

Function prompt{"new_prompt "}

and on the cmd prompt can be changed by calling

prompt $g$g$s

Once the current window is closed all the changes are gone and one will have to change them again when opening new instances of PowerShell or cmd . How can one make these changes permanent?

For PowerShell you'd put your custom Prompt() function in the relevant profile .

function Prompt {
    "PS ${env:USERNAME}@${env:COMPUTERNAME} $(Get-Location)> "
}

For CMD you'd set/modify the PROMPT environment variable, eg via setx :

setx PROMPT "%"USERNAME"%"@"%"COMPUTERNAME"%"$s$m$p$g$s

You have profile where you can put initialization for your PowerShell command prompts.

Type $profile in your PowerShell command to see where it resides

Then modify it or create a new one if there doesn't exist one eg profile.ps1.

eg then add

function prompt { "PS " + $(get-date) ">"}

You can read more about profiles here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM