Repository navigation
feat(bash): read the commands that a bash script runs - #31
Merged
Merged
Conversation
internal/bash reads a script with mvdan.cc/sh's bash parser (the user's OK, pinned at v3.14.1) and returns each command that it runs, as the words that bash passes it: in substitutions, here-documents and functions too, past wrappers such as env, nohup and xargs, and inside the scripts of sh -c and eval. The guard builds on it. Docs: the guard split into bash, guard, guard-orchestrator and belt; decision 50, fact 33, risk 2, and the homebrew row's license notice.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Brief
First part of the guard (split into
bash,guard,guard-orchestratorandbelt, decision 50). The guard has to know which commands a bash tool call runs; a text match missesgit -C x push,nohup git pushor$(git push)and catchesecho 'git push'. The standard library has no bash parser, sointernal/bashuses mvdan.cc/sh/v3 (the user's OK via nudge, pinned exactly at v3.14.1, BSD-3).What changes
bash.Calls(script)gives each command that the script runs, as the words that bash passes it:$X,$(…),$'…') becomes the markerbash.Dynamic;builtin caffeinate command env exec nice nohup stdbuf sudo time timeout xargs, and Homebrew'sgnames): their options,NAME=valuewords andtimeout's duration;eval, and ofbash dash ksh sh zshwith-c;bash.Name(word): a program's name, lower-cased (a Mac's file system ignores case).internal/bashimports the module.Acceptance
$[…]arithmetic, on which bash fails too), 0.2 s for all.mise run checkgreen.Notes (non-blocking)
find -exec, git aliases, brace expansion,env -S, long options with a separate value. The guard is a seatbelt (risk 2);beltchecks a second one.guarddoes.