Files
fish-config/functions/swapstat.fish
T
rootiest 084e6fb9ca refactor(functions): standardize documentation, metadata, and wrappers
- Add comprehensive `--description` flags to all fish functions for better `help` and `functions` output.
- Introduce and correct `--wraps` flags to ensure proper completions for aliased commands (e.g., `top` wrapping `btop`, `zellij`, `upgrade` wrapping `paru`).
- Prepend descriptive comments before function definitions for better source readability.
- Add standard copyright and SPDX license identifiers to shell scripts.
- Enhance script robustness by ensuring consistent terminal checks (Kitty, WezTerm) and graceful fallbacks in window/tab spawning functions (`spwin`, `tab`).
- Implement graceful fallbacks to basic core utilities when preferred modern alternatives are missing (e.g., `top` falling back to system `top` if `btop` is missing, `view` falling back to `less` or `cat` if `nvim` is unavailable).
- Improve overall code consistency across the `functions/` directory.
2026-04-30 23:16:28 -04:00

39 lines
1.6 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# View colorized zRAM and swappiness status
function swapstat --description 'View colorized zRAM and swappiness status'
set -l swappiness (sysctl -n vm.swappiness)
set -l zdata (zramctl --bytes --noheadings --output DATA,TOTAL /dev/zram0 2>/dev/null)
echo (set_color --bold blue)"── Memory & zRAM Report ──"(set_color normal)
# Kernel & Compression Stats
if test -n "$zdata"
set -l raw (echo $zdata | awk '{print $1}')
set -l compressed (echo $zdata | awk '{print $2}')
if test "$compressed" -gt 0
set -l ratio (math -s2 "$raw / $compressed")
echo (set_color yellow)"Compression Ratio: "(set_color normal)"$ratio:1"
end
end
echo (set_color yellow)"Kernel Swappiness: "(set_color normal)"$swappiness"
echo ""
# Colorized zRAM Table
# Colors the header green and the device path (/dev/...) cyan
echo (set_color --bold --underline magenta)"zRAM Device Details"(set_color normal)
zramctl --output NAME,ALGORITHM,DISKSIZE,DATA,COMPR,TOTAL,STREAMS | sed \
-e "1s/.*/$(set_color --bold green)&$(set_color normal)/" \
-e "s|/dev/zram[0-9]|$(set_color cyan)&$(set_color normal)|"
echo ""
# Colorized Swapon Table
# Colors the header green and the device path cyan
echo (set_color --bold --underline magenta)"Active Swap Priority"(set_color normal)
swapon --show | sed \
-e "1s/.*/$(set_color --bold green)&$(set_color normal)/" \
-e "s|/dev/[^ ]*|$(set_color cyan)&$(set_color normal)|"
end