From c4241d7015bc22d8aed29e01e00a49f854fd3bb6 Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Sun, 6 Sep 2026 12:30:51 +0200 Subject: [PATCH] feat(zsh): provision Oh-My-Zsh and plugins for all users on login Co-authored-by: Junie --- config/packages/01-base.list | 3 ++ .../etc/profile.d/xdg_dirs_desktop_session.sh | 1 + .../hypr/scripts/install-dots-prompt.sh | 37 +++++++++++++++++++ data/skel/.zshrc | 21 +++++++++++ stages/07-skel-and-user.sh | 37 ++++++++++++++++++- 5 files changed, 98 insertions(+), 1 deletion(-) diff --git a/config/packages/01-base.list b/config/packages/01-base.list index 5551f8f..864dd60 100644 --- a/config/packages/01-base.list +++ b/config/packages/01-base.list @@ -61,3 +61,6 @@ unrar unzip zram-tools zsh +zsh-autosuggestions +zsh-doc +zsh-syntax-highlighting diff --git a/data/etc/profile.d/xdg_dirs_desktop_session.sh b/data/etc/profile.d/xdg_dirs_desktop_session.sh index 42dd443..83030bb 100755 --- a/data/etc/profile.d/xdg_dirs_desktop_session.sh +++ b/data/etc/profile.d/xdg_dirs_desktop_session.sh @@ -1,3 +1,4 @@ +#!/bin/sh # /etc/profile.d/desktop_session_xdg_dirs.sh - Prepend a $DESKTOP_SESSION-named directory to $XDG_CONFIG_DIRS and $XDG_DATA_DIRS DEFAULT_XDG_CONFIG_DIRS="/etc/xdg" diff --git a/data/skel/.config/hypr/scripts/install-dots-prompt.sh b/data/skel/.config/hypr/scripts/install-dots-prompt.sh index b520dfa..4bbe9e9 100755 --- a/data/skel/.config/hypr/scripts/install-dots-prompt.sh +++ b/data/skel/.config/hypr/scripts/install-dots-prompt.sh @@ -49,6 +49,40 @@ mark_as_prompted() { touch "$MARKER_FILE" 2>/dev/null || true } +install_oh_my_zsh() { + local zsh_dir="$HOME/.oh-my-zsh" + printf "\n" + printf "%b\n" "${CLR_BOLD}${CLR_CYAN}==============================================================================${CLR_RESET}" + printf "%b\n" "${CLR_BOLD}${CLR_CYAN} Oh-My-Zsh & Shell-Konfiguration ${CLR_RESET}" + printf "%b\n" "${CLR_BOLD}${CLR_CYAN}==============================================================================${CLR_RESET}" + printf "\n" + + if [[ ! -d "$zsh_dir" ]]; then + printf "%b\n" "${CLR_CYAN}[INFO] Richte Oh-My-Zsh für $USER ein...${CLR_RESET}" + if command -v git >/dev/null 2>&1; then + if git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$zsh_dir"; then + mkdir -p "$zsh_dir/custom/plugins" + git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "$zsh_dir/custom/plugins/zsh-autosuggestions" 2>/dev/null || true + git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting "$zsh_dir/custom/plugins/zsh-syntax-highlighting" 2>/dev/null || true + printf "%b\n" "${CLR_GREEN}[✓] Oh-My-Zsh erfolgreich eingerichtet.${CLR_RESET}" + else + printf "%b\n" "${CLR_YELLOW}[WARNUNG] Oh-My-Zsh konnte nicht geklont werden.${CLR_RESET}" + fi + else + printf "%b\n" "${CLR_RED}[FEHLER] 'git' ist nicht installiert. Oh-My-Zsh konnte nicht eingerichtet werden.${CLR_RESET}" + fi + else + # Plugins sicherstellen + if [[ ! -d "$zsh_dir/custom/plugins/zsh-autosuggestions" ]] && command -v git >/dev/null 2>&1; then + git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "$zsh_dir/custom/plugins/zsh-autosuggestions" 2>/dev/null || true + fi + if [[ ! -d "$zsh_dir/custom/plugins/zsh-syntax-highlighting" ]] && command -v git >/dev/null 2>&1; then + git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting "$zsh_dir/custom/plugins/zsh-syntax-highlighting" 2>/dev/null || true + fi + printf "%b\n" "${CLR_GREEN}[✓] Oh-My-Zsh ist bereits vorhanden und konfiguriert.${CLR_RESET}" + fi +} + install_junie_cli_and_skills() { printf "\n" printf "%b\n" "${CLR_BOLD}${CLR_CYAN}==============================================================================${CLR_RESET}" @@ -308,6 +342,9 @@ while true; do esac done +# Oh-My-Zsh & Plugins einrichten +install_oh_my_zsh + # JetBrains Junie CLI & AwesomeJunieSkills installieren install_junie_cli_and_skills diff --git a/data/skel/.zshrc b/data/skel/.zshrc index 3a390ca..c567396 100755 --- a/data/skel/.zshrc +++ b/data/skel/.zshrc @@ -3,6 +3,27 @@ export ZSH="$HOME/.oh-my-zsh" +# Automatic Oh-My-Zsh installation on login / shell startup if not yet installed +if [[ ! -d "$ZSH" ]]; then + if command -v git >/dev/null 2>&1; then + echo "Oh-My-Zsh ist nicht eingerichtet. Installiere Oh-My-Zsh für $USER..." + if git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$ZSH" 2>/dev/null; then + mkdir -p "${ZSH_CUSTOM:-$ZSH/custom}/plugins" + git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-autosuggestions" 2>/dev/null || true + git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting "${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-syntax-highlighting" 2>/dev/null || true + echo "Oh-My-Zsh erfolgreich eingerichtet." + fi + fi +else + # Plugins sicherstellen, falls Oh-My-Zsh existiert aber Custom-Plugins fehlen + if [[ ! -d "${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-autosuggestions" ]] && command -v git >/dev/null 2>&1; then + git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-autosuggestions" 2>/dev/null || true + fi + if [[ ! -d "${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-syntax-highlighting" ]] && command -v git >/dev/null 2>&1; then + git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting "${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-syntax-highlighting" 2>/dev/null || true + fi +fi + apt_pref='apt' apt_upgr='upgrade' diff --git a/stages/07-skel-and-user.sh b/stages/07-skel-and-user.sh index 9b0a371..d470f8b 100755 --- a/stages/07-skel-and-user.sh +++ b/stages/07-skel-and-user.sh @@ -51,6 +51,21 @@ if [[ -d "$SCRIPT_DIR/data/skel/.config" ]]; then chmod 0755 /etc/skel/.config/hypr/scripts/*.sh 2>/dev/null || true fi fi + +# Provision Oh-My-Zsh template in /etc/skel so newly created users receive it automatically +if command_exists git; then + if [[ ! -d /etc/skel/.oh-my-zsh ]]; then + log_info "Provisioning Oh-My-Zsh template in /etc/skel/.oh-my-zsh..." + git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git /etc/skel/.oh-my-zsh 2>/dev/null || log_warn "Could not clone Oh-My-Zsh into /etc/skel." + fi + if [[ -d /etc/skel/.oh-my-zsh ]]; then + mkdir -p /etc/skel/.oh-my-zsh/custom/plugins + [[ -d /etc/skel/.oh-my-zsh/custom/plugins/zsh-autosuggestions ]] || \ + git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions /etc/skel/.oh-my-zsh/custom/plugins/zsh-autosuggestions 2>/dev/null || true + [[ -d /etc/skel/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting ]] || \ + git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting /etc/skel/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting 2>/dev/null || true + fi +fi chown -R root:root /etc/skel # 3. Synchronize User Environment for Target User @@ -85,11 +100,23 @@ fi # 4. Install Oh-My-Zsh for Target User (if not already installed) if [[ ! -d "$TARGET_HOME/.oh-my-zsh" ]]; then log_substep "Installing Oh-My-Zsh repository for $TARGET_USER..." - if command_exists git; then + if [[ -d /etc/skel/.oh-my-zsh ]]; then + cp -r /etc/skel/.oh-my-zsh "$TARGET_HOME/.oh-my-zsh" + elif command_exists git; then run_as_target_user git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$TARGET_HOME/.oh-my-zsh" 2>/dev/null || log_warn "Could not clone Oh-My-Zsh repository." fi fi +if [[ -d "$TARGET_HOME/.oh-my-zsh" ]]; then + mkdir -p "$TARGET_HOME/.oh-my-zsh/custom/plugins" + if [[ ! -d "$TARGET_HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]] && command_exists git; then + run_as_target_user git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "$TARGET_HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" 2>/dev/null || true + fi + if [[ ! -d "$TARGET_HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]] && command_exists git; then + run_as_target_user git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting "$TARGET_HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" 2>/dev/null || true + fi +fi + # Fix ownership chown -R "$TARGET_USER:$TARGET_USER" "$TARGET_HOME/.zshrc" "$TARGET_HOME/Templates" "$TARGET_HOME/.config" "$TARGET_HOME/.junie" if [[ -d "$TARGET_HOME/.oh-my-zsh" ]]; then @@ -110,6 +137,14 @@ if [[ -x "$ZSH_BIN" ]]; then else log_info "Default shell for $TARGET_USER is already $ZSH_BIN" fi + + # Configure default shell for newly created users + if command_exists useradd; then + useradd -D -s "$ZSH_BIN" 2>/dev/null || true + fi + if [[ -f /etc/adduser.conf ]]; then + sed -i -E 's|^#?\s*DSHELL=.*|DSHELL='"$ZSH_BIN"'|' /etc/adduser.conf 2>/dev/null || true + fi else log_warn "Zsh binary not found at $ZSH_BIN. Skipping chsh." fi