diff --git a/setup_ubuntu.sh b/setup_ubuntu.sh index 55ae8f7..2bce183 100644 --- a/setup_ubuntu.sh +++ b/setup_ubuntu.sh @@ -1,56 +1,196 @@ -#!/usr/bin/env bash -# === Ubuntu / UOS Quick Setup === -# Docker + Fastfetch + Neovim + Zsh(eza/fzf/zoxide/atuin/starship) -set -euo pipefail +#!/bin/bash +set -e -echo -e "\n🚀 === Ubuntu Environment Setup ===\n" - -# --- Base --- +# ============================= +# 基础软件 +# ============================= sudo apt update -sudo apt install -y curl git ca-certificates gnupg lsb-release software-properties-common +sudo apt install -y \ + build-essential curl wget git unzip \ + ca-certificates gnupg lsb-release software-properties-common \ + zsh neovim eza fzf zoxide -# --- PPA --- -sudo add-apt-repository -y ppa:neovim-ppa/unstable || true -sudo add-apt-repository -y ppa:zhangsongcui3371/fastfetch || true +# ============================= +# 安装 Docker +# ============================= +echo ">>> Installing Docker..." -# --- Docker --- -if ! command -v docker >/dev/null 2>&1; then - echo -e "\n🐳 Installing Docker (official script)..." - curl -fsSL https://get.docker.com | sh -else - echo "🐳 Docker already installed" +sudo install -m 0755 -d /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg + +echo \ +"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ +https://download.docker.com/linux/ubuntu \ +$(lsb_release -sc) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + +sudo apt update +sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +# 加入 Docker 组(避免 sudo) +sudo usermod -aG docker "$USER" +echo ">>> Added $USER to docker group" + +# ============================= +# 安装 Atuin +# ============================= +echo ">>> Installing Atuin..." +curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh | bash + +# ============================= +# 安装 Starship +# ============================= +echo ">>> Installing Starship..." +curl -sS https://starship.rs/install.sh | sh -s -- -y + +# ============================= +# 安装 JetBrainsMono Nerd Font +# ============================= +FONT_NAME="JetBrainsMono" +ZIP_URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${FONT_NAME}.zip" +ZIP_FILE="/tmp/${FONT_NAME}.zip" +FONT_DIR="$HOME/.local/share/fonts" + +echo ">>> Downloading Nerd Font..." + +mkdir -p "$FONT_DIR" + +# 下载失败自动切换 FastGit +wget -O "$ZIP_FILE" "$ZIP_URL" || \ +wget -O "$ZIP_FILE" "https://download.fastgit.org/ryanoasis/nerd-fonts/releases/latest/download/${FONT_NAME}.zip" + +unzip -o "$ZIP_FILE" -d "$FONT_DIR" +fc-cache -fv + +# ============================= +# 安装 zsh 插件 +# ============================= +echo ">>> Installing zsh plugins..." + +PLUGIN_DIR="$HOME/.config/zsh/plugins" +mkdir -p "$PLUGIN_DIR" + +# zsh-autosuggestions +if [ ! -d "$PLUGIN_DIR/zsh-autosuggestions" ]; then + git clone https://github.com/zsh-users/zsh-autosuggestions "$PLUGIN_DIR/zsh-autosuggestions" fi -# --- Package --- -CORE_PKGS=(fastfetch neovim zsh eza fzf zoxide ripgrep tealdeer) -for pkg in "${CORE_PKGS[@]}"; do - if apt-cache show "$pkg" >/dev/null 2>&1; then - sudo apt install -y "$pkg" - else - echo "⚠️ Package not found in repos: $pkg" +# syntax-highlighting +if [ ! -d "$PLUGIN_DIR/zsh-syntax-highlighting" ]; then + git clone https://github.com/zsh-users/zsh-syntax-highlighting "$PLUGIN_DIR/zsh-syntax-highlighting" +fi + +# fzf-tab +if [ ! -d "$PLUGIN_DIR/fzf-tab" ]; then + git clone https://github.com/Aloxaf/fzf-tab "$PLUGIN_DIR/fzf-tab" +fi + +# ============================= +# 生成 .zshrc +# ============================= +echo ">>> Generating ~/.zshrc..." + +cat > ~/.zshrc << 'EOF' +# ======================== +# Locale & Editor +# ======================== +export EDITOR=nano + +export PATH="$HOME/.atuin/bin:$PATH" + +# ======================== +# History +# ======================== +HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/zsh/history" +mkdir -p "$(dirname "$HISTFILE")" +HISTSIZE=10000 +SAVEHIST=10000 +setopt HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY INC_APPEND_HISTORY + +# ======================== +# Tools Integration +# ======================== +if [[ -o interactive ]]; then + # AtuIn + if command -v atuin >/dev/null 2>&1; then + eval "$(atuin init zsh)" fi -done -# --- Atuin --- -if ! command -v atuin >/dev/null 2>&1; then - echo -e "\n📜 Installing Atuin..." - curl -sS https://raw.githubusercontent.com/ellie/atuin/main/install.sh | bash -else - echo "Atuin already installed" + # zoxide + if command -v zoxide >/dev/null 2>&1; then + eval "$(zoxide init zsh)" + fi + + # starship + if command -v starship >/dev/null 2>&1; then + eval "$(starship init zsh)" + fi fi -# --- Starship --- +# ======================== +# Colors & Aliases +# ======================== +autoload -U colors && colors + +alias ls='eza --icons=auto --group-directories-first' +alias ll='eza -lh --icons=auto --group-directories-first' +alias la='eza -lha --icons=auto --group-directories-first' + +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' +alias ..='cd ..' +alias ...='cd ../..' + +# ======================== +# Completion +# ======================== +autoload -Uz compinit +mkdir -p ~/.cache/zsh +compinit -d ~/.cache/zsh/zcompdump +setopt CORRECT + +if [[ -o interactive ]]; then + source ~/.config/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh + source ~/.config/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + source ~/.config/zsh/plugins/fzf-tab/fzf-tab.plugin.zsh + + ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' + ZSH_AUTOSUGGEST_STRATEGY=(history completion) + + bindkey -e +fi + +# ======================== +# Prompt +# ======================== if ! command -v starship >/dev/null 2>&1; then - echo -e "\n🌟 Installing Starship..." - curl -sS https://starship.rs/install.sh | sh -s -- -y + PROMPT='%F{green}%n@%m%f:%F{blue}%~%f %# ' + RPROMPT='%F{yellow}[%D{%H:%M}]%f' +fi +EOF + +# ============================= +# 设置 GNOME Terminal 字体 +# ============================= +if command -v gsettings >/dev/null; then + if gsettings list-schemas | grep -q "org.gnome.Terminal"; then + echo ">>> Setting GNOME Terminal font..." + + PROFILE_ID=$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d "'") + PROFILE_PATH="org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:$PROFILE_ID/" + + gsettings set "$PROFILE_PATH" font 'JetBrainsMono Nerd Font Mono 14' || true + else + echo "⚠️ 检测到不是 GNOME Terminal,跳过字体设置。" + fi else - echo "Starship already installed" + echo "⚠️ gsettings 不可用,跳过终端字体设置。" fi -# --- Shell --- -if [ "$SHELL" != "$(command -v zsh)" ]; then - echo -e "\n💫 Changing default shell to zsh" - chsh -s "$(command -v zsh)" -fi +# ============================= +# 更改默认 shell 为 zsh +# ============================= +echo ">>> Changing default shell to zsh..." +chsh -s "$(which zsh)" -echo -e "\n✅ All done! Restart your terminal or run 'exec zsh' to enjoy!" \ No newline at end of file +echo ">>> 完成!重新登录即可生效所有配置。" diff --git a/zsh/.zshrc b/zsh/.zshrc index f8ee8ff..fce1c8c 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -1,7 +1,6 @@ # ======================== # Locale & Editor # ======================== -export LANG=zh_CN.UTF-8 export EDITOR=nano export PATH="$HOME/.atuin/bin:$PATH" @@ -75,4 +74,4 @@ fi if ! command -v starship >/dev/null 2>&1; then PROMPT='%F{green}%n@%m%f:%F{blue}%~%f %# ' RPROMPT='%F{yellow}[%D{%H:%M}]%f' -fi \ No newline at end of file +fi