update
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Colors
|
||||
cyan=$'\e[1;36m'; green=$'\e[1;32m'; red=$'\e[1;31m'
|
||||
magenta=$'\e[1;35m'; blue=$'\e[1;34m'
|
||||
reset=$'\e[0m'
|
||||
|
||||
# Box drawing chars (UTF-8 fallback safe)
|
||||
tl="╭"; tr="╮"; bl="╰"; br="╯"; h="─"; v="│"
|
||||
if ! locale charmap 2>/dev/null | grep -qi 'utf'; then
|
||||
tl="+"; tr="+"; bl="+"; br="+"; h="-"; v="|"
|
||||
fi
|
||||
|
||||
# Strip ANSI escapes
|
||||
strip_colors() { printf '%s' "$1" | sed -r 's/\x1B\[[0-9;]*[mK]//g'; }
|
||||
|
||||
# System age
|
||||
sys_age=$(( ( $(date +%s) - $(stat -c %W / 2>/dev/null || echo 0) ) / 86400 ))
|
||||
|
||||
# Packages
|
||||
pkg_count=$(find /var/db/pkg -mindepth 2 -maxdepth 2 -type d 2>/dev/null | wc -l)
|
||||
|
||||
# --- Define lines (easy to add new ones) ---
|
||||
lines=(
|
||||
"${green}Age${reset}: ${sys_age} days"
|
||||
"${magenta}Pkgs${reset}: ${pkg_count}"
|
||||
)
|
||||
|
||||
# --- Compute max width ---
|
||||
maxlen=0
|
||||
for l in "${lines[@]}"; do
|
||||
stripped=$(strip_colors "$l")
|
||||
slen=${#stripped}
|
||||
((slen > maxlen)) && maxlen=$slen
|
||||
done
|
||||
|
||||
# --- Borders ---
|
||||
hline=$(printf "%${maxlen}s" "" | sed "s/ /$h/g")
|
||||
printf '%s%s%s\n' "$tl" "$hline" "$tr"
|
||||
|
||||
for l in "${lines[@]}"; do
|
||||
# split into label and value at first colon
|
||||
label="${l%%:*}:" # label including colon
|
||||
value="${l#*: }" # everything after colon + space
|
||||
|
||||
# strip colors for length calculation
|
||||
stripped_label=$(strip_colors "$label")
|
||||
stripped_value=$(strip_colors "$value")
|
||||
|
||||
# compute padding: value is right-aligned
|
||||
label_len=${#stripped_label}
|
||||
value_len=${#stripped_value}
|
||||
pad=$((maxlen - label_len - value_len))
|
||||
|
||||
# print line: label left, pad spaces, value right
|
||||
printf '%s%s%*s%s%s\n' "$v" "$label" "$pad" "" "$value" "$v"
|
||||
done
|
||||
|
||||
# --- Bottom ---
|
||||
printf '%s%s%s\n' "$bl" "$hline" "$br"
|
||||
|
||||
Reference in New Issue
Block a user