From b19d76dea0e9b8bb531e8c9aac63bdcb5f9e5452 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 03:36:03 +0000 Subject: [PATCH] feat: add headers and colors to top-hogs.sh - Use `awk` to preserve table headers when sorting process list - Add ANSI colors to section headers for better readability - Ensure top 10 processes are shown correctly --- .Jules/palette.md | 4 ++++ ops/monitoring/top-hogs.sh | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.Jules/palette.md b/.Jules/palette.md index 25d68a2..fda0ca8 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -1,3 +1,7 @@ ## 2025-12-14 - [Bash Script UX] **Learning:** CLI tools in this repo are heavily macOS-dependent but lack compatibility checks, leading to confusing errors on other systems. **Action:** When working on shell scripts, always add `command -v` checks or OS detection to provide clear feedback instead of raw errors. + +## 2025-12-15 - [CLI Header Retention] +**Learning:** Standard `sort` commands in pipelines often swallow or displace CSV/Table headers, making output unreadable. +**Action:** Use `awk 'NR==1 {print; next} {print | "sort ..."}'` pattern to reliably preserve headers in sorted CLI output. diff --git a/ops/monitoring/top-hogs.sh b/ops/monitoring/top-hogs.sh index 931acf0..d1aa8b5 100755 --- a/ops/monitoring/top-hogs.sh +++ b/ops/monitoring/top-hogs.sh @@ -4,8 +4,13 @@ set -e -echo "[top-hogs] Top 10 CPU-consuming processes:" -ps aux | sort -nrk 3 | head -n 11 +# ANSI Color Codes +BLUE='\033[0;34m' +BOLD='\033[1m' +RESET='\033[0m' -echo "\n[top-hogs] Top 10 Memory-consuming processes:" -ps aux | sort -nrk 4 | head -n 11 \ No newline at end of file +echo -e "${BLUE}${BOLD}[top-hogs] Top 10 CPU-consuming processes:${RESET}" +ps aux | awk 'NR==1 {print; next} {print | "sort -nrk 3 | head -n 10"}' + +echo -e "\n${BLUE}${BOLD}[top-hogs] Top 10 Memory-consuming processes:${RESET}" +ps aux | awk 'NR==1 {print; next} {print | "sort -nrk 4 | head -n 10"}'