better stow (vielleicht :/

This commit is contained in:
2025-11-10 19:49:56 +01:00
parent 89a95d9bd7
commit 94118d682b
61 changed files with 139 additions and 19 deletions

109
config-stow Executable file
View File

@@ -0,0 +1,109 @@
#!/usr/bin/env python3
import subprocess
from argparse import ArgumentParser
from pathlib import Path
BASE_PKGS = [
"clang",
"scripts",
"stow"
]
TUI_PKGS = [
*BASE_PKGS,
"fastfetch",
"nvim",
"shell",
"yazi"
]
GUI_BASE_PKGS = [
*TUI_PKGS,
"kitty",
"ghostty",
"misc",
"mpv",
"wallpaper",
]
HYPRLAND_PKGS = [
*GUI_BASE_PKGS,
"eww",
"hypr",
"mako",
"rofi",
"waybar",
"wlogout"
]
NIRI_PKGS = [
*GUI_BASE_PKGS,
"niri",
"quickshell",
"rofi",
"wlogout"
]
PKGS = {
"base": BASE_PKGS,
"tui": TUI_PKGS,
"gui": GUI_BASE_PKGS,
"hyprland": HYPRLAND_PKGS,
"niri": NIRI_PKGS
}
PKGS_PATH = Path(__file__).resolve().parent.resolve() / "config"
DEST_PATH = Path.home().expanduser()
def _log(level: str, message: str):
color = "\033[92m" if level == "INFO" else "\033[91m" if level == "ERROR" else "\033[0m"
reset = "\033[0m"
print(f"{color}[{level}] {message}{reset}")
def stow(pkg: str):
subprocess.run(["stow", "-v", "-d", str(PKGS_PATH), "-t", str(DEST_PATH), pkg], check=True)
def switch(session: str):
subprocess.run(["config-switch", session], check=True)
def main():
parser = ArgumentParser(description="Stow configuration packages.")
parser.add_argument(
"package",
choices=PKGS.keys(),
help="The configuration package to stow."
)
args = parser.parse_args()
selected_pkgs = PKGS[args.package]
for pkg in selected_pkgs:
try:
stow(pkg)
_log("INFO", f"Successfully stowed package '{pkg}'.")
except subprocess.CalledProcessError as e:
_log("ERROR", f"Failed to stow package '{pkg}': {e}")
if args.package == "hyprland":
try:
switch("Hypr")
_log("INFO", "Switched session to hyprland.")
except subprocess.CalledProcessError as e:
_log("ERROR", f"Failed to switch session: {e}")
elif args.package == "niri":
try:
switch("niri")
_log("INFO", "Switched session to niri.")
except subprocess.CalledProcessError as e:
_log("ERROR", f"Failed to switch session: {e}")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1 @@
.alt/ghostty-default

View File

@@ -0,0 +1 @@
.alt/ghostty-niri

View File

@@ -0,0 +1 @@
.alt/kitty-default

View File

@@ -0,0 +1 @@
.alt/kitty-niri

View File

@@ -295,7 +295,7 @@ screenshot-path "~/Pictures/Screenshots/.niri_screenshot.png"
binds {
// Apps
Mod+C { spawn-sh "code --password-store=gnome-libsecret"; }
Mod+E { spawn-sh "nautilus --new-window"; }
Mod+E { spawn-sh "dolphin --new-window"; }
Mod+W { spawn-sh "zen || zen-browser"; }
Mod+X { spawn "gnome-text-editor" "--new-window"; }
Mod+B { spawn-sh "pkill -x -n btop || ghostty -e btop"; }

View File

@@ -1,27 +1,29 @@
#!/usr/bin/env bash
path="$(dirname "$(readlink -f "$0")")"
if [ -z "$1" ]; then
desktop="$XDG_CURRENT_DESKTOP"
else
desktop="$1"
fi
config_path="$path/../../.."
for item in "kitty" "ghostty" "wlogout"; do
for target in "$item" "$item-niri"; do
if [ ! -L "$HOME/.config/$target" ] && [ -e "$HOME/.config/$target" ]; then
echo "Error: $HOME/.config/$target exists and is not a symlink." >&2
if [ ! -L "$HOME/.config/$item" ] && [ -e "$HOME/.config/$item" ]; then
echo "Error: $HOME/.config/$item exists and is not a symlink." >&2
exit 1
elif [ -L "$HOME/.config/$item" ]; then
rm "$HOME/.config/$item" || {
echo "Error: Failed to remove existing symlink $HOME/.config/$item." >&2
exit 1
fi
stow -t "$HOME" -d "$config_path" -D "$target"
done
}
fi
if [ "$desktop" = "niri" ] || [ "$desktop" = "GNOME" ]; then
stow -t "$HOME" -d "$config_path" "$item-niri"
if [ -e "$HOME/.config/.alt/${item}-niri" ]; then
ln -svf ".alt/${item}-niri" "$HOME/.config/$item"
elif [ -e "$HOME/.config/.alt/${item}-default" ]; then
ln -svf ".alt/${item}-default" "$HOME/.config/$item"
fi
else
stow -t "$HOME" -d "$config_path" "$item"
[ -e "$HOME/.config/.alt/${item}-default" ] && ln -svf ".alt/${item}-default" "$HOME/.config/$item"
fi
done

View File

@@ -11,6 +11,7 @@ from shutil import copy2
# autopep8: off
import gi
gi.require_version("Notify", "0.7")
from gi.repository import Notify, GLib
# autopep8: on
@@ -50,9 +51,9 @@ def take_screenshot(filepath: Path, typeStr: str):
wait_until_file_exists(filepath)
elif "niri" in currentDesktop:
cmd = {
ScreenshotType.FULL: f"niri msg action screenshot-screen",
ScreenshotType.AREA: f"niri msg action screenshot",
ScreenshotType.WINDOW: f"niri msg action screenshot-window",
ScreenshotType.FULL: "niri msg action screenshot-screen",
ScreenshotType.AREA: "niri msg action screenshot",
ScreenshotType.WINDOW: "niri msg action screenshot-window",
}
niriScreenshotPath = SCREENSHOT_DIR / ".niri_screenshot.png"
if niriScreenshotPath.exists():
@@ -77,6 +78,7 @@ def take_screenshot(filepath: Path, typeStr: str):
def edit_screenshot(filepath: Path):
subprocess.run(f"gradia {filepath}", shell=True)
# subprocess.run(f"spectacle -l --edit-existing {filepath}", shell=True)
def file_name(dir: Path, prefix="screenshot", ext=".png"):
@@ -131,7 +133,7 @@ if __name__ == "__main__":
n = Notify.Notification.new(
"Screenshot taken",
# Mako doesn't have action buttons displayed with notification cards,
"Click to edit"
"Click to edit",
)
n.add_action(
# so default action is used here, which will be triggered on clicking the notification card
@@ -139,7 +141,7 @@ if __name__ == "__main__":
# But for my (or to be precise, Noctalia's) quickshell config, buttons will be displayed with label
"Open in Editor",
edit_callback,
None
None,
)
# set timeout for close_callback

1
config/stow/.stowrc Normal file
View File

@@ -0,0 +1 @@
--target=~

View File

Before

Width:  |  Height:  |  Size: 969 B

After

Width:  |  Height:  |  Size: 969 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 877 B

After

Width:  |  Height:  |  Size: 877 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 969 B

After

Width:  |  Height:  |  Size: 969 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 877 B

After

Width:  |  Height:  |  Size: 877 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1 @@
.alt/wlogout-default

View File

@@ -0,0 +1 @@
.alt/wlogout-niri