1
0
Fork 0
cfg/.config/i3blocks/wifi

22 lines
701 B
Bash
Executable file

#!/bin/bash
set -euo pipefail
interface=$(ip a | grep 'wlp.*:' | sed -E 's/^[0-9]*: ([^:]+):.*/\1/')
# We found no wlp* interface: Get out here
[ -z "${interface}" ] && exit
ip=$(ip a show ${interface} | awk '/inet .* scope global/{ print $2 }' | cut -d '/' -f1)
# We found no ip: Get out here
[ -z "${ip}" ] && exit
network=$(networkctl status -a | awk -F ': ' '/Wi-Fi access point/{ print $2 }' | cut -d ' ' -f 1)
# We found no network: Get out here
[ -z "${network}" ] && exit
printf "\uf1eb <span color=\"#8FAAFC\">%s</span> <span color=\"#50fa7b\">(%s)</span>\n" ${network} ${ip}
# On click copy IP
[ -n "${BLOCK_BUTTON:-}" ] && echo -n "${ip}" | tr -d '\n' | xclip -selection c || true