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

Automatically apply changes from all the config files chemzoi manages #748

Closed
Zackhardtoname opened this issue May 13, 2020 · 12 comments
Closed
Labels
enhancement New feature or request

Comments

@Zackhardtoname
Copy link

Sometimes I have to run the apply commit with all my dotfiles. Even after enabling auto-commit and auto-push, it could still get tedious. Is there any way we can have a command like chezmoi -apply-all?

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

twpayne commented May 13, 2020

Could you give an example of the command you would like?

chezmoi apply already updates all the files in the destination directory by default, and does not change anything in the source directory.

Autocommit and autopush are only relevant when there are changes to the source directory.

@Zackhardtoname
Copy link
Author

Zackhardtoname commented May 13, 2020

"apply-all" is probably a really bad name choice.

Example:
change ~/.zhrc
change ~/.bashrc
change some other dotfile
...

Then I run the command,
it would do the following
chezmoi add ~/.zhrc
chezmoi add ~/.bashrc
chezmoi add all the other files that are tracked but not added with chezmoi by the user

In that case, I don't have to keep track of the files I have modified. I can just run one command after applying lots of changes to multiple dotfiles.

@twpayne
Copy link
Owner

twpayne commented May 13, 2020

Thanks for the further details.

If you chezmoi add a file that's already managed by chezmoi then chezmoi will forget any attributes like empty_, encrypted_, and .tmpl so it's not safe to use in the general case. For example, if ~/.zshrc is generated by a template then running chezmoi add ~/.zshrc will replace the dot_zshrc.tmpl template with a non-template dot_zshrc containing the only the result of the template, which is probably not what the user wants.

If you can train your muscle memory to run, instead of typing $EDITOR ~/.zshrc; chezmoi add ~/.zshrc, typing instead:

chezmoi edit --apply ~/.zshrc

then you'll get the benefits of the changes being saved in the source state, applied to ~/.zshrc, and autocommitted and autopushed, if you have those turned on. chezmoi edit also knows about encrypted files and automatically decrypts and re-encrypts them for you transparently.

With version 2, there'll be a chezmoi status command that will tell you which files are out of data, which will also be helpful.

@Zackhardtoname
Copy link
Author

Thank you for your explanation! The reason why I did not do chezmoi edit --apply ~/.zshrc is that sometimes I wasn't sure if the file was previously managed by chezmoi or not.

Anyway, for now, I will add an alias for chezmoi edit --apply .

@Zackhardtoname
Copy link
Author

I just remembered the true reason why I used the vim + chezmoi add workflow:
Sometimes I don't know if my changes would work or not, so I experiment with them first.
After enabling auto commit and auto pull, chezmoi edit --apply would potentially pollute my git history with incorrect changes.
It often involves multiple files, then the functionality in the request would come handy.

Please let me know what you think. Thanks!

@twpayne
Copy link
Owner

twpayne commented May 15, 2020

For the reasons mentioned above, chezmoi add is not safe.

Once chezmoi status is implemented (targeted for version 2, work in progress in #654), then you'll be able to quickly see which files you've modified locally add add them.

@liukun
Copy link

liukun commented May 22, 2020

Can there be chezmoi push command that does commit and push all changes? It does the same as auto-commit/push, but triggered manually.

@twpayne
Copy link
Owner

twpayne commented May 23, 2020

Can there be chezmoi push command that does commit and push all changes? It does the same as auto-commit/push, but triggered manually.

You can do this with:

chezmoi git -- commit -m "Add all changes" .
chezmoi git -- push

@liukun
Copy link

liukun commented Jun 16, 2020

Thanks, so the one-liner would be

chezmoi git -- status && chezmoi git -- add -A && chezmoi git -- commit -m 'All' && chezmoi git -- push

@tkolleh
Copy link

tkolleh commented Oct 1, 2020

Until status is released, to add the changes of all target files (edited target), I use the command (without the --dry-run):

chezmoi managed | xargs -I _ -n1 chezmoi --dry-run add --prompt _

As @twpayne stated above chezmoi edit --apply <path/to/file> is the ideal approach to editing files for chezmoi.

@Zackhardtoname
Copy link
Author

Until status is released, to add the changes of all target files (edited target), I use the command (without the --dry-run):

chezmoi managed | xargs -I _ -n1 chezmoi --dry-run add --prompt _

Just as a reference for myself, when actually ready to run it:
chezmoi managed | xargs -I _ -n1 chezmoi add _ or chezmoi managed | xargs -I arg chezmoi add arg

@twpayne
Copy link
Owner

twpayne commented May 15, 2021

Fixed with #1208.

@twpayne twpayne closed this as completed May 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2021
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

No branches or pull requests

4 participants