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.
This commit is contained in:
2026-06-22 17:05:38 +00:00
parent 0239f49aaa
commit 0e5670b5e8
+32 -6
View File
@@ -4,11 +4,13 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
CTRL_DATA_DIR="${CTRL_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/ctrl}" CTRL_DATA_DIR="${CTRL_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/ctrl}"
CTRL_ECOSYSTEM_DIR="${CTRL_ECOSYSTEM_DIR:-$CTRL_DATA_DIR/ecosystems}" CTRL_ECOSYSTEM_DIR="${CTRL_ECOSYSTEM_DIR:-$CTRL_DATA_DIR/ecosystems}"
SHOW_ALL="${PM2_MANAGER_SHOW_ALL:-0}"
declare -a APP_NAMES=() declare -a APP_NAMES=()
declare -a APP_DIRS=() declare -a APP_DIRS=()
declare -a APP_ECOSYSTEMS=() declare -a APP_ECOSYSTEMS=()
declare -a APP_SOURCES=() declare -a APP_SOURCES=()
declare -A SEEN_SERVICES=()
trim() { trim() {
local s="$1" local s="$1"
@@ -42,10 +44,17 @@ extract_app_cwd() {
add_ecosystem() { add_ecosystem() {
local file="$1" local file="$1"
local source="$2" local source="$2"
local app_name project_dir local app_name project_dir key
app_name="$(extract_app_name "$file")" app_name="$(extract_app_name "$file")"
project_dir="$(extract_app_cwd "$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_NAMES+=("$app_name")
APP_DIRS+=("$project_dir") APP_DIRS+=("$project_dir")
APP_ECOSYSTEMS+=("$file") APP_ECOSYSTEMS+=("$file")
@@ -76,7 +85,7 @@ discover_ecosystems() {
} }
print_services() { print_services() {
local i rel local i rel cwd_rel
if [ "${#APP_NAMES[@]}" -eq 0 ]; then if [ "${#APP_NAMES[@]}" -eq 0 ]; then
echo "No ecosystem config files found under $ROOT_DIR" echo "No ecosystem config files found under $ROOT_DIR"
return return
@@ -87,11 +96,23 @@ print_services() {
if [[ "${APP_ECOSYSTEMS[$i]}" == "$ROOT_DIR/"* ]]; then if [[ "${APP_ECOSYSTEMS[$i]}" == "$ROOT_DIR/"* ]]; then
rel="${APP_ECOSYSTEMS[$i]#"$ROOT_DIR/"}" rel="${APP_ECOSYSTEMS[$i]#"$ROOT_DIR/"}"
else else
rel="${APP_ECOSYSTEMS[$i]}" rel="$(basename "${APP_ECOSYSTEMS[$i]}")"
fi 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 done
if [ "$SHOW_ALL" != "1" ]; then
echo
echo "Showing preferred configs only. Use '$0 list-all' to include repo-local duplicates."
fi
} }
run_action() { run_action() {
@@ -175,6 +196,7 @@ usage() {
Usage: Usage:
$0 # interactive mode $0 # interactive mode
$0 list $0 list
$0 list-all
$0 <action> <service> $0 <action> <service>
Actions: Actions:
@@ -218,9 +240,13 @@ main() {
exit 0 exit 0
fi fi
if [ "${1:-}" = "list-all" ]; then
SHOW_ALL=1
fi
discover_ecosystems discover_ecosystems
if [ "${1:-}" = "list" ]; then if [ "${1:-}" = "list" ] || [ "${1:-}" = "list-all" ]; then
print_services print_services
exit 0 exit 0
fi fi