-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated eww bash scripts, improved code and logic.
- Loading branch information
gh0stzk
committed
Feb 9, 2025
1 parent
6d7d23d
commit cf2bba6
Showing
4 changed files
with
194 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,88 @@ | ||
#!/usr/bin/env bash | ||
# █████╗ ██╗██████╗ ██████╗ ██╗ █████╗ ███╗ ██╗███████╗ | ||
# ██╔══██╗██║██╔══██╗██╔══██╗██║ ██╔══██╗████╗ ██║██╔════╝ | ||
# ███████║██║██████╔╝██████╔╝██║ ███████║██╔██╗ ██║█████╗ | ||
# ██╔══██║██║██╔══██╗██╔═══╝ ██║ ██╔══██║██║╚██╗██║██╔══╝ | ||
# ███████║██║██████╔╝██████╔╝██║ ███████║██╔██╗ ██║█████╗ | ||
# ██╔══██║██║██╔══██╗██╔═══╝ ██║ ██╔══██║██║╚██╗██║██╔══╝ | ||
# ██║ ██║██║██║ ██║██║ ███████╗██║ ██║██║ ╚████║███████╗ | ||
# ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝ | ||
# Script to control my eww widget arirplane options. | ||
# gh0stzk | https://github.com/gh0stzk/dotfiles | ||
# 12.07.2024 10:12:26 | ||
# Copyright (C) 2021-2025 gh0stzk <[email protected]> | ||
|
||
cache_dir="$HOME/.cache/$USER" | ||
cache_file="$cache_dir/airplane_state" | ||
|
||
cache_file=$HOME/.cache/$(whoami)/airplane_state | ||
mkdir -p "$cache_dir" | ||
[[ -f "$cache_file" ]] || echo "Off" > "$cache_file" | ||
|
||
mkdir -p "$(dirname "$cache_file")" | ||
[[ ! -f "$cache_file" ]] && echo Off > "$cache_file" | ||
# Function to check if the system has Bluetooth and if the service is active | ||
has_bluetooth() { | ||
if ! rfkill list bluetooth &>/dev/null; then | ||
return 1 | ||
fi | ||
|
||
if systemctl is-active bluetooth &>/dev/null; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
get_state() { | ||
cat "$cache_file" | ||
head -n 1 "$cache_file" 2>/dev/null || echo "Off" | ||
} | ||
|
||
icon() { | ||
if [[ $(get_state) == "On" ]]; then | ||
echo "" | ||
else | ||
echo "" | ||
fi | ||
case "$(get_state)" in | ||
"On") echo "" ;; | ||
*) echo "" ;; | ||
esac | ||
} | ||
|
||
airplane_on() { | ||
nmcli networking off | ||
systemctl is-active --quiet bluetooth.service && bluetoothctl power off | ||
notify-send --urgency=normal -i airplane-mode "Airplane Mode" "Airplane mode has been turned on!" | ||
echo On >"$cache_file" | ||
nmcli networking off | ||
|
||
if has_bluetooth; then | ||
local bluetooth_state | ||
bluetooth_state=$(bluetoothctl show | grep -q "Powered: yes" && echo "On" || echo "Off") | ||
|
||
if [[ "$bluetooth_state" == "On" ]]; then | ||
bluetoothctl power off | ||
fi | ||
|
||
printf "On\n%s" "$bluetooth_state" > "$cache_file" | ||
else | ||
echo "On" > "$cache_file" | ||
fi | ||
|
||
notify-send -u normal -i airplane-mode "Airplane Mode Activated" "Network disabled$(has_bluetooth && echo " and Bluetooth disabled")" | ||
} | ||
|
||
airplane_off() { | ||
nmcli networking on | ||
systemctl is-active --quiet bluetooth.service && bluetoothctl power on | ||
notify-send --urgency=normal -i airplane-mode "Airplane Mode" "Airplane mode has been turned off!" | ||
echo Off >"$cache_file" | ||
nmcli networking on | ||
|
||
if has_bluetooth; then | ||
local prev_bluetooth_state | ||
prev_bluetooth_state=$(sed -n '2p' "$cache_file" 2>/dev/null) | ||
|
||
if [[ "$prev_bluetooth_state" == "On" ]]; then | ||
bluetoothctl power on | ||
fi | ||
fi | ||
|
||
echo "Off" > "$cache_file" | ||
|
||
notify-send -u normal -i airplane-mode "Airplane Mode Off" "Network reactivated$(has_bluetooth && echo " and Bluetooth restored to its previous state")" | ||
} | ||
|
||
toggle() { | ||
if [[ $(get_state) == "Off" ]]; then | ||
airplane_on | ||
else | ||
airplane_off | ||
fi | ||
[[ "$(get_state)" == "Off" ]] && airplane_on || airplane_off | ||
} | ||
|
||
case "$1" in | ||
--toggle) toggle ;; | ||
--icon) icon ;; | ||
--icon) icon ;; | ||
--status) get_state ;; | ||
*) echo "Uso: $0 [--toggle|--icon|--status]" ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,49 +8,71 @@ | |
# Script to detect and control the bluetooth information on my eww widget. | ||
# gh0stzk | https://github.com/gh0stzk/dotfiles | ||
# 12.07.2024 09:51:19 | ||
# Copyright (C) 2021-2025 gh0stzk <[email protected]> | ||
|
||
|
||
# Function to check if the system has Bluetooth and if the service is active | ||
has_bluetooth() { | ||
if ! rfkill list bluetooth &>/dev/null; then | ||
return 1 | ||
fi | ||
|
||
if systemctl is-active bluetooth &>/dev/null; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Function to get the Bluetooth icon | ||
get_icon() { | ||
if systemctl is-active --quiet bluetooth.service; then | ||
if [[ $(bluetoothctl show | grep "Powered" | awk '{print $2}') == "yes" ]]; then | ||
echo "" | ||
else | ||
echo "" | ||
fi | ||
else | ||
echo "" | ||
fi | ||
if has_bluetooth; then | ||
if bluetoothctl show | grep -q "Powered: yes"; then | ||
echo "" | ||
else | ||
echo "" | ||
fi | ||
else | ||
echo "" | ||
fi | ||
} | ||
|
||
# Function to get connected device name or status | ||
get_name() { | ||
if systemctl is-active --quiet bluetooth.service; then | ||
if [[ $(bluetoothctl show | grep "Powered" | awk '{print $2}') == "yes" ]]; then | ||
connected_devices=$(bluetoothctl devices Connected | awk '{print $3}') | ||
if [ -n "$connected_devices" ]; then | ||
echo "$connected_devices" | ||
else | ||
echo "On" | ||
fi | ||
else | ||
echo "Off" | ||
fi | ||
else | ||
echo "Null" | ||
fi | ||
if has_bluetooth; then | ||
if bluetoothctl show | grep -q "Powered: yes"; then | ||
connected_devices=$(bluetoothctl devices Connected | awk '{print $3}') | ||
if [[ -n "$connected_devices" ]]; then | ||
echo "$connected_devices" | ||
else | ||
echo "On" | ||
fi | ||
else | ||
echo "Off" | ||
fi | ||
else | ||
echo "Null" | ||
fi | ||
} | ||
|
||
# Function to toggle Bluetooth status | ||
toggle() { | ||
if [[ $(bluetoothctl show | grep "Powered" | awk '{print $2}') == "no" ]]; then | ||
bluetoothctl power on | ||
dunstify --icon=bluetooth --appname=Bluetooth --urgency=normal "Bluetooth" "Bluetooth has been turned on." | ||
else | ||
bluetoothctl power off | ||
dunstify --icon=bluetooth-disabled --appname=Bluetooth --urgency=normal "Bluetooth" "Bluetooth has been turned off." | ||
fi | ||
if has_bluetooth; then | ||
if bluetoothctl show | grep -q "Powered: yes"; then | ||
bluetoothctl power off | ||
dunstify --icon=bluetooth-disabled --appname=Bluetooth --urgency=normal "Bluetooth" "Bluetooth has been turned off." | ||
else | ||
bluetoothctl power on | ||
dunstify --icon=bluetooth --appname=Bluetooth --urgency=normal "Bluetooth" "Bluetooth has been turned on." | ||
fi | ||
else | ||
dunstify --icon=bluetooth-disabled --appname=Bluetooth --urgency=normal "Bluetooth" "Bluetooth is not available or the service is inactive." | ||
fi | ||
} | ||
|
||
case "$1" in | ||
--status) get_status ;; | ||
--icon) get_icon ;; | ||
--name) get_name ;; | ||
--toggle) toggle ;; | ||
--icon) get_icon ;; | ||
--name) get_name ;; | ||
--toggle) toggle ;; | ||
*) echo "Uso: $0 [--icon|--name|--toggle]" ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,73 @@ | ||
#!/usr/bin/env bash | ||
# ██████╗ █████╗ ███╗ ███╗███████╗███╗ ███╗ ██████╗ ██████╗ ███████╗ | ||
# ██╔════╝ ██╔══██╗████╗ ████║██╔════╝████╗ ████║██╔═══██╗██╔══██╗██╔════╝ | ||
# ██║ ███╗███████║██╔████╔██║█████╗ ██╔████╔██║██║ ██║██║ ██║█████╗ | ||
# ██║ ██║██╔══██║██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║██║ ██║██║ ██║██╔══╝ | ||
# ██║ ███╗███████║██╔████╔██║█████╗ ██╔████╔██║██║ ██║██║ ██║█████╗ | ||
# ██║ ██║██╔══██║██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║██║ ██║██║ ██║██╔══╝ | ||
# ╚██████╔╝██║ ██║██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║╚██████╔╝██████╔╝███████╗ | ||
# ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ | ||
# Disables picom, notifications and configure the processor in performance mode | ||
# gh0stzk | https://github.com/gh0stzk/dotfiles | ||
# 11.07.2024 13:25:51 | ||
# Copyright (C) 2021-2025 gh0stzk <[email protected]> | ||
|
||
CACHE_FILE="$HOME/.cache/$(whoami)/gamemode_state" | ||
|
||
CACHE_DIR="$HOME/.cache/$USER" | ||
CACHE_FILE="$CACHE_DIR/gamemode_state" | ||
CPU_GOVERNOR_PATH="/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" | ||
|
||
mkdir -p "$(dirname "$CACHE_FILE")" | ||
[[ -f "$CACHE_FILE" ]] || echo Off >"$CACHE_FILE" | ||
# Create cache directory if it does not exist | ||
mkdir -p "$CACHE_DIR" | ||
[[ -f "$CACHE_FILE" ]] || echo "Off" > "$CACHE_FILE" | ||
|
||
# Function to obtain the current state of Game Mode | ||
get_state() { | ||
cat "$CACHE_FILE" | ||
head -n 1 "$CACHE_FILE" 2>/dev/null || echo "Off" | ||
} | ||
|
||
# Function to change CPU governor | ||
set_cpu_governor() { | ||
local governor=$1 | ||
echo $governor | pkexec tee /sys/devices/system/cpu/*/cpufreq/scaling_governor | ||
echo "$governor" | pkexec tee /sys/devices/system/cpu/*/cpufreq/scaling_governor >/dev/null | ||
} | ||
|
||
# Function to activate Game Mode | ||
gamemode_on() { | ||
local prev_governor | ||
prev_governor=$(cat "$CPU_GOVERNOR_PATH") | ||
echo "$prev_governor" > "$CACHE_DIR/cpu_governor" | ||
|
||
dunstctl set-paused true | ||
pkill -f picom | ||
set_cpu_governor performance | ||
echo On >"$CACHE_FILE" | ||
pkill -f picom | ||
set_cpu_governor performance | ||
echo "On" > "$CACHE_FILE" | ||
|
||
} | ||
|
||
# Function to deactivate Game Mode | ||
gamemode_off() { | ||
dunstctl set-paused false | ||
picom --config "$HOME"/.config/bspwm/picom.conf & | ||
set_cpu_governor ondemand | ||
echo Off >"$CACHE_FILE" | ||
dunstctl set-paused false | ||
picom --config "$HOME/.config/bspwm/src/config/picom.conf" & | ||
|
||
local prev_governor | ||
prev_governor=$(cat "$CACHE_DIR/cpu_governor") | ||
set_cpu_governor "$prev_governor" | ||
|
||
echo "Off" > "$CACHE_FILE" | ||
|
||
notify-send -u normal -i games "Game Mode" "Game Mode desactivado. Picom reiniciado, notificaciones reanudadas y CPU $prev_governor restaurada." | ||
} | ||
|
||
# Function to toggle Game Mode | ||
toggle() { | ||
if [[ $(get_state) == "Off" ]]; then | ||
if [[ $(get_state) == "Off" ]]; then | ||
gamemode_on | ||
else | ||
gamemode_off | ||
fi | ||
} | ||
|
||
|
||
case "$1" in | ||
--toggle) toggle ;; | ||
--status) get_state ;; | ||
*) echo "Usage: $0 [--toggle|--status]" ;; | ||
*) echo "Uso: $0 [--toggle|--status]" ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,31 +9,59 @@ | |
# https://github.com/gh0stzk/dotfiles | ||
# This script checks if you are connected to the internet and sets values. | ||
# 23.09.2023 13:39:59 | ||
# Copyright (C) 2021-2025 gh0stzk <[email protected]> | ||
|
||
ID=$(ip link | awk '/state UP/ {print $2}' | tr -d :) | ||
|
||
if command -v nmcli >/dev/null 2>&1 ; then | ||
SSID=$(nmcli -t -f active,ssid dev wifi show | sed -n '1{s/SSID: //p}') | ||
fi | ||
|
||
# Function to check if there is an Internet connection | ||
is_online() { | ||
ping -c 1 archlinux.org &>/dev/null | ||
ping -c 1 -W 1 archlinux.org &>/dev/null | ||
} | ||
|
||
if is_online; then | ||
if [[ $ID == e* ]]; then | ||
STATUS="$ID" | ||
ICON="" | ||
# Get the connection type and network name | ||
get_network_info() { | ||
local connection_type="" | ||
local network_name="" | ||
|
||
# Use nmcli to detect active connection | ||
local connected_device | ||
connected_device=$(nmcli -t -f DEVICE,TYPE,STATE dev status | awk -F: ' | ||
$3 == "connected" && $1 != "lo" && $2 ~ /^(ethernet|wifi)$/ {print $1,$2; exit} | ||
') | ||
|
||
if [[ -n "$connected_device" ]]; then | ||
connection_type=$(cut -d' ' -f2 <<< "$connected_device") | ||
network_name=$(nmcli -t -f DEVICE,CONNECTION dev status | awk -F: -v dev="$(cut -d' ' -f1 <<< "$connected_device")" ' | ||
$1 == dev {print $2; exit} | ||
') | ||
fi | ||
|
||
# Determine status and icon | ||
if is_online; then | ||
case "$connection_type" in | ||
"ethernet") | ||
STATUS="Ethernet" | ||
ICON="" | ||
;; | ||
"wifi") | ||
STATUS="${network_name:-Wi-Fi}" | ||
ICON="" | ||
;; | ||
*) | ||
STATUS="Desconocido" | ||
ICON="" | ||
;; | ||
esac | ||
else | ||
STATUS="$SSID" | ||
ICON="" | ||
STATUS="Offline" | ||
ICON="" | ||
fi | ||
else | ||
STATUS="Offline" | ||
ICON="" | ||
fi | ||
} | ||
|
||
# Get network information | ||
get_network_info | ||
|
||
case "$1" in | ||
--status) echo "$STATUS" ;; | ||
--icon) echo "$ICON" ;; | ||
--icon) echo "$ICON" ;; | ||
*) echo "Uso: $0 [--status|--icon]" ;; | ||
esac |