scripts, build, just: POSIX Compliance

Enforce POSIX shell syntax with ShellCheck using `--shell sh`.
This commit is contained in:
Lorenz Leutgeb
2026-10-30 12:45:40 +01:00
parent 9e80d2d4b9
commit c7d71df4ab
26 changed files with 94 additions and 92 deletions
+23 -17
View File
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
set -euo pipefail
# Replace '...' with '…' (U+2026) in markdown, just and Rust files, but ignore:
@@ -6,22 +6,28 @@ set -euo pipefail
# - Git ranges with ref paths, e.g. feature/1...rad/patches/f2de534
# - Standalone '...' lines used as output wildcards in CLI example tests
# - Wildcards for CLI example tests, i.e. [...]
patterns=('*.md' '*.rs' '*justfile')
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' 0
trap 'exit 1' HUP INT TERM
# Get all regular files (exclude symlinks, directories, etc.)
files=()
while IFS= read -r -d '' file; do
if [ -f "$file" ] && [ ! -L "$file" ]; then
files+=("$file")
fi
done < <(git ls-files -z "${patterns[@]}")
# Keep NUL-delimited filenames so spaces and newlines are preserved.
git ls-files -z '*.md' '*.rs' '*justfile' > "$tmp/tracked"
# The child shell expands these variables.
# shellcheck disable=SC2016
xargs -0 sh -c '
for file do
if [ -f "$file" ] && [ ! -L "$file" ]; then
printf "%s\000" "$file"
fi
done
' sh < "$tmp/tracked" > "$tmp/files"
if [ ${#files[@]} -eq 0 ]; then
if [ ! -s "$tmp/files" ]; then
exit 0
fi
# Checksum files before sed so we detect only changes it makes.
before=$(printf '%s\0' "${files[@]}" | xargs -0 md5sum)
xargs -0 md5sum < "$tmp/files" > "$tmp/before"
standalone_wildcard='^[[:space:]]*\.\.\.[[:space:]]*$'
git_hex_range='[0-9a-f]{4,}\.\.\.[0-9a-f]{4,}'
@@ -30,20 +36,20 @@ bracket_wildcard='\[[[:space:]]*\.\.\.[[:space:]]*\]'
# Detect GNU vs BSD sed to apply the correct in-place flag
if sed --version >/dev/null 2>&1; then
sed_cmd=(sed -i -E)
set -- -i -E
else
sed_cmd=(sed -i '' -E)
set -- -i '' -E
fi
printf '%s\0' "${files[@]}" | xargs -0 "${sed_cmd[@]}" \
xargs -0 sed "$@" \
-e "/${standalone_wildcard}/b" \
-e "/${git_hex_range}/b" \
-e "/${git_ref_range}/b" \
-e "/${bracket_wildcard}/b" \
-e "/${bracket_wildcard}/b" < "$tmp/files"
after=$(printf '%s\0' "${files[@]}" | xargs -0 md5sum)
xargs -0 md5sum < "$tmp/files" > "$tmp/after"
changed=$(diff <(echo "$before") <(echo "$after") | grep '^>' | sed 's/^> [a-f0-9]* //' || true)
changed=$(diff "$tmp/before" "$tmp/after" | grep '^>' | sed 's/^> [a-f0-9]* //' || true)
if [ -n "$changed" ]; then
echo "error: Replaced '...' with '…' (U+2026) in the following files:"
+7 -7
View File
@@ -1,11 +1,11 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
set -e
HOOK_SCRIPT=$1
HOOKS=$2
TEMPLATE="$HOOK_SCRIPT"
OUTDATED=()
OUTDATED=""
MISSING=0
TOTAL=0
@@ -13,9 +13,9 @@ for hook in $HOOKS; do
TOTAL=$((TOTAL + 1))
if [ ! -f ".git/hooks/$hook" ]; then
MISSING=$((MISSING + 1))
OUTDATED+=("$hook")
OUTDATED="$OUTDATED $hook"
elif ! cmp -s "$TEMPLATE" ".git/hooks/$hook"; then
OUTDATED+=("$hook")
OUTDATED="$OUTDATED $hook"
fi
done
@@ -23,12 +23,12 @@ if [ "$MISSING" -eq "$TOTAL" ] && [ "$TOTAL" -gt 0 ]; then
echo ""
echo "${HINT}No git hooks are installed. Run 'just install-hooks' to install them.${NORMAL}"
echo ""
elif [ ${#OUTDATED[@]} -gt 0 ]; then
elif [ -n "$OUTDATED" ]; then
echo ""
echo "${WARN}WARNING: The following git hooks are missing or out of date:${NORMAL}"
echo ""
for hook in "${OUTDATED[@]}"; do
echo -e "\t$hook"
for hook in $OUTDATED; do
printf '\t%s\n' "$hook"
done
echo ""
echo "${HINT}Check them with 'diff $HOOK_SCRIPT .git/hooks/<hook name>' then run 'just install-hooks'${NORMAL}"
+1 -1
View File
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
set -e
echo "${CHECK}Checking for forbidden words in staged files…${NORMAL}"
+1 -1
View File
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
set -euo pipefail
FILE=$1
+1 -1
View File
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
if command -v alejandra >/dev/null 2>&1; then
alejandra --check .
+4 -3
View File
@@ -1,11 +1,12 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
set -e
HOOK_SCRIPT=$1
HOOKS=$2
read -r -p "Overwrite existing hooks '${HOOKS}'? [y/N] " confirm
[[ "$confirm" == "y" ]] || exit 1
printf "Overwrite existing hooks '%s'? [y/N] " "$HOOKS"
read -r confirm
[ "$confirm" = "y" ] || exit 1
for hook in $HOOKS; do
if [ -f ".git/hooks/$hook" ]; then
+1 -1
View File
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
set -e
TOOL=$1
PKG_NAME=$2