Skip to content

Update defer template example#200

Merged
rossmacarthur merged 1 commit into
rossmacarthur:trunkfrom
MiSawa:trunk
May 10, 2026
Merged

Update defer template example#200
rossmacarthur merged 1 commit into
rossmacarthur:trunkfrom
MiSawa:trunk

Conversation

@MiSawa

@MiSawa MiSawa commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Thank you for creating such a great tool!

Since I use sheldon daily, I noticed a couple of issues with the current defer template shown in the documentation:

  • It invokes zsh-defer once per file being sourced, and each invocation of zsh-defer adds a small amount of overhead.
  • hooks.pre / hooks.post are executed outside the zsh-defer context. As a result, hooks.post may run before the plugin is actually sourced, which can lead to counter-intuitive behavior.

With the revised example, the output generated by sheldon would look like this:

zsh-defer -c "$(cat <<'SHELDON_DEFER'
echo "pre"
source "first-file"
source "second-file"
echo "post"
SHELDON_DEFER
)"

A here-document is used to avoid the need to escape hook contents (except the case when it include SHELDON_DEFER which I didn't handle).

@rossmacarthur

Copy link
Copy Markdown
Owner

Interesting, I wonder if sheldon should actually have a mechanism for putting multiple plugins behind a single zsh-defer.

@MiSawa

MiSawa commented Mar 14, 2026

Copy link
Copy Markdown
Contributor Author

It's a bit hacky but I believe this works

[plugins.zsh-defer]
github = "romkatv/zsh-defer"

[plugins.defer-start]
inline = """
zsh-defer -c "$(cat <<'SHELDON_DEFER'
"""

[plugins.whatever]
github = "whoever/whatever"

# other plugins...

[plugins.defer-end]
inline = """
SHELDON_DEFER
)"
"""

@rossmacarthur
rossmacarthur force-pushed the trunk branch 2 times, most recently from 2d57c54 to 807bb36 Compare May 10, 2026 20:43
@rossmacarthur
rossmacarthur merged commit eff4f19 into rossmacarthur:trunk May 10, 2026
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants