diff --git a/setup_ubuntu.sh b/setup_ubuntu.sh index fe0d966..55ae8f7 100644 --- a/setup_ubuntu.sh +++ b/setup_ubuntu.sh @@ -1,98 +1,56 @@ #!/usr/bin/env bash +# === Ubuntu / UOS Quick Setup === +# Docker + Fastfetch + Neovim + Zsh(eza/fzf/zoxide/atuin/starship) set -euo pipefail -SCRIPT_NAME=$(basename "$0") -echo -e "\n=== Ubuntu Repos and Plugins Setup Script ===\n" +echo -e "\n🚀 === Ubuntu Environment Setup ===\n" -# Detect Ubuntu codename -CODENAME=$(lsb_release -cs) -echo "Detected Ubuntu codename: $CODENAME" +# --- Base --- +sudo apt update +sudo apt install -y curl git ca-certificates gnupg lsb-release software-properties-common -# Docker 官方支持的 Ubuntu 版本 -DOCKER_SUPPORTED_CODENAMES=("focal" "jammy") +# --- PPA --- +sudo add-apt-repository -y ppa:neovim-ppa/unstable || true +sudo add-apt-repository -y ppa:zhangsongcui3371/fastfetch || true -# 如果当前 codename 不在支持列表,回退到 jammy -if [[ ! " ${DOCKER_SUPPORTED_CODENAMES[*]} " =~ " ${CODENAME} " ]]; then - echo "Docker does not officially support '$CODENAME', falling back to 'jammy'" - CODENAME="jammy" +# --- 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" fi -# ==== 清理旧 Docker 源和包 ==== -echo "Cleaning old Docker sources and packages..." -sudo rm -f /etc/apt/sources.list.d/docker.list -sudo rm -f /usr/share/keyrings/docker-archive-keyring.gpg -sudo apt remove -y docker docker-engine docker.io containerd runc || true - -# ==== 函数 ==== -# 添加 PPA -add_ppa() { - local PPA="$1" - local PPA_NAME="${PPA#*:}" - if ! grep -Rq "$PPA_NAME" /etc/apt/sources.list.d 2>/dev/null; then - echo "Adding PPA: $PPA" - sudo add-apt-repository -y "$PPA" - else - echo "PPA already exists: $PPA" - fi -} - -# 添加 Docker 源 -add_docker_repo() { - local KEYRING="/usr/share/keyrings/docker-archive-keyring.gpg" - if [ ! -f "$KEYRING" ]; then - echo "Adding Docker GPG key and repository" - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | - sudo gpg --dearmor -o "$KEYRING" - echo "deb [arch=$(dpkg --print-architecture) signed-by=$KEYRING] https://download.docker.com/linux/ubuntu $CODENAME stable" | - sudo tee /etc/apt/sources.list.d/docker.list >/dev/null - else - echo "Docker repository already configured" - fi -} - -# ==== 添加 PPA ==== -add_ppa ppa:fish-shell/release-3 -add_ppa ppa:neovim-ppa/unstable -add_ppa ppa:zhangsongcui3371/fastfetch - -# ==== 添加 Docker 源 ==== -add_docker_repo - -# ==== 更新软件列表 ==== -echo -e "\nUpdating package lists..." -sudo apt update - -# 核心软件包 -CORE_PKGS=(docker-ce docker-ce-cli containerd.io fastfetch neovim fish tealdeer) - +# --- 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 - echo "Installing $pkg..." sudo apt install -y "$pkg" else - echo "Package not found in repos, skipping: $pkg" + echo "⚠️ Package not found in repos: $pkg" fi done -# ==== 安装 fisher 和 fish 插件 ==== -echo -e "\nInstalling Fisher and fish plugins..." -fish -c 'curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher' -fish -c 'fisher install bruno-ricard/fish-autopair Pure-Fish/pure' - -# ==== 安装 Atuin ==== +# --- Atuin --- if ! command -v atuin >/dev/null 2>&1; then - echo -e "\nInstalling Atuin..." + echo -e "\n📜 Installing Atuin..." curl -sS https://raw.githubusercontent.com/ellie/atuin/main/install.sh | bash else echo "Atuin already installed" fi -# ==== 改默认 shell 为 fish ==== -if [ "$SHELL" != "$(which fish)" ]; then - echo "Changing default shell to fish" - chsh -s "$(which fish)" +# --- Starship --- +if ! command -v starship >/dev/null 2>&1; then + echo -e "\n🌟 Installing Starship..." + curl -sS https://starship.rs/install.sh | sh -s -- -y else - echo "Default shell is already fish" + echo "Starship already installed" fi -echo -e "\n=== Setup Complete! Restart your terminal to apply changes. ===" +# --- Shell --- +if [ "$SHELL" != "$(command -v zsh)" ]; then + echo -e "\n💫 Changing default shell to zsh" + chsh -s "$(command -v zsh)" +fi + +echo -e "\n✅ All done! Restart your terminal or run 'exec zsh' to enjoy!" \ No newline at end of file diff --git a/zsh/.zshrc b/zsh/.zshrc new file mode 100644 index 0000000..f8ee8ff --- /dev/null +++ b/zsh/.zshrc @@ -0,0 +1,78 @@ +# ======================== +# Locale & Editor +# ======================== +export LANG=zh_CN.UTF-8 +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 + + # 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 + +# ======================== +# 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 + PROMPT='%F{green}%n@%m%f:%F{blue}%~%f %# ' + RPROMPT='%F{yellow}[%D{%H:%M}]%f' +fi \ No newline at end of file