#!/bin/bash

function _exec {
    if [[ $IS_DOCKER == "true" ]]; then
        ${@:2}
    else
        docker-compose exec $@
    fi
}

case $1 in
    init)
        touch docker/.zsh_history
        touch docker/composer-auth.json
        touch docker/php-overrides.local.ini

        echo "Done!"

        echo "Add any custom php configurations to docker/php-overrides.local.ini."

        echo "Copy docker-compose.override.yml.dist to docker-compose.override.yml and remove any containers you do not want to run locally."
        ;;
    link-logfile)
        while true; do
            ln -sf /dev/stdout /site/storage/logs/laravel-$(date +'%F').log

            sleep 3600
        done
        ;;
    tmux-start)
        _exec tmux php artisan tmux-ui:start
        ;;
    tmux-restart)
        _exec tmux php artisan tmux-ui:restart
        ;;
    tmux-attach)
        _exec tmux tmux attach
        ;;
    tmux-stop)
        _exec tmux php artisan tmux-ui:stop --kill
        ;;
esac
