#!/usr/bin/env bash # # ... # # 使用方法: # URL="https://git.1-h.cc/Scripts/Linux/raw/branch/2026/zram/show_status.sh"; curl -fsSL "$URL" | bash # URL="https://git.1-h.cc/Scripts/Linux/raw/branch/2026/zram/show_status.sh"; wget -q -O - "$URL" | bash format_zram_bytes() { awk -v bytes="$1" 'BEGIN { split("B KiB MiB GiB TiB PiB", units, " ") idx = 1 while (bytes >= 1024 && idx < 6) { bytes /= 1024 idx++ } printf "%.2f %s", bytes, units[idx] }' } show_zram_status() { echo "========== zram 运行战报 ==========" if ! command -v zramctl >/dev/null 2>&1; then echo "未安装 zramctl。" return 1 fi local table table=$(zramctl --noheadings --output NAME,ALGORITHM,DISKSIZE,DATA,COMPR,TOTAL,COMP-RATIO,MOUNTPOINT 2>/dev/null || true) if [ -z "$table" ]; then echo "未发现活跃的 zram 设备。" return 0 fi printf '%s\n' "$table" local stats stats=$(zramctl --bytes --raw --noheadings --output DATA,COMPR,TOTAL 2>/dev/null || true) if [ -z "$stats" ]; then echo "未发现活跃的 zram 设备。" return 0 fi local data_size compr_size total_mem saved_bytes ratio read -r data_size compr_size total_mem <