diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 23b9ce4a..334502ca 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -41,7 +41,7 @@ COPY --chown=gitpod:gitpod .gp/bash/scaffold-project.sh /tmp RUN sudo bash -c ". /tmp/scaffold-project.sh" && rm /tmp/scaffold-project.sh # Aliases -COPY --chown=gitpod:gitpod .gp/bash/snippets/server-functions /tmp -COPY --chown=gitpod:gitpod .gp/bash/snippets/browser-functions /tmp -RUN cp /tmp/server-functions ~/.bashrc.d/server-functions \ - && cp /tmp/browser-functions ~/.bashrc.d/browser-functions \ No newline at end of file +COPY --chown=gitpod:gitpod .gp/bash/snippets/server-functions.sh /tmp +COPY --chown=gitpod:gitpod .gp/bash/snippets/browser-functions.sh /tmp +RUN cp /tmp/server-functions.sh ~/.bashrc.d/server-functions \ + && cp /tmp/browser-functions.sh ~/.bashrc.d/browser-functions \ No newline at end of file diff --git a/.gp/bash/snippets/browser-functions b/.gp/bash/snippets/browser-functions deleted file mode 100644 index b529be42..00000000 --- a/.gp/bash/snippets/browser-functions +++ /dev/null @@ -1,52 +0,0 @@ -__php_port="8000" -__apache_port="8001" -debug_on() { - local usage='Usage: debug_on server-type [no-refresh]' - local err='Error: debug_on():' - local php_port="8000" - local apache_port="8001" - local refresh - refresh=$(echo "$2" | tr '[:upper:]' '[:lower:]') - local stype - stype=$(echo "$1" | tr '[:upper:]' '[:lower:]') - [ -z $stype ] && echo "$err must have at least one argument" && echo $usage && return - [ "$refresh" != '' ] && [ "$refresh" != 'no-refresh' ] && echo "$err invalid refresh argument: $refresh" && return - case $stype in - "php") - [ "$refresh" == 'no-refresh' ] && gp preview "$(gp url $__php_port)?XDEBUG_SESSION_START=$stype" && return - gp preview "$(gp url $__php_port)?XDEBUG_SESSION_START=$stype" && sleep 1 && gp preview $(gp url $__php_port) - ;; - "apache") - [ "$refresh" == 'no-refresh' ] && gp preview "$(gp url $__apache_port)?XDEBUG_SESSION_START=$stype" && return - gp preview "$(gp url $__apache_port)?XDEBUG_SESSION_START=$stype" && sleep 1 && gp preview $(gp url $__apache_port) - ;; - *) - echo "$err invalid server type: $1" - esac -} - -debug_off() { - local usage='Usage: debug_off server-type [no-refresh]' - local err='Error: debug_off():' - local php_port=8000 - local apache_port=8001 - local refresh - refresh=$(echo "$2" | tr '[:upper:]' '[:lower:]') - local stype - stype=$(echo "$1" | tr '[:upper:]' '[:lower:]') - [ -z "$stype" ] && echo "$err must have at least one argument" && echo $usage && return - [ "$refresh" != '' ] && [ "$refresh" != 'no-refresh' ] && echo "$err invalid refresh argument: $refresh" && return - case $stype in - "php") - [ "$refresh" == 'no-refresh' ] && gp preview "$(gp url $__php_port)?XDEBUG_SESSION_STOP=$stype" && return - gp preview "$(gp url $__php_port)?XDEBUG_SESSION_STOP=$stype" && sleep 1 && gp preview $(gp url $__php_port) - ;; - "apache") - [ "$refresh" == 'no-refresh' ] && gp preview "$(gp url $__apache_port)?XDEBUG_SESSION_STOP=$stype" && return - gp preview "$(gp url $__apache_port)?XDEBUG_SESSION_STOP=$stype" && sleep 1 && gp preview $(gp url $__apache_port) - ;; - *) - echo "$err invalid server type: $1" - ;; - esac -} diff --git a/.gp/bash/snippets/browser-functions.sh b/.gp/bash/snippets/browser-functions.sh new file mode 100644 index 00000000..7af263cf --- /dev/null +++ b/.gp/bash/snippets/browser-functions.sh @@ -0,0 +1,54 @@ +# shellcheck shell=bash +server_port() { + local err='Error: get_server_port():' + case $(echo "$1" | tr '[:upper:]' '[:lower:]') in + 'php') + echo 8000 + ;; + 'apache') + echo 8001 + ;; + 'nginx') + echo 8002 + ;; + *) + echo 8001 ; exit 1 + ;; + esac +} + +debug_on() { + local refresh stype port + local usage='Usage: debug_on server-type [no-refresh]' + local err='Error: debug_on():' + refresh=$(echo "$2" | tr '[:upper:]' '[:lower:]') + stype=$(echo "$1" | tr '[:upper:]' '[:lower:]') + # Error handling + [ -z "$stype" ] && echo "$err must have at least one argument" && echo "$usage" && return + [[ $stype != 'php' && $stype != 'apache' && $stype != 'nginx' ]] \ + && echo -e "$err Invalid default server type $stype.\nCheck starter.ini for supported values" && return + [ "$refresh" != '' ] && [ "$refresh" != 'no-refresh' ] && echo "$err invalid refresh argument: $refresh" && return + # Set port + if ! port=$(server_port stype); then echo "Internal $err server_port() defaulted to $port"; fi + # Start debug session + [ "$refresh" == 'no-refresh' ] && gp preview "$(gp url "$port")?XDEBUG_SESSION_START=$stype" && return + gp preview "$(gp url "$port")?XDEBUG_SESSION_START=$stype" && sleep 1 && gp preview "$(gp url "$port")" +} + +debug_off() { + local refresh stype port + local usage='Usage: debug_off server-type [no-refresh]' + local err='Error: debug_off():' + refresh=$(echo "$2" | tr '[:upper:]' '[:lower:]') + stype=$(echo "$1" | tr '[:upper:]' '[:lower:]') + # Error handling + [ -z "$stype" ] && echo "$err must have at least one argument" && echo "$usage" && return + [[ $stype != 'php' && $stype != 'apache' && $stype != 'nginx' ]] \ + && echo -e "$err Invalid default server type $stype.\nCheck starter.ini for supported values" && return + [ "$refresh" != '' ] && [ "$refresh" != 'no-refresh' ] && echo "$err invalid refresh argument: $refresh" && return + # Set port + if ! port=$(server_port stype); then echo "Internal $err server_port() defaulted to $port"; fi + # Stop debug session + [ "$refresh" == 'no-refresh' ] && gp preview "$(gp url "$port")?XDEBUG_SESSION_STOP=$stype" && return + gp preview "$(gp url "$port")?XDEBUG_SESSION_STOP=$stype" && sleep 1 && gp preview "$(gp url "$port")" +} diff --git a/.gp/bash/snippets/server-functions b/.gp/bash/snippets/server-functions.sh similarity index 100% rename from .gp/bash/snippets/server-functions rename to .gp/bash/snippets/server-functions.sh