Personalize your command prompt with ANSI Escape Codes


hsehestedt

Well-known member
Guru
VIP
Local time
3:54 PM
Posts
4,087
Location
Texas, USA
OS
Win11 Pro 24H2
Some of you real old timers may remember the ASCII and ANSI art that was typical of BBS pages way back in the day.

With ASCII art, you could create banners and even complete images just using an arrangement of ASCII characters. By adding ANSI Escape Codes, you could add color.

Support for ANSI Escape Codes was discontinued in Windows after Windows Me and Windows NT, but returned decades later with Windows 10 1511.

Recently, I was running a whole bunch of commands and I wanted to get some rough idea of how long some of these commands took to run. Coincidentally I came upon a posting that made me realize that I could modify my command prompt to include the time in prompt and even add some color using ANSI Escape Codes.

NOTE: If you want to follow along, please feel free to type the commands below in a command prompt. These changes will affect only the current command prompt, they make no permanent changes. As soon as you close that command prompt, the change is lost. When you open a new command prompt, the prompt will be back to the default. See below if you want to make permanent changes. This works both with a standard command prompt and in Windows Terminal.

Here is an example of showing the time with the prompt, just run this command:

Code:
prompt [$T$H$H$H] $P$G

This makes the prompt look like this:

Image1.jpg

NOTE: If you run the command prompt /? you will see a list of codes that you can use with the prompt command. The default is $P$G. The $P shows the current drive and path while the $G shows a greater than sign.

Using ANSI Escape Codes, we can add a bit of color to the prompt like this:

Code:
prompt $E[38;5;84m$E[48;5;0m[$T$H$H$H]$E[38;5;15m$E[48;5;0m$S$P$G

Here is what the prompt looks like now:

Image2.jpg

For a reference of ANSI Escape Codes, please see this. In particular, take a look at the "256 colors" section:


That's really as far as I think I would normally need to go, but you could take this a whole lot further. Below is one more simple sample, but you could potentially get way fancier than that. I don't see a practical purpose for this, but it gives you an small idea of what is possible:

Code:
prompt $_$E[38;5;210m$E[48;5;0m▓   ▓ ▓▓▓▓▓ ▓     ▓     ▓▓▓▓▓$_▓   ▓ ▓     ▓     ▓     ▓   ▓$_▓   ▓ ▓     ▓     ▓     ▓   ▓$_▓▓▓▓▓ ▓▓▓▓▓ ▓     ▓     ▓   ▓$_▓   ▓ ▓     ▓     ▓     ▓   ▓$_▓   ▓ ▓     ▓     ▓     ▓   ▓$_▓   ▓ ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓$_$_$E[38;5;15m$E[48;5;0m$P$G

Result of the above command:

Image3.jpg

NOTE: The blocks in the above command are ASCII character 172. You can print this by opening an app like Notepad, pressing and holding down the ALT key, typing "172" on the number pad, then release the ALT key. Once you have one, just copy and paste. The same holds true for other ASCII characters that you don't see on your keyboard.

For a list of all ASCII characters that may be useful, just search on ASCII character chart in your browser.

If you want to make permanent changes to your prompt, use one of these two methods:

METHOD 1

The below instructions work with Windows 11 22H2 build 1778. If the screens look different, you may need to determine how to get to the "Advanced system settings" screen in your version of Windows.

Navigate to Settings > System > About

Under the Device specifications section, click the link that called Advanced system settings. This will open System Properties. Select the Advanced tab, then Environment Variables.... Under the section User variables for <Your User Name>, change the value of PROMPT. If this variable does not exist, create it.

NOTE: You could set this under the System variables section, but it is more common to set it as a user variable.

If you have a command prompt already open, close it and reopen it to see the change take effect.

METHOD 2

Use the SETX command from an elevated command prompt.

This method does the same thing a setting the user variable in the GUI as noted above.

Open an elevated command prompt (in other words, open it as Administrator).

Run this command:

SETX PROMPT $P$G (replace the $P$G with whatever you want to set the prompt to).

You will need to restart the command prompt to see the changes.
 

My Computers

System One System Two

  • OS
    Win11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Self-built
    CPU
    Intel i7 11700K
    Motherboard
    ASUS Prime Z590-A MB
    Memory
    64GB (Waiting for warranty replacement of another 64GB for 128GB total)
    Graphics Card(s)
    No GPU - Built-in Intel Graphics
    Sound Card
    Integrated
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 1TB NVMe SSD
    1 x 2TB NVMe SSD
    1 x 4TB NVMe SSD
    3 x 512GB 2.5" SSD
    1 x 4TB 2.5" SSD
    5 x 8TB Seagate Barracuda HDD
    PSU
    Corsair HX850i
    Case
    Corsair iCUE RGB 5000X mid tower case
    Cooling
    Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Home Computer Specifications, Configuration, and Usage Notes General Specifications ASUS Prime Z590-A motherboard, serial number M1M0KC222467ARP Intel Core i7-11700K CPU (11th Gen Rocket Lake / LGA 1200 Socket) 128GB Crucial Ballistix RGB DDR4 3200 MHz DRAM (4 x 32GB) Corsair iCUE RGB 5000X mid tower case Noctua NH-D15 chromax.black CPU cooler Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Corsair LL-120 RGB Fans (Qty. 3)
    Keyboard
    Corsair K70 Max RGB Magnetic Keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    1Gb Up / 1 Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    The five 8TB drives and three 512GB SSDs are part of a DrivePool using StableBit DrivePool software. The three SSDs are devoted purely to caching for the 8TB drives. All of the important data is stored in triplicate so that I can withstand simultaneous failure of 2 disks.

    Networking: 2.5Gbps Ethernet and WiFi 6e
  • Operating System
    Win11 Pro 23H2
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo ThinkBook 13x Gen 2
    CPU
    Intel i7-1255U
    Memory
    16 GB
    Graphics card(s)
    Intel Iris Xe Graphics
    Sound Card
    Realtek® ALC3306-CG codec
    Monitor(s) Displays
    13.3-inch IPS Display
    Screen Resolution
    WQXGA (2560 x 1600)
    Hard Drives
    2 TB 4 x 4 NVMe SSD
    PSU
    USB-C / Thunderbolt 4 Power / Charging
    Mouse
    Buttonless Glass Precision Touchpad
    Keyboard
    Backlit, spill resistant keyboard
    Internet Speed
    1Gb Up / 1Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    WiFi 6e / Bluetooth 5.1 / Facial Recognition / Fingerprint Sensor / ToF (Time of Flight) Human Presence Sensor

Latest Support Threads

Back
Top Bottom