forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.sh
More file actions
70 lines (62 loc) · 1.96 KB
/
Copy pathformat.sh
File metadata and controls
70 lines (62 loc) · 1.96 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
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Auto-format hook for Cursor
# Formats code after file edits based on file type
set -e
# Get the file path from stdin (Cursor passes file path)
FILE_PATH="${1:-}"
if [ -z "$FILE_PATH" ]; then
echo "No file path provided"
exit 0
fi
# Skip if file doesn't exist
if [ ! -f "$FILE_PATH" ]; then
exit 0
fi
# Get file extension
EXT="${FILE_PATH##*.}"
BASENAME=$(basename "$FILE_PATH")
# Skip auto-generated files
if [[ "$BASENAME" == *.gen.dart ]] || [[ "$BASENAME" == *.g.dart ]]; then
exit 0
fi
# Format based on file type
case "$EXT" in
py)
# Python files in backend/
if [[ "$FILE_PATH" == backend/* ]]; then
if command -v black &> /dev/null; then
echo "Formatting Python: $FILE_PATH"
black --line-length 120 --skip-string-normalization "$FILE_PATH" 2>/dev/null || true
fi
fi
;;
dart)
# Dart files in app/
if [[ "$FILE_PATH" == app/* ]]; then
if command -v dart &> /dev/null; then
echo "Formatting Dart: $FILE_PATH"
dart format --line-length 120 "$FILE_PATH" 2>/dev/null || true
fi
fi
;;
c|cpp|cc|cxx|h|hpp)
# C/C++ files in firmware directories
if [[ "$FILE_PATH" == omi/* ]] || [[ "$FILE_PATH" == omiGlass/* ]]; then
if command -v clang-format &> /dev/null; then
echo "Formatting C/C++: $FILE_PATH"
clang-format -i "$FILE_PATH" 2>/dev/null || true
fi
fi
;;
ts|tsx|js|jsx)
# TypeScript/JavaScript files in web/
if [[ "$FILE_PATH" == web/* ]]; then
# Check for prettier in web directory
if [ -f "web/frontend/node_modules/.bin/prettier" ]; then
echo "Formatting TypeScript/JavaScript: $FILE_PATH"
cd web/frontend && npx prettier --write "../../$FILE_PATH" 2>/dev/null || true
fi
fi
;;
esac
exit 0