restructure some scripts + make new init script

This commit is contained in:
pika 2025-06-22 11:10:47 +02:00
parent a0d20383c3
commit ff563f2e0d
5 changed files with 197 additions and 124 deletions

View file

@ -24,28 +24,24 @@ barsetup() {
proc-kill-if "$bar" proc-kill-if "$bar"
# case "$bar" in case "$bar" in
# hyprpanel) hyprpanel)
# pkill hyprpanel hyprpanel &
# hyprpanel & ;;
# ;; gBar)
# gBar) gBar bar 0 &
# pkill gBar ;;
# gBar bar 0 & waybar)
# ;; waybar &
# waybar) ;;
# pkill waybar quickshell)
# waybar & proc-kill-if "qs"
# ;; qs &
# quickshell) ;;
# pkill qs *)
# qs & $bar &
# ;; ;;
# *) esac
# pkill $bar
# $bar &
# ;;
# esac
} }
if barsetup "$@"; then if barsetup "$@"; then

View file

@ -1,41 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SCRIPTS="$HOME/.config/hypr/scripts"
# ─< Check if the given command exists silently >───────────────────────────────────────── # ─< Check if the given command exists silently >─────────────────────────────────────────
command-exists() { command-exists() {
command -v "$@" >/dev/null 2>&1 command -v "$@" >/dev/null 2>&1
} }
kill-all() { setup-wm-modules() {
# ─< Kill already running processes >─────────────────────────────────────────────────────
hyprpanel="gjs" # since hyprpanel has so many different wordings, making it clear that this is currently the hyprpanel service name
_ps=(swaync gBar rofi fuzzel wofi swaync waybar $hyprpanel)
for _prs in "${_ps[@]}"; do
if pidof "${_prs}" >/dev/null; then
pkill "${_prs}"
fi
done
}
SCRIPTS="$HOME/.config/hypr/scripts"
# Logging helper
log_notify() {
level="$1" # e.g., low, normal, critical
title="$2"
message="$3"
notify-send -u "$level" "$title" "$message"
}
setup-desktop() {
# if command-exists qs; then
# qs
# else
bash -c "$SCRIPTS/bar" bash -c "$SCRIPTS/bar"
log_notify low "Bar" "Initializing.." notify-send -u "low" "Bar" "Bar setup done"
# fi
bash "$SCRIPTS/wallpaper" sleep 0.5
log_notify low "Wallpaper" "Initializing.."
bash -c "$SCRIPTS/wallpaper"
notify-send -u "low" "SWWW" "Wallpaper setup done"
sleep 0.5
local modules local modules
@ -49,40 +30,42 @@ setup-desktop() {
for module in "${modules[@]}"; do for module in "${modules[@]}"; do
if command-exists $module; then if command-exists $module; then
log_notify low "$module" "Initializing.."
case $module in case $module in
copyq) copyq)
if ! pgrep copyq; then if ! pgrep copyq; then
copyq --start-server copyq --start-server
fi fi
notify-send -u "low" "$module" "Started server"
;; ;;
lxappearance) lxappearance)
if ! pgrep lxappearance; then if ! pgrep lxappearance; then
lxappearance >/dev/null 2>&1 & lxappearance >/dev/null 2>&1 &
fi fi
notify-send -u "low" "$module" "Starting.."
;; ;;
'nwg-look') 'nwg-look')
nwg-look -a >/dev/null 2>&1 & nwg-look -a >/dev/null 2>&1 &
notify-send -u "low" "$module" "Starting.."
;; ;;
# handled in $SCRIPTS/bar
# swww)
# swww-daemon &
# if ! swww query; then
# swww init
# fi
# ;;
redshift) redshift)
. "$SCRIPTS/redshift.sh" . "$SCRIPTS/redshift.sh"
;; ;;
wob) wob)
local fifo="/tmp/$HYPRLAND_INSTANCE_SIGNATURE.wob" local fifo="/tmp/$HYPRLAND_INSTANCE_SIGNATURE.wob"
notify-send -u "low" "$module" "Creating fifo.."
rm -f "$fifo" rm -f "$fifo"
mkfifo "$fifo" mkfifo "$fifo"
tail -f "$fifo" | wob & tail -f "$fifo" | wob &
;; ;;
esac esac
fi fi
sleep 0.15
done done
} }
@ -99,14 +82,12 @@ init-polkit() {
for agent in "${agents[@]}"; do for agent in "${agents[@]}"; do
if [ -x "$agent" ]; then if [ -x "$agent" ]; then
log_notify "normal" "INFO" "Starting Polkit agent: $(basename "$agent")" # local polkit="$(basename $agent)"
notify-send -u "normal" "Polkit" "Starting Polkit agent: $(basename $agent)"
"$agent" & "$agent" &
return 0
fi fi
done done
log_notify "low" "WARNING" "No Polkit authentication agent found. Please install one."
return 1
} }
# Initialize XDG desktop portals # Initialize XDG desktop portals
@ -116,28 +97,25 @@ init-xdg-portal() {
if [ -x "$xdg_hyprland" ]; then if [ -x "$xdg_hyprland" ]; then
killall xdg-desktop-portal-hyprland xdg-desktop-portal-wlr xdg-desktop-portal 2>/dev/null killall xdg-desktop-portal-hyprland xdg-desktop-portal-wlr xdg-desktop-portal 2>/dev/null
sleep 1
sleep 0.5
"$xdg_hyprland" & "$xdg_hyprland" &
sleep 1
sleep 0.5
"$xdg_portal" & "$xdg_portal" &
sleep 1
sleep 0.5
dbus-update-activation-environment --systemd --all & dbus-update-activation-environment --systemd --all &
log_notify "normal" "INFO" "XDG desktop portals initialized." notify-send -u "normal" "xdg-portal" "XDG desktop portals initialized."
else else
log_notify "low" "WARNING" "xdg-desktop-portal-hyprland not found. Please install it." notify-send -u "low" "WARNING" "xdg-desktop-portal-hyprland not found. Please install it."
fi fi
} }
main() { main() {
kill-all setup-wm-modules
sleep 0.3
setup-desktop
if [ -x "/usr/lib/hyprpolkitagent" ]; then
systemctl --user start hyprpolkitagent
else
init-polkit init-polkit
fi
init-xdg-portal init-xdg-portal
} }

145
scripts/init.bak Executable file
View file

@ -0,0 +1,145 @@
#!/bin/sh
# ─< Check if the given command exists silently >─────────────────────────────────────────
command-exists() {
command -v "$@" >/dev/null 2>&1
}
kill-all() {
# ─< Kill already running processes >─────────────────────────────────────────────────────
hyprpanel="gjs" # since hyprpanel has so many different wordings, making it clear that this is currently the hyprpanel service name
_ps=(swaync gBar rofi fuzzel wofi swaync waybar $hyprpanel)
for _prs in "${_ps[@]}"; do
if pidof "${_prs}" >/dev/null; then
pkill "${_prs}"
fi
done
}
SCRIPTS="$HOME/.config/hypr/scripts"
# Logging helper
log_notify() {
level="$1" # e.g., low, normal, critical
title="$2"
message="$3"
notify-send -u "$level" "$title" "$message"
}
setup-desktop() {
# if command-exists qs; then
# qs
# else
bash -c "$SCRIPTS/bar"
log_notify low "Bar" "Initializing.."
# fi
bash "$SCRIPTS/wallpaper"
log_notify low "Wallpaper" "Initializing.."
local modules
modules=(
"copyq"
"nwg-look"
"lxappearance"
"wob"
"redshift"
)
for module in "${modules[@]}"; do
if command-exists $module; then
log_notify low "$module" "Initializing.."
case $module in
copyq)
if ! pgrep copyq; then
copyq --start-server
fi
;;
lxappearance)
if ! pgrep lxappearance; then
lxappearance >/dev/null 2>&1 &
fi
;;
'nwg-look')
nwg-look -a >/dev/null 2>&1 &
;;
# handled in $SCRIPTS/bar
# swww)
# swww-daemon &
# if ! swww query; then
# swww init
# fi
# ;;
redshift)
. "$SCRIPTS/redshift.sh"
;;
wob)
local fifo="/tmp/$HYPRLAND_INSTANCE_SIGNATURE.wob"
rm -f "$fifo"
mkfifo "$fifo"
tail -f "$fifo" | wob &
;;
esac
fi
done
}
# Start polkit authentication agent
init-polkit() {
agents=(
"/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1"
"/usr/lib/polkit-kde-authentication-agent-1"
"/usr/libexec/polkit-gnome-authentication-agent-1"
"/usr/lib/x86_64-linux-gnu/libexec/polkit-kde-authentication-agent-1"
"/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1"
"/usr/lib/polkit-1/polkit-agent-helper-1"
)
for agent in "${agents[@]}"; do
if [ -x "$agent" ]; then
log_notify "normal" "INFO" "Starting Polkit agent: $(basename "$agent")"
"$agent" &
return 0
fi
done
log_notify "low" "WARNING" "No Polkit authentication agent found. Please install one."
return 1
}
# Initialize XDG desktop portals
init-xdg-portal() {
xdg_hyprland="/usr/lib/xdg-desktop-portal-hyprland"
xdg_portal="/usr/lib/xdg-desktop-portal"
if [ -x "$xdg_hyprland" ]; then
killall xdg-desktop-portal-hyprland xdg-desktop-portal-wlr xdg-desktop-portal 2>/dev/null
sleep 1
"$xdg_hyprland" &
sleep 1
"$xdg_portal" &
sleep 1
dbus-update-activation-environment --systemd --all &
log_notify "normal" "INFO" "XDG desktop portals initialized."
else
log_notify "low" "WARNING" "xdg-desktop-portal-hyprland not found. Please install it."
fi
}
main() {
kill-all
sleep 0.3
setup-desktop
if [ -x "/usr/lib/hyprpolkitagent" ]; then
systemctl --user start hyprpolkitagent
else
init-polkit
fi
init-xdg-portal
}
main

0
scripts/init.sh.bak Normal file → Executable file
View file

View file

@ -1,46 +0,0 @@
#!/usr/bin/env bash
# ─< Check if the given command exists silently >─────────────────────────────────────────
command-exists() {
command -v "$@" >/dev/null 2>&1
}
check-env() {
local dir bin
bin=quickshell
dir="$HOME/.config/quickshell"
if command-exists $bin; then
return 0
else
return 69
fi
if [ -d "${dir}" ]; then
return 0
else
return 69
fi
}
check-env
init-quickshell() {
local modules
local dir="$HOME/.config/quickshell"
modules=(
"activate-linux"
)
for mod in "${modules[@]}"; do
module="${dir}/${mod}.qml"
if [ -f "$module" ]; then
quickshell -p "$module" &
fi
done
}
init-quickshell