-
-
Save mattdanielbrown/b93a13d0df70225d1c5f368ba65bc607 to your computer and use it in GitHub Desktop.
Copy repositories to make them easily digestable for LLMs.
This file contains hidden or 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 | |
| # llmfeed.sh - Copy repository contents to make them easily digestable for LLMs | |
| # | |
| # Author: Felix Weiglhofer | |
| # License: MIT | |
| # | |
| # Description: | |
| # Flattens the (text) content of a repository into a single string that can be | |
| # easily read by LLMs. Inspired by uithub.com. | |
| # | |
| # Usage: | |
| # - Copy to clipboard (Wayland): | |
| # ./llmfeed.sh <targetDir> | wl-copy | |
| # | |
| # - Copy to clipboard (X11): | |
| # ./llmfeed.sh <targetDir> | xclip | |
| # | |
| targetDir=$1 | |
| if [[ - z $targetDir ]]; then | |
| echo "Error: Target directory missing." | |
| echo "" | |
| echo "Usage: $0 <targetDir>" | |
| exit 1 | |
| fi | |
| findFlags=( | |
| # Exclude directories | |
| -path '*/.git' -prune -o | |
| -path '*/build' -prune -o | |
| -type f -print0 | |
| ) | |
| is_binary() { | |
| if [[ -z $(file -b --mime-type "$1" | grep -v "^text/") ]]; then | |
| return 1 | |
| else | |
| return 0 | |
| fi | |
| } | |
| mapfile -d '' -t listOfFile < <(find $targetDir ${findFlags[@]}) | |
| content="" | |
| for file in "${listOfFile[@]}" | |
| do | |
| if is_binary $file; then | |
| continue | |
| fi | |
| content+=">>> $file" | |
| content+=$'\n' | |
| content+=$(cat $file) | |
| content+=$'\n' | |
| done | |
| echo "$content" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment