8000 feat: improve usability of spell.sh by theseion · Pull Request #3238 · coreruleset/coreruleset · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: improve usability of spell.sh #3238

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

Merged
merged 4 commits into from
Jun 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 71 additions & 8 deletions util/fp-finder/spell.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,83 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if ! command -v spell > /dev/null 2>&1; then
echo "This program requires spell to be installed. Aborting"
exit 1
fi

RULES_DIR="${SCRIPT_DIR}/../../rules/"
check() {
local datafile="${1}"
local datafile_name="${datafile##*/}"

for datafile in "$RULES_DIR"*.data; do
DATAFILE_NAME=${datafile##*/}

echo "-> checking ${DATAFILE_NAME}"
if ! ${MACHINE_READABLE}; then
echo "-> checking ${datafile_name}"
fi

for word in $(grep -E '^[a-z]+$' "${datafile}" | uniq | sort); do
IS_NOT_ENGLISH=$(echo "${word}" | spell | wc -l)
if [ "${IS_NOT_ENGLISH}" -lt 1 ]; then
echo " \`- found English word: ${word}"
if ! ${MACHINE_READABLE}; then
printf " \`- found English word: "
fi
echo "${word}"
fi
done

echo ""
if ! ${MACHINE_READABLE}; then
echo ""
fi
}

usage() {
cat <<EOF
usage: spell.sh [-mh] [file]
Finds English words in files that contain word lists.

The optional file argument is the path to a file you want to check. If omitted,
all files with the .data suffix in the rules directory will be searched.

-h, --help Show this message and exit
-m, --machine Print machine readable output
EOF
}

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

RULES_DIR="${SCRIPT_DIR}/../../rules/"

MACHINE_READABLE=false

POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
# shellcheck disable=SC2221,SC2222
case $1 in
-m|--machine)
MACHINE_READABLE=true
shift # past argument
;;
-h|--help)
usage
exit 1
;;
-*|--*)
echo "Unknown option $1"
usage
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters


if [ -n "${1}" ]; then
check "${1}"
else
for datafile in "${RULES_DIR}"*.data; do
check "${datafile}"
done
fi
0