Skip to content

Instantly share code, notes, and snippets.

@b0o
Created August 12, 2021 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b0o/9978dd3aef808ff41d86440f3f0856a8 to your computer and use it in GitHub Desktop.
Save b0o/9978dd3aef808ff41d86440f3f0856a8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
function main() {
local -i row_width=${1:-990}
local -i total_height=${2:-500}
local -i row_height=$((total_height / 4))
local mods=".w${row_width}.h${row_height}.d"
local -a gallium=(
"$mods"
"cpu=CPU-Load-"
"+GPU-load=GPU-Load-"
","
"$mods"
".d"
"sensors_temp_cu-k10temp-pci-00c3.Tctl=CPU-Temp-"
"+temperature=GPU-Temp-"
","
"$mods"
"mapped-VRAM=VRAM-Mapped----"
"+VRAM-usage=VRAM-Usage-----"
"+VRAM-vis-usage=VRAM-Vis-Usage-"
","
"$mods"
"diskstat-rd-nvme1n1=system_maddymach-Read--"
"+diskstat-wr-nvme1n1=system_maddymach-Write-"
"+diskstat-rd-sda=backups_lovelace-Read--"
"+diskstat-wr-sda=backups_lovelace-Write-"
)
local _IFS="$IFS"
IFS=""
export GALLIUM_HUD="${gallium[*]}"
IFS="$_IFS"
# shellcheck disable=1004,2016
alacritty -e sh -c '
tmux="tmux -L ttop";
if $tmux attach-session &>/dev/null; then exit; fi;
$tmux -f <(echo "
set -g exit-empty on
set -g exit-unattached on
set -g status off
set -g key-table ttop
set -g prefix None
set-environment -g TTOP_INTERVAL 0.75
bind-key -T ttop q detach-client
bind-key -T ttop C-c detach-client
bind-key -T ttop C-d detach-client
bind-key -T ttop \"{\" run-shell \"TTOP_SLEEP_PID=\\\"\$($tmux show-environment -g TTOP_SLEEP_PID 2>/dev/null | sed -E \\\"s/^.+=//\\\")\\\"; if [[ \\\$TTOP_SLEEP_PID -gt 1 ]]; then kill -USR1 \\\$TTOP_SLEEP_PID; fi\"
bind-key -T ttop \"}\" run-shell \"TTOP_SLEEP_PID=\\\"\$($tmux show-environment -g TTOP_SLEEP_PID 2>/dev/null | sed -E \\\"s/^.+=//\\\")\\\"; if [[ \\\$TTOP_SLEEP_PID -gt 1 ]]; then kill -USR2 \\\$TTOP_SLEEP_PID; fi\"
bind-key -T ttop M-1 select-pane -t 1
bind-key -T ttop M-2 select-pane -t 2
bind-key -T ttop M-3 select-pane -t 3
") new-session "
# pane 0.1
$tmux split-window -p 58 -v \"sudo -A -p \\\"[sudo] Administrator access is required for iftop. Password for \$USER:\\\" iftop\";
# pane 0.3
$tmux split-window -p 65 -v \"htop -d 20; $tmux kill-server\";
# pane 0.2
$tmux split-window -p 45 -h -t 0.1 \"radeontop -c -t 60\ | sed -E \\\"2s/\x1b\[0;7m//; s/\x1b\[40m//g\\\"\";
$tmux select-pane -t 0.3;
$tmux switch-client -T ttop;
function reset_term() {
clear;
tput civis;
tput cup \$ROWS \$COLUMNS;
};
trap reset_term SIGWINCH;
reset_term;
while :; do
TTOP_INTERVAL=\"\$($tmux show-environment -g TTOP_INTERVAL 2>/dev/null | sed -E \"s/^.+=//\")\";
s=\$TTOP_INTERVAL
if [[ \$s -eq 0 ]]; then
s=365d
fi
sleep \${s:-1} &;
TTOP_SLEEP_PID=\$!;
echo -en \"\\\r\";
printf \"%0\$((COLUMNS - 76))s\" \" \";
printf \" \e[01;46m %s \e[00m\e[21;47m\e[30m %.02fs \e[00m\" \"Interval\" \"\$TTOP_INTERVAL\";
printf \" \e[22;45m\e[30m %s \e[21;47m %s \e[00m\" \\
\"{\" \"-0.25s\" \\
\"}\" \"+0.25s\" \\
\"M-[1-3]\" \"Select Pane\" \\
\"q\" \"quit\";
$tmux send-keys -t 0.3 =
$tmux set-environment -g TTOP_SLEEP_PID \$TTOP_SLEEP_PID;
wait \$TTOP_SLEEP_PID || {
if [[ \$? -eq 138 ]]; then
op=\"-\"
else
op=\"+\"
fi
TTOP_INTERVAL=\"\$(bc <<<\"n=\$TTOP_INTERVAL \$op 0.25; if (n > 0.0) if (n < 2.0) n else 2.0 else 0.0\")\";
$tmux set-environment -g TTOP_INTERVAL \$TTOP_INTERVAL;
};
TTOP_SLEEP_PID=-1;
$tmux set-environment -g TTOP_SLEEP_PID \$TTOP_SLEEP_PID;
done
";
'
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment