Guest User

Untitled

a guest
Jun 25th, 2024
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Output file
  4. output_file="project_context.md"
  5.  
  6. # Remove the output file if it already exists
  7. rm -f "$output_file"
  8.  
  9. # Function to process each file
  10. process_file() {
  11. local file="$1"
  12. echo "Path: $file" >> "$output_file"
  13. echo "" >> "$output_file"
  14.  
  15. # Determine the file extension
  16. extension="${file##*.}"
  17.  
  18. # Set the appropriate language for the code block
  19. case "$extension" in
  20. toml) language="toml" ;;
  21. rs) language="rust" ;;
  22. qml) language="qml" ;;
  23. cpp|h) language="cpp" ;;
  24. md) language="" ;;
  25. *) language="plaintext" ;;
  26. esac
  27.  
  28. echo "\`\`\`$language" >> "$output_file"
  29. cat "$file" >> "$output_file"
  30. echo "\`\`\`" >> "$output_file"
  31. echo "" >> "$output_file"
  32. echo "-----------" >> "$output_file"
  33. echo "" >> "$output_file"
  34. }
  35.  
  36. # Check if fd is installed
  37. if ! command -v fd &> /dev/null; then
  38. echo "Error: fd is not installed. Please install fd and try again."
  39. exit 1
  40. fi
  41.  
  42. # Find files using fd, sort them by depth, then process each file
  43. fd -t f -e toml -e rs -e qml -e cpp -e h -e md |
  44. sort -n -t'/' -k'1' |
  45. while read -r file; do
  46. process_file "$file"
  47. done
  48.  
  49. echo "Files have been combined into $output_file"
Advertisement
Add Comment
Please, Sign In to add comment