Skip to content

Instantly share code, notes, and snippets.

@Djerbiien
Created May 21, 2026 08:47
Show Gist options
  • Select an option

  • Save Djerbiien/573a1000e3ecb1a7a7e8cca622f50e68 to your computer and use it in GitHub Desktop.

Select an option

Save Djerbiien/573a1000e3ecb1a7a7e8cca622f50e68 to your computer and use it in GitHub Desktop.
# ~/.bash_functions
sys() {
# ── Colors ────────────────────────────────────────────
local R=$'\e[0m'
local B=$'\e[1m'
local DIM=$'\e[2m'
local CYA=$'\e[38;5;110m'
local WHT=$'\e[38;5;255m'
local LBL=$'\e[38;5;250m'
local YEL=$'\e[38;5;179m'
local GRN=$'\e[38;5;108m'
local RED=$'\e[38;5;167m'
local MAG=$'\e[38;5;183m'
local SEP=$'\e[38;5;59m'
# ── Collect stats ──────────────────────────────────────
read load1 _ _ _ < /proc/loadavg
local cpu_pct
cpu_pct=$(awk '/^cpu /{u=$2+$4; t=$2+$3+$4+$5; printf "%.0f", u*100/t}' /proc/stat)
local mem_pct mem_used mem_total
read mem_total mem_used < <(free -m | awk '/Mem:/{print $2, $3}')
mem_pct=$(awk "BEGIN{printf \"%.0f\", ($mem_used/$mem_total)*100}")
local disk_pct
disk_pct=$(df / | awk 'NR==2{gsub(/%/,"",$5); print $5}')
local up_str
up_str=$(awk '{
s = int($1)
d = int(s/86400); s -= d*86400
h = int(s/3600); s -= h*3600
m = int(s/60)
if (d) printf "%dd %dh %dm", d, h, m
else if (h) printf "%dh %dm", h, m
else printf "%dm", m
}' /proc/uptime)
local next_backup
next_backup=$(systemctl show borgmatic.timer --property=NextElapseUSecRealtime | cut -d= -f2 | awk '{print $1, $2}')
# ── Threshold colors ───────────────────────────────────
local cpu_col ram_col dsk_col
if [ "$cpu_pct" -ge 80 ]; then cpu_col="$RED"
elif [ "$cpu_pct" -ge 50 ]; then cpu_col="$YEL"
else cpu_col="$GRN"
fi
if [ "$mem_pct" -ge 80 ]; then ram_col="$RED"
elif [ "$mem_pct" -ge 60 ]; then ram_col="$YEL"
else ram_col="$GRN"
fi
if [ "$disk_pct" -ge 80 ]; then dsk_col="$RED"
elif [ "$disk_pct" -ge 50 ]; then dsk_col="$YEL"
else dsk_col="$GRN"
fi
# ── Header ─────────────────────────────────────────────
printf "\n"
printf "${SEP}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${R}\n"
printf "${CYA}${B} 󰒋 System Dashboard${R}\n"
printf "${SEP}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${R}\n"
# ── Status bar ─────────────────────────────────────────
printf "\n"
printf " ${cpu_col}󰻠 ${B}${cpu_pct}%%${R} "
printf "${SEP}│${R} "
printf "${ram_col}󰍛 ${B}${mem_pct}%%${R} "
printf "${SEP}│${R} "
printf "${dsk_col}󰋊 ${B}${disk_pct}%%${R} "
printf "${SEP}│${R} "
printf "${LBL}󰾆 ${WHT}${load1}${R} "
printf "${SEP}│${R} "
printf "${LBL}󰅐 ${WHT}${up_str}${R} "
printf "${SEP}│${R} "
printf "${CYA}󰃰 ${WHT}${next_backup}${R}\n"
# ── Storage ────────────────────────────────────────────
printf "\n ${CYA}${B}󰋊 Storage${R}\n"
printf " ${SEP}───────────────────────────────────────────────────${R}\n"
df -hT -x tmpfs -x devtmpfs | awk \
-v R="$R" -v DIM="$DIM" \
-v CYA="$CYA" -v WHT="$WHT" -v LBL="$LBL" \
-v YEL="$YEL" -v GRN="$GRN" -v RED="$RED" \
-v MAG="$MAG" -v SEP="$SEP" '
$2 ~ /^(ext4|btrfs|xfs)$/ {
gsub(/%/, "", $6)
pct = $6 + 0
if (pct < 50) col = GRN
else if (pct < 80) col = YEL
else col = RED
bar = ""
n = int(pct / 5)
for (i = 0; i < 20; i++)
bar = bar (i < n ? "█" : "░")
if ($7 == "/") {
icon = "󰋊"
label = "OS SSD"
} else {
icon = "󰉖"
label = "DATA SSD"
}
printf " %s%s %-10s%s %s%-5s%s %ssize%s %-7s %sused%s %-7s %sfree%s %-7s %s[%s]%s %s%3s%%%s %s%s%s\n",
MAG, icon, label, R,
DIM, $2, R,
LBL, WHT, $3,
LBL, WHT, $4,
LBL, WHT, $5,
col, bar, R,
col, pct, R,
SEP, $7, R
}'
# ── Temperatures ───────────────────────────────────────
printf "\n ${CYA}${B}󱃃 Temperatures${R}\n"
printf " ${SEP}───────────────────────────────────────────────────${R}\n"
local labels=("OS SSD" "DATA SSD")
local i=0
for disk in /dev/nvme0n1 /dev/nvme1n1; do
local raw temp_c
raw=$(sudo nvme smart-log "$disk" 2>/dev/null | grep -i '^temperature')
if echo "$raw" | grep -qi 'celsius\|°C'; then
temp_c=$(echo "$raw" | grep -oE '[0-9]+' | head -n1)
elif echo "$raw" | grep -qi 'fahrenheit\|°F'; then
local f
f=$(echo "$raw" | grep -oE '[0-9]+' | head -n1)
[ -n "$f" ] && temp_c=$(awk "BEGIN{printf \"%.0f\", ($f-32)*5/9}")
else
temp_c=$(echo "$raw" | grep -oE '[0-9]+' | head -n1)
fi
local t_col
if [ "${temp_c:-0}" -ge 65 ]; then t_col="$RED"
elif [ "${temp_c:-0}" -ge 50 ]; then t_col="$YEL"
else t_col="$GRN"
fi
local fill=0 bar=""
[ -n "$temp_c" ] && fill=$(( (temp_c < 100 ? temp_c : 99) * 20 / 100 ))
for (( j=0; j<20; j++ )); do
[ $j -lt $fill ] && bar+="█" || bar+="░"
done
printf " ${CYA}󰋊 ${MAG}%-10s${R} ${t_col}${B}%s°C${R} ${DIM}[${t_col}%s${DIM}]${R}\n" \
"${labels[$i]}" "${temp_c:---}" "$bar"
(( i++ ))
done
# ── Footer ─────────────────────────────────────────────
printf "\n${SEP}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${R}\n\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment