-
Notifications
You must be signed in to change notification settings - Fork 715
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
Option to override environment variables in child processes #5063
base: master
Are you sure you want to change the base?
Conversation
Today I have to restart Kakoune in order to set environment variables in shell expansions globally. For example KAK_LSP_FORCE_PROJECT_ROOT. When running ":git" commands, there is an ambiguity on whether to use the $PWD or the buffer's worktree. We use $PWD but it should be possible to override this behavior. An obvious way to do this is to override Git environment variables: set-option -add global env GIT_WORK_TREE=/path/to/my/repo GIT_DIR=/path/to/my/repo.git (another in-flight patch adds the obvious default to GIT_DIR so we don't need to set that). --- There are some minor issues left - If a user sets PATH, this will stomp the one we setenv()'d. - Today both key and value require escaping for = and \. This is not intuitive. Since neither environment variables nor ui_options ever need a = in the key name, we can get rid of the escaping. Alternative approach: The str-to-str-map can be somewhat clunky. We could instead export any option named like env_FOO. Not yet sure which approach is better. Closes mawww#4482 That issues asks for a separate client-specific env as well but we don't have a client scope so I'm not sure.
To use, either patch Kakoune using mawww/kakoune#5063 and set preferred servers for each buffer like set-option -add buffer env KAK_LSP_LANGUAGE_SERVER=pylsp_main # or pylsp_test Alternatively, use (untested) unset-option buffer lsp_cmd set-option buffer lsp_cmd "KAK_LSP_LANGUAGE_SERVER=pylsp_main %opt{lsp_cmd}"
@@ -146,6 +146,8 @@ Vector<String> generate_env(StringView cmdline, const Context& context, GetValue | |||
static const Regex re(R"(\bkak_(quoted_)?(\w+)\b)"); | |||
|
|||
Vector<String> env; | |||
for (const auto& [key, value] : context.options()["env"].get<HashMap<String, String, MemoryDomain::Options>>()) | |||
env.push_back(format("{}={}", key, value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an ergonomic abstraction but it's incomplete in that it does not allow to unset environment variables, and neither does it allow to erase the entire environment (though I don't think there is a use case for that).
A more flexible (but probably not better) approach would be to allow overriding KAKOUNE_POSIX_SHELL
dynamically, then we can set it to env ... "$@"
..
I'd like to integrate kakoune with Is there anything happening around here? |
Nothing wrong with using this patch (I do use it occasionally). One alternative approach is to simply add The advantage of the
This means that the |
Today I have to restart Kakoune in order to set environment variables
in shell expansions globally. For example KAK_LSP_FORCE_PROJECT_ROOT or RUST_BACKTRACE.
Another use case is when using
rust-analyzer
's test framework.When a test fails, it tells me to run
env UPDATE_EXPECT=1 cargo test
to update test with the actual behavior.The
kakoune-cargo
plugin does not provide a way to set environment variables.The reason I want to run this from the editor is that this allows me to run only the test at cursor (using
rust-analyzer
code lenses).When running ":git" commands, there is an ambiguity on whether to
use the $PWD or the buffer's worktree. We use $PWD but it should be
possible to override this behavior. An obvious way to do this is to
override Git environment variables:
(another in-flight patch adds the obvious default to GIT_DIR so we don't need to set that).
There are some minor issues left
intuitive. Since neither environment variables nor ui_options ever
need a = in the key name, we can get rid of the escaping.
Alternative approach: The str-to-str-map can be somewhat clunky. We
could instead export any option named like env_FOO. Not yet sure
which approach is better.
Alternative: maybe a
setenv
orexport
command?Closes #4482
That issues asks for a separate client-specific env as well but we
don't have a client scope so I'm not sure.