-
Notifications
You must be signed in to change notification settings - Fork 1
/
updatecorrections.sh
executable file
·51 lines (36 loc) · 1.33 KB
/
updatecorrections.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
#!/bin/bash
set -e
scriptdir=$(dirname "$0")
printf "%s\n" "$scriptdir"
cd "$scriptdir"
git pull || (echo "Not clean merge"; exit 1)
if [[ "$#" -eq 1 ]]; then
autocorrectfile="$1"
else
autocorrectfile=~/.autocorrect
fi
printf "attemping to upload the autocorrect file: %s\n" "$autocorrectfile"
if [[ ! -f "$autocorrectfile" ]]; then
echo "$autocorrectfile does not exist."
exit 2
fi
prevNumCorrections="$(wc -l < corrections.vim)"
# The final sort uses bytewise sorting (LC_ALL=C), but [f]olds the case,
# and uses [d]ictionary order, meaning only blanks and alphanumeric characters
# are considered. This should make the sorting consistent across all my
# computers.
cat "$autocorrectfile" "corrections.vim" | \
sed 's/\r$//' |
sed 's/^iabbrev/ia/' | \
sort -u | \
LC_ALL=C sort -f -d -k 3,3 > tmp && mv tmp corrections.vim
num_new_iabbrevs="$(($(wc -l < corrections.vim) - prevNumCorrections))"
echo "Added $num_new_iabbrevs new iabbrevs into the correction list. $(wc -l < corrections.vim) total."
autocorrectdir=$(dirname "$autocorrectfile")
git commit -am "Add $num_new_iabbrevs iabbrevs"
git push
cp "$autocorrectfile" "$autocorrectdir"/.autocorrect-backup
echo "Created backup at $autocorrectdir/.autocorrect-backup"
# Clear the autocorrect file.
true > "$autocorrectfile"
echo "Cleared $autocorrectfile"