Improved Wifi menu
This commit is contained in:
parent
20757931d0
commit
1ec8462e91
|
@ -7,17 +7,8 @@
|
|||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
FIELDS=SSID,SECURITY
|
||||
FIELDS=SECURITY,SSID
|
||||
|
||||
if [ -r "$DIR/config" ]; then
|
||||
source "$DIR/config"
|
||||
elif [ -r "$HOME/.dotfiles/wofi/wifi" ]; then
|
||||
source "$HOME/.dotfiles/wofi/wifi"
|
||||
else
|
||||
echo "WARNING: config file not found! Using default values."
|
||||
fi
|
||||
|
||||
LIST=$(nmcli --fields "$FIELDS" device wifi list | sed '/^--/d')
|
||||
# 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
|
||||
|
@ -25,9 +16,7 @@ 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
|
||||
LIST=$(nmcli --fields "$FIELDS" device wifi list | sort | uniq | sed -r '/^SECURITY *SSID/d' | sed '/ --/d' | sed "/$CURRSSID/d" | sed -r 's/((WPA[123]|WEP) )+ */ /g')
|
||||
|
||||
if [[ "$CONSTATE" =~ "enabled" ]]; then
|
||||
TOGGLE="toggle off"
|
||||
|
@ -35,24 +24,27 @@ elif [[ "$CONSTATE" =~ "disabled" ]]; then
|
|||
TOGGLE="toggle on"
|
||||
fi
|
||||
|
||||
CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LIST" | uniq -u | wofi -s $HOME/.dotfiles/wofi/style.css -i -d --prompt "Wi-Fi SSID: " -c $HOME/.dotfiles/wofi/sidebar)
|
||||
HEIGHT=$(swaymsg -t get_outputs | tr '\n' ' ' | sed -e 's/ */ /g' | sed -e 's/\(.*"focused": [a-z]*\),/\1\n/' | less | grep '"focused": true' | sed -e 's/.*"rect": {[^}]*"height": \([0-9]*\).*/\1/')
|
||||
|
||||
CURR=''
|
||||
if [ ! -z "$CURRSSID" ]; then
|
||||
CURR=" $CURRSSID\n"
|
||||
fi
|
||||
|
||||
CHENTRY=$(echo -e "${TOGGLE}\nmanual\n${CURR}${LIST}" | uniq -u | ${HOME}/.local/bin/tofi --prompt-text "Wi-Fi: " --height $HEIGHT --width 340 -c $HOME/.dotfiles/tofi/sidebar.toml)
|
||||
if [[ $CHENTRY == "" ]]; then
|
||||
exit
|
||||
fi
|
||||
#echo "$CHENTRY"
|
||||
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $1}')
|
||||
#echo "$CHSSID"
|
||||
|
||||
CHSSID=$(echo "$CHENTRY" | sed -e 's/\([]\) //g' | sed -e 's/ *$//g')
|
||||
|
||||
# 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 -s $HOME/.dotfiles/wofi/style.css -d "Manual Entry: " -c $HOME/.dotfiles/wofi/sidebar)
|
||||
MSSID=$(echo "enter the SSID of the network (SSID,password)" | ${HOME}/.local/bin/tofi --prompt-text "Password" --height $HEIGHT --width 340 -c $HOME/.dotfiles/tofi/sidebar.toml)
|
||||
# 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"
|
||||
|
@ -67,20 +59,15 @@ 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
|
||||
if grep -q "$CHSSID" <<< `echo $KNOWNCON`; then
|
||||
nmcli con up "$CHSSID"
|
||||
else
|
||||
if [[ "$CHENTRY" =~ "WPA2" ]] || [[ "$CHENTRY" =~ "WEP" ]]; then
|
||||
WIFIPASS=$(echo "if connection is stored, hit enter" | wofi -s $HOME/.dotfiles/wofi/style.css -P -d --prompt "password" -c $HOME/.dotfiles/wofi/sidebar)
|
||||
if [[ "$CHENTRY" =~ "" ]]; then
|
||||
WIFIPASS=$(echo "" | ${HOME}/.local/bin/tofi --prompt-text "Password" --height $HEIGHT --width 340 -c $HOME/.dotfiles/tofi/sidebar.toml)
|
||||
if [[ $WIFIPASS == "if connection is stored, hit enter" ]]; then
|
||||
unset WIFIPASS
|
||||
fi
|
||||
fi
|
||||
nmcli dev wifi con "$CHSSID" password "$WIFIPASS"
|
||||
fi
|
||||
|
||||
fi
|
Loading…
Reference in New Issue