summaryrefslogtreecommitdiffstats
path: root/local/bin
diff options
context:
space:
mode:
Diffstat (limited to 'local/bin')
-rwxr-xr-xlocal/bin/network_control.sh48
-rwxr-xr-xlocal/bin/sb-network52
2 files changed, 91 insertions, 9 deletions
diff --git a/local/bin/network_control.sh b/local/bin/network_control.sh
index 381cbec..4dc4b38 100755
--- a/local/bin/network_control.sh
+++ b/local/bin/network_control.sh
@@ -2,21 +2,51 @@
signal=30
-# signal dwmblocks to update volume block
+# signal dwmblocks to update network block
send_signal() {
pkill -RTMIN+$signal dwmblocks
}
+toggle_wifi() {
+ status=$(nmcli radio wifi)
+
+ if [ "$status" = "enabled" ]; then
+ nmcli radio wifi off
+ else
+ nmcli radio wifi on
+ fi
+}
+
+# This one is hard because it requires root, and the VPN interface name
+# 2 ways to toggle, using systemctl, or wg-quick(1)
+# This one might be better controled through a `dmenu` script.
+toggle_vpn() {
+ :
+}
+
+toggle_network_quarantine() {
+ # Check the status of all wireless devices
+ if rfkill list | grep -q "Soft blocked: no"; then
+ # not all blocked
+ rfkill block all
+ else
+ # all blocked
+ rfkill unblock all
+ fi
+}
+
+# WIP
+toggle_bluetooth() {
+ :
+}
+
case $1 in
- inc) pactl set-sink-volume @DEFAULT_SINK@ +$delta% ;;
- dec) pactl set-sink-volume @DEFAULT_SINK@ -$delta% ;;
- mutetoggle) pactl set-sink-mute @DEFAULT_SINK@ toggle ;;
- deafentoggle) pactl set-source-mute @DEFAULT_SOURCE@ toggle ;;
+ wifitoggle) toggle_wifi ;;
+ vpntoggle) toggle_vpn ;;
+ bluetoothtoggle) toggle_bluetooth ;;
+ isolatetoggle) toggle_network_quarantine ;;
*)
- echo Wifi:
- echo -e "\nBluetooth:"
- bluetoothctl show
- echo -e "\nEthernet:"
+ echo "invalid option :)"
;;
esac
diff --git a/local/bin/sb-network b/local/bin/sb-network
new file mode 100755
index 0000000..0bdbe82
--- /dev/null
+++ b/local/bin/sb-network
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# Prints some network connectivity status in emoji
+
+case $BLOCK_BUTTON in
+ 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" ;;
+ 2) wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
+ 4) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+ ;;
+ 5) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%- ;;
+ 3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted.
+- Middle click to mute.
+- Scroll to change." ;;
+ 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+
+set_wlan() {
+ nmcli_status=$(nmcli -t -f TYPE,STATE connection show --active)
+ wifi=$(echo $nmcli_status | grep -q "802-11-wireless:activated" && echo "📶")
+ vpn=$(echo $nmcli_status | grep -q "wireguard:activated" && echo "🔒")
+ wlan="$wifi$vpn"
+}
+
+
+set_bt() {
+ # If bluetooth is on, show number of connected devices and their initials
+ if ! bluetoothctl show | grep -q "Powered: yes"; then return; fi
+ ds=$(bluetoothctl devices Connected | cut -d ' ' -f 3-)
+ if [ -z "$ds" ]; then
+ bt=$(echo "🦷")
+ return
+ fi
+ N=$(echo "$ds" | wc -l)
+ ds=$(echo "$ds" | cut -c 1-3 | paste -sd ",")
+ bt=$(echo "🦷$N:$ds")
+}
+
+
+check_network_quarantine() {
+ # If all wireless devices are (software) blocked,
+ # change status bar icon and exit
+ if ! rfkill list | grep -q "Soft blocked: no"; then
+ echo "🗿"
+ exit
+ fi
+}
+
+
+check_network_quarantine
+set_wlan
+set_bt
+echo "$wlan$bt"