zsh.nix (5941B)
1 { config, lib, nixosConfig, pkgs, ... }: 2 let 3 shellConfig = import ./shell.nix { inherit config lib pkgs; }; 4 stable = lib.versionOlder nixosConfig.system.nixos.release "24.05"; 5 in 6 { 7 home.packages = with pkgs; [ 8 zsh-syntax-highlighting 9 nix-zsh-completions 10 ]; 11 12 home.file."${config.programs.zsh.dotDir}/completion.zsh".source = ./zsh/completion.zsh; 13 home.file."${config.programs.zsh.dotDir}/prompt.zsh".source = ./zsh/prompt.zsh; 14 home.file."${config.programs.zsh.dotDir}/functions/j".source = ./zsh/j; 15 16 programs = { 17 direnv.enableZshIntegration = true; 18 }; 19 20 programs.zsh = { 21 enable = true; 22 enableCompletion = true; 23 autocd = true; 24 dotDir = ".config/zsh"; 25 defaultKeymap = "emacs"; 26 history = { 27 expireDuplicatesFirst = true; 28 extended = true; 29 ignoreDups = true; 30 path = "${config.xdg.dataHome}/zsh_history"; 31 save = shellConfig.historySize; 32 share = true; 33 }; 34 envExtra = shellConfig.env; 35 initExtra = '' 36 # c.f. https://wiki.gnupg.org/AgentForwarding 37 gpgconf --create-socketdir &! 38 path+="$HOME/${config.programs.zsh.dotDir}/functions" 39 fpath+="$HOME/.nix-profile/share/zsh/site-functions" 40 fpath+="$HOME/${config.programs.zsh.dotDir}/functions" 41 for func ($HOME/${config.programs.zsh.dotDir}/functions) autoload -U $func/*(x:t) 42 autoload -Uz select-word-style; select-word-style bash 43 if [ -e /home/vincent/.nix-profile/etc/profile.d/nix.sh ]; then . /home/vincent/.nix-profile/etc/profile.d/nix.sh; fi 44 #if [ -n "$INSIDE_EMACS" ]; then 45 # chpwd() { print -P "\033AnSiTc %d" } 46 # print -P "\033AnSiTu %n" 47 # print -P "\033AnSiTc %d" 48 #fi 49 if [[ "$TERM" == "dumb" || "$TERM" == "emacs" ]] 50 then 51 TERM=eterm-color 52 unsetopt zle 53 unsetopt prompt_cr 54 unsetopt prompt_subst 55 unfunction precmd 56 unfunction preexec 57 PS1='$ ' 58 return 59 fi 60 # make sure navigation using emacs keybindings works on all non-alphanumerics 61 # syntax highlighting 62 source $HOME/${config.programs.zsh.dotDir}/plugins/zsh-nix-shell/nix-shell.plugin.zsh 63 source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 64 ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') 65 ZSH_HIGHLIGHT_PATTERNS+=('rm -fR *' 'fg=white,bold,bg=red') 66 ZSH_HIGHLIGHT_PATTERNS+=('rm -fr *' 'fg=white,bold,bg=red') 67 source $HOME/${config.programs.zsh.dotDir}/completion.zsh 68 source $HOME/${config.programs.zsh.dotDir}/plugins/powerlevel10k/powerlevel10k.zsh-theme 69 source $HOME/${config.programs.zsh.dotDir}/prompt.zsh 70 source $HOME/${config.programs.zsh.dotDir}/plugins/kubectl-config-switcher/kubectl-config-switcher.plugin.zsh 71 setopt HIST_IGNORE_SPACE 72 alias -g L="|less" 73 alias -g EEL=' 2>&1 | less' 74 alias -g GB='`git rev-parse --abbrev-ref HEAD`' 75 alias -g GR='`git rev-parse --show-toplevel`' 76 alias -s {ape,avi,flv,m4a,mkv,mov,mp3,mp4,mpeg,mpg,ogg,ogm,wav,webm}=mpv 77 alias -s org=emacs 78 (( $+commands[jq] )) && alias -g MJ="| jq -C '.'" || alias -g MJ="| ${pkgs.python3}/bin/python -mjson.tool" 79 (( $+functions[zshz] )) && compdef _zshz j 80 [[ -n $INSIDE_EMACS ]] && \ 81 function ff () { 82 print "\e]51;Efind-file $(readlink -f $1)\e\\" 83 } 84 ''; 85 loginExtra = '' 86 if [[ -z $DISPLAY && $TTY = /dev/tty1 ]]; then 87 exec sway 88 fi 89 ''; 90 profileExtra = '' 91 if [ -e /home/vincent/.nix-profile/etc/profile.d/nix.sh ]; then . /home/vincent/.nix-profile/etc/profile.d/nix.sh; fi 92 ''; 93 localVariables = { 94 EMOJI_CLI_KEYBIND = "^n"; 95 EMOJI_CLI_USE_EMOJI = "yes"; 96 ZSH_HIGHLIGHT_HIGHLIGHTERS = [ "main" "brackets" "pattern" ]; 97 }; 98 sessionVariables = { RPROMPT = ""; }; 99 plugins = [ 100 { 101 name = "kubectl-config-switcher"; 102 src = pkgs.fetchFromGitHub { 103 owner = "chmouel"; 104 repo = "kubectl-config-switcher"; 105 rev = "faccc5d3c1f98170c38d3889f50fe74f3f6fe2cc"; 106 sha256 = "sha256-BOMvC/r6uN9Hewp8OxPIp38+V9Usp6XbMvNoDim0qmc="; 107 }; 108 } 109 { 110 name = "emoji-cli"; 111 src = pkgs.fetchFromGitHub { 112 owner = "b4b4r07"; 113 repo = "emoji-cli"; 114 rev = "0fbb2e48e07218c5a2776100a4c708b21cb06688"; 115 sha256 = "sha256-ii7RDTK/m+IqK7N+Xb6cEbziLPUQh7ZsbvQiX56F0sE="; 116 }; 117 } 118 { 119 name = "zsh-z"; 120 src = pkgs.fetchFromGitHub { 121 owner = "agkozak"; 122 repo = "zsh-z"; 123 rev = "aaafebcd97424c570ee247e2aeb3da30444299cd"; 124 sha256 = "sha256-9Wr4uZLk2CvINJilg4o72x0NEAl043lP30D3YnHk+ZA="; 125 }; 126 } 127 { 128 name = "async"; 129 src = pkgs.fetchFromGitHub { 130 owner = "mafredri"; 131 repo = "zsh-async"; 132 rev = "v1.8.5"; 133 sha256 = "sha256-mpXT3Hoz0ptVOgFMBCuJa0EPkqP4wZLvr81+1uHDlCc="; 134 }; 135 } 136 { 137 name = "zsh-completions"; 138 src = pkgs.fetchFromGitHub { 139 owner = "zsh-users"; 140 repo = "zsh-completions"; 141 rev = "0.34.0"; 142 sha256 = "sha256-qSobM4PRXjfsvoXY6ENqJGI9NEAaFFzlij6MPeTfT0o="; 143 }; 144 } 145 { 146 name = "powerlevel10k"; 147 src = pkgs.fetchFromGitHub { 148 owner = "romkatv"; 149 repo = "powerlevel10k"; 150 rev = "v1.16.1"; 151 sha256 = "sha256-DLiKH12oqaaVChRqY0Q5oxVjziZdW/PfnRW1fCSCbjo="; 152 }; 153 } 154 { 155 name = "zsh-nix-shell"; 156 src = pkgs.fetchFromGitHub { 157 owner = "chisui"; 158 repo = "zsh-nix-shell"; 159 rev = "v0.5.0"; 160 sha256 = "sha256-IT3wpfw8zhiNQsrw59lbSWYh0NQ1CUdUtFzRzHlURH0="; 161 }; 162 } 163 ]; 164 shellAliases = shellConfig.aliases; 165 } // (if stable then { 166 enableAutosuggestions = true; 167 } else { 168 autosuggestion.enable = true; 169 }); 170 }