hypr/.scripts/bar
2025-05-04 14:43:48 +02:00

83 lines
1.7 KiB
Bash
Executable file

#!/usr/bin/env bash
# Logging helper
log_notify() {
level="$1" # e.g., low, normal, critical
title="$2"
message="$3"
notify-send -u "$level" "$title" "$message"
}
# Check if the given command exists silently
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# Function to handle errors
handle_error() {
local exit_code=$1
local command_name=$2
if [ $exit_code -ne 0 ]; then
log_notify "critical" "Error" "Failed to execute $command_name"
exit $exit_code
fi
}
# fallback() {
# if command_exists hyprpanel; then
# pkill hyprpanel
# handle_error $? "pkill hyprpanel"
# hyprpanel &
# handle_error $? "hyprpanel"
# elif command_exists gBar; then
# pkill gBar
# handle_error $? "pkill gBar"
# gBar bar 0 &
# handle_error $? "gBar bar 0"
# elif command_exists waybar; then
# pkill waybar
# handle_error $? "pkill waybar"
# waybar &
# handle_error $? "waybar"
# else
# log_notify "critical" "Error" "No compatible bar found"
# exit 1
# fi
# }
barsetup() {
local bar="${1:-hyprpanel}"
case "$bar" in
hyprpanel)
pkill hyprpanel
# handle_error $? "pkill hyprpanel"
hyprpanel &
handle_error $? "hyprpanel"
;;
gBar)
pkill gBar
handle_error $? "pkill gBar"
gBar bar 0 &
handle_error $? "gBar bar 0"
;;
waybar)
pkill waybar
handle_error $? "pkill waybar"
waybar &
handle_error $? "waybar"
;;
*)
pkill $bar
# handle_error $? "pkill $bar"
$bar &
handle_error $? "$bar"
;;
esac
}
if barsetup "$@"; then
log_notify "normal" "Status-Bar" "initialized $bar"
else
log_notify "critical" "Status-Bar" "Something went wrong, your bar is probably not up.. sorry.."
fi