Skip to content

Instantly share code, notes, and snippets.

@mattstauffer
Created July 6, 2020 15:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattstauffer/984414323ecfbf851b2e003f5a7e67a8 to your computer and use it in GitHub Desktop.
Save mattstauffer/984414323ecfbf851b2e003f5a7e67a8 to your computer and use it in GitHub Desktop.
Simple BASH Xdebug toggler

Written by Matt Stauffer

Note: This expects that you've enabled Xdebug in a specific file: /usr/local/php/X.x/conf.d/ext-xdebug.ini.

Installation

Add this function to your .zshrc or similar file.

Usage

On the command line, type xdebug and hit enter. This will toggle whether or not Xdebug is running.

Inspiration

https://github.com/ihorvorotnov/xdebug.sh

function xdebug {
PHP_VERSION="$(php -r "\$v=explode('.', PHP_VERSION ); echo implode('.', array_splice(\$v, 0, -1));")"
CONFIG_PATH="$(brew --prefix)/etc/php/${PHP_VERSION}/conf.d"
CONFIG_FILE="${CONFIG_PATH}/ext-xdebug.ini"
CONFIG_FILE_DISABLED="${CONFIG_PATH}/ext-xdebug.ini.disabled"
if test -f "$CONFIG_FILE"; then
mv "${CONFIG_FILE}" "${CONFIG_FILE_DISABLED}"
echo -e "\nXdebug disabled.\n"
elif test -f "$CONFIG_FILE_DISABLED"; then
mv "${CONFIG_FILE_DISABLED}" "${CONFIG_FILE}"
echo -e "\nXdebug enabled.\n"
else
echo -e "\nError: Can't find any Xdebug config file at ${CONFIG_FILE}."
exit
fi
valet restart php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment