Skip to content

Instantly share code, notes, and snippets.

@ejfox
Created April 17, 2024 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejfox/e97f19d4232ef839dddc93bc3ae87fe8 to your computer and use it in GitHub Desktop.
Save ejfox/e97f19d4232ef839dddc93bc3ae87fe8 to your computer and use it in GitHub Desktop.
Usage: `./files-to-md.sh *`
#!/bin/bash
for file in "$@"; do
# Extract filename with extension
filename=$(basename "$file")
# Print Markdown header with filename (including extension)
echo "## $filename"
echo '```'
cat "$file"
echo '```'
echo ""
done
@ejfox
Copy link
Author

ejfox commented Apr 17, 2024

#!/bin/bash

for file in "$@"; do
  # Ignore package-lock.json
  if [ "$file" == "package-lock.json" ]; then
    continue
  fi
  # Ignore anything in .gitignore
  if grep -q "$file" .gitignore; then
    continue
  fi
  # Ignore any files in node_modules
  if [[ "$file" == *"node_modules"* ]]; then
    continue
  fi
  # Extract filename with full path
  filename=$(realpath "$file") 
  # Print Markdown header with full path
  echo "## $filename"
  echo '```'
  cat "$file"
  echo '```'
  echo ""
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment