2026-03-09 00:07:31 -04:00

258 lines
6.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT=$(basename "$0")
BASE_LAUNCHER=('rofi' '-theme-str' 'window {width: 20%;}' '-c' '-dmenu' '-i')
UPDATE_COMMAND="yay -Syu"
CURRENT_THEME=$(wpg -c)
THEME_LIST=$(wpg -l) # | grep -v "$CURRENT_THEME")
log() {
logger -i -t "$SCRIPT" "$*"
}
show_main_menu() {
local options="Services\nSystem\nTools\nPassword"
echo -e "$options" | "${BASE_LAUNCHER[@]}" -l "$(echo -e "$options" | wc -l)" -p "Menu:"
}
show_system_menu() {
local options="Update\nRefresh Mirrors\nPurge Cache"
echo -e "$options" | "${BASE_LAUNCHER[@]}" -l "$(echo -e "$options" | wc -l)" -p "System:"
}
show_tools_menu() {
local options="Calculator\nClipboard\nColor Picker\nScreenshot\nSymbols\nTheme"
echo -e "$options" | "${BASE_LAUNCHER[@]}" -l "$(echo -e "$options" | wc -l)" -p "Tools:"
}
show_screenshot_menu() {
local options="Fullscreen\nSelection"
echo -e "$options" | "${BASE_LAUNCHER[@]}" -l "$(echo -e "$options" | wc -l)" -p "Screenshot:"
}
handle_update() {
local update_script="$UPDATE_COMMAND && echo 'Update completed successfully!' || { echo 'Update failed! Press any key to close...'; read -n 1; }"
$TERMINAL --title "System Update" -e bash -c "$update_script"
}
handle_refresh_mirrors() {
local mirror_script="sudo /usr/bin/reflector -c US -a 12 --sort rate --save /etc/pacman.d/mirrorlist && echo 'Mirrors refreshed successfully!' || { echo 'Mirror refresh failed! Press any key to close...'; read -n 1; }"
$TERMINAL --title "Refresh Mirrors" -e bash -c "$mirror_script"
}
handle_purge_cache() {
local purge_script="systemctl start paccache.service && systemctl start yaycache.service && localepurge && echo 'Cache purged successfully!' || { echo 'Cache purge failed! Press any key to close...'; read -n 1; }"
$TERMINAL --title "Purge Cache" -e bash -c "$purge_script"
}
handle_calculator() {
rofi -show calc -no-show-match -no-sort -i -theme-str 'window {width: 20%; height: 10%;}'
}
handle_clipboard() {
clipcat-menu
}
handle_colorpicker() {
sleep 0.5
hyprpicker 2>/dev/null | wl-copy
}
handle_screenshot() {
local screenshot_type
screenshot_type=$(show_screenshot_menu)
case "$screenshot_type" in
"Fullscreen")
sleep 0.5
local filename="$(date +%Y%m%d-%H%M%S).png"
local current_monitor
current_monitor=$(hyprctl cursorpos -j | jq -r '. as $cursor | hyprctl monitors -j | .[] | select(.x <= $cursor.x and $cursor.x < (.x + .width) and .y <= $cursor.y and $cursor.y < (.y + .height)) | .name' 2>/dev/null || hyprctl monitors -j | jq -r '.[0].name')
grim -o "$current_monitor" "$HOME/Pictures/Screenshots/$filename"
wl-copy < "$HOME/Pictures/Screenshots/$filename"
notify-send "Saved $filename"
;;
"Selection")
sleep 0.5
local filename="$(date +%Y%m%d-%H%M%S).png"
if slurp | grim -g - "$HOME/Pictures/Screenshots/$filename"; then
wl-copy < "$HOME/Pictures/Screenshots/$filename"
notify-send "Saved $filename"
else
return 0
fi
;;
"")
return 0
;;
*)
return 1
;;
esac
}
handle_symbols() {
rofi -modi "emoji:rofimoji" -show emoji -i -theme-str 'window {width: 20%; height: 12%;}'
}
handle_passwords() {
passwordmenu
}
handle_theme() {
if [[ -z "$THEME_LIST" ]]; then
log "No themes available"
return 1
fi
MONITORS=$(hyprctl monitors -j | jq -r '.[].name')
local monitor1
monitor1=$(echo "$MONITORS" | head -n 1)
local monitor2
monitor2=$(echo "$MONITORS" | tail -n 1)
local wallpaper_mode
wallpaper_mode=$(echo -e "Single\nDual" | "${BASE_LAUNCHER[@]}" -l 2 -p "Wallpaper:")
if [[ -z "$wallpaper_mode" ]]; then
return 0
fi
local theme_count
theme_count=$(echo "$THEME_LIST" | wc -l)
local selected_theme
selected_theme=$(echo "$THEME_LIST" | "${BASE_LAUNCHER[@]}" -l "$theme_count" -p "$CURRENT_THEME:")
if [[ -n "$selected_theme" && "$selected_theme" != "$CURRENT_THEME" ]]; then
if [[ "$wallpaper_mode" == "Dual" ]]; then
local second_wallpaper
second_wallpaper=$(echo "$THEME_LIST" | "${BASE_LAUNCHER[@]}" -l "$theme_count" -p "Second Wallpaper:")
if [[ -z "$second_wallpaper" ]]; then
return 0
fi
wpg -s "$selected_theme" -n || {
log "Failed to set theme: $selected_theme"
return 1
}
local wallpaper_conf="$XDG_CONFIG_HOME/hypr/wallpaper.conf"
sed -i "s|exec-once = swaybg -o $monitor1.*|exec-once = swaybg -o $monitor1 -m fill -i \$XDG_CONFIG_HOME/wpg/wallpapers/$selected_theme|" "$wallpaper_conf"
sed -i "s|exec-once = swaybg -o $monitor2.*|exec-once = swaybg -o $monitor2 -m fill -i \$XDG_CONFIG_HOME/wpg/wallpapers/$second_wallpaper|" "$wallpaper_conf"
pkill swaybg
swaybg -o "$monitor1" -i "$XDG_CONFIG_HOME/wpg/wallpapers/$selected_theme" -m fill &
swaybg -o "$monitor2" -i "$XDG_CONFIG_HOME/wpg/wallpapers/$second_wallpaper" -m fill &
log "Successfully set dual wallpapers: $selected_theme ($monitor1) and $second_wallpaper ($monitor2)"
else
wpg -s "$selected_theme" || {
log "Failed to set theme: $selected_theme"
return 1
}
local wallpaper_conf="$XDG_CONFIG_HOME/hypr/wallpaper.conf"
sed -i "s|exec-once = swaybg -o $monitor1.*|exec-once = swaybg -o $monitor1 -m fill -i \$XDG_CONFIG_HOME/wpg/wallpapers/\$(wpg -c)|" "$wallpaper_conf"
sed -i "s|exec-once = swaybg -o $monitor2.*|exec-once = swaybg -o $monitor2 -m fill -i \$XDG_CONFIG_HOME/wpg/wallpapers/\$(wpg -c)|" "$wallpaper_conf"
pkill swaybg
swaybg -o "$monitor1" -i "$XDG_CONFIG_HOME/wpg/wallpapers/$selected_theme" -m fill &
swaybg -o "$monitor2" -i "$XDG_CONFIG_HOME/wpg/wallpapers/$selected_theme" -m fill &
log "Successfully changed theme to: $selected_theme"
fi
fi
}
handle_system() {
local system_action
system_action=$(show_system_menu)
case "$system_action" in
"Update")
handle_update
;;
"Refresh Mirrors")
handle_refresh_mirrors
;;
"Purge Cache")
handle_purge_cache
;;
"")
return 0
;;
*)
log "Unknown system action: $system_action"
return 1
;;
esac
}
handle_tools() {
local tools_action
tools_action=$(show_tools_menu)
case "$tools_action" in
"Calculator")
handle_calculator
;;
"Clipboard")
handle_clipboard
;;
"Color Picker")
handle_colorpicker
;;
"Screenshot")
handle_screenshot
;;
"Symbols")
handle_symbols
;;
"Theme")
handle_theme
;;
"")
return 0
;;
*)
log "Unknown tools action: $tools_action"
return 1
;;
esac
}
main() {
local action
action=$(show_main_menu)
case "$action" in
"Services")
uuctl
;;
"System")
handle_system
;;
"Tools")
handle_tools
;;
"Password")
handle_passwords
;;
"")
exit 0
;;
*)
log "Unknown action: $action"
exit 1
;;
esac
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi