Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

How to check if fonts are properly set up in .zshrc in order to implement an automatic fallback config? #835

Closed
lumbric opened this issue May 11, 2018 · 2 comments

Comments

@lumbric
Copy link

lumbric commented May 11, 2018

I have a working setup on most machines, but occasionally I have to SSH to one of my machine from a different machine (from some random Windows computer, from my mobile phone, ...) and I cannot install fonts there. Can I check if fonts are installed in .zshrc?

If yes, it would be possible to configure a fallback way for the powerlevel9k config which does look fine also without special fonts installed.

Note: Don't confuse with the fallback-strategy for fonts, I am talking about a fallback .zshrc config.

See also: #436 #253

@dritter
Copy link
Member

dritter commented May 11, 2018

Unfortunately we haven't found a way to automatically detect fonts yet. At least no proper reliable way. Neofetch does font detection of the terminal. And we adopted that solution for debugging purposes. But these solutions try to get that information from your terminal (as this is the program that uses the set font to display) and it won't detect a putty terminal..

So, you could set an env variable when connecting with putty and use that to switch your config.

@lumbric
Copy link
Author

lumbric commented May 12, 2018

That's bad and good news at the same time. Your hint with env variables helped to find a way to achieve what I need. It's quite hackish, but works for me - maybe for others with the same problem too. Thanks!

I've added the code in this commit lumbric/dot-file-repo@a39cd84 to my dot file repository. If anyone wants to copy it.

Basically the idea is that wherever my dot file repository and my .zshrc is in use, I will also have correct fonts installed. When SSH-ing from a client without my environment into a server with my environment, I can detect this by setting a env variable in my .zshrc and in this case load a fallback zsh theme or remove undisplayable symbols (that's what I did).

Env variables with names LC_* are passed automatically from client to server by default in OpenSS. This is meant for passing the locale to the server, but we can use it as others have done before. Look for these lines in your /etc/ssh/sshd_config:

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

On server side LC_CLIENT_HAS_DOT_FILE_REPO is never set explicitely (only via SSH), on client side it is obviously only run if .zshrc is executed. This means if the variable is not set, a fallback theme can be loaded:

source ~/.dot-file-repo/zsh/powerlevel9k_settings.sh

# Fall back mode for powerlevel9k when SSH-ing to server with dot-file-repo and
# powerlevel9k installed, but dot-file-repo and fonts not available on client.
if [ -z $SSH_CLIENT ]; then
    # this env variable will be available only if this .zshrc is used on client
    export LC_CLIENT_HAS_DOT_FILE_REPO=1
fi
if [ -z $LC_CLIENT_HAS_DOT_FILE_REPO ]; then
    source ~/.dot-file-repo/zsh/powerlevel9k_settings_no_font_fallback.sh
fi

I did something very cheap, I simply disabled all broken features until it looked good enough:

POWERLEVEL9K_HOME_ICON=''
POWERLEVEL9K_HOME_SUB_ICON=''
POWERLEVEL9K_FOLDER_ICON=''
POWERLEVEL9K_SSH_ICON=''

POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR=""
POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR=""
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=""
POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR=""

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(host dir_writable dir vcs)

One could also try to find symbols supported with normal fonts or load a standard zsh theme. Please let me know if you have suggestions how to imrpove this part of my config and make the fallback more beautiful!

@lumbric lumbric closed this as completed May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants