diff --git a/.zshrc b/.zshrc new file mode 100644 index 0000000..d9bd396 --- /dev/null +++ b/.zshrc @@ -0,0 +1,164 @@ +# Powerlevel10k instant prompt. Keep near the top of ~/.zshrc. +if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then + source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" +fi + +# Environment +path=(~/.local/bin $path) +typeset -x XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" +typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet + +# Shell options +setopt correct +setopt interactive_comments + +# Load zinit and OMZ libs +load_omz_lib() { + local i + for i in theme-and-appearance.zsh git.zsh prompt_info_functions.zsh history.zsh; do + zinit snippet "OMZL::${i}" + done + + for i in completion.zsh key-bindings.zsh; do + zinit ice lucid wait="1" + zinit snippet "OMZL::${i}" + done +} + +load_zinit_compinit_function() { + zpcompinit + zpcdreplay +} + +# Install zinit manually (official way) with GitHub proxy for China mainland +ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git" +[[ ! -d "${ZINIT_HOME}" ]] && mkdir -p "$(dirname "${ZINIT_HOME}")" +[[ ! -d "${ZINIT_HOME}/.git" ]] && git clone https://gh-proxy.org/https://github.com/zdharma-continuum/zinit.git "${ZINIT_HOME}" +source "${ZINIT_HOME}/zinit.zsh" +load_omz_lib + +# Theme: Powerlevel10k +zinit ice depth=1 +zinit light romkatv/powerlevel10k +skip_global_compinit=1 +load_zinit_compinit_function + +# Plugins (zinit official style) +# command-not-found: command missing 时提示可安装的软件包 +if [[ -e /usr/lib/command-not-found ]]; then + zinit ice lucid wait="0" + zinit snippet OMZP::command-not-found +fi + +# colored-man-pages: man 页面彩色高亮 +zinit ice lucid wait="3" +zinit snippet OMZP::colored-man-pages + +# fast-syntax-highlighting: 命令行语法高亮 +zinit ice wait lucid atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" +zinit light zdharma-continuum/fast-syntax-highlighting + +# zsh-autosuggestions: 基于历史记录的命令自动建议 +zinit ice wait lucid atload"_zsh_autosuggest_start" +zinit light zsh-users/zsh-autosuggestions + +# sudo: 双击 ESC 为当前命令加 sudo 前缀 +zinit ice lucid wait="2" +zinit snippet OMZP::sudo + +# z: 目录访问频率跳转 +zinit ice lucid wait="1" +zinit snippet OMZP::z +unsetopt BG_NICE + +# git: 提供 git 常用别名与函数 +zinit ice lucid wait="1" +zinit snippet OMZP::git + +# extract: 一条命令解压多种压缩格式,并加载其补全 +zinit ice lucid wait="1" +zinit snippet OMZP::extract + +# OMZ kubectl: kubectl 别名、补全与辅助函数 +zinit ice lucid wait="1" +zinit snippet OMZP::kubectl + +# Powerlevel10k config +[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh + +# Aliases +alias ...=../.. +alias ....=../../.. +alias .....=../../../.. +alias ......=../../../../.. +alias 1='cd -' +alias 2='cd -2' +alias 3='cd -3' +alias 4='cd -4' +alias 5='cd -5' +alias 6='cd -6' +alias 7='cd -7' +alias 8='cd -8' +alias 9='cd -9' +alias _='sudo ' +alias afind='ack -il' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' +alias gc1='git clone --recursive --depth=1' +alias globurl='noglob urlglobber ' +alias grep='grep --color=auto' +alias md='mkdir -p' +alias rd='rmdir' + +if [[ -n "$(command -v eza)" ]]; then + DISABLE_LS_COLORS=true + alias ls='eza --color=auto' + alias l='eza -lbah --icons=auto' + alias la='eza -labgh --icons=auto' + alias ll='eza -lbg --icons=auto' + alias lt='eza -lTbg --icons=auto' + alias lsa='eza -lbagR --icons=auto' + alias lst='eza -lTabgh --icons=auto' +else + alias ls='ls --color=auto' + alias l='ls -lah' + alias la='ls -lAh' + alias ll='ls -lh' + alias lsa='ls -lah' + alias lst='tree -pCsh' +fi + +# yazi: open and jump to last cwd +function y() { + local tmp cwd + tmp="$(mktemp -t yazi-cwd.XXXXXX)" + yazi "$@" --cwd-file="$tmp" + cwd="$(cat -- "$tmp")" + if [[ -n "$cwd" && "$cwd" != "$PWD" ]]; then + builtin cd -- "$cwd" + fi + rm -f -- "$tmp" +} + +# uv: Python package manager(自动补全) +if (( $+commands[uv] )); then + eval "$(uv generate-shell-completion zsh)" +fi + +# 快速开关代理(添加到 ~/.bashrc) +alias proxy-on='export http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890' +alias proxy-off='unset http_proxy https_proxy' + +# Required packages +# - zsh +# - git +# - zinit +# - powerlevel10k +# - eza (optional, for modern ls aliases) +# - tree (optional, fallback for lst alias) +# - ack (optional, for afind alias) +# - yazi (terminal file manager) +# - uv (Python package manager) +# - kubectl (for OMZ kubectl plugin) +# - command-not-found (optional, distro package name may vary) +# - bat or batcat (optional, if you later add bat aliases) diff --git a/README.md b/README.md index 96bf7ed..07c10b8 100644 --- a/README.md +++ b/README.md @@ -1 +1,193 @@ -# dotfiles +# luochen570/dotfiles + +个人 Linux/WSL 环境配置,集成 **ZSH** + **Neovim (NvChad)**。 + +## 总览 + +| 项目 | 内容 | +|------|------| +| Shell | ZSH + zinit + Powerlevel10k | +| 编辑器 | Neovim + NvChad v2.5 + lazy.nvim | +| 系统 | WSL / Debian / Ubuntu | + +--- + +## 安装 + +### 1. 克隆仓库 + +```bash +git clone git@github.com:luochen570/dotfiles.git ~/dotfiles +cd ~/dotfiles +``` + +### 2. 安装必要包 + +```bash +# Debian / Ubuntu +sudo apt install -y \ + zsh git curl wget \ + eza tree bat \ + unzip ripgrep fd-find \ + fzf command-not-found + +# yazi(终端文件管理器) +# curl -sL https://github.com/sxyazi/yazi/releases/latest/download/yazi-x86_64-unknown-linux-gnu.zip +# 或使用包管理器 / cargo +# cargo install yazi-fm + +# uv(Python 包管理器) +curl -LsSf https://astral.sh/uv/install.sh | sh +``` + +### 3. 安装 ZSH + +```bash +# 设置 ZSH 为默认 shell +chsh -s $(which zsh) + +# 安装 zinit(如未自动安装) +ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git" +mkdir -p "$(dirname "$ZINIT_HOME")" +git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME" +``` + +### 4. 部署配置 + +```bash +# ZSH 配置 +ln -sf ~/dotfiles/.zshrc ~/.zshrc + +# Neovim 配置(NvChad) +ln -sf ~/dotfiles/nvim ~/.config/nvim + +# Powerlevel10k 配置(可选) +ln -sf ~/dotfiles/.p10k.zsh ~/.p10k.zsh +``` + +### 5. 安装 Neovim 插件 + +启动 Neovim 后自动安装: + +```bash +nvim +``` + +等待 lazy.nvim 下载完成即可。 + +--- + +## ZSH 配置 + +### 主题:Powerlevel10k + +使用 [Powerlevel10k](https://github.com/romkatv/powerlevel10k) 作为 ZSH 主题,提供丰富的提示信息: + +- Git 状态(分支、修改、未跟踪) +- 命令执行时间 +- 当前目录 +- 后台作业 +- 错误码状态 + +首次启动会进入交互式配置向导,按喜好选择样式即可。 + +### 插件管理器:zinit + +使用 [zinit](https://github.com/zdharma-continuum/zinit) 作为插件管理器,支持异步加载,启动速度快。 + +### 加载的插件 + +| 插件 | 说明 | 加载方式 | +|------|------|---------| +| **OMZL::git** | Git 补全与函数 | 同步 | +| **OMZL::history** | 历史记录设置 | 同步 | +| **OMZL::key-bindings** | 按键绑定 | 延迟 1s | +| **OMZL::completion** | 补全系统 | 延迟 1s | +| **command-not-found** | 命令缺失提示 | 延迟 0s | +| **colored-man-pages** | man 页彩色高亮 | 延迟 3s | +| **fast-syntax-highlighting** | 命令行语法高亮 | 异步 | +| **zsh-autosuggestions** | 历史命令建议 | 异步 | +| **sudo** | 双击 ESC 加 sudo | 延迟 2s | +| **z** | 目录频率跳转 | 延迟 1s | +| **git** | Git 别名与函数 | 延迟 1s | +| **extract** | 一键解压 | 延迟 1s | +| **kubectl** | Kubernetes 补全 | 延迟 2s | +| **helm** | Helm 补全 | 延迟 2s | + +### 别名 + +| 命令 | 说明 | +|------|------| +| `ls` | eza(现代 ls,带颜色/图标) | +| `l` / `la` / `ll` / `lt` | eza 各种格式输出 | +| `lst` | 树形目录(eza tree 或 tree) | +| `...` / `....` | cd ../.. / cd ../../.. | +| `1` ~ `9` | cd -1 ~ cd -9(目录历史快速跳转) | +| `_` | sudo(空格加命令) | +| `gc1` | git clone --recursive --depth=1 | +| `md` | mkdir -p | +| `rd` | rmdir | +| `proxy-on` / `proxy-off` | HTTP 代理开关(127.0.0.1:7890) | +| `y` | yazi 文件管理器并自动 cd 到退出目录 | +| `uv` | Python 包管理器(含自动补全) | + +--- + +## Neovim 配置 + +使用 [NvChad v2.5](https://github.com/NvChad/NvChad) 作为基础,通过 lazy.nvim 管理插件。 + +### 结构 + +``` +nvim/ +├── init.lua # 入口 +├── lua/ +│ ├── chadrc.lua # NvChad 配置覆盖 +│ ├── mappings.lua # 自定义快捷键 +│ ├── options.lua # 编辑器选项 +│ ├── autocmds.lua # 自动命令 +│ ├── plugins/ +│ │ └── init.lua # 额外插件 +│ └── configs/ +│ ├── lazy.lua # lazy.nvim 配置 +│ ├── lspconfig.lua # LSP 配置 +│ └── conform.lua # 格式化配置 +└── lazy-lock.json # 插件版本锁 +``` + +### 快捷键 + +| 按键 | 说明 | +|------|------| +| `` | Leader 键 | +| `ff` | 查找文件 (Telescope) | +| `fg` | 查找文本 (Telescope) | +| `fb` | 查找缓冲区 (Telescope) | +| `e` | 文件树 (NvimTree) | +| `K` | 查看 LSP 文档 | +| `gd` | 跳转到定义 | +| `gr` | 查找引用 | + +### 已配置的语言支持 + +开箱即用的 LSP + 格式化: + +- Lua(lua_ls + stylua) +- Go(gopls + gofmt) +- Python(pyright + black) +- TypeScript / JavaScript(ts_ls + prettier) +- Rust(rust_analyzer) +- YAML / JSON / Markdown + +--- + +## 国内加速 + +如需在中国大陆使用,zinit 和 Neovim 插件管理器会自动使用 GitHub 代理镜像加速。 + +--- + +## 许可证 + +MIT diff --git a/nvim b/nvim new file mode 160000 index 0000000..e3572e1 --- /dev/null +++ b/nvim @@ -0,0 +1 @@ +Subproject commit e3572e1f5e1c297212c3deeb17b7863139ce663e