rossmacarthur / sheldon

:bowtie: Fast, configurable, shell plugin manager
https://sheldon.cli.rs
Apache License 2.0
958 stars 21 forks source link

Customizing Variables #126

Closed JP-Ellis closed 1 year ago

JP-Ellis commented 2 years ago

A number of plugins allow for their functionality to be customized by defining and/or changing environment variables (or using zstyle).

Whilst it is of course possible to define these after eval $(sheldon source), I was wondering whether there might be support for this within the Sheldon config?

Perhaps something like

[plugins]

    [plugins.enhancd]
        github = "b4b4r07/enhancd"

        [plugins.enhancd.variables]
            ENHANCD_HOOK_AFTER_CD = "ls"

Which would effectively run

$ sheldon --source
source "~/.local/share/sheldon/repos/github.com/b4b4r07/enhancd/enhancd.plugin.zsh"
ENHANCD_HOOK_AFTER_CD="ls"

If this is a feature that might be useful, I could have a look at implementing it if I get time.

rossmacarthur commented 2 years ago

I think this is a great idea, I would be happy to accept a pull request for this change. I think the variable should be set before the plugin is sourced though.

queensferryme commented 2 years ago

Hi @rossmacarthur, I have been thinking about a pre/post hook feature for sheldon for some time and it might fit @JP-Ellis 's use case just well.

Here is the idea:


[plugins]

[plugins.enhancd]
github = "b4b4r07/enhancd"

[plugins.enhancd.hooks]
pre  = """
# run something before sourcing the plugin
"""
post = """
# run something after the plugin is sourced
export ENHANCD_HOOK_AFTER_CD='ls'
"""

The hook feature seems more generic as it can do more than setting customized variables. I'd be happy to try submit a pull request if you find this feature useful :)