From ff563f2e0d2226e85178637de6d5e6228950d8a4 Mon Sep 17 00:00:00 2001 From: pika Date: Sun, 22 Jun 2025 11:10:47 +0200 Subject: [PATCH] restructure some scripts + make new init script --- scripts/bar | 40 ++++++------ scripts/init | 90 +++++++++++---------------- scripts/init.bak | 145 ++++++++++++++++++++++++++++++++++++++++++++ scripts/init.sh.bak | 0 scripts/quickshell | 46 -------------- 5 files changed, 197 insertions(+), 124 deletions(-) create mode 100755 scripts/init.bak mode change 100644 => 100755 scripts/init.sh.bak delete mode 100755 scripts/quickshell diff --git a/scripts/bar b/scripts/bar index 9c1f5d7..fdcaa44 100755 --- a/scripts/bar +++ b/scripts/bar @@ -24,28 +24,24 @@ barsetup() { proc-kill-if "$bar" - # case "$bar" in - # hyprpanel) - # pkill hyprpanel - # hyprpanel & - # ;; - # gBar) - # pkill gBar - # gBar bar 0 & - # ;; - # waybar) - # pkill waybar - # waybar & - # ;; - # quickshell) - # pkill qs - # qs & - # ;; - # *) - # pkill $bar - # $bar & - # ;; - # esac + case "$bar" in + hyprpanel) + hyprpanel & + ;; + gBar) + gBar bar 0 & + ;; + waybar) + waybar & + ;; + quickshell) + proc-kill-if "qs" + qs & + ;; + *) + $bar & + ;; + esac } if barsetup "$@"; then diff --git a/scripts/init b/scripts/init index eefdc4e..c035dc6 100755 --- a/scripts/init +++ b/scripts/init @@ -1,41 +1,22 @@ #!/usr/bin/env bash +SCRIPTS="$HOME/.config/hypr/scripts" + # ─< 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 +setup-wm-modules() { bash -c "$SCRIPTS/bar" - log_notify low "Bar" "Initializing.." - # fi + notify-send -u "low" "Bar" "Bar setup done" - bash "$SCRIPTS/wallpaper" - log_notify low "Wallpaper" "Initializing.." + sleep 0.5 + + bash -c "$SCRIPTS/wallpaper" + notify-send -u "low" "SWWW" "Wallpaper setup done" + + sleep 0.5 local modules @@ -49,40 +30,42 @@ setup-desktop() { 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 + + notify-send -u "low" "$module" "Started server" ;; lxappearance) if ! pgrep lxappearance; then lxappearance >/dev/null 2>&1 & fi + + notify-send -u "low" "$module" "Starting.." ;; 'nwg-look') 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) . "$SCRIPTS/redshift.sh" ;; wob) local fifo="/tmp/$HYPRLAND_INSTANCE_SIGNATURE.wob" + + notify-send -u "low" "$module" "Creating fifo.." + rm -f "$fifo" mkfifo "$fifo" tail -f "$fifo" | wob & ;; esac fi + + sleep 0.15 done } @@ -99,14 +82,12 @@ init-polkit() { for agent in "${agents[@]}"; do 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" & - return 0 fi done - - log_notify "low" "WARNING" "No Polkit authentication agent found. Please install one." - return 1 } # Initialize XDG desktop portals @@ -116,28 +97,25 @@ init-xdg-portal() { if [ -x "$xdg_hyprland" ]; then killall xdg-desktop-portal-hyprland xdg-desktop-portal-wlr xdg-desktop-portal 2>/dev/null - sleep 1 + + sleep 0.5 "$xdg_hyprland" & - sleep 1 + + sleep 0.5 "$xdg_portal" & - sleep 1 + + sleep 0.5 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 - 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 } main() { - kill-all - sleep 0.3 - setup-desktop + setup-wm-modules - if [ -x "/usr/lib/hyprpolkitagent" ]; then - systemctl --user start hyprpolkitagent - else - init-polkit - fi + init-polkit init-xdg-portal } diff --git a/scripts/init.bak b/scripts/init.bak new file mode 100755 index 0000000..8b16dcf --- /dev/null +++ b/scripts/init.bak @@ -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 diff --git a/scripts/init.sh.bak b/scripts/init.sh.bak old mode 100644 new mode 100755 diff --git a/scripts/quickshell b/scripts/quickshell deleted file mode 100755 index bc9e558..0000000 --- a/scripts/quickshell +++ /dev/null @@ -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