Skip to content

Instantly share code, notes, and snippets.

@mattdanielbrown
Forked from fweig/llmfeed.sh
Created March 24, 2025 17:17
Show Gist options
  • Select an option

  • Save mattdanielbrown/b93a13d0df70225d1c5f368ba65bc607 to your computer and use it in GitHub Desktop.

Select an option

Save mattdanielbrown/b93a13d0df70225d1c5f368ba65bc607 to your computer and use it in GitHub Desktop.
Copy repositories to make them easily digestable for LLMs.
#!/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