Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add script hooks that use configured interpreters #4154

Merged
merged 1 commit into from
Dec 23, 2024
Merged

Conversation

twpayne
Copy link
Owner

@twpayne twpayne commented Dec 23, 2024

Fixes #4151.

Draft PR, not quite ready yet.

@bradenhilton
Copy link
Collaborator

Would adding a new script option (with the configured interpreters) for hooks be better?

I agree that it isn't ideal, but the current implementation is correct because it's a command option. I wouldn't expect, for example, executing .\script.ps1 in CMD to work properly. It just so happens that this works well on UNIX-like platforms because of shebangs.

script and command would be mutually exclusive and both would allow args.

@twpayne
Copy link
Owner Author

twpayne commented Dec 23, 2024

Would adding a new script option (with the configured interpreters) for hooks be better?

Yes, this is a great idea and would be much better, thank you! I'll definitely implement this instead.

@twpayne twpayne force-pushed the fix-4151 branch 4 times, most recently from 694d31b to ae48deb Compare December 23, 2024 15:36
@twpayne twpayne marked this pull request as ready for review December 23, 2024 16:15
@twpayne twpayne requested a review from bradenhilton December 23, 2024 16:16
@twpayne twpayne changed the title feat: Use interpreters for hooks feat: Add script hooks that use configured interpreters Dec 23, 2024
Copy link
Collaborator

@bradenhilton bradenhilton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a quick test with all permutations of this

# .chezmoiscripts/windows/.greet.ps1

if ($args.Count -eq 0) {
    Write-Output 'Hello'
} elseif ($args.Count -eq 1) {
    Write-Output "Hello $($args[0])"
} else {
    Write-Output "Hello $($args[0..($args.Count - 2)] -join ', ') and $($args[-1])"
}

and it worked as expected.

@twpayne twpayne merged commit 0a0d607 into master Dec 23, 2024
30 checks passed
@twpayne twpayne deleted the fix-4151 branch December 23, 2024 17:46
@twpayne
Copy link
Owner Author

twpayne commented Dec 23, 2024

Yay! Thanks for the review and testing :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add interpreter support for hooks
2 participants