feat(script): update BatteryNotify.sh
This commit is contained in:
1 parent
26c5bea6dc
commit
347a63ee11
11 files changed
+286
-349
No files matched your search
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#!/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 "$@"
|
||||
-140
@@ -1,140 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# <<--------- Settings --------->> #
|
||||
|
||||
# Set the directory where the notes are stored
|
||||
NOTES_DIR="$HOME/Documents/Notes"
|
||||
# Set the editor to use
|
||||
EDITOR="nvim"
|
||||
# Set the file extension for the notes
|
||||
EXTENSION="*"
|
||||
|
||||
# <<--------- Choosing Templates --------->> #
|
||||
Basic() {
|
||||
|
||||
notify-send "Basic Document Created!"
|
||||
cd $NOTES_DIR
|
||||
cp $NOTES_DIR/Templates/SimpleNote.md $NOTES_DIR/"$note_name.md"
|
||||
nvim $NOTES_DIR/"$note_name.md"
|
||||
}
|
||||
|
||||
LaTeX() {
|
||||
|
||||
notify-send "LaTeX Document Created!"
|
||||
cd $NOTES_DIR
|
||||
cp $NOTES_DIR/Templates/LaTeX.tex $NOTES_DIR/"$note_name.tex"
|
||||
nvim $NOTES_DIR/"$note_name.tex"
|
||||
}
|
||||
|
||||
Presentation() {
|
||||
|
||||
notify-send "Beamer Presentation Created!"
|
||||
cd $NOTES_DIR
|
||||
cp $NOTES_DIR/Templates/Presentation.tex $NOTES_DIR/"$note_name.tex"
|
||||
nvim $NOTES_DIR/"$note_name.tex"
|
||||
}
|
||||
|
||||
RMark() {
|
||||
|
||||
notify-send "R Markdown Document Created!"
|
||||
cd $NOTES_DIR
|
||||
cp $NOTES_DIR/Templates/RMarkdown.rmd $NOTES_DIR/"$note_name.rmd"
|
||||
nvim $NOTES_DIR/"$note_name.rmd"
|
||||
}
|
||||
|
||||
template() {
|
||||
|
||||
echo "1. Basic"
|
||||
echo "2. LaTeX"
|
||||
echo "3. R Markdown"
|
||||
echo "4. Presentation"
|
||||
read -p "Enter your choice: " TYPE
|
||||
case $TYPE in
|
||||
1) Basic ;;
|
||||
2) LaTeX ;;
|
||||
3) RMark ;;
|
||||
4) Presentation ;;
|
||||
*) echo "Invalid!" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# <<--------- Functions --------->> #
|
||||
create_note() {
|
||||
|
||||
read -p "Enter the name of the note: " "note_name"
|
||||
if [ -f $NOTES_DIR/$note_name.$EXTENSION ]; then
|
||||
echo "Note already exists"
|
||||
echo "1. Overwrite"
|
||||
echo "2. Cancel"
|
||||
read -p "Enter your choice: " choice
|
||||
case $choice in
|
||||
1) notify-send "New Note Created!" &&
|
||||
nvim $NOTES_DIR/$note_name.$EXTENSION ;;
|
||||
2) main ;;
|
||||
*) echo "Invalid choice" ;;
|
||||
esac
|
||||
else
|
||||
template
|
||||
fi
|
||||
}
|
||||
|
||||
view_note() {
|
||||
|
||||
note=$(find $NOTES_DIR -type f -name "*.$EXTENSION" | fzf --preview 'bat --color=always {}')
|
||||
if [ -z "$note" ]; then
|
||||
exit
|
||||
else
|
||||
nvim "$note"
|
||||
view_note
|
||||
fi
|
||||
}
|
||||
|
||||
delete_note() {
|
||||
|
||||
note=$(find $NOTES_DIR -type f -name "*.$EXTENSION" | fzf --preview 'bat --color=always {}')
|
||||
if [ -z "$note" ]; then
|
||||
main
|
||||
else
|
||||
rm $note
|
||||
echo "Note Removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
# <<--------- Main --------->> #
|
||||
|
||||
main() {
|
||||
|
||||
# Check if the note directory exists
|
||||
if [ ! -d $NOTES_DIR ]; then
|
||||
mkdir $NOTES_DIR
|
||||
fi
|
||||
|
||||
# Check if the note directory is empty
|
||||
if [ ! "$(ls -A $NOTES_DIR)" ]; then
|
||||
echo "No notes found"
|
||||
echo "Creating a new note"
|
||||
create_note
|
||||
else
|
||||
echo "Notes found"
|
||||
echo "1. Create a new note"
|
||||
echo "2. View a note"
|
||||
echo "3. Delete a note"
|
||||
echo "4. Exit"
|
||||
read -p "Enter your choice: " choice
|
||||
|
||||
case $choice in
|
||||
1) create_note ;;
|
||||
2) view_note ;;
|
||||
3) delete_note ;;
|
||||
4) exit 0 ;;
|
||||
*) echo "Invalid choice" ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
# <<--------- Arguments --------->> #
|
||||
if [ "$1" = "view" ]; then
|
||||
view_note
|
||||
else
|
||||
main
|
||||
fi
|
||||
Reference in new issue
Block a user