script: function style

This commit is contained in:
Morgan 2018-09-13 21:14:23 +02:00
parent 435ea0ce45
commit 43d38fac70

View File

@ -3,22 +3,29 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
url="${1:-}" fetch_top_words() {
basedir=$(dirname "$0") local url
local basedir
if [[ "${url:-}" = "" ]]; then url="${1:-}"
grep --only-matching --extended-regexp '[a-zA-Z]{3,}' "$basedir/README.md" \ basedir=$(dirname "$0")
| tr '[:upper:]' '[:lower:]' \
| grep --invert-match --word-regexp --fixed-strings --file=stopwords.txt \
| sort \ if [[ "${url:-}" = "" ]]; then
| uniq --count \ grep --only-matching --extended-regexp '[a-zA-Z]{3,}' "$basedir/README.md" \
| sort -n | tr '[:upper:]' '[:lower:]' \
else | grep --invert-match --word-regexp --fixed-strings --file=stopwords.txt \
curl "$url" \ | sort \
| grep --only-matching --extended-regexp '[a-zA-Z]{3,}' \ | uniq --count \
| tr '[:upper:]' '[:lower:]' \ | sort -n
| grep --invert-match --word-regexp --fixed-strings --file=stopwords.txt \ else
| sort \ curl "$url" \
| uniq --count \ | grep --only-matching --extended-regexp '[a-zA-Z]{3,}' \
| sort -n | tr '[:upper:]' '[:lower:]' \
fi | grep --invert-match --word-regexp --fixed-strings --file=stopwords.txt \
| sort \
| uniq --count \
| sort -n
fi
}
fetch_top_words "$@"