Idea from https://aubreypwd.dev/wp-cli-localwp-without-open-site-shell-redux
To test, run the testing command in sed-replacement.sh
To do the actual replacement, run the actual replacement command.
Idea from https://aubreypwd.dev/wp-cli-localwp-without-open-site-shell-redux
To test, run the testing command in sed-replacement.sh
To do the actual replacement, run the actual replacement command.
| # Testing | |
| DB_HOST=$(sh -c "$(curl -fsSL https://gist.githubusercontent.com/afragen/4581d6c0f5fea2cd72c5d6f07db0be23/raw/socket-db-host.sh)");sed "s|define( 'DB_HOST', 'localhost' );|${DB_HOST}|" wp-config.php | |
| # Actual replacement | |
| DB_HOST=$(sh -c "$(curl -fsSL https://gist.githubusercontent.com/afragen/4581d6c0f5fea2cd72c5d6f07db0be23/raw/socket-db-host.sh)");sed -i '' "s|define( 'DB_HOST', 'localhost' );|${DB_HOST}|" wp-config.php |
| SOCKET=$(mysqld --verbose --help | grep ^socket | awk '{print $2, $3}') | |
| echo "defined( 'WP_CLI' ) \\&\\& WP_CLI ? define( 'DB_HOST', 'localhost:${SOCKET}' ) : define( 'DB_HOST', 'localhost' );" |
I keep trying to add the newline/tab but I don't think it's worth the effort.