init
This commit is contained in:
56
waybar/scripts/get_wg_status.sh
Executable file
56
waybar/scripts/get_wg_status.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to format output as JSON
|
||||
function format {
|
||||
local tooltip=""
|
||||
local first=true
|
||||
|
||||
while IFS= read -r line; do
|
||||
if [[ -z "$line" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if the line starts with "interface" or "peer"
|
||||
if [[ "$line" == interface:* ]]; then
|
||||
if [ "$first" = false ]; then
|
||||
tooltip+="\n"
|
||||
fi
|
||||
tooltip+="Interface: <b>${line#*: }</b>"
|
||||
first=false
|
||||
elif [[ "$line" == peer:* ]]; then
|
||||
if [ "$first" = false ]; then
|
||||
tooltip+="\n"
|
||||
fi
|
||||
tooltip+="Peer: <b>${line#*: }</b>"
|
||||
first=false
|
||||
elif [[ "$line" == *"received,"* ]]; then
|
||||
# Extract received and sent data
|
||||
received=$(echo "$line" | grep -oP '\d+\.\d+ (B|KiB|MiB|GiB) received' | awk '{print $1 " " $2}')
|
||||
sent=$(echo "$line" | grep -oP '\d+\.\d+ (B|KiB|MiB|GiB) sent' | awk '{print $1 " " $2}')
|
||||
tooltip+="\n<span foreground='#eed49f'> $received</span> <span foreground='#b7bdf8'> $sent</span>"
|
||||
else
|
||||
# For other lines
|
||||
if [ "$first" = false ]; then
|
||||
tooltip+="\n"
|
||||
fi
|
||||
key=$(echo "$line" | sed "s/ //" | awk -F ': ' '{print $1}')
|
||||
value=$(echo "$line" | awk -F ': ' '{print $2}')
|
||||
tooltip+="$key: <b>$value</b>"
|
||||
first=false
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$tooltip"
|
||||
}
|
||||
|
||||
# Read wg show output and format
|
||||
wg_show_output=$(sudo wg show)
|
||||
|
||||
if [[ -z $wg_show_output ]]; then
|
||||
echo "{ \"text\": \"---\", \"tooltip\": \"disconnected\", \"class\": \"\", \"percentage\": 0 }"
|
||||
else
|
||||
tooltip=$(echo "$wg_show_output" | format)
|
||||
echo "{ \"text\": \"$(echo $wg_show_output | grep -o 'wg[0-9]*')\", \"tooltip\": \"$tooltip\", \"class\": \"\", \"percentage\": 0 }"
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user