helix icon indicating copy to clipboard operation
helix copied to clipboard

feat: load local config

Open AlexanderBrevig opened this issue 2 years ago • 11 comments

This will enable having a .helix/config.toml in a project repo and have it override default and ~/.config/helix/config.toml settings.

This behaviour is controlled with config.toml:

[editor.security]
load-local-config = false
confirm-local-config = true

The default keeps Helix working as it is. If you only set load-local-config = true then you'll be promted to answer yes before loading. This prompt can be removed by setting confirm-local-config = false.

AlexanderBrevig avatar Jul 27 '22 00:07 AlexanderBrevig

Thanks for the review and input @kirawi! I've fixed the requested changes (an embarrassing reminder that late night sessions may lead to weird things...) and fixed clippy lint errors locally.

AlexanderBrevig avatar Jul 27 '22 08:07 AlexanderBrevig

This should be optional, as one may not want to use custom config coming with someone else's repo and, more important, this could harm the user's computer, for example by resetting a common key bind to some harmful shell command.

diktomat avatar Jul 30 '22 08:07 diktomat

That probably falls under something like https://github.com/helix-editor/helix/issues/2697 (or is similar in spirit). It's notable that we already merge in .helix/languages.toml and I think you could easily craft a malicious languages.toml like so:

[[language]]
name = "toml"
language-server = { command = "rm", args = ["-rf", "/"] }

the-mikedavis avatar Jul 30 '22 13:07 the-mikedavis

I've added this to config.toml

[editor.security]
load-local-config = false
confirm-local-config = true

(commented out, you will also see -languages versions for a future PR)

That's the default. If you toggle both, then Helix will load $PWD/.helix/config.toml without asking to do so.

What do you think? I very much like the feature, but I am not married to the implementation details. I'll fix anything you see fit.

AlexanderBrevig avatar Aug 02 '22 23:08 AlexanderBrevig

Updated the docs and merged with master. hx -c ~/team/hx/config.toml will now load the "team" config, and then ask to load $PWD/.helix/config.toml if [editor.security] load-local-config = true.

Anything I can do to help this PR forward? (I understand the team is under a lot of load)

AlexanderBrevig avatar Aug 09 '22 18:08 AlexanderBrevig

I've fixed your suggestions @kirawi, do you have some more feedback or questions? :)

AlexanderBrevig avatar Aug 28 '22 10:08 AlexanderBrevig

NOTE: I merged in master to try and fix a bug that's been introduced somehow. Details below.

Huge thank you @pickfire I can see that I maybe wrote this code a bit prematurely in terms of how well (let's be honest, bad) I knew Rust.

However, the strange thing now (before the refactor too) is that I seem to lose ability to input text after the editor is loaded. It did not use to be that way.

Reproduce: Add [editor.security] load-local-config = true and maybe some config file in ./helix/config.toml. Then cargo run . will first ask you to type yes<RET> if you have a file, then open the file picker - here you can type. When you open a file, suddenly I cannot type any more. I have very little idea where to check, and somehow doubt that its this code that introduces this error. ~~Unless std::io::stdin().read_line somehow blocks the events coming in after...?~~

I did some cleanup in addition to yours. It is better now, at least. A bit unsure if the functions should be in config.rs or simply at the bottom of main.rs.

AlexanderBrevig avatar Aug 29 '22 13:08 AlexanderBrevig

load_local_config part seemed okay to me but I am not sure about the confirm_local_config part.

I am in favor of removing the confirmation prompt. Should I do it?

AlexanderBrevig avatar Sep 19 '22 13:09 AlexanderBrevig

I am in favor of removing the confirmation prompt. Should I do it?

Yes, I think for now we can keep it with a small change to only have a config to allow loading local config. That would be easier review and try it out.

pickfire avatar Sep 19 '22 13:09 pickfire

The security aspect of this still bothers me a bit - it ends up really nerfing the feature. I think it's silly in the same way that git's cve-2022-24765 (the safe.directory one) is silly, and to my knowledge no other terminal based editor is careful about this. I would argue at least that this should be enabled by default.

the-mikedavis avatar Sep 25 '22 23:09 the-mikedavis

The security aspect of this still bothers me a bit - it ends up really nerfing the feature. I think it's silly in the same way that git's cve-2022-24765 (the safe.directory one) is silly, and to my knowledge no other terminal based editor is careful about this. I would argue at least that this should be enabled by default.

Since three of four voices in this PR seems to agree, I'll change the default.

AlexanderBrevig avatar Sep 26 '22 00:09 AlexanderBrevig

Somehow I totally forgot this. Sorry.

AlexanderBrevig avatar Nov 18 '22 08:11 AlexanderBrevig

Hello fellows! This feature looks great. What needs to be done to be able to merge this? Thanks

Nazariglez avatar Jan 21 '23 21:01 Nazariglez

Hello fellows! This feature looks great. What needs to be done to be able to merge this? Thanks

I did a refactor on config loading, https://github.com/helix-editor/helix/pull/5636. ~~I'm in the process of merging~~ Merged this PR with that branch, hoping that it can help getting this one merged too.

gibbz00 avatar Jan 23 '23 12:01 gibbz00

That's awesome @gibbz00, thank you!

Nazariglez avatar Jan 23 '23 18:01 Nazariglez

I Hope I'm not too late, but I would like helix to also support (config|languages).local.toml, that way I can easily have a global gitignore for it and avoid polluting repos with my configs and/or ignores.

The exact behavior can either be local replaces the non-local file or is merged with it, favoring the local one (I prefer the second option but both can be argued for)

poliorcetics avatar Jan 23 '23 18:01 poliorcetics

I Hope I'm not too late, but I would like helix to also support (config|languages).local.toml, that way I can easily have a global gitignore for it and avoid polluting repos with my configs and/or ignores.

The exact behavior can either be local replaces the non-local file or is merged with it, favoring the local one (I prefer the second option but both can be argued for)

What exactly is the advantage of config.local.toml over .helix/config.toml in that regard? I think adding .helix/** to the global gitignore would be enough (that would also take care of .helix/languages.toml)

pascalkuthe avatar Jan 23 '23 19:01 pascalkuthe

As helix becomes more used, I expect some repos will start having a config in their git, like many already do for VSCode, jetbrains IDEs or vim/neovim, in this case .helix/** won't be enough

poliorcetics avatar Jan 23 '23 19:01 poliorcetics

.helix/languages.toml and .helix/config.toml also work in the global gitignore. I also don't see the advantage to using config.local.toml and languages.local.toml: it should be equivalent to .helix/config.toml and .helix/languages.toml respectively, no?

the-mikedavis avatar Jan 23 '23 19:01 the-mikedavis

No, what I mean is, in the project repo, people will start committing <my repo>/.helix/{config,languages}.toml (and ideally it should be .config/helix/... even locally, like cargo-nextest does), and having the hability to override it locally without having to play with the Git index would be nice.

As an example, search path:/.vscode/settings.json. The results are murkier for Vim and Jetbrains IDEs but there are examples.

poliorcetics avatar Jan 23 '23 20:01 poliorcetics

Oh I see, config.local.toml would be in addition to .helix/config.toml, right?

For scenarios like this I think it would be better to make use of the -c <config-file> CLI option and have a wrapper around hx -c to control which config is used based on the directory it's called in

the-mikedavis avatar Jan 23 '23 20:01 the-mikedavis

For scenarios like this I think it would be better to make use of the -c <config-file> CLI option and have a wrapper around hx -c to control which config is used based on the directory it's called in

That seems like a very fast path to the disaster that is using $CARGO_TARGET_DIR globally and doesn't allow for merging configs in the local -> project -> user order, because projects may be settings configs to help users go in more smoothly and having to pass -c is simply a workaround

poliorcetics avatar Jan 23 '23 20:01 poliorcetics

The security aspect of this still bothers me a bit - it ends up really nerfing the feature. I think it's silly in the same way that git's cve-2022-24765 (the safe.directory one) is silly, and to my knowledge no other terminal based editor is careful about this. I would argue at least that this should be enabled by default.

Both vim and emacs disallow modelines from configuring settings that can result in executables being run by default / without user approval.

charles-dyfis-net avatar Aug 28 '23 22:08 charles-dyfis-net