-
Notifications
You must be signed in to change notification settings - Fork 1
/
tl-spelling.sh
executable file
·106 lines (88 loc) · 2.05 KB
/
tl-spelling.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
# name: tl-spelling.sh
# description: Script to test speeling.
# author: while-true-do.io
# license: BSD-3-Clause
# shellcheck disable=SC1091,SC2034
# Variables
SCRIPT_NAME=$(basename "$0")
SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
WORK_PATH=$(pwd)
# shellcheck source=_lib.sh
source "$SCRIPT_PATH/_lib.sh"
# Complex
function installAspell() {
sudo dnf -y install aspell-en ||\
sudo yum -y install aspell-en ||\
sudo apt-get update ||\
sudo apt-get -y install aspell-en ||\
sudo zypper -n install aspell-en
RETURN=$?
return $RETURN
}
function testAspellTxt() {
files=$(find "$WORK_PATH" \( -iname "*.txt" ! -iname "kudos.txt" \) )
echo "$SCRIPT_PATH/.tl-aspell"
for file in $files
do
BADWORDS=""
BADWORDS=$(aspell --personal="$WORK_PATH"/.aspell.en.pws --lang=en --encoding=utf-8 list < "$file" | sort -u)
if [[ -n $BADWORDS ]]
then
printf "file: %s\n" "$file"
printf "%s\n" "$BADWORDS"
RETURN="1"
fi
done
return $RETURN
}
function testAspellMd() {
files=$(find "$WORK_PATH" -iname "*.md")
for file in $files
do
BADWORDS=""
BADWORDS=$(aspell --personal="$WORK_PATH"/.aspell.en.pws --lang=en --encoding=utf-8 list < "$file" | sort -u)
if [[ -n $BADWORDS ]]
then
printf "file: %s\n" "$file"
printf "%s\n" "$BADWORDS"
RETURN="1"
fi
done
return $RETURN
}
function help() {
# help: action to show help
printf "\n"
printf "Usage: %s ACTION\n" "$SCRIPT_NAME"
printf "\n"
printf "Script to test speeling.\n"
printf "\n"
printf "Actions:\n"
printf "\t help) Show the help\n"
printf "\t prep) Run all preparations\n"
printf "\t test) Run all tests\n"
printf "\n"
}
function prep() {
# test: action to do preparations
printf "[%s|%s]\n" "$SCRIPT_NAME" "${FUNCNAME[0]}"
try "installAspell"
sum
}
function test() {
# test: action to run tests
printf "[%s|%s]\n" "$SCRIPT_NAME" "${FUNCNAME[0]}"
run "testAspellTxt"
run "testAspellMd"
sum
}
# Main
if [[ -n "$*" ]]
then
ACTION="$1"
shift
$ACTION "$@"
else
help
fi