Files
dotfiles/home/.tmux/network.sh
Andrejus 8138d44c73 Replace red with amber, unify palette, add fetch/pull aliases
- Add git aliases: f (fetch), p (pull) and shell aliases: gf, gp
- Replace all #F40404 (red) with #F88C14 (amber) across prompt, gitconfig,
  vim, bat theme, and tmux scripts for colourblind-friendly palette
- Standardise hex case to uppercase throughout
- Unify #728cb8 → #7290B8 (fix blue inconsistency)
- Replace unique #8787AF with palette #7290B8 in gitconfig
- Remove unused red colour definition from prompt.zsh
- Update dark diff backgrounds from red-tinted to amber-tinted

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-25 17:38:47 +00:00

55 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Network indicator for tmux status bar.
# Pings 1.1.1.1 to measure latency, detects wired vs wifi.
# Caches result for 10s to avoid excessive pinging.
cache="${TMPDIR:-/tmp}/.tmux_network_cache"
# Return cached result if fresh (<10s old)
if [[ -f "$cache" ]]; then
age=$(( $(date +%s) - $(stat -f%m "$cache" 2>/dev/null || stat -c%Y "$cache" 2>/dev/null || echo 0) ))
if (( age < 10 )); then
cat "$cache"
exit 0
fi
fi
# Detect connection type
wired=1
if [[ "$(uname)" == "Darwin" ]]; then
iface=$(route -n get default 2>/dev/null | awk '/interface:/{print $2}')
if networksetup -listallhardwareports 2>/dev/null | grep -A1 'Wi-Fi' | grep -q "$iface"; then
wired=""
fi
else
iface=$(ip route show default 2>/dev/null | awk '{print $5; exit}')
[[ -d "/sys/class/net/${iface}/wireless" ]] && wired=""
fi
# Measure latency
ms=""
if [[ "$(uname)" == "Darwin" ]]; then
ms=$(ping -c1 -t1 1.1.1.1 2>/dev/null | awk '/time=/{gsub(/.*time=/,""); printf "%.0f", $1}')
else
ms=$(ping -c1 -W1 1.1.1.1 2>/dev/null | awk '/time=/{gsub(/.*time=/,""); printf "%.0f", $1}')
fi
# Pick icon: wired 󰈀 vs wifi 󰤨
if [[ -n "$wired" ]]; then
icon="󰈀"
else
icon="󰤨"
fi
if [[ -z "$ms" ]]; then
result="#[fg=#F88C14]󰤭 --#[default]"
elif (( ms <= 50 )); then
result="#[fg=#808080]${icon} ${ms}ms#[default]"
elif (( ms <= 150 )); then
result="#[fg=#F88C14]${icon} ${ms}ms#[default]"
else
result="#[fg=#F88C14]${icon} ${ms}ms#[default]"
fi
echo "$result" | tee "$cache"