I use vim with vim-airline that can use patched fonts for additional awesomeness.
I also use fish shell (if you want read zsh here since it is equivalent for the analysis) with a theme that also uses patched fonts.
I save my dotfiles online and I use them in different systems. But in some of them I don't have a patched font.
I would really love to have generic dotfiles that for example do not use a theme that needs patched font if the current font is not patched. Also in my vimrc I disabled the use of patched characters for vim-airline because of this.
Is there a way to programmatically know if the font that is currently in use is a patched one so that is possible to write generic dotfiles that fit perfectly in all the situations?
In Vim, you would need to directly ask your terminal emulator what font it is currently using. The exact method will certainly be different from terminal to terminal and from OS to OS. If that's even possible.
If you have it on all your systems, you could use lsof to find what font is currently used by a given program:
$ lsof | grep iTerm | grep '\.\(otf\|ttf\)'
In GVim/MacVim, you would check if the current font name matches some pattern with something like:
if &guifont =~? 'powerline'
" do something
else
" do something else
endif
And that's assuming your font's filename contains that pattern.
But it's impossible to guarantee that an actual "powerline font" has powerline in its file name and it's equally impossible to guarantee that a font with powerline in its file name is an actual "powerline font".
It would be safer to check for the presence of the Powerline string somewhere in the font with something like:
$ xxd ~/Downloads/FuraMono-Bold\ Powerline.otf | grep Powerline
But that's assuming:
xxd is available,That's a lot of assumptions and seemingly a lot of work for something as superficial as a "powerline font".
You can do this the other way around and only enable Powerline fonts for known machines in your .vimrc e.g.
let hostname = substitute(system('hostname'), '\n', '', '')
let patched_font_hosts = ['host1', 'host2', 'host3'] " List of know patched hosts
if(index(patched_font_hosts, hostname) >= 0)
let g:airline_powerline_fonts = 1
endif
It's easier to know which hosts you have patched and it's not a really a problem if the list is not up to date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With