dotfiles/dot_config/tmux/plugins/executable_common

40 lines
821 B
Plaintext
Raw Permalink Normal View History

2021-06-17 17:21:38 -04:00
#!/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)'\
'}')"
}