ADD more plugins to tmux

This commit is contained in:
Nathan Dwarshuis 2021-06-17 17:21:38 -04:00
parent 12a6be7238
commit 34ffddbd4b
5 changed files with 119 additions and 39 deletions

View File

@ -0,0 +1,39 @@
#!/bin/bash
cache_vals(){
echo "$1" > "$3"
echo -n "$2" >> "$3"
}
cached_eval(){
local dir
local a0
local t0
local a1
local t1
dir="/tmp/$1"
a1="$2"
t1="$3"
if [ -f "$dir" ]; then
a0="$(head -n1 "$dir")"
t0="$(tail -n+2 "$dir")"
cache_vals "$a1" "$t1" "$dir"
awk -v a1="$a1" \
-v t1="$t1" \
-v a0="$a0" \
-v t0="$t0" \
'BEGIN {print (a1-a0)/(t1-t0)}'
else
cache_vals "$a1" "$t1" "$dir"
echo -n 0
fi
}
fmt_percent(){
awk "$(printf '%s' \
'{x=$1*100} END { '\
'if (x>=100) printf("%d%% ", x); '\
'else if (x>=10) printf("%.1f%%", x); '\
'else printf("%.2f%%", x)'\
'}')"
}

36
dot_config/tmux/plugins/executable_cpu_perc Executable file → Normal file
View File

@ -1,41 +1,11 @@
#!/bin/bash
cache_vals(){
echo "$1" > "$3"
echo -n "$2" >> "$3"
}
cached_eval(){
local dir
local a0
local t0
local a1
local t1
dir="/tmp/tmux_cpu_perc"
a1="$1"
t1="$2"
if [ -f "$dir" ]; then
a0="$(head -n1 "$dir")"
t0="$(tail -n+2 "$dir")"
cache_vals "$a1" "$t1" "$dir"
awk -v a1="$a1" \
-v t1="$t1" \
-v a0="$a0" \
-v t0="$t0" \
'BEGIN {print 100*(a1-a0)/(t1-t0)}'
else
cache_vals "$a1" "$t1" "$dir"
echo -n 0
fi
}
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "$this_dir/common"
get_cpu(){
grep 'cpu ' /proc/stat | \
awk '{a=($2+$4)}; {t=($2+$4+$5)} END {printf("%s %s", a, t)}'
}
cpu_percentage_format="%.2f%%"
cached_eval $(get_cpu) \
| awk -v f="$cpu_percentage_format" \
'{usage=$NF} END {printf(f, usage)}'
cached_eval "cpu_perc" $(get_cpu) | fmt_percent

View File

@ -0,0 +1,6 @@
#!/bin/bash
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "$this_dir/common"
free | grep Mem | awk '{ printf("%.5f", $3/$2) }' | fmt_percent

View File

@ -0,0 +1,44 @@
#!/bin/bash
iface="$1"
cmd="$2"
net_format="%3d"
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "$this_dir/common"
get_bits() {
awk '{print($1*8)}' "$1"
}
get_down(){
get_bits "/sys/class/net/$iface/statistics/rx_bytes"
}
get_up(){
get_bits "/sys/class/net/$iface/statistics/tx_bytes"
}
get_time() {
date +%s.%N
}
if [[ "$cmd" == "down" ]]; then
bits="$(get_down)"
elif [[ "$cmd" == "up" ]]; then
bits="$(get_up)"
else
echo "Invalid command"
exit 1
fi
cached_eval "network_$cmd" "$bits" "$(get_time)" \
| awk -v f="$net_format" \
"$(printf '%s' \
'{x=$1} END { '\
'if (x>=1073741824) printf(f " Gib/s", x/1073741824); '\
'else if (x>=1048576) printf(f " Mib/s", x/1048576); '\
'else if (x>=1024) printf(f " Kib/s", x/1024); '\
'else printf(f " bit/s", x)'\
'}')"

View File

@ -28,8 +28,8 @@ bind | split-window -h
# window navigation
bind -n M-Tab next-window
bind -n M-BTab previous-window
bind -n C-M-Tab swap-window -t +1 \; next-window
bind -n C-M-BTab swap-window -t -1 \; previous-window
bind -n M-] swap-window -t +1 \; next-window
bind -n M-[ swap-window -t -1 \; previous-window
bind -n M-| choose-window "join-pane -h -t '%%'"
bind -n M-- choose-window "join-pane -v -t '%%'"
@ -117,12 +117,33 @@ bind -T off F12 \
set -u window-status-current-style \;\
refresh-client -S
mem_perc="free | grep Mem | awk '{ printf(\"%.2f%%\", $3/$2 * 100.0) }'"
set -g status-right "CPU: #($XDG_CONFIG_HOME/tmux/plugins/cpu_perc) $status_sep RAM: #($mem_perc) "
# if on local machine, put bar at top, if not put bar at bottom with some nice
# stats that the local machine already has via conky
{{- if eq .chezmoi.hostname "petrucci4prez" }}
set -g status-position top
{{- else }}
# TODO this is super annoying
{{- if eq .chezmoi.hostname "portnoy4prez" }}
iface="enp0s31f6"
{{- else if eq .chezmoi.hostname "mangini4mayor" }}
iface="enp3s0"
{{- else if eq .chezmoi.hostname "harrison4hegemon" }}
iface="eth0"
{{- else if eq .chezmoi.hostname "peart4prez" }}
iface="ens3"
{{- else if eq .chezmoi.hostname "myung4mayor" }}
iface="extern1"
{{- end }}
down="#($XDG_CONFIG_HOME/tmux/plugins/network $iface down)"
up="#($XDG_CONFIG_HOME/tmux/plugins/network $iface up)"
net="NET(↑/↓): $up$down"
cpu="CPU: #($XDG_CONFIG_HOME/tmux/plugins/cpu_perc)"
mem="RAM: #($XDG_CONFIG_HOME/tmux/plugins/mem_perc)"
set -g status-position bottom
set -g status-right-length 64
set -g status-right "$net $status_sep $cpu $status_sep $mem "
{{ end }}