-
-
Save rafamoreira/ad924de6b91ee5aa1fe6e187f45418bc to your computer and use it in GitHub Desktop.
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 | |
# | |
# This script will create a 'backend.md' and 'frontend.md' containing | |
# all the source code in the current directory. You can then upload these | |
# files to a custom GPT. It's setup for my golang project but you can easily | |
# modify it to suit your needs. | |
# | |
# This script requires 'fd' to be installed. | |
set -e | |
function file_to_markdown() { | |
path=$1 | |
ext="${path##*.}" | |
declare -A ext_map | |
ext_map=( | |
["js"]="javascript" | |
["go"]="go" | |
["html"]="html" | |
["css"]="css" | |
["rb"]="ruby" | |
["rs"]="rust" | |
["ts"]="typescript" | |
["py"]="python" | |
["java"]="java" | |
["c"]="c" | |
["cpp"]="cpp" | |
["lua"]="lua" | |
# add more languages here | |
) | |
# Get filetype from the extension | |
filetype="${ext_map[$ext]}" | |
echo -e "## File: $path \n\`\`\`$filetype" | |
cat $path | |
echo -e "\`\`\`\n" | |
echo -e "---\n\n" | |
} | |
if [ ! -x "$(command -v fd)" ]; then | |
echo "fd is not installed" | |
exit 1 | |
fi | |
# cleanup | |
rm -f frontend.md backend.md | |
# create frontend.md | |
for f in $(fd -e js -e html -e css); do | |
file_to_markdown "$f" >> frontend.md | |
done | |
# create backend.md | |
for f in $(fd -e go); do | |
file_to_markdown "$f" >> backend.md | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment