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
function prompt { "PS " + (get-location).Path + [System.Environment]::NewLine + ">" }
I've placed it in my PowerShell profile folder, but I haven't yet discovered a means of adding the pushd/popd stack. Have you done something similar with your PowerShell prompt?
My thought is this: I wonder how well this app would work to allow you to manage these various environments...
...Either way it is not unusual for me to have 4-6 consoles open at once, and it's almost remeniscent of a huge game of hunt the wumpus especially when each one has different environment settings....
$depth = ""
for($i = 0; $i -lt (get-location -stack).count; $i++)
{ $depth += "+" }
However, if I go into Edit | Settings | Appearance and select a custom color for my font, that color "takes over" and everything appears in that color. Colors specified in PowerShell (e.g. write-host -foregroundcolor red "Hello World") are ignored.
Anyone know how to get around this?
The possibilities for Console 2 (I must look at the eConsole original too) had my brain spinning. I was thinking the same as Arthur, and I love what Arild does.
The idea of an IDE wrapper for console sessions is super-cool. I can also see it as a way to build a friendlier way for newbies to learn how to deal with this world, something that has to be dealt with as part of learning to do native system development (i.e., in conjunction with VC++ 2005 Express Edition).
Not like I haven't created enough incomplete projects for myself or anything like that, but this is definitely on my list for supporting new developers once I've completed on my promise to document console-sessions for beginners.
- Dennis
PS: Being groggy, I clicked "Kick It" and now have no idea what else I am getting myself into. I figured it was new geek-speak for leaving comments. Sigh.
PPS: I'm at a wedding on July 22, so I won't make the Portland CodeCamp. Maybe I can wear my startling Seattle CodeCamp T-shirt under my suit? Sort of a secret sympathy move?
[%ComputerName%\%Username%] $t$_$p$_$_$+$g
Which helps me a lot as I 'Run As' different accounts a lot according to required privileges at the time.
Now I should start looking into how to make PowerShell do this as well (unless someone already has this figured and can post it).
Comments are closed.
It's like staring into a magic eye painting. I've gone crosseyed.
At least with Aero Glass, the non-functional areas of the window are semi-transparent. The main work area of the window is still opaque and easy to read.