-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrtignore.sh
More file actions
executable file
·64 lines (49 loc) · 1.24 KB
/
crtignore.sh
File metadata and controls
executable file
·64 lines (49 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
59
60
61
62
63
#!/bin/bash
# Function to display usage
usage() {
echo "Usage: $0 <directory>"
exit 1
}
# Check if exactly one argument is provided
if [ "$#" -ne 1 ]; then
usage
fi
# Directory where .gitignore will be created
TARGET_DIR="$1"
# Array of file types to ignore (hardcoded)
FILETYPES=()
# Check if the directory exists
if [ ! -d "$TARGET_DIR" ]; then
echo "Error: Directory '$TARGET_DIR' does not exist."
exit 1
fi
# Create or overwrite the .gitignore file in the specified directory
GITIGNORE_FILE="$TARGET_DIR/.gitignore"
# Start writing to the .gitignore file
echo "# Automatically generated .gitignore" > "$GITIGNORE_FILE"
# Add common entries to the .gitignore file
cat <<EOL >> "$GITIGNORE_FILE"
# Ignore Python bytecode files
__pycache__/
*.py[cod]
# Ignore virtual environment directories
.venv/
# Ignore MyPy cache directory
.mypy_cache/
# Ignore Rope project directory
.ropeproject/
# Ignore other potential temporary files
*.log
*.tmp
*.swp
EOL
# Add custom file types to the .gitignore file
for FILETYPE in "${FILETYPES[@]}"; do
echo "*.$FILETYPE" >> "$GITIGNORE_FILE"
done
# Display the content of the .gitignore file using bat
if command -v bat > /dev/null; then
bat "$GITIGNORE_FILE"
else
cat "$GITIGNORE_FILE"
fi