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

feat: load local config #3207

Conversation

AlexanderBrevig
Copy link
Contributor

@AlexanderBrevig AlexanderBrevig commented Jul 27, 2022

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.

helix-loader/src/main.rs Outdated Show resolved Hide resolved
helix-term/src/main.rs Outdated Show resolved Hide resolved
@AlexanderBrevig
Copy link
Contributor Author

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.

Copy link
Contributor Author

@AlexanderBrevig AlexanderBrevig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should use eprintln and inform the user on startup (file and error message) much like the current behaviour.

Probably also should update the docs. Will fix this tomorrow (no computer today).

✔️ This is now implemented.

@diktomat
Copy link
Contributor

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.

@the-mikedavis
Copy link
Member

That probably falls under something like #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", "/"] }

@AlexanderBrevig
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

helix-term/src/main.rs Outdated Show resolved Hide resolved
helix-term/src/main.rs Outdated Show resolved Hide resolved
helix-term/src/main.rs Outdated Show resolved Hide resolved
helix-term/src/main.rs Outdated Show resolved Hide resolved
helix-term/src/main.rs Outdated Show resolved Hide resolved
@AlexanderBrevig
Copy link
Contributor Author

AlexanderBrevig commented Aug 29, 2022

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.

book/src/configuration.md Outdated Show resolved Hide resolved
helix-term/src/config.rs Outdated Show resolved Hide resolved
helix-term/src/config.rs Outdated Show resolved Hide resolved
helix-term/src/config.rs Outdated Show resolved Hide resolved
@AlexanderBrevig
Copy link
Contributor Author

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.

pickfire
pickfire previously approved these changes Sep 27, 2022
Copy link
Contributor

@pickfire pickfire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for working on this.

book/src/configuration.md Outdated Show resolved Hide resolved
book/src/configuration.md Outdated Show resolved Hide resolved
@the-mikedavis the-mikedavis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Oct 13, 2022
@AlexanderBrevig
Copy link
Contributor Author

Somehow I totally forgot this. Sorry.

@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 18, 2022
@Nazariglez
Copy link

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

@gibbz00
Copy link
Contributor

gibbz00 commented Jan 23, 2023

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, #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 gibbz00 mentioned this pull request Jan 23, 2023
5 tasks
@Nazariglez
Copy link

That's awesome @gibbz00, thank you!

@poliorcetics
Copy link
Contributor

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)

@pascalkuthe
Copy link
Member

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)

@poliorcetics
Copy link
Contributor

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

@the-mikedavis
Copy link
Member

.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?

@poliorcetics
Copy link
Contributor

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.

@the-mikedavis
Copy link
Member

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

@poliorcetics
Copy link
Contributor

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

@pascalkuthe pascalkuthe mentioned this pull request Jan 31, 2023
gibbz00 added a commit to gibbz00/helix that referenced this pull request Feb 15, 2023
Probably introduced when merging with helix-editor#3207.

Refreshing config from failed state would not update to set
theme from default theme. Reason being that theme was being loaded
before config was being set. One would have to refresh the config twice
to update the theme as well. This commit changes the refresh order such
that the config is actually set before refreshing the theme.
@charles-dyfis-net
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.