Nov 052014
 

What’s a Command Prompt?

This is the line of text prefixed automatically by the environment to the command you’re writing for an e.g. see below screenshot…

Customizing Command Prompt

How Can I Customize The Command Prompt?

Microsoft provides a built in command named as Prompt. As the name suggests this just help customize the prompt text shown in a command window. See the help for this command…

c:\Windows\System32>prompt /?
Changes the cmd.exe command prompt.

PROMPT text

text    Specifies a new command prompt.

Prompt 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)
$N   Current drive
$P   Current drive and path
$Q   = (equal sign)
$S     (space)
$T   Current time
$V   Windows version number
$_   Carriage return and linefeed
$$   $ (dollar sign)

If Command Extensions are enabled the PROMPT command supports
the following additional formatting characters:

$+   zero or more plus sign (+) characters depending upon the
depth of the PUSHD directory stack, one character for each
level pushed.

$M   Displays the remote name associated with the current drive
letter or the empty string if current drive is not a network
drive.

Some Killer Sample Prompt Commands and Their Output

Please refer above help to figure what every character after the $ mean…

  • Command: prompt ——$G$P$G
    • New Prompt: ——>c:\Windows\System32>
  • Command: c:\Windows\System32>prompt $V$G$P$G
    • New Prompt: Microsoft Windows [Version 6.3.9600]>c:\Windows\System32>
  • Command: c:\Windows\System32>|>prompt $P$G$B$+$G
    • New Prompt: c:\Windows\System32>|>.
      The above prompt adds a ‘+’ sign for every pushd you do and removes the last ‘+’ after a popd. See below…
  • c:\Windows\System32>|>pushd c:\
    c:\>|+>pushd e:\
    e:\>|++>popd
    c:\>|+>popd
    c:\Windows\System32>|>
  • Funky Command:  prompt ╔═════════════════════╗$_║$P:$G$+║$_╚═════════════════════╝$_
    • New Prompt:
      ╔═════════════════════╗
      ║c:\Windows\System32:>║
      ╚═════════════════════╝

This just shows that you can customize the prompt to some extent. Above prompt will be ok if the current directory path is a small one but once it gets bigger you’ll have to adjust the square…

How to Make the Command Prompt Permanent?

Your custom command prompt will stick only for this session of cmd. If you start another instance of a cmd.exe you’ll end up seeing the default value or the one that’s setup elsewhere (as shown below).

So the question is how do we setup a command prompt that stays across sessions? Via the environment variable PROMPT. See below for my case…

Permanently Customizing Command Prompt

My personal favorite prompt is the one set by following command…

PROMPT $P$G$_$$$G

To set this as your prompt you can add an environment variable called PROMPT. Open environment variable window and then add the value as shown below…

Permanently Customizing Command Prompt

So now if you open a cmd instance you should see the following prompt…

Permanently Customizing Command Prompt

How do I revert my changes to the Command Prompt?

Valid question. To revert back to the original prompt, just type in command PROMPT without any arguments. You should see the prompt revert back to default. You might also want to remove the environment variable PROMPT else for next session you’ll again see the prompt you’ve setup.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.