Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:sfalken
nmcli-rofi
nmcli-rofi-0.0.0.git~cb46668.obscpio
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File nmcli-rofi-0.0.0.git~cb46668.obscpio of Package nmcli-rofi
07070100000000000081A40000000000000000000000015EAF208600000448000000000000000000000000000000000000002500000000nmcli-rofi-0.0.0.git~cb46668/LICENSEThe MIT License (MIT) Copyright (c) 2018 Sinésio Santos da Silva Neto Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 07070100000001000081A40000000000000000000000015EAF208600000444000000000000000000000000000000000000002700000000nmcli-rofi-0.0.0.git~cb46668/README.md# nmcli-rofi A simple manager for network connections using [rofi](https://github.com/DaveDavenport/rofi) and [nmcli](https://jlk.fjfi.cvut.cz/arch/manpages/man/nmcli.1). Strongly inspired/based on [rofi-wifi-menu](https://github.com/zbaylin/rofi-wifi-menu). Most of the code (I would say all code) was copied from the original creator. I've only refactored the code to improve performance and easily add new features. ## Features * Disable/Enable device * Connect to existing network * Disconnect from active networking * Requests password * Manual Connections * Resquest SSID and Password of the network * External source config ## Requirements * NetworkManager (nmcli) * Rofi * wireless_tools ## Usage ### To use with click event on polybar ``` [module/network] type = internal/network ... format-connected = %{A1:$HOME/.config/polybar/scripts/nmcli-rofi:}<ramp-signal>%{A} format-disconnected = %{A1:$HOME/.config/polybar/scripts/nmcli-rofi:}icon-or-label%{A} ... ``` ### To use with i3wm keybinding ``` bindsym $mod+n exec /path/to/nmcli-rofi ``` Replace modifier if you need 07070100000002000081A40000000000000000000000015EAF208600000114000000000000000000000000000000000000002400000000nmcli-rofi-0.0.0.git~cb46668/config# Config for rofi-wifi-menu NMCLI_ROFI_SOURCE=$HOME/config # position values: # 1 2 3 # 8 0 4 # 7 6 5 POSITION=3 #y-offset YOFF=30 #x-offset XOFF=0 #window width correction MAGIC=-5 #fields to be displayed FIELDS=SSID,SECURITY,BARS #font FONT="DejaVu Sans Mono Bold 12" 07070100000003000081ED0000000000000000000000015EAF20860000144F000000000000000000000000000000000000002800000000nmcli-rofi-0.0.0.git~cb46668/nmcli-rofi#!/usr/bin/env bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # default config FIELDS=SSID,SECURITY,BARS POSITION=0; XOFF=0; YOFF=0 MAGIC=-4 FONT="DejaVu Sans Mono Bold 14" # supported locales (en, ru, de, fr, hi, ja) declare -A LOC_ENABLE=(["en"]="enabled" ["ru"]="включен" ["de"]="aktiviert" ["fr"]="activé" ["hi"]="सक्षम" ["ja"]="有効") # get current locale CURRLOCALE=$(locale | grep 'LANG=[a-z]*' -o | sed 's/^LANG=//g') # 'enabled' in currnet locale ENABLED="${LOC_ENABLE["$CURRLOCALE"]}" # get current uuid CURRUUID=$(nmcli -f UUID,TYPE con show --active | grep wifi | awk '{print $1}') # get wifi state function wifistate () { echo "$(nmcli -fields WIFI g | sed -n 2p)" } # get active wifi connections function wifiactive () { echo "$(nmcli con show --active | grep wifi)" } function if_wifistate () { # return a expression based on wifi state [[ "$(wifistate)" =~ $ENABLED ]] && rt=$1 || rt=$2 echo $rt } function toggle_wifi () { toggle=$(if_wifistate "Disable Network" "Enable Network") echo $toggle } function current_connection () { currssid=$(iwgetid -r) [[ "$currssid" != '' ]] && currcon="Disconnect from $currssid" || currcon="" echo $currcon } function nmcli_list () { # get list of available connections without the active connection (if it's connected) echo "$(nmcli --fields IN-USE,"$FIELDS" device wifi list | sed "s/^IN-USE\s//g" | sed '/*/d' | sed 's/^ *//')" } function count_lines () { echo "$1" | wc -l } function linenum () { wa=$(wifiactive) list_lines_num=$(count_lines "$1") [[ "$wa" != '' ]] && ops=4 || ops=3 lines=$(if_wifistate "$(($list_lines_num+$ops))" 1) echo $lines } function rwidth () { rwidth=$(echo "$1" | head -n 1 | awk '{print length($0); }') [[ $rwidth -lt ${#2} ]] && rwidth=${#2} [[ $rwidth -lt ${#3} ]] && rwidth=${#3} let rwidth=$rwidth+$MAGIC echo $rwidth } function menu () { wa=$(wifiactive); ws=$(wifistate); if [[ $ws =~ $ENABLED ]]; then if [[ "$wa" != '' ]]; then echo "$1\n\n$2\n$3\nManual Connection" else echo "$1\n\n$3\nManual Connection" fi else echo "$3" fi } function rofi_cmd () { # don't repeat lines with uniq -u echo -e "$1" | uniq -u | rofi -dmenu -p "Wi-Fi SSID" -lines "$LINENUM" \ -location "$POSITION" -yoffset "$YOFF" -xoffset "$XOFF" -font "$FONT" -width "$RWIDTH" } function rofi_menu () { TOGGLE=$(toggle_wifi) CURRCONNECT=$(current_connection) [[ "$TOGGLE" =~ 'Enable' ]] && LIST="" || LIST=$(nmcli_list) MENU=$(menu "$LIST" "$CURRCONNECT" "$TOGGLE") LINENUM=$(linenum "$LIST") RWIDTH=$(rwidth "$LIST" "$TOGGLE" "$CURRCONNECT") rofi_cmd "$MENU" } function get_ssid () { # get fields in order eval FIELDSARR=( $(cat $NMCLI_ROFI_SOURCE | awk 'BEGIN { FS=","; OFS="\n" } /^FIELDS/ \ { $1 = substr($1, 8); print $0; }') ) # get position of SSID field for i in "${!FIELDSARR[@]}"; do if [[ "${FIELDSARR[$i]}" = "SSID" ]]; then SSID_POS="${i}"; fi done # let for arithmetical vars let AWKSSIDPOS=$SSID_POS+1 # get SSID from AWKSSIDPOS CHSSID=$(echo "$1" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $'$AWKSSIDPOS'}') 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 main () { if [ -r "$DIR/config" ]; then source "$DIR/config" elif [ -r "$HOME/.config/rofi/wifi" ]; then source "$HOME/.config/rofi/wifi" else echo "WARNING: config file not found! Using default values." fi OPS=$(rofi_menu) CHSSID=$(get_ssid "$OPS") if [[ "$OPS" =~ 'Disable' ]]; then nmcli radio wifi off elif [[ "$OPS" =~ 'Enable' ]]; then nmcli radio wifi on elif [[ "$OPS" =~ 'Disconnect' ]]; then nmcli con down uuid $CURRUUID elif [[ "$OPS" =~ 'Manual' ]]; then # Manual entry of the SSID 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") # If the user entered a manual password, then use the password nmcli command if [ "$MPASS" = "" ]; then nmcli dev wifi con "$MSSID" elif [ "$MSSID" != '' ] && [ "$MPASS" != '' ]; then nmcli dev wifi con "$MSSID" password "$MPASS" 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") fi if [[ "$CHSSID" != '' ]] && [[ "$WIFIPASS" != '' ]]; then nmcli dev wifi con "$CHSSID" password "$WIFIPASS" fi fi } # clean up obsoleted connections # nmcli --fields UUID,TIMESTAMP-REAL,DEVICE con show | grep never | awk '{print $1}' | while read line; do nmcli con delete uuid $line; done main 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!17 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor