#!/usr/bin/env bash list-dotenv() { TASK_DOTENV_DIR=${TASK_DOTENV_DIR:="$HOME/.config/taskfile.build"} # Define column widths local name_width=30 local type_width=10 local path_width=40 # Adjust as needed # Print table header printf "| %-${name_width}s | %-${type_width}s | %-${path_width}s |\n" "Name" "Type" "Path" echo "|$(printf '%*s' $((name_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((type_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((path_width + 2)) '' | tr ' ' '-')|" relative-path() { local target="$1" local base="$2" if command -v realpath >/dev/null 2>&1; then realpath --relative-to="$base" "$target" 2>/dev/null || echo "$target" else if [[ "$target" == "$base"/* ]]; then echo "${target#$base/}" else echo "$target" fi fi } # Process files in TASK_DOTENV_DIR for env_file in "$TASK_DOTENV_DIR"/.env.*; do if [[ -f "$env_file" ]]; then local env_name="${env_file##*/}" env_name="${env_name#.env.}" local env_type="odoo" if [[ "$env_name" == "template" ]]; then env_type="template" elif grep -q "NEXTCLOUD" "$env_file"; then env_type="nextcloud" elif grep -q "ODOO_CONTAINER" "$env_file"; then env_type="upgrade" fi local rel_path rel_path=$(relative-path "$env_file" "$PWD") printf "| %-${name_width}s | %-${type_width}s | %-${path_width}s |\n" "$env_name" "$env_type" "$rel_path" fi done # Process files in current directory (PWD) for env_file in .env.*; do if [[ -f "$env_file" ]]; then local env_name="${env_file##*/}" env_name="${env_name#.env.}" local env_type="project" if [[ "$env_name" == "template" ]]; then env_type="template" fi local rel_path rel_path=$(relative-path "$env_file" "$PWD") printf "| %-${name_width}s | %-${type_width}s | %-${path_width}s |\n" "$env_name" "$env_type" "$rel_path" fi done }