A better PROMPT for CMD.EXE or Cool Prompt Environment Variables and a nice transparent multi-prompt
A number a people have commented on my simple, but customized command prompt. Actually I have a few, but for cmd.exe, I do this. Right-click on My Computer|Properties. Then from the Advanced Tab, click Environment Variables, then add a new User Variable called PROMPT and set it to $p$_$+$g. This came originally from Craig Andera, who got it from Shawn Van Ness. Sahil Malik also has some great command line tricks. Junfeng points out the little known ntcmds.chm.
Here's the breakdown:
- $P = Current Directory's Path
- $_ = Carriage Return
- $+ = A plus sign for each level in the PUSHD/POPD stack.
Here's some other interesting prompts. Paste these into any CMD.EXE window:
set prompt=[%computername%] $d$s$t$_$p$_$_$+$g
yields this. Note the use of an environment variables within a prompt. Here's an extensive list of environment variables.
[SCOTTPC] Thu 07/13/2006 22:19:20.40
C:\Documents and Settings\Scott
Another nice one:
set=prompt=$m$_$p$g
yields this when on a UNC Mapped Drive:
\\FREDPC\C$
Z:\Documents and Settings\Fred
There's all sorts of crap that PROMPT /? gives you:
$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 XP version number
$_ Carriage return and linefeed
$$ $ (dollar sign)
$+ 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.
Here's my command prompt. It's transparent because I use the awesome Console 2.00 Beta, build 122 hosted at SourceForge. I blogged about this last November.
Note the multiple tabs. I've got PowerShell, CMD.EXE and two VisualStudio Windows, each in their own tab. I could add a tab for Cygwin, but really, with PowerShell, who needs ls -alogF?
Console uses a XML settings file (console.xml) that takes a while to understand. Here's a snippet of my settings. I used short filenames in the VS.NET stuff for simplicity and avoidance of quoted quotes. Remember, DIR /X will give you short filenames for things like this.
...Snip...this is a PARTIAL snippet for illustrative purposes...
<tabs>
<tab title="Console">
<console shell="" init_dir=""/>
</tab>
<tab title="PowerShell">
<console shell="c:\program files\windows powershell\v1.0\powershell.exe" init_dir=""/>
</tab>
<tab title="VS.NET 2003">
<console shell="cmd /k C:\PROGRA~1\MICROS~2.NET\Common7\Tools\vsvars32.bat" init_dir=""/>
</tab>
<tab title="VS.NET 2005">
<console shell="cmd /k C:\PROGRA~1\MID05A~1\VC\vcvarsall.bat" init_dir=""/>
</tab>
</tabs>
My font is Consolas, Size 15, Kermit Green (0x00FF00). Enjoy.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.



About Newsletter