Random Notes

Emoji Support for WeeChat

Unicode versions 7 and 8 have added many new emoji to the standard. These emojis first became available in mobile phones and are supported by default on modern Android and iOS devices. OS X also has a builtin emoji input method. As such, emojis are beginning to appear on IRC too and it’s useful to be able to see them.


UPDATE 2015-08-15: Glibc 2.22 has been released with Unicode 7.0 support. This means the fix is not necessary on systems that have that version. If you don’t have the latest Glibc, read on for the workaround.


WeeChat does not support emoji out of the box, because the current Glibc version is based on Unicode 5.1. Fedora have patched Glibc to support Unicode 7.0, but it will take a while for the patches to make their way to other distros. Luckily there is another solution.

The gist of it is that you have to build your own version of libwcwidth, which is used to find out how many columns a certain wide character takes. You can get the sources file wcwidth.c here. Don’t worry that the source says it’s for Unicode 5.0, it works regardless (I don’t know why, maybe someone could enlighten me on that). The command I used to compile the source into a library was

gcc -shared -fPIC -Dmk_wcwidth=wcwidth -Dmk_wcswidth=wcswidth -o libwcwidth.so wcwidth.c

When the library is built, it needs to be loaded to WeeChat with LD_PRELOAD (there are probably other ways to do this part but this is the one I used). To load the library while WeeChat is running, you can use the command

/set env LD_PRELOAD /path/to/libwcwidth.so

Note that the path must be absolute or it won’t work. After the command you should /upgrade to ensure that the library is loaded. There are many ways to persist the change over reboots, but a simple one is to define an alias for the command weechat which loads the library every time:

alias weechat='LD_PRELOAD=/path/to/libwcwidth.so /path/to/weechat'

Some other stuff that may disable emoji support even if you have enabled it in WeeChat:

When all is set up correctly, the result should look something like this:

Here's what it looks like in iTerm2 on my OS X system. So cool. 😎

Now just sit back and enjoy the 😁 💩 👍 🎉 🎊 🎈!

PS. I haven’t thoroughly checked which of all the emoji are supported by the libwcwidth version, but all Unicode 7.0 emojis have worked fine so far. Your mileage may vary. Additionally, I run the latest stable WeeChat (1.1.1 at the time of writing), so if the instructions don’t seem to work, it’s a good idea to update your client.