Intro

You can skip down to the steps if you are not interested to know how I came to need this ;).

I happened to watch Dan North’s Power use of UNIX video where he talks about zsh. I have been using bash for almost 2 decades which felt like a good milestone to look into a new shell so I decided to explore it. This led to an old fashioned web serfing session, and after a few links, going through Oh My Zsh, I discovered the cool powerline based themes that caught my eye. Out of the box, the characters do not work and I found that I needed a bit of tweaking with my fonts to make them work.

For my OS terminal(MATE Terminal running on Linux Mint 17.2) I found the following from the powerline installation documentation: https://powerline.readthedocs.io/en/latest/installation/linux.html#font-installation where I following the instruction in the font-installation section which worked quite nicely.

When writting code in IntelliJ IDE I tend to also use a lot the Terminal tool window where the symbols did not work even after making them work for the terminal.

I knew that the jre uses it’s own fonts for applications using it’s own UI libraries, and IntelliJ is such an app. This is not the case for applications that use native UI libraries such as Eclipse which is using GWT.

So this would need me to setup these fonts for the JRE running my IntelliJ instance.

Steps

Please note that this procedure is a hack and it worked for me but please keep in mind that intellij is quite picky about the fonts that it will allow you to use so this might not work for you. Also I think it would be a pretty good idea to keep a backup of the jre folder whose fonts you will work on.

The summary of what we are going to do is that we will take the font that we want to use and merge it with the powerline symbols font. In my case I am using the Source Code Pro font Git hub repo

These steps assume that you have installed the symbol font for the system terminal according to the following: [Installation on Linux] (https://powerline.readthedocs.io/en/latest/installation/linux.html#font-installation) and so it assumes files are in positions dictated by it’s instructions.

Finding the JRE

To avoid frustration I believe it to be a good idea to find
the path of the actual JRE that is running IntelliJ. Having
the IDE running use the following


gaganis@i7-mint:~$ ps x|grep -i idea
14247 ? S 0:00 /bin/sh /home/gaganis/programming/idea-IC-141.2735.5/bin/idea.sh %f
14296 ? Sl 1:52 /opt/java/jdk1.8.0_60/bin/java -Xbootclasspath/a:/home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/boot.jar -classpath /home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/bootstrap.jar:/home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/extensions.jar:/home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/util.jar:/home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/jdom.jar:/home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/log4j.jar:/home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/trove4j.jar:/home/gaganis/programming/idea-IC-141.2735.5/bin/../lib/jna.jar:/opt/java/jdk1.8.0_60/lib/tools.jar -Xms128m -Xmx3750m -XX:MaxPermSize=750m -XX:ReservedCodeCacheSize=225m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Dawt.useSystemAAFontSettings=lcd -Djb.vmOptionsFile=/home/gaganis/programming/idea-IC-141.2735.5/bin/idea64.vmoptions -XX:ErrorFile=/home/gaganis/java_error_in_IDEA_%p.log -Djb.restart.code=88 -Didea.paths.selector=IdeaIC14 com.intellij.idea.Main %f
14333 ? S 0:00 /home/gaganis/programming/idea-IC-141.2735.5/bin/fsnotifier64
18675 pts/12 R+ 0:00 grep --color=auto -i idea

The really long one is the jre process running IntelliJ. In my case we can see it running with the jdk that is intalled in /opt/java/jdk1.8.0_60/

Converting the font to TTF

This symbol font is provided in OTF format, whereas the JRE requires a font in TTF format so we will convert it.

For this I am using the steps as outlined in the following blog post http://www.stuermer.ch/blog/convert-otf-to-ttf-font-on-ubuntu.html

Install fontforge using your package manager

In my case I used:


$ sudo apt-get install fontforge

Go to your ~/.fonts/ directory and verify you have the

symbols font


s@i7-mint:~$ cd ~/.fonts
gaganis@i7-mint:~/.fonts$ ls
PowerlineSymbols.otf
gaganis@i7-mint:~/.fonts$

Create a script named otf2ttf.sh and put the following into it


#!/usr/local/bin/fontforge
# Quick and dirty hack: converts a font to truetype (.ttf)
Print("Opening "+$1);
Open($1);
Print("Saving "+$1:r+".ttf");
Generate($1:r+".ttf");
Quit(0);

Run the conversion


gaganis@i7-mint:~/fontwork$ fontforge -script otf2ttf.sh
PowerlineSymbols.otf
Copyright (c) 2000-2012 by George Williams.
Executable based on sources from 14:57 GMT 31-Jul-2012-ML.
Library based on sources from 14:57 GMT 31-Jul-2012.
Opening PowerlineSymbols.otf
Saving PowerlineSymbols.ttf

Get Source Code Pro regular TTF file

Download Source Code Pro font package your can find here: Latest Release.


gaganis@i7-mint:~/fontwork$ wget https://github.com/adobe-fonts/source-code-pro/archive/2.030R-ro/1.050R-it.tar.gz

and untar it


gaganis@i7-mint:~/fontwork$ tar -zxf 1.050R-it.tar.gz

We need to work on the regular TTF font file so I copy it to the folder I am working on.


gaganis@i7-mint:~/fontwork$ cp source-code-pro-2.030R-ro-1.050R-it/TTF/SourceCodePro-Regular.ttf .

Merging the two fonts

I will again use fontforge for this so I will do


gaganis@i7-mint:~/fontwork$ fontforge SourceCodePro-Regular.ttf

Fontforge has a windowed UI which I used to do this

Merging the Power Symbols font into Source Code Pro

menu option

file selection

I do not understand what this is about but selecting ‘No’ worked fine for me.

kerningselection.png

Then I save the new font with name SourceCodePro-Regular-symbol.ttf.

savefont.png

savewithname.png

I get two warning that I also do not understand but ignoring them seemed to work for me.

warning1.png

warning2.png

Copy the newly converted font to the JRE font folder

Please remember to update the paths accordingly to where your JRE is located as we found in the beggining.


gaganis@i7-mint:~/fontwork$ sudo cp SourceCodePro-Regular-symbol.ttf /opt/java/jdk1.8.0_60/jre/lib/fonts/

Exit and restart your IDE and you should be good to go!

Remember to change the paths so they reflect the JRE location you found in the first step.

Warning! IntelliJ is very picky about the fonts it uses.

I have found the created font to work very well for me, I had not a absolutely no real problem. The only issue I had was more frustration than a real problem. Because the generated font contains some errors, IntelliJ will not present it in the font selection dropdowns. I have found that if I had already selected it on a previous run it is used nonetheless. The problem with this is that if you select another font you cannot reselect it back. The solution to this is pretty simple, though frustrating, you delete the merged font from the JRE fonts folder, restart, select it anew, recopy it, and then restart again. I personaly tend to settle on the default font so I do not expect to have to do that very much.

Happy hacking!

9 thoughts on “Making powerline fonts work inside IntelliJ IDEA terminal

    1. Thank you Suren. I considered providing the generated font, but from the research I did on the licences of these fonts I wasn’t sure whether distributing the generated font would be legal or not. So I decided not to distribute the modified font. Sorry 😦

      Like

  1. Hi, thanks for this. Might you also know how to fix the colors so that white prompt text displays better on light backgorunds?

    Like

  2. I am using IntelliJ iDEA 2018 and it’s possible to change Terminal Font via “Editor -> Color Scheme -> Console Font”, and Terminal Colors via “Editor -> Color Scheme -> Console Colors”.

    Liked by 1 person

  3. There is a simpler solution. I’m using PopOS! (it is Ubuntu clone). I had installed OhMyZSH and set ZSH as default console. Then I figured out that PyCharm console has a problem to display most of the special characters. To solve that problem I changed main console font to “Source Code Pro” and set Fallback font as “PowerlineSymbols”. That is all that needs to be done to enjoy the powerline theme in ZSH.

    Like

  4. There is a simpler solution. I’m using PopOS! (it is Ubuntu clone). I had installed OhMyZSH and set ZSH as default console. Then I figured out that PyCharm console has a problem to display most of the special characters. To solve that problem I changed main console font to “Source Code Pro” and set Fallback font as “PowerlineSymbols”. That is all that needs to be done to enjoy the powerline theme in ZSH.

    Like

Leave a comment