Created
September 22, 2024 18:49
-
-
Save sullyo/c750a71eef30a71bd0580e2fd23f4e62 to your computer and use it in GitHub Desktop.
Clones a github repo and puts all the code into a single text file perfect for LLMs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if a GitHub URL is provided as an argument | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <github_url>" | |
exit 1 | |
fi | |
# Store the GitHub URL | |
GIT_URL="$1" | |
# Extract the repository name from the URL | |
REPO_NAME=$(basename -s .git "$GIT_URL") | |
# Clone the GitHub repository | |
git clone "$GIT_URL" | |
# Change directory to the cloned repository | |
cd "$REPO_NAME" || exit 1 | |
# Create or clear the 'code' file | |
> code | |
# Define an array of popular code file extensions | |
EXTENSIONS=("py" "js" "ts" "jsx" "tsx" "rs" "ex" "exs" "go" "java" "c" "cpp" "h" "hpp" \ | |
"cs" "rb" "php" "html" "css" "kt" "swift" "scala" "sh" "pl" "r" "lua" "m" "erl" "hs") | |
# Build the find command arguments to search for files with the specified extensions | |
FIND_ARGS=() | |
for EXT in "${EXTENSIONS[@]}"; do | |
FIND_ARGS+=( -iname "*.$EXT" -o ) | |
done | |
# Remove the last '-o' (logical OR) operator | |
unset 'FIND_ARGS[${#FIND_ARGS[@]}-1]' | |
# Find all files matching the extensions and process them | |
find . -type f \( "${FIND_ARGS[@]}" \) | while read -r FILE; do | |
# Append the filename to the 'code' file | |
echo "$FILE" >> code | |
# Append the file content to the 'code' file | |
cat "$FILE" >> code | |
done |
Awesome
Since the script write its output into a file ("code") inside the repository, the author the repo you clone has full control of what file this might be. It could for example be a symlink to a file you don't want to be written to.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Thank you.