Created
November 18, 2025 12:03
-
-
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
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 | |
| # 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." |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just run the script from the project root.