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

apply file changes on write with edit --apply #752

Closed
jmattheis opened this issue May 16, 2020 · 5 comments · Fixed by #2272
Closed

apply file changes on write with edit --apply #752

jmattheis opened this issue May 16, 2020 · 5 comments · Fixed by #2272
Labels
enhancement New feature or request

Comments

@jmattheis
Copy link

My current workflow for changing my config is

$ chezmoi edit --apply ~/.config/some/config

then I've to write quit my $EDITOR to apply the changes. It would be cool, if I didn't have to close my editor and only write the file (:w in vim). Chezmoi could listen on file changes (with something like inotify) and then apply them.

Usecases are:

  • vim: edit config, write, source applied config from chezmoi
  • i3: edit config, write, inplace reload i3 without killing existing windows

This is only a minor inconvenience so feel free to close the issue if you don't see the need for it.

Anyway, keep up the good work with chezmoi!

@jmattheis jmattheis added the enhancement New feature or request label May 16, 2020
@twpayne
Copy link
Owner

twpayne commented May 16, 2020

Interesting idea, and related to what @Zackhardtoname is asking for.

This should be fairly straightforward to implement, but I'd like to get the v2 rework done first. I expect to add this though :)

@twpayne twpayne added this to the v2.0.0 milestone May 16, 2020
@Lilja
Copy link

Lilja commented May 17, 2020

So I randomly looked into this thread and felt a bit bored and decided to create my first vim plugin.

It solves this problem by getting the current PID of the vim process, looks up the parent PID and sees if chezmoi was invoked(chezmoi edit $dotfile). If so, it will listen to buffer write and invoke the chezmoi apply $dotfile automatically.

Feel free to use it! https://github.com/lilja/vim-chezmoi

@camgraff
Copy link

camgraff commented Nov 8, 2020

+1 for this! I'd love to get back the ability to make a change to my .vimrc, save, re-source, and test if my change results in the expected functionality all without ever heaving to leave the editor.

@twpayne if you're too busy right now and this doesn't conflict with the v2 rework, I'd be happy to get a PR up for this. I'd just need a little direction on the design i.e. would you want this to become the default behavior or introduce a new flag with chezmoi edit?

@twpayne
Copy link
Owner

twpayne commented Nov 15, 2020

@camgraff Thanks for your offer - it's not quite time to work on this yet.

At the moment, the v2 branch is nearing completion (please do check out the v2 branch and try it) but one of the two remaining things left to implement are chezmoi edit with encrypted files, which is a prerequisite for implementing the file watching functionality. In the case of encrypted source files, chezmoi edit decrypts the source file to a temporary private directory, opens the decrypted file in $EDITOR, and then re-encrypts the edited file and writes it back to the source directory when the editor exits. This means that file to watch for updates is not the file in the source directory but instead the decrypted file in the temporary private directory. This mechanism is not yet complete in the v2 branch.

@twpayne twpayne modified the milestones: v2.0.0, v2.1 Apr 3, 2021
@twpayne twpayne removed this from the v2.1 milestone Sep 12, 2021
@tnek213
Copy link

tnek213 commented Sep 20, 2021

I hacked this together which auto applies on each save (and not only when the editor exits. It can be convenient when editing some configuration where a tight edit-test-loop is required. Use at your own risk! ;-)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants