Files
nixos/home/zsh.nix
luochen570 88414eb346 fix: replace invalid 'options' attr with setopt in initExtra
home-manager's programs.zsh has no 'options' attribute.
Use 'setopt correct' and 'setopt interactive_comments' inside initExtra instead.
2026-05-26 12:50:23 +08:00

122 lines
3.1 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{ 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 的 setoptNixOS 中需写在 initExtra 里)
# options 属性在 home-manager 中不存在,用 setopt 命令代替
# 初始化 - 对应 .zshrc 中的 Powerlevel10k instant prompt 和函数定义
initExtra = ''
# Shell options
setopt correct
setopt interactive_comments
# 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"
];
};
};
}