Skip to content

Commit

Permalink
RF+ENH: add commands for list-ing and also fix-sorted to apply on out…
Browse files Browse the repository at this point in the history
…put of list-hits-sorted
  • Loading branch information
yarikoptic committed Jan 2, 2024
1 parent 2788c19 commit e7b8342
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions codespellit
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,46 @@ if [[ "$codespell_version_full" =~ \.dev ]]; then
echo " For the action etc we will mention tagged version $codespell_version".
fi


function list() {
codespell "$@" || {
echo
echo "Problematic?:"
echo
codespell "$@" | grep ','
}
}

function list-hits-sorted() {
codespell "$@" | grep -e '==>' | sed -e 's,.*: *,,g' | sort | uniq -c | sort -n
}

# given filtered output from list-hits-sorted, apply those which were left
function fix-sorted() { # shellcheck disable=SC2120
if ! git diff-index --quiet HEAD --; then
echo "Repository is dirty. Please commit your changes first."
exit 1
fi

nfixes=$(cat "$@" | grep -e '==>' -c )
cat "$@" | grep -e '==>' | while read -r _ fr _ to; do
git grep -l "\<$fr\>" | xargs sed -i -e "s,\<$fr\>,$to,g"
done

git commit -m "Fix $nfixes typos found by codespell
Here are typos with their counts and introduced fix:
$(grep -e '==>' "$@")
" -a
}

# poor man shortcuts for just doing it using the regex etc
cmd="${1:-}"
case "$cmd" in
list|list-hits-sorted|fix-sorted) shift; "$cmd" "$@"; exit $?;;
esac

git checkout -b enh-codespell

skips=".git,*.pdf,*.svg,go.sum"
Expand Down Expand Up @@ -122,9 +162,4 @@ EOF
git commit -m 'Add pre-commit definition for codespell'
fi

codespell || {
echo
echo "Problematic?:"
echo
codespell | grep ','
}
list "$@"

0 comments on commit e7b8342

Please sign in to comment.