Repository navigation
Expand file tree
/
Copy pathyeetCode.sh
More file actions
247 lines (213 loc) · 7.06 KB
/
Copy pathyeetCode.sh
File metadata and controls
247 lines (213 loc) · 7.06 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
# Educate the normies
yeet_usage() {
echo "Usage: $0 <directory> [--hidden] [--ignore pattern1 pattern2 ...]"
echo " --hidden: See the forbidden files"
echo " --ignore: Skip files/folders matching these patterns"
exit 1
}
# Summon the appropriate comment runes
summon_comment_runes() {
local scroll="$1"
local ancient_text="${scroll##*.}"
case "${ancient_text,,}" in
js|jsx|ts|tsx|java|c|cpp|h|hpp)
echo "// NEW FILE: $2"
;;
py|rb|yml|yaml|sh)
echo "# NEW FILE: $2"
;;
html|htm|xml|md)
echo "<!-- NEW FILE: $2 -->"
;;
css|scss|less)
echo "/* NEW FILE: $2 */"
;;
*)
echo "### NEW FILE: $2 ###"
;;
esac
}
# Check if file is cursed (binary)
is_file_cursed() {
local scroll="$1"
# Ask the ancient 'file' command for wisdom
if file "$scroll" | grep -q "text"; then
return 1 # Blessed text file
else
return 0 # Cursed binary file
fi
}
# Read and parse the sacred .yeet file
read_yeet_file() {
local yeet_path="$1/.yeet"
local patterns=()
if [ -f "$yeet_path" ]; then
# Read the forbidden scroll (.yeet file)
while IFS= read -r line || [ -n "$line" ]; do
# Trim whitespace and skip empty lines/comments
line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -n "$line" ] && [[ ! "$line" =~ ^[[:space:]]*# ]]; then
# Convert Windows paths to Unix paths (just in case)
line=$(echo "$line" | sed 's/\\/\//g')
patterns+=("$line")
fi
done < "$yeet_path"
fi
# Return the patterns as a space-separated string
echo "${patterns[*]}"
}
# Check if path matches ignore patterns
should_ignore_path() {
local check_path="$1"
local pattern
# Remove leading slash if present
check_path="${check_path#/}"
for pattern in "${IGNORE_PATTERNS[@]}"; do
# Remove leading slash if present
pattern="${pattern#/}"
# Remove trailing slash if present
pattern="${pattern%/}"
# If pattern ends with *, modify it to include all files
if [[ $pattern == *'/*' ]]; then
# Remove the /* from the end
pattern="${pattern%/*}"
# Add regex to match anything in this directory
pattern="^${pattern}(/.*)?$"
else
# Convert glob pattern to regex
pattern="${pattern//\./\\.}" # Escape dots
pattern="${pattern//\*\*/.*}" # Handle ** (match any depth)
pattern="${pattern//\*/[^/]*}" # Handle * (match within directory)
pattern="${pattern//\?/.}" # Handle ? (match single character)
pattern="^${pattern}/?.*" # Match entire directory contents
fi
if [[ "$check_path" =~ $pattern ]]; then
return 0 # Should ignore
fi
done
return 1 # Should not ignore
}
# Initialize variables
FOLDER_OF_DESTINY=""
SNEAKY_MODE=0
DESTINY_MANIFEST="yeet_manifest.md" # The sacred destination has been renamed!
ABSOLUTE_WINS=()
EPIC_FAILS=()
IGNORE_PATTERNS=()
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--hidden)
SNEAKY_MODE=1
shift
;;
--ignore)
shift
while [[ $# -gt 0 && ! "$1" =~ ^-- ]]; do
IGNORE_PATTERNS+=("$1")
shift
done
;;
-*)
echo "Unknown option: $1"
yeet_usage
;;
*)
if [ -z "$FOLDER_OF_DESTINY" ]; then
FOLDER_OF_DESTINY="$1"
else
echo "Error: Multiple directories specified"
yeet_usage
fi
shift
;;
esac
done
# Check if we got a directory
if [ -z "$FOLDER_OF_DESTINY" ]; then
echo "Error: No directory specified"
yeet_usage
fi
# Make sure the chosen folder exists in this realm
if [ ! -d "$FOLDER_OF_DESTINY" ]; then
echo "Error: The folder '$FOLDER_OF_DESTINY' does not exist in this dimension"
exit 1
fi
# Read the .yeet file if it exists
if YEET_PATTERNS=$(read_yeet_file "$FOLDER_OF_DESTINY"); then
if [ -n "$YEET_PATTERNS" ]; then
echo "Found .yeet file! Adding its forbidden knowledge to the ignore list..."
# Add .yeet patterns to existing ignore patterns
for pattern in $YEET_PATTERNS; do
IGNORE_PATTERNS+=("$pattern")
done
fi
else
echo "Failed to read .yeet file (task failed successfully)"
exit 1
fi
# Create temporary scroll of power
TEMP_SCROLL=$(mktemp)
echo "Initiating folder yoinking ritual: $FOLDER_OF_DESTINY"
echo "Sneaky mode activated: $([[ $SNEAKY_MODE -eq 1 ]] && echo "yes" || echo "no")"
if [ ${#IGNORE_PATTERNS[@]} -gt 0 ]; then
echo "Ignoring patterns: ${IGNORE_PATTERNS[*]}"
fi
# The grand file yeeting ceremony
yeet_files() {
local current_realm="$1"
local base_realm="$2"
while IFS= read -r -d '' scroll; do
local scroll_path="${scroll#$base_realm/}"
# Auto-ignore our sacred scrolls
if [ "$(basename "$scroll")" = ".yeet" ]; then
EPIC_FAILS+=("$scroll_path (sacred scroll (.yeet file))")
continue
fi
# No yeet-ception allowed!
if [ "$(basename "$scroll")" = "yeet_manifest.md" ]; then
EPIC_FAILS+=("$scroll_path (previous yeet manifest (no yeet-ception allowed))")
continue
fi
# Check ignore patterns first - this takes precedence over everything
if should_ignore_path "$scroll_path"; then
EPIC_FAILS+=("$scroll_path (explicitly ignored)")
continue
fi
# Dodge the sneaky files
if [[ $SNEAKY_MODE -eq 0 && $(basename "$scroll") == .* ]]; then
EPIC_FAILS+=("$scroll_path (too sneaky)")
continue
fi
# Check for cursed files
if is_file_cursed "$scroll"; then
EPIC_FAILS+=("$scroll_path (cursed binary)")
continue
fi
# Check scroll permissions
if [ ! -r "$scroll" ]; then
EPIC_FAILS+=("$scroll_path (no read privileges, sadge)")
continue
fi
# Summon comment runes and yeet into destiny
local runes=$(summon_comment_runes "$scroll" "$scroll_path")
echo -e "\n$runes\n" >> "$TEMP_SCROLL"
cat "$scroll" >> "$TEMP_SCROLL"
ABSOLUTE_WINS+=("$scroll_path")
done < <(find "$current_realm" -type f -print0)
}
# Commence the ritual
yeet_files "$FOLDER_OF_DESTINY" "$FOLDER_OF_DESTINY"
# The prophecy must be fulfilled
mv "$TEMP_SCROLL" "$DESTINY_MANIFEST"
# Victory royale stats
echo -e "\nFiles that got rekt:"
for scroll in "${EPIC_FAILS[@]}"; do
echo "💀 $scroll"
done
echo -e "\nFiles that made it (POG):"
for scroll in "${ABSOLUTE_WINS[@]}"; do
echo "✨ $scroll"
done
echo -e "\nGG EZ: Output yeeted to $DESTINY_MANIFEST"