function generate_env() { DB_NAME=${1} ENV_PATH=${2-$HOME/.sql.env} cp $ENV_PATH ./.env echo "DB_NAME='$DB_NAME'" >> ./.env } function install_nodemon() { FILE=${1-package.json} if grep -q nodemon "$FILE"; then echo 'nodemon exists;' else bun i -D nodemon sed -i '/\"scripts\":\ {/a\ \ \ \ \"watch\":\"nodemon server.js\",' $FILE fi } function swap_localhost_home() { grep -r --exclude-dir=node_modules -l "localhost". | xargs awk -i inplace '{gsub("localhost", "127.0.0.1")} 1' } function setup() { ENV_PATH=${1-$HOME/.sql.env} SCHEMA_PATH=${2-db/schema.sql} DB_NAME=$(grep -oP '(?<=CREATE DATABASE )(.*)(?=;)' $SCHEMA_PATH) generate_env $DB_NAME bun install install_nodemon PGPASSWORD=$(grep -oP '(?<=DB_PASSWORD=)(.*)' $ENV_PATH) psql -U postgres -a -f $SCHEMA_PATH if [[ "$OSTYPE" == "darwin"* ]]; then swap_localhost_home elif [[ "$OSTYPE" == "linux-gnu"* ]]; then swap_localhost_home elif [[ "$OSTYPE" == "freebsd"* ]]; then swap_localhost_home else echo "no need to localhost, not unix" fi if [ -f "seeds/index.js" ]; then node seeds/index.js elif [ -f "seeds/seed.js" ]; then node seeds/seed.js else echo "no seed file" fi } alias gfc="~/git-file-cleanup.sh" alias dircp="cp -r" alias clean_node_modules="find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +" alias md2org="find . -name \\*.md -type f -exec pandoc -f markdown -t org -o {}.org {} \\;" alias icat="kitten icat"