September 20, 2006
Custom Windows CMD Prompt
I figured I would add this for the windows users out there who spend their fair share fo time in the cmd prompt. There is a certain format I’m accusomted to on all my machines. They show me who I am, the machine I’m on, the dir I’m in, and the time of the last commands completion. So i set out using some of the inspiration I found in the Hansel Mintutes podcast which I suggest everyone listen to. There is a lot of MS fanboy action but there are also a lot of valuable productivity tips so you take the good and try to ignore the bad.
I would give credit to the show they talked about altering the prompt but I don’t remember and couldn’t find it using their website and all it took for me was knowing it could be done and I quickly figured out how to do it on my own using methods. First I had to figure out what commands where available to the prompt. Easy enough there is a command called prompt that allows you to view the options available.
#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 XP 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.
If Command Extensions are enabled the PROMPT command supports the following additional formatting characters:
It’s a good starting point to look at. Next I had to look at the environment and see what options I had available there. Using the set command with no options gave me everything I needed there.
set PROMPT=[%USERNAME%@%COMPUTERNAME%$b$p] [$t]$_#
This gave me pretty much everything I needed with one little annoyance. I’m all about accurate timing but to the hundredth of a second is a bit extreme for me. So I started playing around trying to figure out a way to get the time sans the extras when I discovered something not in the documentation $h. What $h does is delete the previous character. So I placed $h$h$h in the line and came up with the following solution.