tmux-bond-device

tmux plugin to show active bond interface
git clone git://git.pyratebeard.net/tmux-bond-device.git
Log | Files | Refs | README | LICENSE

commit 9eca19e20e8914e75ebd4568b8c0d2e7abd27c53
parent 442e037917c68ef29c5bd7684cdb8b7bef3bb78e
Author: pyratebeard <root@pyratebeard.net>
Date:   Fri, 10 Jul 2020 16:32:32 +0100

working script

tmux file and script to find current active bond device

Diffstat:
Abond_device.tmux | 19+++++++++++++++++++
Ascripts/bond_interface.sh | 37+++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/bond_device.tmux b/bond_device.tmux @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +device="#($CURRENT_DIR/scripts/bond_interface.sh)" +interpolate_string="\#{bond_device}" + +interpolate() { + local -r status="$1" + local -r status_value=$(tmux show-option -gqv "$status") + tmux set-option -gq "$status" "${status_value/$interpolate_string/$device}" +} + +main() { + interpolate "status-left" + interpolate "status-right" +} + +main diff --git a/scripts/bond_interface.sh b/scripts/bond_interface.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +bond_device="bond0" +ethernet="ethernet" +wifi="wi-fi" +bond_option="@bond" +ethernet_option="@ethernet" +wifi_option="@wifi" + +get_tmux_option() { + local -r option="$1" + local -r default_option="$2" + local -r option_value="$(tmux show-option -gqv "$option")" + if [ -z "$option_value" ] ; then + echo "$default_option" + else + echo "$option_value" + fi +} + +network_device() { + local bond_device="$(get_tmux_option "$bond_option" "$bond_device")" + local current_device="$(awk '/Currently Active/ {print $NF}' /proc/net/bonding/${bond_device})" + if [[ $current_device =~ ^e ]] ; then + current_device="$(get_tmux_option "$ethernet_option" "$ethernet")" + elif [[ $current_device =~ ^w ]] ; then + current_device="$(get_tmux_option "$wifi_option" "$wifi")" + fi + + echo "$current_device" +} + +main() { + network_device +} + +main