Skip to content

pre-commit hooks use bash-isms that block contributors on other shell (e.g, zsh) #3693

Description

@jiengup

Problem

Several pre-commit hooks invoke scripts that rely on bash-specific builtins (mapfile) and GNU extensions (sed -i without backup extension). These fail on non-bash shells like zsh, preventing contributors from committing code.

Affected bash-isms

mapfile (bash >= 4.0 builtin)

mapfile does not exist in POSIX sh or zsh. Hooks using it will abort with mapfile: command not found.

sed -i without backup extension (GNU sed extension)

BSD sed (default on macOS) requires sed -i "" with an explicit backup argument. Bare sed -i errors with sed: invalid command code.

Proposed fix

mapfilewhile IFS= read -r loop

# Before (bash >= 4.0)
mapfile -t items < <(some_command)

# After (POSIX-compatible)
items=()
while IFS= read -r line; do items+=("$line"); done < <(some_command)

sed -i → backup-then-remove

# Before (GNU sed only)
sed -i "s/old/new/" "$file"

# After (works on both GNU and BSD sed)
sed -i.bak "s/old/new/" "$file" && rm -f "$file.bak"

Both patterns already have precedent in the repo (the sed -i.bak + rm pattern exists in one CI script; a portable sed -i wrapper exists in a release script).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions