summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-05-02 17:14:58 +0200
committerLeah (ctucx) <leah@ctu.cx>2021-05-02 17:14:58 +0200
commitb7d7ffcbf06966a220c942f60809a660ef440bde (patch)
tree00e4781da415eda442a7145174f411ea18668875
parent8ec7c9c6ff0bb68979596577c30246fb5de491a6 (diff)
downloaddotfiles-b7d7ffcbf06966a220c942f60809a660ef440bde.tar.gz
dotfiles-b7d7ffcbf06966a220c942f60809a660ef440bde.tar.bz2
dotfiles-b7d7ffcbf06966a220c942f60809a660ef440bde.zip
.config/waybar: add wifi-connection menu to network-indicator
-rw-r--r--private_dot_config/waybar/config.tmpl2
-rw-r--r--private_dot_config/waybar/scripts/executable_nm-wifi-menu.sh89
2 files changed, 90 insertions, 1 deletions
diff --git a/private_dot_config/waybar/config.tmpl b/private_dot_config/waybar/config.tmpl
index 2e377e3..bd789f9 100644
--- a/private_dot_config/waybar/config.tmpl
+++ b/private_dot_config/waybar/config.tmpl
@@ -73,7 +73,7 @@
"format-linked": "",
"format-disconnected": "",
"tooltip-format": "{ifname}: {ipaddr}/{cidr}",
- "on-click": "nm-connection-editor"
+ "on-click": "~/.config/waybar/scripts/nm-wifi-menu.sh"
},
"pulseaudio": {
"scroll-step": 1,
diff --git a/private_dot_config/waybar/scripts/executable_nm-wifi-menu.sh b/private_dot_config/waybar/scripts/executable_nm-wifi-menu.sh
new file mode 100644
index 0000000..7865400
--- /dev/null
+++ b/private_dot_config/waybar/scripts/executable_nm-wifi-menu.sh
@@ -0,0 +1,89 @@
+#!/usr/bin/env bash
+
+# Source: https://github.com/fourstepper/wofi-wifi-menu
+# Starts a scan of available broadcasting SSIDs
+# nmcli dev wifi rescan
+
+FIELDS=SSID,SECURITY,BARS
+POSITION=3
+YOFF=10
+XOFF=-20
+
+LIST=$(nmcli --fields "$FIELDS" device wifi list | sed '/^--/d')
+# For some reason wofi always approximates character width 2 short... hmmm
+RWIDTH=$(($(echo "$LIST" | head -n 1 | awk '{print length($0); }')*10))
+# Dynamically change the height of the wofi menu
+LINENUM=$(echo "$LIST" | wc -l)
+# Gives a list of known connections so we can parse it later
+KNOWNCON=$(nmcli connection show)
+# Really janky way of telling if there is currently a connection
+CONSTATE=$(nmcli -fields WIFI g)
+
+CURRSSID=$(LANGUAGE=C nmcli -t -f active,ssid dev wifi | awk -F: '$1 ~ /^yes/ {print $2}')
+
+if [[ ! -z $CURRSSID ]]; then
+ HIGHLINE=$(echo "$(echo "$LIST" | awk -F "[ ]{2,}" '{print $1}' | grep -Fxn -m 1 "$CURRSSID" | awk -F ":" '{print $1}') + 1" | bc )
+fi
+
+# HOPEFULLY you won't need this as often as I do
+# If there are more than 8 SSIDs, the menu will still only have 8 lines
+if [ "$LINENUM" -gt 8 ] && [[ "$CONSTATE" =~ "enabled" ]]; then
+ LINENUM=8
+elif [[ "$CONSTATE" =~ "disabled" ]]; then
+ LINENUM=1
+fi
+
+
+if [[ "$CONSTATE" =~ "enabled" ]]; then
+ TOGGLE="toggle off"
+elif [[ "$CONSTATE" =~ "disabled" ]]; then
+ TOGGLE="toggle on"
+fi
+
+
+CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LIST" | uniq -u | wofi -i -d --prompt "Wi-Fi SSID: " --lines "$LINENUM" --location "$POSITION" --yoffset "$YOFF" --xoffset "$XOFF" --width $RWIDTH)
+#echo "$CHENTRY"
+CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $1}')
+#echo "$CHSSID"
+
+# If the user inputs "manual" as their SSID in the start window, it will bring them to this screen
+if [ "$CHENTRY" = "manual" ] ; then
+ # Manual entry of the SSID and password (if appplicable)
+ MSSID=$(echo "enter the SSID of the network (SSID,password)" | wofi -d "Manual Entry: " --lines 1)
+ # Separating the password from the entered string
+ MPASS=$(echo "$MSSID" | awk -F "," '{print $2}')
+
+ #echo "$MSSID"
+ #echo "$MPASS"
+
+ # If the user entered a manual password, then use the password nmcli command
+ if [ "$MPASS" = "" ]; then
+ nmcli dev wifi con "$MSSID"
+ else
+ nmcli dev wifi con "$MSSID" password "$MPASS"
+ fi
+
+elif [ "$CHENTRY" = "toggle on" ]; then
+ nmcli radio wifi on
+
+elif [ "$CHENTRY" = "toggle off" ]; then
+ nmcli radio wifi off
+
+else
+
+ # If the connection is already in use, then this will still be able to get the SSID
+ if [ "$CHSSID" = "*" ]; then
+ CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $3}')
+ fi
+
+ # Parses the list of preconfigured connections to see if it already contains the chosen SSID. This speeds up the connection process
+ if [[ $(echo "$KNOWNCON" | grep "$CHSSID") = "$CHSSID" ]]; then
+ nmcli con up "$CHSSID"
+ else
+ if [[ "$CHENTRY" =~ "WPA2" ]] || [[ "$CHENTRY" =~ "WEP" ]]; then
+ WIFIPASS=$(echo "if connection is stored, hit enter" | wofi -P -d --prompt "password" --lines 1 --location "$POSITION" --yoffset "$YOFF" --xoffset "$XOFF" --width $RWIDTH)
+ fi
+ nmcli dev wifi con "$CHSSID" password "$WIFIPASS"
+ fi
+
+fi