Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions nmcli-rofi
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function rofi_menu () {
rofi_cmd "$MENU"
}

function get_ssid () {
function get_ssid_device () {
# get fields in order
eval FIELDSARR=( $(cat $NMCLI_ROFI_SOURCE | awk 'BEGIN { FS=","; OFS="\n" } /^FIELDS/ \
{ $1 = substr($1, 8); print $0; }') )
Expand All @@ -116,18 +116,24 @@ function get_ssid () {
done

# let for arithmetical vars
let AWKSSIDPOS=$SSID_POS+1
let AWKFIELDPOS=$SSID_POS+$2

# get SSID from AWKSSIDPOS
CHSSID=$(echo "$1" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $'$AWKSSIDPOS'}')
echo "$CHSSID"
CHSSID=$(echo "$1" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $'$AWKFIELDPOS'}')

echo "$CHSSID"
}

function cleanup_networks () {
nmcli --fields UUID,TIMESTAMP-REAL,DEVICE con show | grep -e '--' | awk '{print $1}' \
| while read line; do nmcli con delete uuid $line; done
}

function get_available_connections() {
avail_conn=$(nmcli connection show | cut -d" " -f1 | tail -n +2)
echo $avail_conn
}

function main () {
if [ -r "$DIR/config" ]; then
source "$DIR/config"
Expand All @@ -138,11 +144,28 @@ function main () {
fi

OPS=$(rofi_menu)
CHSSID=$(get_ssid "$OPS")
CHSSID=$(get_ssid_device "$OPS", 1)
CHDEV=$(get_ssid_device "$OPS", 3)
AVALABLE_CONNECTIONS=$(get_available_connections)

if [[ "$OPS" =~ 'Disable' ]]; then
nmcli radio wifi off


elif [[ "$CHSSID" == '--' ]]; then
MSSID=$(echo -en "" | rofi -dmenu -p "SSID: " -mesg "Enter the SSID of the network" \
-lines 0 -font "$FONT")

# manual entry of the PASSWORD
MPASS=$(echo -en "" | rofi -dmenu -password -p "PASSWORD: " -mesg \
"Enter the PASSWORD of the network" -lines 0 -font "$FONT")

nmcli c del "$MSSID"
nmcli c add type wifi con-name "$MSSID" ifname "$CHDEV" ssid "$MSSID"
nmcli c modify "$MSSID" wifi-sec.key-mgmt wpa-psk
nmcli c modify "$MSSID" wifi-sec.psk "$MPASS"
nmcli c u "$MSSID"

elif [[ "$OPS" =~ 'Enable' ]]; then
nmcli radio wifi on

Expand All @@ -151,28 +174,36 @@ function main () {

elif [[ "$OPS" =~ 'Manual' ]]; then
# Manual entry of the SSID
MSSID=$(echo -en "" | rofi -dmenu -p "SSID" -mesg "Enter the SSID of the network" \
MSSID=$(echo -en "" | rofi -dmenu -p "SSID: " -mesg "Enter the SSID of the network" \
-lines 0 -font "$FONT")

# manual entry of the PASSWORD
MPASS=$(echo -en "" | rofi -dmenu -password -p "PASSWORD" -mesg \
MPASS=$(echo -en "" | rofi -dmenu -password -p "PASSWORD: " -mesg \
"Enter the PASSWORD of the network" -lines 0 -font "$FONT")

# If the user entered a manual password, then use the password nmcli command
if [ "$MPASS" = "" ]; then
nmcli dev wifi con "$MSSID"
nmcli dev wifi con "$MSSID" ifname "$CHDEV"
elif [ "$MSSID" != '' ] && [ "$MPASS" != '' ]; then
nmcli dev wifi con "$MSSID" password "$MPASS"
nmcli dev wifi con "$MSSID" password "$MPASS" ifname "$CHDEV"
fi

else
if [[ "$OPS" =~ "WPA2" ]] || [[ "$OPS" =~ "WEP" ]]; then
WIFIPASS=$(echo -en "" | rofi -dmenu -password -p "PASSWORD" \
-mesg "Enter the PASSWORD of the network" -lines 0 -font "$FONT")
if [[ `echo "$AVALABLE_CONNECTIONS" |grep -w "$CHSSID"` ]]; then
nmcli c u "$CHSSID"
else
WIFIPASS=$(echo -en "" | rofi -dmenu -password -p "PASSWORD: " \
-mesg "Enter the PASSWORD of the network" -lines 0 -font "$FONT")

if [[ "$CHSSID" != '' ]] && [[ "$WIFIPASS" != '' ]]; then
nmcli dev wifi con "$CHSSID" password "$WIFIPASS" ifname "$CHDEV"
fi
fi
fi

if [[ "$CHSSID" != '' ]] && [[ "$WIFIPASS" != '' ]]; then
nmcli dev wifi con "$CHSSID" password "$WIFIPASS"
nmcli dev wifi con "$CHSSID" password "$WIFIPASS" ifname "$CHDEV"
fi
fi
}
Expand Down