tinted-theming / tinty

A base16 and base24 color scheme manager
MIT License
58 stars 5 forks source link

[Feature request] skip the hook if it is not `apply` #70

Closed twnaing closed 1 month ago

twnaing commented 1 month ago

Is your feature request related to a problem? Please describe.

No, it is not.

Describe the solution you'd like

Solution: skip the hook if it is not apply

Reason: there are cases where hook is used to create config file such as copying the template file cp -f %f ~/.config/i3/color. Such kind of hook is only required when we are applying new theme, AFAIK. If we can skip the hook on init we can increase speed and reduce resource usage.

Describe alternatives you've considered

The alternative could be

a. different hooks for apply and init b. pass init or apply to hook as a template variable and deal with the resource usage in the hook command

Additional context

The following config always create config file and reload the i3 every time tinty init is called.

# ... global config
[[items]]
name = "base16-i3"
path = "https://github.com/tinted-theming/base16-i3"
themes-dir = "colors"
hook = "cp -f %f ~/.config/i3/colors && cat ~/.config/i3/colors ~/.config/i3/base > ~/.config/i3/config && i3-msg reload"
JamyGolden commented 1 month ago

Thanks for creating the issue. What would imagine the config item look like for this? hook_init and hook for normal and hook is executed if hook_init doesn't exist for init? Trying to figure out a way to get it done without making it overly complex

twnaing commented 1 month ago

On a second thought, I think I am having this feature request because

Currently

works the way I want.

Making two hooks seem complex.

JamyGolden commented 1 month ago

I'm glad you've got it working like you'd like. Yeah I do see the issue with init and apply and how it can be confusing. init is currently basically tinty apply $(tinty current) which does make me question the necessity of init subcommand in the first place if it's not very different from apply.

twnaing commented 1 month ago

As Tinty have already offloaded "a bit of work" to the hook, passing of the command (init or apply as a template variable) to hook could be less complicated.

Users will have the freedom to do what they want in the hook.

Just a opinion.

JamyGolden commented 1 month ago

Can you give a config.yaml example of that suggestion?

twnaing commented 1 month ago

assume %m is command mode (i.e. init or apply) the config will be like

[[items]]
name = "base16-i3"
path = "https://github.com/tinted-theming/base16-i3"
themes-dir = "colors"
hook = '[ "%m" = "apply" ] && cp -f %f ~/.config/i3/colors && cat ~/.config/i3/colors ~/.config/i3/base > ~/.config/i3/config && i3-msg reload'
JamyGolden commented 1 month ago

Added a PR for this: https://github.com/tinted-theming/tinty/pull/73

JamyGolden commented 1 month ago

Just released the changes, let me know if things aren't as expected.