In the light of the king's countenance is life; and his favour is as a cloud of the latter rain.
Proverbs 16:15, The Bible
Recently, I've looking at different websites on my RSS feed. I do that from time-to-time to steal ideas from others on what to put on this website.
I noticed the use of emojis on some websites and I thought that would be a great addition. Adding emojis could help communicate some ideas more effectively and invoke emotions in the readers of this blog. I see it as "changing the countenance of my text".
It's also a plus that emojis mean more to humans than they do to bots ๐.
In this article, I would like to discuss how I added emoji support to my Linux terminal and ultimately, this website.
It's face time!
countenance (n) - Appearance or expression of the face; look; aspect; mien.
Definition of countenance, Webster dictionary (1913)
It should be no surprise by now that I use Vim as a text editor for everything, from code to documents; I do most of my work from inside a terminal. Rendering color emojis in the terminal does not work right-out-the-box. (I use Arch BTW ๐ค.)
While searching for a solution online, I came across emoji, a Python package for printing emojis, so I installed it on my computer:
$ sudo pacman -S python-emoji
After the installation, I tried to print color emojis to my terminal, and lo and behold, it didn't work:
$ python
>>> import emoji
>>> emoji.emojize(":thumbs_up:")
>>>
Emoji, meet Terminal (๐ + ๐จโ๐ป)
Originally meaning pictograph, the word emoji comes from Japanese e (็ตต, 'picture') + moji (ๆๅญ, 'character'); the resemblance to the English words emotion and emoticon is purely coincidental.
Emoji article, Wikipedia
I found an article that explained the two steps required to add color emoji support to my terminal.
First I installed the Noto Emoji Font on my computer:
$ sudo pacman -S noto-fonts-emoji
Then I set up fonts.conf
:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<alias>
<family>sans-serif</family>
<prefer>
<family>Noto Sans</family>
<family>Noto Color Emoji</family>
<family>Noto Emoji</family>
<family>DejaVu Sans</family>
</prefer>
</alias>
<alias>
<family>serif</family>
<prefer>
<family>Noto Serif</family>
<family>Noto Color Emoji</family>
<family>Noto Emoji</family>
<family>DejaVu Serif</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Noto Mono</family>
<family>Noto Color Emoji</family>
<family>Noto Emoji</family>
</prefer>
</alias>
</fontconfig>
After saving the file to ~/.config/fontconfig/
and re-opening my terminal, I ran:
$ python
>>> import emoji
>>> emoji.emojize(":thumbs_up:")
'๐'
>>>
Voila!
The bottom line
Even though Arch Linux does not support displaying color emojis in the terminal right-out-the-box, adding the functionality to your computer is pretty straightforward. I created a script for myself that can print an emoji:
#!/bin/sh
usage() {
echo "Usage: `basename $0` EMOJI"
echo
echo "Prints an emoji in the terminal"
echo "Example: `basename $0` thumbs_up"
}
EMOJI=$1
if [ $# -eq 0 ]; then
usage
exit 1
fi
python -c "import emoji; e = emoji.emojize(':$EMOJI:'); print(e) if emoji.is_emoji(e) else print(end='')"
With this script, I could easily print the "thumbs-up" emoji onto my Markdown file by executing r! xx-print-emoji.sh thumbs_up
in Vim.
Expect to see a random emojis in posts to come!
Further reading
- Emoji article on Wikipedia
- Enable color emoji support on Manjaro Linux (Works for Arch Linux too!)