Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 669
Amani Avatar asked Sep 06 '25 20:09

Amani


2 Answers

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, e.g. via setx:

setx PROMPT "%"USERNAME"%"@"%"COMPUTERNAME"%"$s$m$p$g$s
like image 148
Ansgar Wiechers Avatar answered Sep 10 '25 00:09

Ansgar Wiechers


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 e.g. profile.ps1.

e.g. then add

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

You can read more about profiles here

like image 21
AndersK Avatar answered Sep 10 '25 00:09

AndersK