Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Output file
- output_file="project_context.md"
- # Remove the output file if it already exists
- rm -f "$output_file"
- # Function to process each file
- process_file() {
- local file="$1"
- echo "Path: $file" >> "$output_file"
- echo "" >> "$output_file"
- # Determine the file extension
- extension="${file##*.}"
- # Set the appropriate language for the code block
- case "$extension" in
- toml) language="toml" ;;
- rs) language="rust" ;;
- qml) language="qml" ;;
- cpp|h) language="cpp" ;;
- md) language="" ;;
- *) language="plaintext" ;;
- esac
- echo "\`\`\`$language" >> "$output_file"
- cat "$file" >> "$output_file"
- echo "\`\`\`" >> "$output_file"
- echo "" >> "$output_file"
- echo "-----------" >> "$output_file"
- echo "" >> "$output_file"
- }
- # Check if fd is installed
- if ! command -v fd &> /dev/null; then
- echo "Error: fd is not installed. Please install fd and try again."
- exit 1
- fi
- # Find files using fd, sort them by depth, then process each file
- fd -t f -e toml -e rs -e qml -e cpp -e h -e md |
- sort -n -t'/' -k'1' |
- while read -r file; do
- process_file "$file"
- done
- echo "Files have been combined into $output_file"
Advertisement
Add Comment
Please, Sign In to add comment