commands
commands ¶
block_command_pattern ¶
Convert a token list into a whitespace-flexible regex pattern.
"*" becomes \S+ (any non-whitespace word), "a|b" becomes an
alternation group, and all other tokens are escaped.
Example
block_command_pattern(["git", "stash", "*"]) 'git\s+stash\s+\S+'
block_command ¶
block_command(
pattern: str | list[str],
*,
reason: str,
hint: str | None = None,
tests: InlineTests | None = None,
) -> None
Register a declarative hook that blocks a Bash command matching a pattern.
Example
block_command(["git", "stash"], reason="git stash is not allowed", hint="Use jj")
warn_command ¶
warn_command(
pattern: str | list[str],
*,
message: str,
tests: InlineTests | None = None,
events: Event = Event.PostToolUse,
) -> None
Register a declarative hook that warns on a Bash command matching a pattern.
Example
warn_command(["python", "-c", "*"], message="Prefer uv run mtest")