VorpalBlade / chezmoi_modify_manager

Tools for chezmoi to handle mixed settings and state
GNU General Public License v3.0
45 stars 5 forks source link

Issue with installing #36

Closed Archie-2021 closed 1 year ago

Archie-2021 commented 1 year ago

Sorry for starting this, I was looking for a Q&A section but could not find any

I downloaded the binary from release page to my mac and put it in .local/bin which is in my path. I added a file with cmm --add. but when i changes some setting and trying to apply with chezmoi apply it creates a .src.ini file and dont apply changes correctly to the config file. I think chezmoi binary is not aware that this plugin exists at all. Is there a step I am missing. I did all the things told in README file.

Sorry again for opening this in inappropriate place. But could find anywhere better to ask help for this issue.

VorpalBlade commented 1 year ago

No problem (there isn't really a more appropriate place currently for this type of question).

One possible cause is that since you said "cmm" here, the tmpl file will still refer to the program with the full name, so if you renamed the program that won't work. If so, I would recommend keeping the full name of the binary but creating a symlink or alias for the shorthand name.

If that is not it, I will need some more details to help you: What exactly happens when you say "dont apply changes correctly to the config file"? Does the config file not change at all? It would be useful if you could provide (after removing any sensitive information of course):

Finally a couple of notes:

Archie-2021 commented 1 year ago

Thanks for your help.

No the binary name is not changed. I just wrote it that way to make it shorter. I add all the files in an tarball including results if chezmoi doctor.

and my mac version is High Sierra. I used MacPorts to install chezmoi as it was the only way to install it on thus outdated version. I have a Linux machine at home which I want to move my settings between these two machines. I have not tested cmm there yet. I just installed in from AUR there this morning.

Archie-2021 commented 1 year ago

Thanks for your help.

No the binary name is not changed. I just wrote it that way to make it shorter. I add all the files in an tarball including results if chezmoi doctor.

and my mac version is High Sierra. I used MacPorts to install chezmoi as it was the only way to install it on thus outdated version. I have a Linux machine at home which I want to move my settings between these two machines. I have not tested cmm there yet. I just installed in from AUR there this morning.

And file I am trying to use a a test is qterminal.ini which doesn't involve anything private.

link to file https://easyupload.io/5fuaj8

VorpalBlade commented 1 year ago

To me it seems that running chezmoi_modify_manager manually on the file work as I would expect (after adjusting the templated path that chezmoi replaces with the correct path).

It ignores any changes in the system the Sessions and MainWindow sections (as you specified), but changes elsewhere are overwritten from the chezmoi source state.

I tested this using the following command while making test changes (again after having manually expanded the source directive that chezmoi would normally expand):

diff cmm-files/qterminal.org.home/qterminal.ini <(chezmoi_modify_manager cmm-files/qterminal.org.src/modify_qterminal.ini.tmpl  < cmm-files/qterminal.org.home/qterminal.ini)

So, some followup questions:

PS. Hint for the future: You can attach an archive directly to a github issue by dragging and dropping it into the comment field.

Archie-2021 commented 1 year ago

I yeah it works. I see jow. but it also create a file for .src ini file? is it normal? Should I manually put them in .chezmoiignore file?

I am using github on Android. so I can't use drag and drop. I was expecting a way to attach file and was surprised that could not find any

VorpalBlade commented 1 year ago

but it also create a file for .src ini file? is it normal? Should I manually put them in .chezmoiignore file?

Ah, yes. This is mentioned in the README (section installation), but perhaps it should be more prominent:

To your root .chezmoiignore add: **/*.src.ini. These files should not be checked out into your target directory, but acts as the "source of truth" for the modify script.

chezmoi_modifymanager needs two files for every file it handles: The *.src.ini which is the source file (and works pretty much like any normal file managed by chezmoi, except it is ignored). Then it needs the `modify*.tmplfile, which chezmoi will execute as if it was a script, exceptchezmoi_modify_manageris the "interpreter" for that script (thanks to the#! ...` line at the start).

chezmoi_modify_manager however is no ordinary interpreter, instead treating that file as a configuration file describing what modifications to perform when merging the system state and source state to get the new system state.

Archie-2021 commented 1 year ago

but it also create a file for .src ini file? is it normal? Should I manually put them in .chezmoiignore file?

Ah, yes. This is mentioned in the README (section installation), but perhaps it should be more prominent:

To your root .chezmoiignore add: **/*.src.ini. These files should not be checked out into your target directory, but acts as the "source of truth" for the modify script.

chezmoi_modifymanager needs two files for every file it handles: The *.src.ini which is the source file (and works pretty much like any normal file managed by chezmoi, except it is ignored). Then it needs the `modify*.tmplfile, which chezmoi will execute as if it was a script, exceptchezmoi_modify_manageris the "interpreter" for that script (thanks to the#! ...` line at the start).

chezmoi_modify_manager however is no ordinary interpreter, instead treating that file as a configuration file describing what modifications to perform when merging the system state and source state to get the new system state.

I see, yeah I think README file is a but unclear about it.

Thank you very much for your hel.p and maintaining this great program

Archie-2021 commented 1 year ago

Is it possible to use templater syntax in src.ini file. I want to change keybindings based of the os using .chezmoi.os , it seems that it doesn't parse chezmoi syntax inside src fiel. is there a way around that?

VorpalBlade commented 1 year ago

Is it possible to use templater syntax in src.ini file. I want to change keybindings based of the os using .chezmoi.os , it seems that it doesn't parse chezmoi syntax inside src fiel. is there a way around that?

I debated that, (see issue #4). The problem is that it breaks re-adding ini-files to the source state (which was an important use case for me). Instead I settled on the .tmpl file having the templating and using "set" commands there. There is also "remove" but I would argue a "set" is better as it is less likely to be overwritten by mistake when re-adding on a host that lacks those entries.

Here is an example from my modify_private_kglobalshortcutsrc.tmpl file to deal with different settings between home and work:

{{ if (.custom.is_work) }}
set "khotkeys" "{5cef61b9-6823-4258-85d3-bab6a0bd47de}" "Ctrl+Alt+Y,none,Move simulator windows" separator="="
{{ end }}

That said, I'm not opposed to adding optional support for directly templating the src.ini file, but it is not something I have a need of myself. But a well written PR will likely be accepted. I believe the general behaviour should be:

If you are interested in doing this I can outline the needed steps for the PR:

VorpalBlade commented 1 year ago

I have now added a new chezmoi_modify_manager --doctor modelled after chezmoi doctor that should be able to detect the original problem of this issue.

I have also create a specific support request issue template to simplify in the future.

Archie-2021 commented 1 year ago

Is it possible to use templater syntax in src.ini file. I want to change keybindings based of the os using .chezmoi.os , it seems that it doesn't parse chezmoi syntax inside src fiel. is there a way around that?

I debated that, (see issue #4). The problem is that it breaks re-adding ini-files to the source state (which was an important use case for me). Instead I settled on the .tmpl file having the templating and using "set" commands there. There is also "remove" but I would argue a "set" is better as it is less likely to be overwritten by mistake when re-adding on a host that lacks those entries.

Here is an example from my modify_private_kglobalshortcutsrc.tmpl file to deal with different settings between home and work:

{{ if (.custom.is_work) }}
set "khotkeys" "{5cef61b9-6823-4258-85d3-bab6a0bd47de}" "Ctrl+Alt+Y,none,Move simulator windows" separator="="
{{ end }}

That said, I'm not opposed to adding optional support for directly templating the src.ini file, but it is not something I have a need of myself. But a well written PR will likely be accepted. I believe the general behaviour should be:

  • Check for a new directive in the .tmpl file such as templated. This enables running the .src.ini file through chezmoi execute-template. We don't want to do it by default (to reduce the overhead).
  • Run the src.ini through chezmoi execute-template prior to the merging if this directive is set. Then proceed as normal.

If you are interested in doing this I can outline the needed steps for the PR:

  • Which files and methods will likely need changing
  • How to add an automated test for the functionality
  • How to install chezmoi itself in CI (not currently done, but would be needed for calling chezmoi execute-template)
  • What documentation needs to be updated.

I see, I think I can live with use set command for adding lines I want to have specific on my different machines to avoid any issues with re-add. I think the overlap of an init config file and machine specific ones are small enough to do that.

I have now added a new chezmoi_modify_manager --doctor modelled after chezmoi doctor that should be able to detect the original problem of this issue.

I have also create a specific support request issue template to simplify in the future.

That is very nice I would update to test it when I get to work and have access to mac machine. On Linux I should wait for AUR update.

Thanks

VorpalBlade commented 1 year ago

On Linux I should wait for AUR update.

That happens within minutes of publishing a release (may take a few more minutes due to web server caches etc). I have automated publishing of new versions to AUR directly from Github Actions.

Archie-2021 commented 1 year ago

On Linux I should wait for AUR update.

That happens within minutes of publishing a release (may take a few more minutes due to web server caches etc). I have automated publishing of new versions to AUR directly from Github Actions.

Oh.. so you are yourself the maintainer. Nice