From 0e5670b5e8ca084391257baa2b053e4f5304015d Mon Sep 17 00:00:00 2001 From: LyAhn Date: Mon, 22 Jun 2026 17:05:38 +0000 Subject: [PATCH] fix(pm2): display compact, deduped list - Ctrl-managed configs are preferred. - Repo-local duplicates for the same name + cwd are hidden - Each service is one line: index, app name, source, cwd, config - list-all still shows every discovered ecosystem file when you need to debug stale/duplicate configs. --- pm2/pm2-manager.sh | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/pm2/pm2-manager.sh b/pm2/pm2-manager.sh index 0b47203..b61bfe4 100755 --- a/pm2/pm2-manager.sh +++ b/pm2/pm2-manager.sh @@ -4,11 +4,13 @@ set -euo pipefail ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" CTRL_DATA_DIR="${CTRL_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/ctrl}" CTRL_ECOSYSTEM_DIR="${CTRL_ECOSYSTEM_DIR:-$CTRL_DATA_DIR/ecosystems}" +SHOW_ALL="${PM2_MANAGER_SHOW_ALL:-0}" declare -a APP_NAMES=() declare -a APP_DIRS=() declare -a APP_ECOSYSTEMS=() declare -a APP_SOURCES=() +declare -A SEEN_SERVICES=() trim() { local s="$1" @@ -42,10 +44,17 @@ extract_app_cwd() { add_ecosystem() { local file="$1" local source="$2" - local app_name project_dir + local app_name project_dir key app_name="$(extract_app_name "$file")" project_dir="$(extract_app_cwd "$file")" + key="${app_name}|${project_dir}" + + if [ "$SHOW_ALL" != "1" ] && [ -n "${SEEN_SERVICES[$key]:-}" ]; then + return + fi + + SEEN_SERVICES[$key]=1 APP_NAMES+=("$app_name") APP_DIRS+=("$project_dir") APP_ECOSYSTEMS+=("$file") @@ -76,7 +85,7 @@ discover_ecosystems() { } print_services() { - local i rel + local i rel cwd_rel if [ "${#APP_NAMES[@]}" -eq 0 ]; then echo "No ecosystem config files found under $ROOT_DIR" return @@ -87,11 +96,23 @@ print_services() { if [[ "${APP_ECOSYSTEMS[$i]}" == "$ROOT_DIR/"* ]]; then rel="${APP_ECOSYSTEMS[$i]#"$ROOT_DIR/"}" else - rel="${APP_ECOSYSTEMS[$i]}" + rel="$(basename "${APP_ECOSYSTEMS[$i]}")" fi - printf " %2d) %-18s %-4s %s\n" "$((i + 1))" "${APP_NAMES[$i]}" "${APP_SOURCES[$i]}" "$rel" - printf " cwd: %s\n" "${APP_DIRS[$i]}" + + if [[ "${APP_DIRS[$i]}" == "$ROOT_DIR/"* ]]; then + cwd_rel="${APP_DIRS[$i]#"$ROOT_DIR/"}" + else + cwd_rel="${APP_DIRS[$i]}" + fi + + printf " %2d) %-16s %-4s %-24s %s\n" \ + "$((i + 1))" "${APP_NAMES[$i]}" "${APP_SOURCES[$i]}" "$cwd_rel" "$rel" done + + if [ "$SHOW_ALL" != "1" ]; then + echo + echo "Showing preferred configs only. Use '$0 list-all' to include repo-local duplicates." + fi } run_action() { @@ -175,6 +196,7 @@ usage() { Usage: $0 # interactive mode $0 list + $0 list-all $0 Actions: @@ -218,9 +240,13 @@ main() { exit 0 fi + if [ "${1:-}" = "list-all" ]; then + SHOW_ALL=1 + fi + discover_ecosystems - if [ "${1:-}" = "list" ]; then + if [ "${1:-}" = "list" ] || [ "${1:-}" = "list-all" ]; then print_services exit 0 fi