mirror of
https://github.com/Dichgrem/dotfiles.git
synced 2025-12-16 13:02:00 -05:00
fix:setup.sh
This commit is contained in:
222
setup_ubuntu.sh
222
setup_ubuntu.sh
@@ -1,56 +1,196 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
# === Ubuntu / UOS Quick Setup ===
|
set -e
|
||||||
# Docker + Fastfetch + Neovim + Zsh(eza/fzf/zoxide/atuin/starship)
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
echo -e "\n🚀 === Ubuntu Environment Setup ===\n"
|
# =============================
|
||||||
|
# 基础软件
|
||||||
# --- Base ---
|
# =============================
|
||||||
sudo apt update
|
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
|
# 安装 Docker
|
||||||
sudo add-apt-repository -y ppa:zhangsongcui3371/fastfetch || true
|
# =============================
|
||||||
|
echo ">>> Installing Docker..."
|
||||||
|
|
||||||
# --- Docker ---
|
sudo install -m 0755 -d /etc/apt/keyrings
|
||||||
if ! command -v docker >/dev/null 2>&1; then
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
echo -e "\n🐳 Installing Docker (official script)..."
|
|
||||||
curl -fsSL https://get.docker.com | sh
|
echo \
|
||||||
else
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
|
||||||
echo "🐳 Docker already installed"
|
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
|
fi
|
||||||
|
|
||||||
# --- Package ---
|
# syntax-highlighting
|
||||||
CORE_PKGS=(fastfetch neovim zsh eza fzf zoxide ripgrep tealdeer)
|
if [ ! -d "$PLUGIN_DIR/zsh-syntax-highlighting" ]; then
|
||||||
for pkg in "${CORE_PKGS[@]}"; do
|
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$PLUGIN_DIR/zsh-syntax-highlighting"
|
||||||
if apt-cache show "$pkg" >/dev/null 2>&1; then
|
fi
|
||||||
sudo apt install -y "$pkg"
|
|
||||||
else
|
# fzf-tab
|
||||||
echo "⚠️ Package not found in repos: $pkg"
|
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
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
# --- Atuin ---
|
# zoxide
|
||||||
if ! command -v atuin >/dev/null 2>&1; then
|
if command -v zoxide >/dev/null 2>&1; then
|
||||||
echo -e "\n📜 Installing Atuin..."
|
eval "$(zoxide init zsh)"
|
||||||
curl -sS https://raw.githubusercontent.com/ellie/atuin/main/install.sh | bash
|
fi
|
||||||
else
|
|
||||||
echo "Atuin already installed"
|
# starship
|
||||||
|
if command -v starship >/dev/null 2>&1; then
|
||||||
|
eval "$(starship init zsh)"
|
||||||
|
fi
|
||||||
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
|
if ! command -v starship >/dev/null 2>&1; then
|
||||||
echo -e "\n🌟 Installing Starship..."
|
PROMPT='%F{green}%n@%m%f:%F{blue}%~%f %# '
|
||||||
curl -sS https://starship.rs/install.sh | sh -s -- -y
|
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
|
else
|
||||||
echo "Starship already installed"
|
echo "⚠️ gsettings 不可用,跳过终端字体设置。"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Shell ---
|
# =============================
|
||||||
if [ "$SHELL" != "$(command -v zsh)" ]; then
|
# 更改默认 shell 为 zsh
|
||||||
echo -e "\n💫 Changing default shell to zsh"
|
# =============================
|
||||||
chsh -s "$(command -v zsh)"
|
echo ">>> Changing default shell to zsh..."
|
||||||
fi
|
chsh -s "$(which zsh)"
|
||||||
|
|
||||||
echo -e "\n✅ All done! Restart your terminal or run 'exec zsh' to enjoy!"
|
echo ">>> 完成!重新登录即可生效所有配置。"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# ========================
|
# ========================
|
||||||
# Locale & Editor
|
# Locale & Editor
|
||||||
# ========================
|
# ========================
|
||||||
export LANG=zh_CN.UTF-8
|
|
||||||
export EDITOR=nano
|
export EDITOR=nano
|
||||||
|
|
||||||
export PATH="$HOME/.atuin/bin:$PATH"
|
export PATH="$HOME/.atuin/bin:$PATH"
|
||||||
@@ -75,4 +74,4 @@ fi
|
|||||||
if ! command -v starship >/dev/null 2>&1; then
|
if ! command -v starship >/dev/null 2>&1; then
|
||||||
PROMPT='%F{green}%n@%m%f:%F{blue}%~%f %# '
|
PROMPT='%F{green}%n@%m%f:%F{blue}%~%f %# '
|
||||||
RPROMPT='%F{yellow}[%D{%H:%M}]%f'
|
RPROMPT='%F{yellow}[%D{%H:%M}]%f'
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user