Last active
March 25, 2025 08:58
-
-
Save fweig/badbbe2d3744da285bd0c404e1bdb8b3 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 -selection clipboard | |
# | |
# TODO: | |
# - Add flag to estimate token count | |
# - Add flag to prune first N lines from file (remove license header to save tokens) | |
# | |
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