#!/usr/bin/env bash # zsh + Oh My Zsh + Powerlevel10k + plugins (autosuggestions, syntax-highlighting). # Patches ~/.zshrc to set the theme, plugin list, fzf hook. set -euo pipefail # shellcheck source=./lib.sh source "$(cd "$(dirname "$0")" && pwd)/lib.sh" require_debian require_not_root apt_install zsh # Make zsh the default shell for $USER (idempotent). current_shell="$(getent passwd "$USER" | cut -d: -f7)" zsh_path="$(command -v zsh)" if [[ "$current_shell" != "$zsh_path" ]]; then log "Setting zsh as default shell for $USER (sudo will prompt)." sudo chsh -s "$zsh_path" "$USER" ok "Default shell set to $zsh_path. Takes effect on next login." else skip "zsh already default shell." fi # Oh My Zsh — install with RUNZSH=no to avoid spawning zsh during the script. OMZ_DIR="$HOME/.oh-my-zsh" if [[ -d "$OMZ_DIR" ]]; then skip "Oh My Zsh already installed." else log "Installing Oh My Zsh." RUNZSH=no CHSH=no KEEP_ZSHRC=yes sh -c \ "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ok "Oh My Zsh installed." fi ZSH_CUSTOM_DIR="${ZSH_CUSTOM:-$OMZ_DIR/custom}" clone_or_skip() { local name="$1" url="$2" dir="$3" if [[ -d "$dir" ]]; then skip "$name already cloned at $dir." else log "Cloning $name." git clone --depth=1 "$url" "$dir" ok "$name installed." fi } # Powerlevel10k theme. clone_or_skip "Powerlevel10k" \ "https://github.com/romkatv/powerlevel10k.git" \ "$ZSH_CUSTOM_DIR/themes/powerlevel10k" # Plugins. clone_or_skip "zsh-autosuggestions" \ "https://github.com/zsh-users/zsh-autosuggestions.git" \ "$ZSH_CUSTOM_DIR/plugins/zsh-autosuggestions" clone_or_skip "zsh-syntax-highlighting" \ "https://github.com/zsh-users/zsh-syntax-highlighting.git" \ "$ZSH_CUSTOM_DIR/plugins/zsh-syntax-highlighting" # Patch ~/.zshrc — theme + plugin list + fzf hook. ZSHRC="$HOME/.zshrc" [[ -f "$ZSHRC" ]] || touch "$ZSHRC" if grep -q '^ZSH_THEME=' "$ZSHRC"; then if grep -q '^ZSH_THEME="powerlevel10k/powerlevel10k"' "$ZSHRC"; then skip "ZSH_THEME already powerlevel10k." else sed -i 's#^ZSH_THEME=.*#ZSH_THEME="powerlevel10k/powerlevel10k"#' "$ZSHRC" ok "ZSH_THEME → powerlevel10k/powerlevel10k." fi else echo 'ZSH_THEME="powerlevel10k/powerlevel10k"' >> "$ZSHRC" ok 'Set ZSH_THEME=powerlevel10k/powerlevel10k.' fi PLUGINS_LINE='plugins=(git fzf zoxide direnv zsh-autosuggestions zsh-syntax-highlighting)' if grep -q '^plugins=' "$ZSHRC"; then if grep -q "^$PLUGINS_LINE" "$ZSHRC"; then skip "plugins=(...) already configured." else sed -i "s#^plugins=.*#$PLUGINS_LINE#" "$ZSHRC" ok "plugins=(...) updated." fi else echo "$PLUGINS_LINE" >> "$ZSHRC" ok "plugins=(...) added." fi ensure_line '[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh' "$ZSHRC" ok "zsh + Oh My Zsh + Powerlevel10k ready." log "Next: run 'exec zsh -l' then 'p10k configure' to pick a Powerlevel10k preset."