-
Notifications
You must be signed in to change notification settings - Fork 499
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: Set CHEZMOI_SOURCE_FILE env var for scripts #3518
Conversation
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.
Looks reasonable, but I have not tested it.
I will try: I'm down with a nasty cold at the moment, so it may take a few days before I have energy to deal with this. It will be interesting to see if it speeds up chezmoi diff (currently a no-op one takes about 85 ms on my desktop iirc, and I have run out of ways to speed it up on my side, a single chezmoi_modify_manager invocation is about 2-3 ms) |
No rush at all and wishing you a speedy recovery! |
I actually got the energy to give this a try now. The mechanism in itself doesn't really offer any speed-up (as expected). But this means that every The runtime of $ # With lookup based on env vars but still .tmpl files
$ hyperfine "./chezmoi diff"
Benchmark 1: ./chezmoi diff
Time (mean ± σ): 87.2 ms ± 1.6 ms [User: 72.5 ms, System: 32.4 ms]
Range (min … max): 84.9 ms … 92.8 ms 33 runs
$ # After converting to non-.tmpl files
$ hyperfine "./chezmoi diff"
Benchmark 1: ./chezmoi diff
Time (mean ± σ): 78.5 ms ± 0.8 ms [User: 65.7 ms, System: 27.8 ms]
Range (min … max): 76.9 ms … 80.2 ms 37 runs That is ~90% of the original time, not bad. (Another benefit is not needing the complicated templated line [as shown below] in the modify script.) (The difference between .tmpl with Further improvement ideaDo you still always make a copy of the To support legacy scripts you would need to support copying if required though I guess. Might still be worth detecting the file modes via a |
(Another note, I found it slightly annoying that I need to combine CHEZMOI_SOURCE_DIR and CHEZMOI_SOURCE_FILE to get the path. But if you don't already have that combined on your side for other purposes, it is probably faster to do the string manipulation in the rust code on my side anyway.) |
Thank you for testing!
Yes, the scripts are always written to a temporary directory before being executed. This is always necessary if the script is a template. I agree that if the Even though git preserves the executable attribute, chezmoi's source state is designed to only use regular files and directories. This is important to provide compatibility with all filesystems and version control systems. In theory, chezmoi should work even if the only way to transfer your dotfiles is on a FAT32-formatted USB stick. Although milliseconds can be shaved by avoiding the write to a temporary filesystem, I think the real benefits for the user will come from #2814 and #2670, which should improve chezmoi's running time by multiple seconds.
Concatenating two strings should only take fractional nanoseconds. Thank you again, and hope that you're on your way to recovery. I'll merge this PR. |
Two questions:
|
The next one, which will be either 2.46.1 or 2.47.0 depending on what other features and bug fixes land in the next few weeks. However, you can also test for the presence of the
Yes. To be extra robust, look for the first occurrence of this regexp in the output of |
Not where I need to: I have a flag I wrote some documentation on how all of this works (with placeholder chezmoi version numbers): I cannot just switch over to
Awesome. |
Fixes #2934. It only took nine months.
@VorpalBlade this sets the
$CHEZMOI_SOURCE_FILE
environment variable formodify_
scripts (and also normal scripts), which should be useful for your excellent chezmoi_modify_manager.As background info, this change became possible after 7203d6b (in chezmoi v2.40.3).
Would you be able to test this?