DominicHamon.com

Life is like a grapefruit

Fun with Windows CMD.exe

While I was in a semi-conscious state this morning, my body awaiting the arrival of sweet, sweet caffeine, and due to some issues I’m having with my work environment setup, I happened to check out what environment variables were set. I noticed one named ‘PROMPT’ that I immediately assumed worked similarly to the PS1 and PS2 environment variables under bash.

I briefly searched to see if I could find any documentation on this, but came up short and decided to do my own digging.

The default setting appears to be $P$G, which gives you your current path, followed by the ‘>’ symbol. I went through a heap of $<x> combinations to see what other things I could get into my prompt. Here are the results:

$A &
$B |
$C (
$D Today’s date
$E Some little box character
$F )
$G >
$L <
$N Current path drive letter
$P Current path
$Q =
$S A single space
$T Current time
$V Current version of Windows
$$ $
$& %
$_ Adds a newline
$+<x> x

My new prompt is then

$+[$T$+]$S$P$S$$$S

which looks like:

[ 9:38:26.39] E: $

Now if I can figure out how to get some colour in there, we’re laughing…

On a side note, does tumblr just hate html tables or am I doing something horribly wrong when I try to add them?

Update: If you type ‘prompt /?’ at the command prompt, the above list is laid out for you. That would have saved me some time. If you use the ‘prompt’ command to set your prompt, it seems to only hold for the duration of the cmd process, so it might be useful in a batch file. Perhaps combining this with the ‘color’ command and running that instead of ‘cmd’ directly is the way to get a pretty command prompt.

I’m fairly sure there’s a way to use the $e escape code to get colours too, but no success yet…

Posted on 2008/11/13 in personal | Tagged command-line, WinXP tip | Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Recent Posts

Archives

Search

Search

Copyright © Dominic Hamon 2021. WordPress theme by Ryan Hellyer.