copyEnv() {
	cat .env | grep "$1=\"" | sed "s/.*$1=\"\([^\"]*\)\".*/\1/" | pbcopy && sleep 1
	echo "Copied $1"
}

# Check for --db flag
if [ "$1" = "--db" ]; then
	copyEnv DB_DATABASE
	copyEnv DB_PASSWORD
	copyEnv DB_USERNAME

    echo "Local port 3306 -> Remote MySQL port 3306"
    sshpass -p "$SERVER_PASSWORD" \
        ssh -L 3306:localhost:3306 $SERVER_USER@$SERVER_HOST

else
    sshpass -p "$SERVER_PASSWORD" \
        ssh -t $SERVER_USER@$SERVER_HOST \
        "cd $SERVER_PATH && exec \$SHELL"
fi
