archcraft-openbox/files/rofi/bin/network

66 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
## Copyright (C) 2020-2021 Aditya Shakya <adi1090x@gmail.com>
## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3
STYLE="default"
rofi_command="rofi -theme $HOME/.config/openbox/rofi/$STYLE/network.rasi"
## Get info
IFACE="$(nmcli | grep -i interface | head -n1 | cut -d' ' -f2)"
STATUS="$(nmcli radio wifi)"
_SSID="$(iwgetid -r)"
_LIP="$(nmcli | grep -i server | head -n1 | cut -d' ' -f2)"
_PIP="$(wget --timeout=30 http://ipinfo.io/ip -qO -)"
active=""
urgent=""
if (ping -c 1 archlinux.org || ping -c 1 google.com || ping -c 1 bitbucket.org || ping -c 1 github.com || ping -c 1 sourceforge.net) &>/dev/null; then
if [[ $STATUS == *"enable"* ]]; then
if [[ $IFACE == e* ]]; then
connected=" Connected To Internet"
else
connected=" Connected To Internet"
fi
active="-a 0"
SSID="$_SSID"
PIP="$_PIP"
fi
else
urgent="-u 0"
SSID="Disconnected"
PIP="NA"
connected=" Offline"
fi
## Icons
bmon=" Open Bandwidth Monitor"
launch_cli=" Open Network Manager"
launch=" Open Connection Editor"
options="$connected\n$bmon\n$launch_cli\n$launch"
## Main
chosen="$(echo -e "$options" | $rofi_command -p "$SSID : $PIP" -dmenu $active $urgent -selected-row 1)"
case $chosen in
$connected)
if [[ $STATUS == *"enable"* ]]; then
nmcli radio wifi off
else
nmcli radio wifi on
fi
;;
$bmon)
alacritty -e bmon
;;
$launch_cli)
alacritty -e nmtui
;;
$launch)
nm-connection-editor
;;
esac