From a42df546ce34429759a20bc2c4c240de045dbd0a Mon Sep 17 00:00:00 2001 From: Shubham Saini Date: Mon, 2 Dec 2019 17:51:04 +0530 Subject: using stow --- rofi/.config/rofi/config | 11 ++++ rofi/.config/rofi/rofi-power.sh | 38 ++++++++++++++ rofi/.config/rofi/rofi-wifi.sh | 108 ++++++++++++++++++++++++++++++++++++++++ rofi/.config/rofi/wifi | 19 +++++++ 4 files changed, 176 insertions(+) create mode 100644 rofi/.config/rofi/config create mode 100755 rofi/.config/rofi/rofi-power.sh create mode 100755 rofi/.config/rofi/rofi-wifi.sh create mode 100644 rofi/.config/rofi/wifi (limited to 'rofi/.config') diff --git a/rofi/.config/rofi/config b/rofi/.config/rofi/config new file mode 100644 index 0000000..b096ad7 --- /dev/null +++ b/rofi/.config/rofi/config @@ -0,0 +1,11 @@ +rofi.theme: ~/.cache/wal/colors-rofi-dark.rasi +rofi.lines: 6 +!rofi.separator-style: none +!rofi.columns: 1 +rofi.font: Hermit 12 +!rofi.bw: 0 +!rofi.eh: 2 +!rofi.hide-scrollbar: true +rofi.auto-select: false +!rofi.display-drun:? + diff --git a/rofi/.config/rofi/rofi-power.sh b/rofi/.config/rofi/rofi-power.sh new file mode 100755 index 0000000..2b6f3ab --- /dev/null +++ b/rofi/.config/rofi/rofi-power.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +OPTIONS="Reboot\nShut-down\nSuspend\nLock" + +# source configuration or use default values + LAUNCHER="rofi -location 5 -width 15 -lines 4 -dmenu -i -p power -show-icons " + USE_LOCKER="true" + LOCKER="/home/ssaini/.config/lock.sh" + + +# Show exit wm option if exit command is provided as an argument +if [ ${#1} -gt 0 ]; then + OPTIONS="Exit window manager\n$OPTIONS" +fi + +option=`echo -e $OPTIONS | $LAUNCHER | awk '{print $1}' | tr -d '\r\n'` +if [ ${#option} -gt 0 ] +then + case $option in + Exit) + eval $1 + ;; + Reboot) + sudo reboot + ;; + Shut-down) + sudo poweroff + ;; + Suspend) + sudo zzz + ;; + Lock) + /home/ssaini/.config/lock.sh + ;; + *) + ;; + esac +fi diff --git a/rofi/.config/rofi/rofi-wifi.sh b/rofi/.config/rofi/rofi-wifi.sh new file mode 100755 index 0000000..938fa48 --- /dev/null +++ b/rofi/.config/rofi/rofi-wifi.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Starts a scan of available broadcasting SSIDs +# nmcli dev wifi rescan + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +FIELDS=SSID,SECURITY +POSITION=5 +#YOFF=-40 +#XOFF=-120 +FONT="Hermit 10" + +if [ -r "$DIR/config" ]; then + source ./config +elif [ -r "~/.config/rofi/config" ]; then + source "~/.config/rofi/config" +else + echo "WARNING: config file not found! Using default values." +fi + +LIST=$(nmcli --fields "$FIELDS" device wifi list | sed '/^--/d') +# For some reason rofi always approximates character width 2 short... hmmm +RWIDTH=$(($(echo "$LIST" | head -n 1 | awk '{print length($0); }')+2)) +# Dynamically change the height of the rofi 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=$(iwgetid -r) + +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 + +eval FIELDSARR=( $(cat ./config | awk 'BEGIN { FS=","; OFS="\n" } /^FIELDS/ { $1 = substr($1, 8); print $0; }') ) + +for i in "${!FIELDSARR[@]}"; do + if [[ "${FIELDSARR[$i]}" = "SSID" ]]; then + SSID_POS="${i}"; + fi +done + +let AWKSSIDPOS=$SSID_POS+1 + +CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LIST" | uniq -u | rofi -dmenu -p "Wi-Fi SSID: " -lines "$LINENUM" -a "$HIGHLINE" -location "$POSITION" -yoffset "$YOFF" -xoffset "$XOFF" -font "$FONT" -width -"$RWIDTH") +#echo "$CHENTRY" +CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $'$AWKSSIDPOS'}') +#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)" | rofi -dmenu -p "Manual Entry: " -font "$FONT" -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" | rofi -dmenu -p "password: " -lines 1 -font "$FONT" ) + fi + nmcli dev wifi con "$CHSSID" password "$WIFIPASS" + fi + +fi diff --git a/rofi/.config/rofi/wifi b/rofi/.config/rofi/wifi new file mode 100644 index 0000000..954e4ae --- /dev/null +++ b/rofi/.config/rofi/wifi @@ -0,0 +1,19 @@ +# Config for rofi-wifi-menu + +# position values: +# 1 2 3 +# 8 0 4 +# 7 6 5 +POSITION=3 + +#y-offset +YOFF=17 + +#x-offset +XOFF=0 + +#fields to be displayed +FIELDS=SSID,SECURITY,BARS + +#font +FONT="Source Code Pro 12" -- cgit v1.2.3