diff --git a/.zshrc b/.zshrc index 496dc7b..5fc9ade 100644 --- a/.zshrc +++ b/.zshrc @@ -232,19 +232,58 @@ _alias(){ alias dl="docker compose log -f" alias dc="docker compose" alias appupdate="docker compose pull && docker compose up -d --force-recreate" - drweb() { - if [[ "$1" == "--help" || "$1" == "-h" ]]; then - echo "Usage: drweb [directory] [port]" - echo " directory: Directory to serve (default: current directory)" - echo " port: Port to use (default: 8080)" +drweb() { + drweb_help() { + echo "Usage: drweb [directory] [port]" + echo " server_type: Type of server to use (nginx or php)" + echo " directory: Directory to serve (default: current directory)" + echo " port: Port to use (default: 8080)" return - fi - - local dir="${1:-./}" - local port="${2:-8080}" - - docker run -p "$port:80" -v "$dir:/usr/share/nginx/html:ro" nginx:alpine } + + if [[ "$1" == "--help" || "$1" == "-h" ]]; then + drweb_help + return + fi + + local server_type="$1" + local dir="${2:-./}" + local port="${3:-8080}" + + if [[ ! -d "$dir" ]]; then + echo "Error: Directory $dir does not exist" + drweb_help + return 1 + fi + + case "$server_type" in + nginx) + if [[ -f "$dir/index.html" || -f "$dir/index.php" ]]; then + docker run -p "$port:80" -v "$dir:/usr/share/nginx/html:ro" nginx:alpine + echo "Nginx is serving $dir on port $port" + else + echo "Error: No index.html or index.php found in $dir" + drweb_help + return 1 + fi + ;; + php) + if [[ -f "$dir/index.php" || -f "$dir/index.html" ]]; then + docker run -p "$port:80" -v "$dir:/var/www/html" php:7.4-apache + echo "PHP Apache is serving $dir on port $port" + else + echo "Error: No index.php or index.html found in $dir" + drweb_help + return 1 + fi + ;; + *) + echo "Error: Unsupported server type '$server_type'" + drweb_help + return 1 + ;; + esac +} fi # ─< g stands for GIT >─────────────────────────────────────────────────────────────────────