script: function style
This commit is contained in:
parent
435ea0ce45
commit
43d38fac70
17
top_words.sh
17
top_words.sh
@ -3,17 +3,22 @@ set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
url="${1:-}"
|
||||
basedir=$(dirname "$0")
|
||||
fetch_top_words() {
|
||||
local url
|
||||
local basedir
|
||||
|
||||
if [[ "${url:-}" = "" ]]; then
|
||||
url="${1:-}"
|
||||
basedir=$(dirname "$0")
|
||||
|
||||
|
||||
if [[ "${url:-}" = "" ]]; then
|
||||
grep --only-matching --extended-regexp '[a-zA-Z]{3,}' "$basedir/README.md" \
|
||||
| tr '[:upper:]' '[:lower:]' \
|
||||
| grep --invert-match --word-regexp --fixed-strings --file=stopwords.txt \
|
||||
| sort \
|
||||
| uniq --count \
|
||||
| sort -n
|
||||
else
|
||||
else
|
||||
curl "$url" \
|
||||
| grep --only-matching --extended-regexp '[a-zA-Z]{3,}' \
|
||||
| tr '[:upper:]' '[:lower:]' \
|
||||
@ -21,4 +26,6 @@ else
|
||||
| sort \
|
||||
| uniq --count \
|
||||
| sort -n
|
||||
fi
|
||||
fi
|
||||
}
|
||||
fetch_top_words "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user