Skip to content

Instantly share code, notes, and snippets.

@fionn
Last active March 29, 2025 05:40
Show Gist options
  • Save fionn/0813947b159762330be46dd0dcc11455 to your computer and use it in GitHub Desktop.
Save fionn/0813947b159762330be46dd0dcc11455 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eo pipefail
function main {
local threshold="${1:-2}"
local -r pattern="${2:-*}"
((threshold++))
count=$( (pcre2grep -IO "" --line-number -M "\n{$threshold}" $(git ls-files "$pattern") || true) \
| cut -d ":" -f 1,2 \
| tee /dev/tty \
| wc -l)
return $(( count < 255 ? count : 255 ))
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment