Skip to content

Instantly share code, notes, and snippets.

@svandragt
Created November 18, 2025 12:03
Show Gist options
  • Select an option

  • Save svandragt/60ea32501be8471d56e8a7f9dd4f8844 to your computer and use it in GitHub Desktop.

Select an option

Save svandragt/60ea32501be8471d56e8a7f9dd4f8844 to your computer and use it in GitHub Desktop.
Generate a JetBrains .idea/dataSources.xml file from the output of Altis local server
#!/bin/bash
# Capture the output of the command
OUTPUT=$(composer server db info)
# Extracting the necessary values using grep and awk
DB_NAME=$(echo "$OUTPUT" | grep "Database:" | awk '{print $2}')
DB_USER=$(echo "$OUTPUT" | grep "User:" | awk '{print $2}')
DB_PASSWORD=$(echo "$OUTPUT" | grep "Password:" | awk '{print $2}')
DB_HOST=$(echo "$OUTPUT" | grep "Host:" | awk '{print $2}')
DB_PORT=$(echo "$OUTPUT" | grep "Port:" | awk '{print $2}')
# Generate the .idea/dataSources.xml file
cat <<EOL > .idea/datasources.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="$DB_NAME" uuid="$(uuidgen)">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME</jdbc-url>
<working-dir>\$ProjectFileDir\$</working-dir>
</data-source>
</component>
</project>
EOL
# Notify the user
echo "dataSources.xml generated successfully."
@svandragt
Copy link
Copy Markdown
Author

just run the script from the project root.

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