About two weeks ago I published a short video on adding emoji’s to a BASH prompt (below YouTube link). This is a followup article to add a bit more detail to the process.
UTF8 (Unicode Transformation Format – 8-bit)
The International Organization for Standardization (ISO) created a multi-byte character set in 1989. The ISO 10646 standard contained an annex called UTF-1, providing 32 bit encoding for fonts. The original standard has seen several changes since it was first introduced. UTF-8 can use four byte of data and is capable of encoding over one million values, including symbols, characters from different languages, pictograms (dingbats), and emojis.
UTF8; Web pages, Application, Terminals
The use of UTF8 has spread through most computer programs and application. In Linux, most terminal emulators recognize some parts of the UTF8 character set. So it is possible to use pictograms, emojis, and even characters form different languages in these programs. As was the subject of the above YouTube short, we added an emoji to the Bash PS1 prompt. We could just as easily have added a Chinese character or a pencil pictogram.
Generally most Operating Systems (OS) have some sort of program that lets you view and select characters from aUTF8 font. And baring that, there are many web sites that also let you explore the UTF8 font set.
Testing a UTF8 Character
Before trying to include a non English UTF8 character into a bash prompt using either /etc/bash-bashrc or /home/user/.bashrc, it is a good idea to test it. This can be done by copying the character and pasting it into the Terminal to see if it is recognized and displayed properly.
In many cases terminal programs do not recognize the normal cut copy paste commands. For example, to paste something into XTrem requires using a Shift + Insert. This seems to be pretty standard across a range of terminal emulators. Note that in some terminal emulators it is possible to configure them to recognize the standard cut copy paste commands. But in many cases it is simply easier to use Shift + Insert.
Adding an emoji to the BASH PS1 Prompt
The Bash PS1 prompt is an environmental variable, and it can be set like any environmental variable. To make it lasting though, you need to set it in the Bash configuration file. For general use by all users the global Bash configuration is located at /etc/bash-bashrc, and requires administrative permissions (sudo or su) to edit.
On the other hand a user can override global settings in their own local configuration file, located at /home/user/.bashrc. Because this file belongs to the user, the user does not require administrative permissions to edit it. Note that because it starts with a period (or dot) it will normally be a hidden file. So the user will have to enable hidden files in their file manger or use the -a option with the ls command (ls -a).
After that it is simply a matter of editing the value in the PS1 Prompt field in the file, then saving it. Once saved either close and reopen the terminal to use the new configuration, or use the exec bash command to reset the existing shell.