added rofi scripts
This commit is contained in:
parent
2f4693acc4
commit
18b8db6c31
7 changed files with 2434 additions and 0 deletions
315
user/.config/rofi/scripts/rofi_blue
Executable file
315
user/.config/rofi/scripts/rofi_blue
Executable file
|
@ -0,0 +1,315 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# __ _ _ _ _ _ _
|
||||||
|
# _ __ ___ / _(_) | |__ | |_ _ ___| |_ ___ ___ | |_| |__
|
||||||
|
# | '__/ _ \| |_| |_____| '_ \| | | | |/ _ \ __/ _ \ / _ \| __| '_ \
|
||||||
|
# | | | (_) | _| |_____| |_) | | |_| | __/ || (_) | (_) | |_| | | |
|
||||||
|
# |_| \___/|_| |_| |_.__/|_|\__,_|\___|\__\___/ \___/ \__|_| |_|
|
||||||
|
#
|
||||||
|
# Author: Nick Clyde (clydedroid)
|
||||||
|
# rofi support by: Layerex
|
||||||
|
#
|
||||||
|
# A script that generates a rofi menu that uses bluetoothctl to
|
||||||
|
# connect to bluetooth devices and display status info.
|
||||||
|
#
|
||||||
|
# Depends on:
|
||||||
|
# Arch repositories: rofi, bluez-utils (contains bluetoothctl)
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
divider="---------"
|
||||||
|
goback="Back"
|
||||||
|
|
||||||
|
# Checks if bluetooth controller is powered on
|
||||||
|
power_on() {
|
||||||
|
if bluetoothctl show | grep -F -q "Powered: yes"; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Toggles power state
|
||||||
|
toggle_power() {
|
||||||
|
if power_on; then
|
||||||
|
bluetoothctl power off
|
||||||
|
show_menu
|
||||||
|
else
|
||||||
|
if rfkill list bluetooth | grep -F -q 'blocked: yes'; then
|
||||||
|
rfkill unblock bluetooth && sleep 3
|
||||||
|
fi
|
||||||
|
bluetoothctl power on
|
||||||
|
show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks if controller is scanning for new devices
|
||||||
|
scan_on() {
|
||||||
|
if bluetoothctl show | grep -F -q "Discovering: yes"; then
|
||||||
|
echo "Scan: on"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Scan: off"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Toggles scanning state
|
||||||
|
toggle_scan() {
|
||||||
|
if scan_on; then
|
||||||
|
kill "$(pgrep -F -f "bluetoothctl scan on")"
|
||||||
|
bluetoothctl scan off
|
||||||
|
show_menu
|
||||||
|
else
|
||||||
|
bluetoothctl scan on &
|
||||||
|
echo "Scanning..."
|
||||||
|
sleep 5
|
||||||
|
show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks if controller is able to pair to devices
|
||||||
|
pairable_on() {
|
||||||
|
if bluetoothctl show | grep -F -q "Pairable: yes"; then
|
||||||
|
echo "Pairable: on"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Pairable: off"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Toggles pairable state
|
||||||
|
toggle_pairable() {
|
||||||
|
if pairable_on; then
|
||||||
|
bluetoothctl pairable off
|
||||||
|
show_menu
|
||||||
|
else
|
||||||
|
bluetoothctl pairable on
|
||||||
|
show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks if controller is discoverable by other devices
|
||||||
|
discoverable_on() {
|
||||||
|
if bluetoothctl show | grep -F -q "Discoverable: yes"; then
|
||||||
|
echo "Discoverable: on"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Discoverable: off"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Toggles discoverable state
|
||||||
|
toggle_discoverable() {
|
||||||
|
if discoverable_on; then
|
||||||
|
bluetoothctl discoverable off
|
||||||
|
show_menu
|
||||||
|
else
|
||||||
|
bluetoothctl discoverable on
|
||||||
|
show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks if a device is connected
|
||||||
|
device_connected() {
|
||||||
|
device_info=$(bluetoothctl info "$1")
|
||||||
|
if echo "$device_info" | grep -F -q "Connected: yes"; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Toggles device connection
|
||||||
|
toggle_connection() {
|
||||||
|
if device_connected "$1"; then
|
||||||
|
bluetoothctl disconnect "$1"
|
||||||
|
# device_menu "$device"
|
||||||
|
else
|
||||||
|
bluetoothctl connect "$1"
|
||||||
|
# device_menu "$device"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks if a device is paired
|
||||||
|
device_paired() {
|
||||||
|
device_info=$(bluetoothctl info "$1")
|
||||||
|
if echo "$device_info" | grep -F -q "Paired: yes"; then
|
||||||
|
echo "Paired: yes"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Paired: no"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Toggles device paired state
|
||||||
|
toggle_paired() {
|
||||||
|
if device_paired "$1"; then
|
||||||
|
bluetoothctl remove "$1"
|
||||||
|
device_menu "$device"
|
||||||
|
else
|
||||||
|
bluetoothctl pair "$1"
|
||||||
|
device_menu "$device"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks if a device is trusted
|
||||||
|
device_trusted() {
|
||||||
|
device_info=$(bluetoothctl info "$1")
|
||||||
|
if echo "$device_info" | grep -F -q "Trusted: yes"; then
|
||||||
|
echo "Trusted: yes"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Trusted: no"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Toggles device connection
|
||||||
|
toggle_trust() {
|
||||||
|
if device_trusted "$1"; then
|
||||||
|
bluetoothctl untrust "$1"
|
||||||
|
device_menu "$device"
|
||||||
|
else
|
||||||
|
bluetoothctl trust "$1"
|
||||||
|
device_menu "$device"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prints a short string with the current bluetooth status
|
||||||
|
# Useful for status bars like polybar, etc.
|
||||||
|
print_status() {
|
||||||
|
if power_on; then
|
||||||
|
printf ''
|
||||||
|
|
||||||
|
mapfile -t paired_devices < <(bluetoothctl paired-devices | grep -F Device | cut -d ' ' -f 2)
|
||||||
|
counter=0
|
||||||
|
|
||||||
|
for device in "${paired_devices[@]}"; do
|
||||||
|
if device_connected "$device"; then
|
||||||
|
device_alias="$(bluetoothctl info "$device" | grep -F "Alias" | cut -d ' ' -f 2-)"
|
||||||
|
|
||||||
|
if [ $counter -gt 0 ]; then
|
||||||
|
printf ", %s" "$device_alias"
|
||||||
|
else
|
||||||
|
printf " %s" "$device_alias"
|
||||||
|
fi
|
||||||
|
|
||||||
|
((counter++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
printf "\n"
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# A submenu for a specific device that allows connecting, pairing, and trusting
|
||||||
|
device_menu() {
|
||||||
|
device=$1
|
||||||
|
|
||||||
|
# Get device name and mac address
|
||||||
|
device_name="$(echo "$device" | cut -d ' ' -f 3-)"
|
||||||
|
mac="$(echo "$device" | cut -d ' ' -f 2)"
|
||||||
|
|
||||||
|
# Build options
|
||||||
|
if device_connected "$mac"; then
|
||||||
|
connected="Connected: yes"
|
||||||
|
else
|
||||||
|
connected="Connected: no"
|
||||||
|
fi
|
||||||
|
paired=$(device_paired "$mac")
|
||||||
|
trusted=$(device_trusted "$mac")
|
||||||
|
options="$connected\n$paired\n$trusted\n$divider\n$goback\nExit"
|
||||||
|
|
||||||
|
# Open rofi menu, read chosen option
|
||||||
|
chosen="$(echo -e "$options" | run_rofi "$device_name")"
|
||||||
|
|
||||||
|
# Match chosen option to command
|
||||||
|
case $chosen in
|
||||||
|
"" | "$divider")
|
||||||
|
echo "No option chosen."
|
||||||
|
;;
|
||||||
|
"$connected")
|
||||||
|
toggle_connection "$mac"
|
||||||
|
;;
|
||||||
|
"$paired")
|
||||||
|
toggle_paired "$mac"
|
||||||
|
;;
|
||||||
|
"$trusted")
|
||||||
|
toggle_trust "$mac"
|
||||||
|
;;
|
||||||
|
"$goback")
|
||||||
|
show_menu
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Opens a rofi menu with current bluetooth status and options to connect
|
||||||
|
show_menu() {
|
||||||
|
# Get menu options
|
||||||
|
if power_on; then
|
||||||
|
power="Power: on"
|
||||||
|
|
||||||
|
# Human-readable names of devices, one per line
|
||||||
|
# If scan is off, will only list paired devices
|
||||||
|
devices=$(bluetoothctl devices | grep -F Device | cut -d ' ' -f 3-)
|
||||||
|
|
||||||
|
# Get controller flags
|
||||||
|
scan=$(scan_on)
|
||||||
|
pairable=$(pairable_on)
|
||||||
|
discoverable=$(discoverable_on)
|
||||||
|
|
||||||
|
# Options passed to rofi
|
||||||
|
options="$devices\n$divider\n$power\n$scan\n$pairable\n$discoverable\nExit"
|
||||||
|
else
|
||||||
|
power="Power: off"
|
||||||
|
options="$power\nExit"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Open rofi menu, read chosen option
|
||||||
|
chosen="$(echo -e "$options" | run_rofi "Bluetooth")"
|
||||||
|
|
||||||
|
# Match chosen option to command
|
||||||
|
case $chosen in
|
||||||
|
"" | "$divider")
|
||||||
|
echo "No option chosen."
|
||||||
|
;;
|
||||||
|
"$power")
|
||||||
|
toggle_power
|
||||||
|
;;
|
||||||
|
"$scan")
|
||||||
|
toggle_scan
|
||||||
|
;;
|
||||||
|
"$discoverable")
|
||||||
|
toggle_discoverable
|
||||||
|
;;
|
||||||
|
"$pairable")
|
||||||
|
toggle_pairable
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
device=$(bluetoothctl devices | grep -F "$chosen")
|
||||||
|
# Open a submenu if a device is selected
|
||||||
|
if [[ $device ]]; then device_menu "$device"; fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
original_args=("$@")
|
||||||
|
|
||||||
|
# rofi command to pipe into. Extra arguments to rofi_blue are passed through to rofi. This
|
||||||
|
# allows the user to set fonts, sizes, colours, etc.
|
||||||
|
run_rofi() {
|
||||||
|
rofi -dmenu "${original_args[@]}" -b -l 5 -i -p "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
--status)
|
||||||
|
print_status
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
show_menu
|
||||||
|
;;
|
||||||
|
esac
|
26
user/.config/rofi/scripts/rofi_edit
Executable file
26
user/.config/rofi/scripts/rofi_edit
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ***This script was made by Clay Gomera (Drake)***
|
||||||
|
# - Description: A simple script for file editing in rofi
|
||||||
|
# - Dependencies: rofi (Everything else can be changed)
|
||||||
|
|
||||||
|
# Show list of options
|
||||||
|
EDITOR="emacsclient -c -a emacs"
|
||||||
|
cd "$HOME" || exit 0
|
||||||
|
file=1
|
||||||
|
while [ "$file" ]; do
|
||||||
|
file=$(fd -LHpd 1 | rofi -dmenu -b -l 10 -p "File to edit: $(basename $(pwd))")
|
||||||
|
if [ -e "$file" ]; then
|
||||||
|
owd=$(pwd)
|
||||||
|
if [ -d "$file" ]; then
|
||||||
|
cd "$file" || exit 0
|
||||||
|
else [ -f "$file" ]
|
||||||
|
if [ "$file" ]; then
|
||||||
|
$EDITOR "$owd/$file" &
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
1839
user/.config/rofi/scripts/rofi_emoji
Executable file
1839
user/.config/rofi/scripts/rofi_emoji
Executable file
File diff suppressed because it is too large
Load diff
56
user/.config/rofi/scripts/rofi_power
Executable file
56
user/.config/rofi/scripts/rofi_power
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ***This script was made by Clay Gomera (Drake)***
|
||||||
|
# - Description: A simple power menu rofi script
|
||||||
|
# - Dependencies: rofi, power-profiles-daemon
|
||||||
|
|
||||||
|
## OPTIONS ##
|
||||||
|
option1="(L) Logout"
|
||||||
|
option2="(R) Reboot"
|
||||||
|
option3="(P) Power off"
|
||||||
|
option4="(S) Suspend"
|
||||||
|
option5="(K) Lock"
|
||||||
|
option6="(C) Change power profile"
|
||||||
|
option7="(X) Cancel"
|
||||||
|
|
||||||
|
## OPTIONS ARRAY ##
|
||||||
|
options="$option1\n$option2\n$option3\n$option4\n$option5\n$option6\n$option7"
|
||||||
|
|
||||||
|
## POWER PROFILE OPTIONS ##
|
||||||
|
pwr1="(P) Performance"
|
||||||
|
pwr2="(B) Balanced"
|
||||||
|
pwr3="(S) Power Saver"
|
||||||
|
pwr4="(X) Cancel"
|
||||||
|
|
||||||
|
## POWER PROFILES ARRAY ##
|
||||||
|
pwrs="$pwr1\n$pwr2\n$pwr3\n$pwr4"
|
||||||
|
|
||||||
|
## MAIN ACTION COMMAND ##
|
||||||
|
action=$(echo -e "$options" | rofi -dmenu -b -i -p " ")
|
||||||
|
case "$action" in
|
||||||
|
$option1*)
|
||||||
|
whoami | xargs -I % sh -c 'pkill -KILL -u %';;
|
||||||
|
$option2*)
|
||||||
|
systemctl reboot;;
|
||||||
|
$option3*)
|
||||||
|
systemctl poweroff;;
|
||||||
|
$option4*)
|
||||||
|
betterlockscreen --suspend;;
|
||||||
|
$option5*)
|
||||||
|
betterlockscreen -l;;
|
||||||
|
$option6*)
|
||||||
|
currentpwr=$(powerprofilesctl get)
|
||||||
|
pwraction=$(echo -e "$pwrs" | rofi -dmenu -b -i -p "Current profile is: ${currentpwr} | Select profile:")
|
||||||
|
case "$pwraction" in
|
||||||
|
$pwr1*)
|
||||||
|
powerprofilesctl set performance && notify-send "Power profile switched to performance";;
|
||||||
|
$pwr2*)
|
||||||
|
powerprofilesctl set balanced && notify-send "Power profile switched to balanced";;
|
||||||
|
$pwr3*)
|
||||||
|
powerprofilesctl set power-saver && notify-send "Power profile switched to power saver";;
|
||||||
|
$pwr4*)
|
||||||
|
exit 0
|
||||||
|
esac;;
|
||||||
|
$option7*)
|
||||||
|
exit 0
|
||||||
|
esac
|
63
user/.config/rofi/scripts/rofi_scrot
Executable file
63
user/.config/rofi/scripts/rofi_scrot
Executable file
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ***This script was made by Clay Gomera (Drake)***
|
||||||
|
# - Description: A simple screenshot dmenu script
|
||||||
|
# - Dependencies: scrot, dmenu, notify-send
|
||||||
|
|
||||||
|
## CREATING SCREENSHOT FOLDER ##
|
||||||
|
mkdir -p "$HOME/Pictures/Screenshots"
|
||||||
|
cd "$HOME/Pictures/Screenshots" || exit 0
|
||||||
|
|
||||||
|
## CHOICES ##
|
||||||
|
cho1="(S) Entire screen"
|
||||||
|
cho2="(D) Entire screen with delay"
|
||||||
|
cho3="(W) Focused window"
|
||||||
|
cho4="(A) Select area"
|
||||||
|
chos="$cho1\n$cho2\n$cho3\n$cho4"
|
||||||
|
|
||||||
|
## DELAY OPTIONS ##
|
||||||
|
del1="(1) 3 sec delay"
|
||||||
|
del2="(2) 5 sec delay"
|
||||||
|
del3="(3) 10 sec delay"
|
||||||
|
dels="$del1\n$del2\n$del3"
|
||||||
|
|
||||||
|
## DELAY FUNCTION ##
|
||||||
|
delays() {
|
||||||
|
del=$(echo -e "$dels" | rofi -dmenu -b -l 3 -i -p "Select: ");
|
||||||
|
case $del in
|
||||||
|
$del1)
|
||||||
|
scrot -d 3 && notify-send "Screenshot saved";;
|
||||||
|
$del2)
|
||||||
|
scrot -d 5 && notify-send "Screenshot saved";;
|
||||||
|
$del3)
|
||||||
|
scrot -d 10 && notify-send "Screenshot saved"
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
## ENTIRE SCREEN FUNCTION ##
|
||||||
|
screen() {
|
||||||
|
scrot && notify-send "Screenshot saved"
|
||||||
|
}
|
||||||
|
|
||||||
|
## FOCUSED WINDOW FUNCTION
|
||||||
|
window() {
|
||||||
|
scrot -u -b && notify-send "Screenshot saved."
|
||||||
|
}
|
||||||
|
|
||||||
|
## SELECTED AREA FUNCTION ##
|
||||||
|
area() {
|
||||||
|
scrot -s && notify-send "Screenshot saved."
|
||||||
|
}
|
||||||
|
|
||||||
|
## MAIN ACTION ##
|
||||||
|
choice=$(echo -e "$chos" | rofi -dmenu -b -l 4 -i -p "Select: ")
|
||||||
|
case $choice in
|
||||||
|
$cho1)
|
||||||
|
screen;;
|
||||||
|
$cho2)
|
||||||
|
delays;;
|
||||||
|
$cho3)
|
||||||
|
window;;
|
||||||
|
$cho4)
|
||||||
|
area
|
||||||
|
esac
|
44
user/.config/rofi/scripts/rofi_wall
Executable file
44
user/.config/rofi/scripts/rofi_wall
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ***This script was made by Clay Gomera (Drake)***
|
||||||
|
# - Description: A simple wallpaper changer script
|
||||||
|
# - Dependencies: rofi, fd, feh
|
||||||
|
|
||||||
|
## MAIN VARIABLES AND COMMANDS ##
|
||||||
|
walldir="Pictures/Wallpapers/" # wallpapers folder, change it to yours, make sure that it ends with a /
|
||||||
|
cd "$walldir" || exit
|
||||||
|
|
||||||
|
## SELECT PICTURE FUNCTION ##
|
||||||
|
selectpic() {
|
||||||
|
wallpaper=$(fd -p "$walldir" | rofi -dmenu -l 10 -b -i -p "Select a wallpaper:")
|
||||||
|
if [ "$wallpaper" ]; then
|
||||||
|
chosenwall=$wallpaper
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
selectpic
|
||||||
|
|
||||||
|
## WALLPAPER SETTING OPTIONS ##
|
||||||
|
option1="Fill"
|
||||||
|
option2="Center"
|
||||||
|
option3="Tile"
|
||||||
|
option4="Max"
|
||||||
|
option5="Scale"
|
||||||
|
options="$option1\n$option2\n$option3\n$option4\n$option5"
|
||||||
|
|
||||||
|
## MAIN ACTION ##
|
||||||
|
action=$(echo -e "$options" | rofi -dmenu -l 10 -b -i -p "Chose the format:")
|
||||||
|
case "$action" in
|
||||||
|
$option1*)
|
||||||
|
feh --bg-fill "$chosenwall";;
|
||||||
|
$option2*)
|
||||||
|
feh --bg-center "$chosenwall";;
|
||||||
|
$option3*)
|
||||||
|
feh --bg-tile "$chosenwall";;
|
||||||
|
$option4*)
|
||||||
|
feh --bg-max "$chosenwall";;
|
||||||
|
$option5*)
|
||||||
|
feh --bg-scale "$chosenwall";;
|
||||||
|
esac
|
||||||
|
exit 0
|
91
user/.config/rofi/scripts/rofi_wifi
Executable file
91
user/.config/rofi/scripts/rofi_wifi
Executable file
|
@ -0,0 +1,91 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ***This script was made by Clay Gomera (Drake)***
|
||||||
|
# - Description: A simple wifi rofi script
|
||||||
|
# - Dependencies: rofi, NetworkManager
|
||||||
|
|
||||||
|
## ROFI VARIABLES ##
|
||||||
|
ROFI1="rofi -dmenu -l 10 -b -i -p"
|
||||||
|
ROFI2="rofi -dmenu -b -p"
|
||||||
|
ROFI3="rofi -dmenu -l 5 -b -i -p"
|
||||||
|
|
||||||
|
## MAIN OPTIONS ##
|
||||||
|
option1="(O) Turn on WiFi"
|
||||||
|
option2="(F) Turn off WiFi"
|
||||||
|
option3="(D) Disconnect WiFi"
|
||||||
|
option4="(C) Connect WiFi"
|
||||||
|
option5="(S) Setup captive portal"
|
||||||
|
option6="(X) Exit"
|
||||||
|
options="$option1\n$option2\n$option3\n$option4\n$option5\n$option6"
|
||||||
|
|
||||||
|
wlan=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f1 | head -1)
|
||||||
|
## TURN OFF WIFI FUNCTION ##
|
||||||
|
turnoff() {
|
||||||
|
nmcli radio wifi off
|
||||||
|
notify-send "WiFi has been turned off"
|
||||||
|
}
|
||||||
|
|
||||||
|
## TURN ON WIFI FUNCTION ##
|
||||||
|
turnon() {
|
||||||
|
nmcli radio wifi on
|
||||||
|
notify-send "WiFi has been turned on"
|
||||||
|
}
|
||||||
|
|
||||||
|
## DISCONNECT WIFI FUNCTION ##
|
||||||
|
disconnect() {
|
||||||
|
nmcli device disconnect "$wlan"
|
||||||
|
sleep 1
|
||||||
|
constate=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f3 | head -1)
|
||||||
|
if [ "$constate" = "disconnected" ]; then
|
||||||
|
notify-send "WiFi has been disconnected"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
## CONNECT FUNCTION ##
|
||||||
|
connect() {
|
||||||
|
notify-send "Scannig networks, please wait"
|
||||||
|
sleep 1
|
||||||
|
bssid=$(nmcli device wifi list | sed -n '1!p' | cut -b 9- | $ROFI1 "Select Wifi :" | cut -d' ' -f1)
|
||||||
|
}
|
||||||
|
|
||||||
|
## SELECT PASSWORD FUNCTION ##
|
||||||
|
password() {
|
||||||
|
pass=$(echo " " | $ROFI2 "Enter Password :")
|
||||||
|
}
|
||||||
|
|
||||||
|
## MAIN CONNECTION COMMAND ##
|
||||||
|
action() {
|
||||||
|
nmcli device wifi connect "$bssid" password "$pass" || nmcli device wifi connect "$bssid"
|
||||||
|
}
|
||||||
|
|
||||||
|
## CHECKING IF WIFI IS WORKING
|
||||||
|
check() {
|
||||||
|
notify-send "Checking if connection was successful"
|
||||||
|
sleep 1
|
||||||
|
currentwfi=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f4 | head -1)
|
||||||
|
if ping -q -c 2 -W 2 google.com >/dev/null; then
|
||||||
|
notify-send "You are now connected to $currentwfi and internet is working properly"
|
||||||
|
else
|
||||||
|
notify-send "Your internet is not working :("
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
## MAIN ACTION COMMANDS ##
|
||||||
|
cases=$(echo -e "$options" | $ROFI3 "What do you want to do?" )
|
||||||
|
case "$cases" in
|
||||||
|
$option1*)
|
||||||
|
turnon;;
|
||||||
|
$option2*)
|
||||||
|
turnoff;;
|
||||||
|
$option3*)
|
||||||
|
disconnect;;
|
||||||
|
$option4*)
|
||||||
|
connect;
|
||||||
|
password;
|
||||||
|
action;
|
||||||
|
check;;
|
||||||
|
$option5*)
|
||||||
|
io.elementary.capnet-assist;;
|
||||||
|
$option6*)
|
||||||
|
exit 0
|
||||||
|
esac
|
Loading…
Reference in a new issue