diff --git a/local/bin/network b/local/bin/network new file mode 100755 index 0000000..fe275bd --- /dev/null +++ b/local/bin/network @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# A simple little script to output Network I/O to a tmux status bar. +# Requires `ifstat`. +# +# $ network +# ↓0.33 KB/s ↑0.12 KB/s + +data=$(ifstat -i en0 -z -S -q 1 1 | tail -1) +down=$(echo $data | cut -f 2 -d " ") +up=$(echo $data | cut -f 3 -d " ") + +if [ $(echo "($down / 1024) > 1" | bc -l) -eq 1 ]; then + down=$(echo "$down / 1024" | bc -l | xargs printf "%.2f") + down="#[fg=red]↓$down MB/s#[fg=]" +else + down="#[fg=green]↓$down KB/s#[fg=]" +fi + +if [ $(echo "($up / 1024) > 1" | bc -l) -eq 1 ]; then + up=$(echo "$up / 1024" | bc -l | xargs printf "%.2f") + up="#[fg=red]↑$up MB/s#[fg=]" +else + up="#[fg=green]↑$up KB/s#[fg=]" +fi + +echo -e $"$down $up" diff --git a/tmux.conf b/tmux.conf index 0172d97..6bfeccf 100644 --- a/tmux.conf +++ b/tmux.conf @@ -65,8 +65,8 @@ set -g status-right-length 100 set -g status-bg black set -g status-fg default set -g status-attr bright -set -g status-interval 5 +set -g status-interval 2 set -g status-justify centre -set -g status-left "#(rainbarf --bg black --width 20 --remaining)" -set -g status-right "#[fg=green]#(curl -4 icanhazip.com) #[fg=blue]%H:%M %b %d %Y" +set -g status-left "#(network) #(rainbarf --bg black --width 10 --remaining)" +set -g status-right "#[fg=blue]#(forecast -m 15) #[fg=green]%H:%M %b %d %Y"