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

Add env configuration to specify environment variables to launch command with #5257

Open
mitchellh opened this issue Jan 20, 2025 · 0 comments · May be fixed by #5309
Open

Add env configuration to specify environment variables to launch command with #5257

mitchellh opened this issue Jan 20, 2025 · 0 comments · May be fixed by #5309

Comments

@mitchellh
Copy link
Contributor

Discussed in #5197

Originally posted by networkhermit January 17, 2025
There are occasions when users want to inject environment variables to the terminal emulator, like the env config provided by alacritty.

Currently there are two ways in ghostty to achieve similar outcome:

  1. Tweak the command configuration like command = /usr/bin/env WINIT_X11_SCALE_FACTOR="1.0" "${SHELL}" -l. Personally I think it is verbose and platform dependent.
  2. Add environment variables in .zshrc/.bashrc/config.fish guarded by if [[ "$TERM_PROGRAM" = ghostty ]]; blocks. It works but I hope to use a more non-intrusive method.

Past closed disscussion in #3776.

Proposal

Introduce an env configuration (similar in its naming simplicity to command). The configuration value is syntax KEY=VALUE and only one may be specified per key, but the key may be repeated. Example:

env = foo=bar
env = bar=baz

Just like any other repeatable string type configuration we support, setting it to empty will reset the value to the default (which in our case is... empty).

jcollie added a commit to jcollie/ghostty that referenced this issue Jan 22, 2025
Fixes ghostty-org#5257

Specify environment variables to pass to commands launched in a terminal
surface. The format is `env=KEY=VALUE`.

`env = foo=bar`
`env = bar=baz`

Setting `env` to an empty string will reset the entire map to default
(empty).

`env =`

Setting a key to an empty string will remove that particular key and
corresponding value from the map.

`env = foo=bar`
`env = foo=`

will result in `foo` not being passed to the launched commands.
Setting a key multiple times will overwrite previous entries.

`env = foo=bar`
`env = foo=baz`

will result in `foo=baz` being passed to the launched commands.

These environment variables _will not_ be passed to commands run by Ghostty
for other purposes, like `open` or `xdg-open` used to open URLs in your
browser.
@jcollie jcollie linked a pull request Jan 22, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant