Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional in config file? #811

Closed
ApolloBian opened this issue Aug 17, 2018 · 16 comments
Closed

Conditional in config file? #811

ApolloBian opened this issue Aug 17, 2018 · 16 comments

Comments

@ApolloBian
Copy link

I would like to manage settings across machines in one file and I have some different configs for each of them. Is it possible to put conditionals in config files, e.g. set different font size according to hostname?

I went through the doc for config file and I didn't find anything related to conditionals. I also tried simple bash if else but doesn't seem to work.

Is it possible? If not, are there any workarounds?

@maximbaz
Copy link
Contributor

Just do it in your bashrc, something like this:

if [ "$(hostname)" = "home" ]; then
  alias kitty='kitty -c ~/.config/kitty/kitty-home.conf'
fi

@ApolloBian
Copy link
Author

ApolloBian commented Aug 17, 2018

@maximbaz thanks for reply. I want to set

macos_hide_titlebar yes

on one machine where chunkwm is installed while macos_hide_titlebar no for others.

Such solution does not seem to work if I use cmd+N to create new window. I think this setting is accessed before bashrc is sourced.

Launching kitty from cmdline works, but I don't think it is a comfortable way to create new windows

@maximbaz
Copy link
Contributor

Right, my bad, bashrc is not suitable for this, it is loaded already in the new kitty instance. Maybe having this globally will work, like in /etc/profile.d/ ? Or change the command that launches kitty itself, i.e. have a different .desktop file?

@Luflosi
Copy link
Contributor

Luflosi commented Aug 17, 2018

Use include device-specific.conf in your kitty.conf, write macos_hide_titlebar yes into device-specific.conf on one machine and leave that file empty on all other devices.

@maximbaz
Copy link
Contributor

This is a cool idea, probably better than what I was thinking if you mostly share configs between different hosts and have only a few minor differences.

@kovidgoyal
Copy link
Owner

The include directive also expands environment variables in the include file name. So in my kitty.conf I have

include ${HOTNAME}.conf

Of course this implies that the HOSTNAME variable is st system wide on your machine.

@arooni
Copy link

arooni commented Oct 31, 2018

I can't seem to get this to work on 0.12.3

When I have in my my kitty.conf file:

include LilArooni.conf # this works great.

include ${HOSTNAME}.conf # does not seem to load -- even though HOSTNAME is set [ubuntu 18.04] -- and HOSTNAME=LilArooni

i tried with including full path names and no dice. what do i seem to be doing wrong?

@kovidgoyal
Copy link
Owner

You need to set the HOSTNAME variable in your global environment ot your shell scripts. Remember that shell scripts are loaded after kitty starts not before. And paths for that directive are relative to the kittyconfig directory

@arooni
Copy link

arooni commented Oct 31, 2018

Got it working thanks.

For anyone else visiting;

edit /etc/enviornment on Ubuntu
and run launchctl setenv VAR variablevalue on mac

@bhushan
Copy link

bhushan commented Jul 9, 2022

@arooni Could you please help me, I am having same issue but seems like things are not working on my mac.

I want to setup theme based on zsh variable exported in my .zshrc file.

in ~/.zshrc

export SET_THEME="github_dimmed"

in ~/.config/kitty/kitty.conf

include ${SET_THEME}.conf

Ironically, This same variable is accessible in my n/vim and tmux and I am able to switch themes based on env variable.

@jonkracht
Copy link

Having a similar problem to bhushan above. I'm trying to standardize fonts across several programs and so have created an environment variable containing the desired font name. Viewing the "current kitty env vars" page within kitty, I can see that kitty indeed sees my font environment variable. Seems like kitty is not expanding the environment variable to obtain its value, maybe contrary to what is indicated in the documentation. Have tried defining the variable within /etc/environment and also /etc/profile.d but seemed to make no differece.

Can someone please advise on how to properly access and use environment variables within the kitty config file? Running kitty version 0.26.3 in Pop 22.04 if that makes any difference.

Thanks much in advance.

@kovidgoyal
Copy link
Owner

Nowhere in the documentation does it say the font_family expands env
vars.

@huyz
Copy link

huyz commented Dec 4, 2022

It would be nice for Kitty to automatically have at least something akin to $OSTYPE. Perhaps, $OSFAMILY that would have darwin or linux. Seems like that would be useful for those of us who are cross-platform.

@kovidgoyal
Copy link
Owner

There you go: d7d96c2

@huyz
Copy link

huyz commented Dec 5, 2022

@kovidgoyal thanks so much! Awesome work on everything, btw, including the key handling effort.

@ooloth
Copy link

ooloth commented May 19, 2024

For anyone on macOS who wants @arooni's solution (launchctl setenv HOSTNAME $(hostname)) to keep working after a reboot, I found the solution in this article (run that command in a ~/Library/LaunchAgents/kitty.environment.plist file) worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants