-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-spelling.sh
More file actions
58 lines (47 loc) · 1.24 KB
/
Copy pathcheck-spelling.sh
File metadata and controls
58 lines (47 loc) · 1.24 KB
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
#!/bin/bash
set -e
# Check if a folder argument is passed
if [ -z "$1" ]; then
echo "Usage: $0 <folder>"
exit 1
fi
TARGET_FOLDER="$1"
# Check folder exists
if [ ! -d "$TARGET_FOLDER" ]; then
echo "Error: Folder '$TARGET_FOLDER' not found."
exit 1
fi
# Path to VS Code user settings
VSCODE_SETTINGS="$HOME/Library/Application Support/Code/User/settings.json"
if [ ! -f "$VSCODE_SETTINGS" ]; then
echo "VS Code settings.json not found at $VSCODE_SETTINGS"
exit 1
fi
# Extract cSpell.userWords using jq
USER_WORDS=$(grep -vE '^\s*//' "$VSCODE_SETTINGS" | jq '.["cSpell.userWords"] // []')
if [ "$USER_WORDS" == "null" ]; then
USER_WORDS="[]"
fi
# Create temporary cspell config
TEMP_CONFIG="$(mktemp).json"
cat > "$TEMP_CONFIG" <<EOF
{
"version": "0.2",
"language": "en",
"words": $USER_WORDS
}
EOF
# echo "Created temporary cspell config at $TEMP_CONFIG"
# Run cspell on the target folder
npx --yes cspell --quiet --config "$TEMP_CONFIG" "$TARGET_FOLDER/**/*"
SPELL_STATUS=$?
# Clean up
rm "$TEMP_CONFIG"
# echo "Temporary config deleted."
# Report and exit with the spell check status
if [ $SPELL_STATUS -ne 0 ]; then
echo "❌ Spelling check failed."
else
echo "✅ No spelling issues found in '$TARGET_FOLDER'."
fi
exit $SPELL_STATUS