97 lines
3.6 KiB
Bash
Executable File
97 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Configuration files
|
|
ConfDir="$HOME/.config"
|
|
hyprlandConf="$ConfDir/hypr/hyprland.conf"
|
|
windowRules="$ConfDir/hypr/UserConfigs/WindowRules.conf"
|
|
animFile="$ConfDir/hypr/UserConfigs/UserSettings.conf"
|
|
PowManFile="$HOME/.cache/PowerManager.conf"
|
|
|
|
# Command-line option
|
|
powerOpt="$1"; shift
|
|
|
|
# Function to append a line to PowerManager.conf
|
|
append() {
|
|
grep -q "$1" "$PowManFile" || { echo "$1" >> "$PowManFile"; echo "$2"; }
|
|
}
|
|
|
|
# Function to remove a line from PowerManager.conf
|
|
remove() {
|
|
grep -q "$1" "$PowManFile" && { sed -i "/$1/d" "$PowManFile"; echo "$2"; }
|
|
}
|
|
|
|
# Ensure PowerManager.conf is sourced in hyprland.conf
|
|
source_files() {
|
|
[[ ! -f $PowManFile ]] && { touch $PowManFile && echo "Added: $hyprlandConf"; }
|
|
grep -q "source = $PowManFile" "$hyprlandConf" || { echo "source = $PowManFile #! This File is modified by Power_Manager options(To remove: 'Power_Manager reset')" >> "$hyprlandConf"; }
|
|
}
|
|
|
|
# Print help message
|
|
print_help() {
|
|
echo "Usage: PowerManager $powerOpt [options]"
|
|
sed -n "/^$powerOpt() {/,/^}/p" "$0" | sed -n '/case/,/esac/p' | grep ') #?' | awk '{gsub(/^[ \t]+/, ""); gsub(/\)/, "]"); gsub(/\|/, "] ["); print}' | awk '{print "["$0}' | awk -F '#?' '{sub("\\?", "", $2); printf "%-30s %s\n", $1, $2}'
|
|
}
|
|
|
|
# Reset power-related settings
|
|
reset() {
|
|
: > "$PowManFile"
|
|
grep -q "source = $PowManFile" "$hyprlandConf" && { sed -i "\#source = $PowManFile#d" "$hyprlandConf"; }
|
|
sed -i 's/^\s*#!\(.*windowrule.*opacity\)/\1/' "$windowRules"
|
|
sed -i 's/\(animation = borderangle,\) 0,/\1 1,/' "$animFile"
|
|
hyprctl reload
|
|
}
|
|
|
|
# Save power-related settings based on command-line options
|
|
save() {
|
|
[[ -z "$@" ]] && { print_help; }
|
|
source_files
|
|
declare -A processed_flags
|
|
for arg in "$@"; do
|
|
if [ "${processed_flags[$arg]}" != "true" ]; then
|
|
case $arg in
|
|
-a|--animations) append "animations:enabled = 0" "DISABLE Animations" ;;
|
|
-ba|--borderangle) append "animation = borderangle, 0" "DISABLE Border angle animation" ;;
|
|
-b|--blur) append "decoration:blur:enabled = 0" "DISABLE Blur" ;;
|
|
-o|--opacity)
|
|
if grep -q '^[^#]*windowrule.*opacity' "$windowRules"; then
|
|
sed -i '/^[^#]*windowrule.*opacity/s/^/#!/' "$windowRules" && echo "DISABLE Transparent opacity"
|
|
fi
|
|
;;
|
|
*) echo "Unknown flag: $arg"; print_help; exit 1 ;;
|
|
esac
|
|
processed_flags[$arg]="true"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Unset (revert) power-related settings based on command-line options
|
|
unset() {
|
|
[[ -z "$@" ]] && { print_help; }
|
|
source_files
|
|
declare -A processed_flags
|
|
for arg in "$@"; do
|
|
if [ "${processed_flags[$arg]}" != "true" ]; then
|
|
case $arg in
|
|
-a|--animations) remove "animations:enabled = 0" "ENABLE Animations" ;;
|
|
-ba|--borderangle)
|
|
remove "animation = borderangle, 0" "ENABLE Border angle animation"
|
|
sed -i 's/\(animation = borderangle,\) 0,/\1 1,/' "$animFile"
|
|
;;
|
|
-b|--blur) remove "decoration:blur:enabled = 0" "ENABLE Blur" ;;
|
|
-o|--opacity) sed -i 's/^\s*#!\(.*windowrule.*opacity\)/\1/' "$windowRules" ;;
|
|
*) echo "Unknown flag: $arg"; print_help; exit 1 ;;
|
|
esac
|
|
processed_flags[$arg]="true"
|
|
fi
|
|
done
|
|
hyprctl reload
|
|
}
|
|
|
|
# Placeholder function for handling power-saving options
|
|
max() {
|
|
echo "Placeholder function for handling power-saving options"
|
|
}
|
|
|
|
# Execute the selected function based on the provided command-line option
|
|
$powerOpt "$@"
|