For a full list of BASHing data blog posts see the index page.     RSS

Changing TTY prompt, font and colors

Changing colors and font in a virtual terminal isn't easy (see below). Changing colors and font in a terminal emulator, on the other hand, is just a matter of adjusting preferences in a GUI dialog. Last year, for example, I changed the color scheme in my terminal emulator. For a long time I'd worked with yellow text on a dark green background:


The text and background colors are roughly the national colors of Australia, modified to look better on my screen. The official colors are #FFCD00 and #00843D.
For more about using ANSI escape colors in variables, see this BASHing data post.

The new color scheme (see next screenshot) is easier on my eyes, and my terminal emulator font has changed, too. I'd always been pretty happy with the monospace default, which was DejaVu Sans Mono in both Xfce4 Terminal and Gnome Terminal. For a while I switched to Noto Mono (see above), but I'm now using Bitstream Vera Sans Mono Roman, which does ANSI bold very nicely and has a dot in the numeral zero to distinguish it from a capital O:


I haven't been able to replicate my emulator configuration in a TTY but I've come close, as described below. Please note that I did this on a desktop running MX 19 Linux. MX 19 avoids systemd as much as possible, and the same steps may not work if your distro has been more thoroughly infected enhanced with systemd.

Screenshots from a TTY. The screenshots below were grabbed with the venerable fbdump utility (2007), available here. Like the more up-to-date but code-heavy fbcat (2017), fbdump generates a full-screen PPM image which I can open and crop in GIMP.

fbdump > ~/Desktop/screenshot

Start here. Here I am on tty1 with an ugly font, colors I don't like and a complicated prompt:


Change the prompt. The default MX 19 prompt code, grabbed from tty1 with echo "$PS1", is:


I found this prompt code in a different format in my .bashrc file under "if [ "$UID" = 0 ]; then...":

PS1="$PURPLE\u$nc@$CYAN\H$nc:$GREEN\w$nc\\n$GREEN\$$nc "

I commented out the above code and replaced it with

PS1="$ "

to get the prompt I wanted:


Change the font. You can view the range of characters in your console font with the command showconsolefont:


The default font configuration is stored in both /etc/default/console-setup and /usr/share/console-setup/console-setup (why two places?), where it looks like this:


So that default font is "TerminusBold" "11x22". Other available console fonts are stored in /usr/share/consolefonts, which on my MX 19 system (based on Debian 10) contains more than 500 different fonts and font sizes.

To see what all these fonts look like, go to this webpage, where the Australian non-profit organisation The ZAP Group has very helpfully indexed screenshots and code pages for console fonts in Linux distros. The Debian console fonts are here. The ZAP Group also makes available its own fonts for virtual terminals, as well as some based on Lucida Sans.

I liked the look of The ZAP Group font zap-light20.psf, so I downloaded it, gzipped it and copied zap-light20.psf.gz to /usr/share/consolefonts. I then edited the two console-setup files to assign this font to the console:


The last step (almost) was to run setupcon. It complained about not being able to access the other TTY's, but it gave me my new font on tty1:


I wrote "almost" above because the font change doesn't persist between system restarts. See below ("Keeping the changes") for a fix.

John Zaitseff from The ZAP Group suggests that the font change should be permanent if you run
/etc/init.d/ force-reload
update-initramfs -u
This doesn't work on my MX 19 system. The init.d script references setupcon, which in turn looks at the font configuration file shown above. In /etc/console-setup, the script says setfont '/usr/share/consolefonts/zap-light20.psf.gz' , as expected.

Change the colors. This step is truly arcane and my solution is based on a Stack Exchange post by contributor "mosvy". The 16 colors used by a virtual console are numbered from 0 to F in hexadecimal. The background color is numbered "0" and the light grey used by MX 19 for text is numbered "7". I couldn't find a configuration file where these color codes are assigned in MX 19, so I printed new codes as commands in tty1. These commands redefined the (black) background as f0fef0 and MX 19's (light grey) text color as black, 000000. I followed this command with "clear", and voilà!

printf %b '\e]P0f0fef0' '\e]P7000000'


Keeping the changes. The change in prompt style persists between system restarts, but the font and color changes don't, and I couldn't work out how to make them permanent. As a workaround I put the relevant commands in the function "termfix" in my .bashrc. After I log in to a TTY (any TTY) I just enter "termfix" and I get my preferred TTY appearance.

termfix() { printf %b '\e]P0f0fef0' '\e]P7000000' && setupcon && clear; }

Last update: 2020-02-19
The blog posts on this website are licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License