From a443546b2f973883b67b0c74454f74d83af5c8c5 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Sun, 19 Oct 2025 22:37:07 +0200 Subject: [PATCH] scripts: deleted 2 & added config-load & edited some --- config/niri/config.kdl | 10 +++--- config/quickshell/Constants/Icons.qml | 4 +-- .../Modules/Bar/Components/TrayExpander.qml | 1 + .../quickshell/Services/BrightnessService.qml | 2 +- config/quickshell/Services/LyricsService.qml | 9 +++-- config/waybar/config.jsonc | 4 +-- memo/powerprofile | 6 ++++ scripts/change-wallpaper | 24 ++++++++++++- scripts/config-load | 34 +++++++++++++++++++ scripts/config-switch | 15 +++++--- scripts/screenshot | 13 +++++-- scripts/set-brightness | 6 ---- scripts/sl-wrap | 4 --- 13 files changed, 97 insertions(+), 35 deletions(-) create mode 100644 memo/powerprofile create mode 100755 scripts/config-load delete mode 100755 scripts/set-brightness delete mode 100755 scripts/sl-wrap diff --git a/config/niri/config.kdl b/config/niri/config.kdl index 8d572a3..85ca299 100644 --- a/config/niri/config.kdl +++ b/config/niri/config.kdl @@ -120,9 +120,6 @@ layer-rule { // Switch configs spawn-sh-at-startup "config-switch niri" -// Idle -spawn-sh-at-startup "hypridle" - // Wallpaper spawn-at-startup "wallpaper-daemon" @@ -149,9 +146,10 @@ spawn-at-startup "sunshine" // spawn-at-startup "spotify" // spawn-at-startup "thunderbird" +// Idle +spawn-at-startup "hypridle" -// Quickshell must start after hypridle, -// otherwise Firefox cannot block idle when playing media +// QuickShell spawn-at-startup "quickshell" /************************Envs************************/ @@ -439,5 +437,5 @@ binds { Mod+M allow-inhibiting=false { quit; } - Mod+Shift+P { power-off-monitors; } + Mod+Shift+P { spawn-sh "(hyprlock &) && niri msg action power-off-monitors"; } } diff --git a/config/quickshell/Constants/Icons.qml b/config/quickshell/Constants/Icons.qml index 3f5f5a3..190f323 100644 --- a/config/quickshell/Constants/Icons.qml +++ b/config/quickshell/Constants/Icons.qml @@ -9,8 +9,8 @@ Singleton { // Nerd fonts icons readonly property string distro: "󰣇" readonly property string tray: "" - readonly property string idleInhibitorActivated: "" - readonly property string idleInhibitorDeactivated: "" + readonly property string idleInhibitorActivated: "󰅶" + readonly property string idleInhibitorDeactivated: "󰾪" readonly property string powerMenu: "󰐥" readonly property string volumeHigh: "" readonly property string volumeMedium: "" diff --git a/config/quickshell/Modules/Bar/Components/TrayExpander.qml b/config/quickshell/Modules/Bar/Components/TrayExpander.qml index 1e287f9..206d456 100644 --- a/config/quickshell/Modules/Bar/Components/TrayExpander.qml +++ b/config/quickshell/Modules/Bar/Components/TrayExpander.qml @@ -18,6 +18,7 @@ Item { anchors.top: parent.top anchors.bottom: parent.bottom + spacing: 0 SymbolButton { symbol: Icons.tray diff --git a/config/quickshell/Services/BrightnessService.qml b/config/quickshell/Services/BrightnessService.qml index 2ad976f..6409cf8 100644 --- a/config/quickshell/Services/BrightnessService.qml +++ b/config/quickshell/Services/BrightnessService.qml @@ -281,7 +281,7 @@ Singleton { Quickshell.execDetached(["ddcutil", "-b", busNum, "setvcp", "10", rounded]) } else { monitor.ignoreNextChange = true - Quickshell.execDetached(["set-brightness", rounded + "%"]) + Quickshell.execDetached(["sh", "-c", "brightnessctl -d $BRIGHTNESSCTL_DEVICE set "+ rounded + "%"]) } if (isDdc) { diff --git a/config/quickshell/Services/LyricsService.qml b/config/quickshell/Services/LyricsService.qml index 91f2b3e..8c98f96 100644 --- a/config/quickshell/Services/LyricsService.qml +++ b/config/quickshell/Services/LyricsService.qml @@ -26,7 +26,7 @@ Singleton { Logger.log("LyricsService", "Starting lyrics syncing"); // fill lyrics with empty lines lyrics = Array(linesCount).fill(" "); - listenProcess.exec(["sh", "-c", `sl-wrap listen -l ${linesCount} -a ${linesAhead} -f ${offsetFile}`]); + listenProcess.exec(["sh", "-c", `pkill -x spotify-lyrics -u $USER; spotify-lyrics listen -l ${linesCount} -a ${linesAhead} -f ${offsetFile}`]); } } @@ -35,14 +35,13 @@ Singleton { Logger.log("LyricsService", "Reference count:", referenceCount); if (referenceCount <= 0) { Logger.log("LyricsService", "Stopping lyrics syncing"); - // Execute again to stop - // kinda ugly but works, but meanwhile: + // kinda ugly but works, meanwhile: // listenProcess.signal(9) // listenProcess.signal(15) // listenProcess.running = false - // counts on exec() to terminate previous exec() + // counting on exec() to terminate previous exec() // all don't work - listenProcess.exec(["sh", "-c", `sl-wrap trackid`]); + listenProcess.exec(["sh", "-c", `pkill -x spotify-lyrics -u $USER`]); } } diff --git a/config/waybar/config.jsonc b/config/waybar/config.jsonc index ad48f48..d8e3c74 100644 --- a/config/waybar/config.jsonc +++ b/config/waybar/config.jsonc @@ -136,8 +136,8 @@ "format-alt-click": "click-right", //"format-icons": ["", ""], "format-icons": [""], - "on-scroll-down": "brightnessctl --class=backlight set -5%", - "on-scroll-up": "brightnessctl --class=backlight set +5%", + "on-scroll-down": "brightnessctl -d $BRIGHTNESSCTL_DEVICE set -5%", + "on-scroll-up": "brightnessctl -d $BRIGHTNESSCTL_DEVICE set +5%", "max-length": 6, "min-length": 6 }, diff --git a/memo/powerprofile b/memo/powerprofile new file mode 100644 index 0000000..c0709f2 --- /dev/null +++ b/memo/powerprofile @@ -0,0 +1,6 @@ +powerprofilectl: + systemctl start/enable --now power-profiles-daemon.service + powerprofilectl set performance/balanced/power-saver + +cpupower: + cpupower frequency-set --governor performance \ No newline at end of file diff --git a/scripts/change-wallpaper b/scripts/change-wallpaper index bc25fe9..1fb8262 100755 --- a/scripts/change-wallpaper +++ b/scripts/change-wallpaper @@ -1,6 +1,28 @@ #!/usr/bin/env bash -# Select image file if none is provided +# Required tools: +# - zenity (for file selection dialog) +# - imagemagick (for image processing) +# - swww (wallpaper daemon) +# - notify-send (for notifications) +# - change-colortheme (from scripts/change-colortheme) +# - flock (usually part of util-linux) + +# Lock + +exec {LOCK_FD}>/tmp/"$(basename "$0")".lock || { + echo "Failed to open lock file" + exit 1 +} + +flock -n "$LOCK_FD" || { + echo "Another instance is running. Exiting." + notify-send -a "change-wallpaper" "Error" "Another instance is running. Exiting." + exit 1 +} + +# Open a file selection dialog if no argument is provided + if [ -z "$1" ]; then image=$(zenity --file-selection --title="Open File" --file-filter="*.jpg *.jpeg *.png *.webp *.bmp *.jfif *.tiff *.avif *.heic *.heif") else diff --git a/scripts/config-load b/scripts/config-load new file mode 100755 index 0000000..40d82a2 --- /dev/null +++ b/scripts/config-load @@ -0,0 +1,34 @@ +#!/bin/sh + +path="$(dirname "$(readlink -f "$0")")" +backupDir="$HOME/.config/config-backup/$(date +%Y%m%d-%H%M%S)" +backupDirCreated=0 + +sources="" +if [ -z "$1" ]; then + sources=$(find "$path/../config/" -maxdepth 1 -not -path "$path/../config") +else + for arg in "$@"; do + src="$path/../config/$arg" + if [ ! -e "$src" ]; then + echo "Error: Config '$arg' does not exist." >&2 + exit 1 + fi + sources="$sources $path/../config/$arg" + done +fi + +for src in $sources; do + name="$(basename "$src")" + dest="$HOME/.config/$name" + + if [ -e "$dest" ] || [ -L "$dest" ]; then + [ "$backupDirCreated" -eq 0 ] && { + mkdir -pv "$backupDir" + backupDirCreated=1 + } + mv -vf "$dest" "$backupDir/" + fi + + ln -sv "$(realpath --relative-to="$HOME/.config" "$src")" "$dest" +done diff --git a/scripts/config-switch b/scripts/config-switch index 2a002f9..21329aa 100755 --- a/scripts/config-switch +++ b/scripts/config-switch @@ -9,13 +9,18 @@ else fi for item in "kitty" "ghostty" "wlogout"; do - [ -L "$HOME/.config/$item" ] || exit 1 - - rm "$HOME/.config/$item" + for target in "$item" "$item-niri"; do + if [ -L "$HOME/.config/$target" ]; then + rm -v "$HOME/.config/$target" + elif [ -e "$HOME/.config/$target" ]; then + echo "Error: $HOME/.config/$target is not a symlink." >&2 + exit 1 + fi + done if [ "$desktop" = "niri" ]; then - ln -s "$path/../config/$item-niri" "$HOME/.config/$item" + ln -sv "$path/../config/$item-niri" "$HOME/.config/$item" else - ln -s "$path/../config/$item" "$HOME/.config/$item" + ln -sv "$path/../config/$item" "$HOME/.config/$item" fi done \ No newline at end of file diff --git a/scripts/screenshot b/scripts/screenshot index 6dd1c98..fd2be65 100755 --- a/scripts/screenshot +++ b/scripts/screenshot @@ -42,7 +42,9 @@ def take_screenshot(filepath: Path, typeStr: str): ScreenshotType.AREA: f"hyprshot -z -m region -o {SCREENSHOT_DIR} -f ", ScreenshotType.WINDOW: f"hyprshot -z -m window -o {SCREENSHOT_DIR} -f ", } - os.system(f"{cmd[type]}{filepath.name}") + if os.system(f"{cmd[type]}{filepath.name}"): + print("Failed to take screenshot.") + exit(1) wait_until_file_exists(filepath) elif "niri" in currentDesktop: cmd = { @@ -53,10 +55,15 @@ def take_screenshot(filepath: Path, typeStr: str): niriScreenshotPath = SCREENSHOT_DIR / ".niri_screenshot.png" if niriScreenshotPath.exists(): niriScreenshotPath.unlink() - os.system(cmd[type]) + if os.system(cmd[type]): + print("Failed to take screenshot.") + exit(1) wait_until_file_exists(niriScreenshotPath) if niriScreenshotPath.exists(): niriScreenshotPath.rename(filepath) + else: + print("Failed to take screenshot.") + exit(1) wait_until_file_exists(filepath) else: print("Unsupported desktop environment.") @@ -120,7 +127,7 @@ if __name__ == "__main__": ) n.add_action( "default", - "Default", + "Open in Editor", edit_callback, None ) diff --git a/scripts/set-brightness b/scripts/set-brightness deleted file mode 100755 index f6834f3..0000000 --- a/scripts/set-brightness +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -[ -z "$1" ] && exit 1 -[ -z "$BRIGHTNESSCTL_DEVICE" ] && BRIGHTNESSCTL_DEVICE="auto" - -brightnessctl -d "$BRIGHTNESSCTL_DEVICE" set "$1" \ No newline at end of file diff --git a/scripts/sl-wrap b/scripts/sl-wrap deleted file mode 100755 index e6d3e27..0000000 --- a/scripts/sl-wrap +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -pgrep -f spotify-lyrics -u "$USER" && (killall spotify-lyrics -u "$USER" || exit 1) -spotify-lyrics "$@"