From d19e726f235d501f769199968e2b573e4d82a7c5 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Wed, 8 Apr 2020 13:45:17 +0300 Subject: [PATCH] - fixed SSH_CLIENT detection - minor fixes per shellcheck --- phpdebug.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/phpdebug.sh b/phpdebug.sh index 7b9d67f..da3fcc4 100644 --- a/phpdebug.sh +++ b/phpdebug.sh @@ -30,11 +30,14 @@ export IDE_ZEND_PORT=10137 export IDE_XDEBUG_PORT=9000 export IDE_KEY="PHPSTORM" -export IDE_SERVERNAME="$(hostname)" +export IDE_SERVERNAME="" + +# @see https://github.com/koalaman/shellcheck/wiki/SC2155 +IDE_SERVERNAME=$(hostname) function _check_xdebug_installed() { - if ! php -i | egrep -q "(xdebug|zend_debugger)"; then + if ! php -i | grep -E -q "(xdebug|zend_debugger)"; then echo "Warning! XDebug or Zend Debugger extension not found" fi } @@ -60,11 +63,11 @@ function _phpdebug() local php_ide_config="serverName=${IDE_SERVERNAME}" # try to autodetect IP if global variable IDE_IP not set - if [ -z ${IDE_IP+x} ]; then + if [ -z "$IDE_IP" ]; then if [ -z "$SSH_CLIENT" ]; then IDE_IP="127.0.0.1"; else - IDE_IP=$( echo $SSH_CLIENT | sed s/\ .*$// ); + IDE_IP=$( echo "$SSH_CLIENT" | cut -d' ' -f1 ); fi fi @@ -79,7 +82,7 @@ function _phpdebug() export XDEBUG_CONFIG="$xdebug_config" export PHP_IDE_CONFIG="$php_ide_config" else - PHP_IDE_CONFIG="$php_ide_config" XDEBUG_CONFIG="$xdebug_config" QUERY_STRING="$zend_debugger_config" php $* + PHP_IDE_CONFIG="$php_ide_config" XDEBUG_CONFIG="$xdebug_config" QUERY_STRING="$zend_debugger_config" php "$@" fi } alias phpdebug="_phpdebug"