From 4349da57eac37080438a58dcd238a7494920e941 Mon Sep 17 00:00:00 2001 From: luochen570 <1160510664@qq.com> Date: Tue, 26 May 2026 12:45:07 +0800 Subject: [PATCH] sync: align home-manager zsh.nix with actual .zshrc - Add envExtra: PATH, XDG_CONFIG_HOME, POWERLEVEL9K_INSTANT_PROMPT, .hermes/node/bin - Add shell options: correct, interactive_comments - Add initExtra: p10k instant prompt, y() function, proxy-on/off aliases - Add missing aliases: cd -# (1-9), _ (sudo), rd, grep variants, afind, globurl - Add missing OMZ plugins: command-not-found, colored-man-pages, kubectl --- home/zsh.nix | 179 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 118 insertions(+), 61 deletions(-) diff --git a/home/zsh.nix b/home/zsh.nix index f5142ce..429232f 100644 --- a/home/zsh.nix +++ b/home/zsh.nix @@ -1,61 +1,118 @@ -{ config, pkgs, inputs, system, ... }: -{ programs.zsh = { - enable = true; - enableCompletion = true; - autosuggestion.enable = true; - syntaxHighlighting.enable = true; - # initContent = "source ~/.p10k.zsh"; - plugins = [ - { - name = "powerlevel10k"; - src = pkgs.zsh-powerlevel10k; - file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme"; - } - { - name = "fzf-tab"; - src = "${pkgs.zsh-fzf-tab}/share/fzf-tab"; - } - # { - # name = "powerlevel10k-config"; - # src = "/home/luochen570/nixos-config/modules/home/p10k/"; - # file = "p10k.zsh"; - # } - ]; - # 设置alias - shellAliases = { - # Git相关 - gc1 = "git clone --recursive --depth=1"; - - # 目录操作 - md = "mkdir -p"; - "..." = "../.."; - "...." = "../../.."; - "....." = "../../../.."; - "......" = "../../../../.."; - - # eza/ls替代 - ls = "eza --color=auto"; - l = "eza -lbah --icons=auto"; - la = "eza -labgh --icons=auto"; - ll = "eza -lbg --icons=auto"; - lt = "eza -lTbg --icons=auto"; - lsa = "eza -lbagR --icons=auto"; - lst = "eza -lTabgh --icons=auto"; - - # bat/cat替代 - cat = "bat -pp"; - ccat = "cat"; - }; - - oh-my-zsh = { - enable = true; - plugins = [ - "sudo" - "z" - "extract" - "git" - # "fzf-tab" - ]; - }; - }; - } \ No newline at end of file +{ config, pkgs, inputs, system, ... }: +{ + programs.zsh = { + enable = true; + enableCompletion = true; + autosuggestion.enable = true; + syntaxHighlighting.enable = true; + + # 环境变量 - 对应 .zshrc 开头的环境设置 + envExtra = '' + path=(~/.local/bin $path) + export XDG_CONFIG_HOME="''${XDG_CONFIG_HOME:-$HOME/.config}" + export POWERLEVEL9K_INSTANT_PROMPT=quiet + export PATH="$HOME/.hermes/node/bin:$PATH" + ''; + + # Shell 选项 - 对应 .zshrc 的 setopt + options = [ "correct" "interactive_comments" ]; + + # 初始化 - 对应 .zshrc 中的 Powerlevel10k instant prompt 和函数定义 + initExtra = '' + # Powerlevel10k instant prompt + 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 + + # Powerlevel10k config + [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh + + # 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" + } + + # 快速开关代理 + 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' + ''; + + plugins = [ + { + name = "powerlevel10k"; + src = pkgs.zsh-powerlevel10k; + file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme"; + } + { + name = "fzf-tab"; + src = "${pkgs.zsh-fzf-tab}/share/fzf-tab"; + } + ]; + + # 设置 alias - 对应 .zshrc 中的 aliases 部分 + shellAliases = { + # 目录导航 + "..." = "../.."; + "...." = "../../.."; + "....." = "../../../.."; + "......" = "../../../../.."; + "1" = "cd -"; + "2" = "cd -2"; + "3" = "cd -3"; + "4" = "cd -4"; + "5" = "cd -5"; + "6" = "cd -6"; + "7" = "cd -7"; + "8" = "cd -8"; + "9" = "cd -9"; + + # 快捷操作 + "_" = "sudo "; + gc1 = "git clone --recursive --depth=1"; + + # 目录操作 + md = "mkdir -p"; + rd = "rmdir"; + + # grep + grep = "grep --color=auto"; + egrep = "egrep --color=auto"; + fgrep = "fgrep --color=auto"; + afind = "ack -il"; + globurl = "noglob urlglobber "; + + # eza/ls 替代 + ls = "eza --color=auto"; + l = "eza -lbah --icons=auto"; + la = "eza -labgh --icons=auto"; + ll = "eza -lbg --icons=auto"; + lt = "eza -lTbg --icons=auto"; + lsa = "eza -lbagR --icons=auto"; + lst = "eza -lTabgh --icons=auto"; + + # bat/cat 替代 + cat = "bat -pp"; + ccat = "cat"; + }; + + oh-my-zsh = { + enable = true; + plugins = [ + "sudo" + "z" + "extract" + "git" + "command-not-found" + "colored-man-pages" + "kubectl" + ]; + }; + }; +}