InioX / matugen

A material you color generation tool
GNU General Public License v2.0
288 stars 14 forks source link

Add hook options to the config to execute shell commands before/after generation. #100

Open Davenchy opened 1 month ago

Davenchy commented 1 month ago

I suggest adding an option to the TOML config file under the template section, such as exec, or perhaps splitting it into pre_exec and post_exec. This option would allow users to specify a shell command to be executed automatically.

I believe this approach would be more effective than implementing commands for each requested app individually. It would give users the flexibility to restart or perform any necessary actions before or after generating templates according to their needs.


I recall something similar might have been added before, possibly called hook, but it’s not mentioned in the documentation, so I’m unsure if it’s the same feature or something different. I am talking about https://github.com/InioX/matugen/issues/83#issuecomment-2197180474


Anyway, Here’s an example using the exec approach:

[templates.swaync]
input_path = '~/.config/swaync/style-template.css'
output_path = '~/.config/swaync/style.css'
exec = 'swaync-client --reload-config && swaync-client --reload-css'

And here’s an example using the {pre/post}_exec approach:

[templates.some_app]
input_path = '~/.config/some_app/template.ext'
output_path = '~/.config/some_app/generated.ext'
pre_exec = 'echo "before generating" >> ~/logs'
post_exec = 'echo "after generating" >> ~/logs'

Originally posted by @Davenchy in https://github.com/InioX/matugen/issues/94#issuecomment-2283292725

InioX commented 1 month ago

Hi,

The documentation is a little bit behind, that's why hook is probably missing. I'll have to update it.

I suggest adding an option to the TOML config file under the template section, such as exec, or perhaps splitting it into pre_exec and post_exec. This option would allow users to specify a shell command to be executed automatically.

I'll definitely add the post/pre part. I don't know whatever to rename hook to exec, but as it wasn't yet mentioned in the documentation I don't think it will cause anything.

I believe this approach would be more effective than implementing commands for each requested app individually. It would give users the flexibility to restart or perform any necessary actions before or after generating templates according to their needs.

I agree, it would also be good to add hooks to the example templates repo.