Home > Mods and hacks, Smart Tip, Windows > Change the prompt of the command prompt

Change the prompt of the command prompt


It all began one day when i was just messing around with command prompt and unknowingly changed the Prompt of the window and did not know how to get it back.

So i decided to do some R&D for it. I do not mess around much with CMD, i have certain commands i work with but have not delved much deep into it so far. Anyways, here is the data required related to Changing your command prompt prompt.

PROMPT is implemented as a hidden* environment variable called PROMPT. You can see it by typing the foll Command in command Prompt.

ECHO %prompt%

Under Normal Conditions, the above command will return the foll result : $P$G

The Syntax for changing the prompt is as below :

Syntax : PROMPT [text] here, text is a text string.

The prompt text [text] can be made up of normal characters and the following special codes:

$A  &           (Ampersand)

$B  |           (pipe)

$C  (           (Left parenthesis)

$D Current date

$E Escape code  (ASCII code 27)

$F  )           (Right parenthesis)

$G >           (greater-than sign)

$H  Backspace   (erases previous character)

$L  <           (less-than sign)
$M  Display the remote name for Network drives

$N  Current drive

$P Current drive and path

$Q  =           (equal sign)

$S              (space)

$T  Current time

$V  Windows NT version number

$_  Carriage return and linefeed
$$  $           (dollar sign)
$+  Will display plus signs (+) one for each level of the PUSHD directory stack

Examples :

Display the UNC path whenever you are using a network drive (mapped with NET USE) : PROMPT $M$_$P$G

Simulate an HP-UX style prompt with the computername and the current folder on separate lines:

PROMPT=$p$_%username%@%computername%:.

Restore the default prompt :  PROMPT $P$G

You can also create a shortcut to the command prompt like this:     CMD /K PROMPT $M$_$P$G .  So that whenever you open cmd using that shortcut, you will see the selected prmpt pattern.

Note : The above methods will work only for the current session. Once you close the window the setting will go away. Also,If Command Extensions are disabled the commands $M and $+ are not supported.

So If you want to force an over-ride of the CMD prompt for all sessions, you can do so by setting a permanent environment variable with the appropriate prompt text. e.g.

SETX PROMPT $P$G

SETX is a command which “Creates or modifies environment variables in the user or system environment. Can set variables based on arguments, regkeys or file input.” SETX writes variables to the master environment in the registry.

Also the same can be done using the SET command. SET is a command that “Displays, sets, or removes cmd.exe environment variables.”

SET PROMPT = $P$G

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: