Commit 5bc6afd23535

Vincent Demeester <vincent@sbr.pm>
2026-02-24 07:09:15
fix(zsh): restore ctrl-e and optimize auto-expand
Restored ctrl-e as end-of-line (accept autosuggestion) instead of edit-command-line (now ctrl-x ctrl-e). Re-enabled autosuggestion via home-manager since the package wasn't reachable from dots. Inlined systemd and grep alias setup to eliminate anonymous functions and forks (~6.7ms saved).
1 parent 475563f
Changed files (5)
dots/config/zsh/core/40-keybindings.zsh
@@ -1,9 +1,11 @@
 # Key bindings
 
-# Edit command line in $EDITOR
+# Edit command line in $EDITOR (ctrl-x ctrl-e, like bash default)
 autoload -U edit-command-line
 zle -N edit-command-line
-bindkey '^e' edit-command-line
+bindkey '^x^e' edit-command-line
+
+# ctrl-e = end-of-line (accept autosuggestion) โ€” zsh/emacs default, don't override
 
 # Rationalise dots: ... โ†’ ../..  .... โ†’ ../../..
 __rationalise-dot() {
dots/config/zsh/core/45-auto-expand.zsh
@@ -24,47 +24,32 @@ has ssh  && abbrev-alias shs=ssh
 
 # Save keystrokes
 has git && abbrev-alias gls="git ls-files"
-has ip && {
-  abbrev-alias ip6='ip -6'
-  abbrev-alias ipb='ip -brief'
-}
+has ip && { abbrev-alias ip6='ip -6'; abbrev-alias ipb='ip -brief'; }
 abbrev-alias tailf="tail -F"
 has mpv && abbrev-alias mpva="mpv --no-video"
 
-# Systemd aliases
-() {
-  local cmd
-  local -a cmds
-  cmds=(start stop reload restart status)
+# Systemd aliases (inlined, no anonymous function)
+if [[ -d /run/systemd/system ]]; then
+  local _sc="${(%):-%(#..sudo )}systemctl"
+  abbrev-alias start="$_sc start"
+  abbrev-alias stop="$_sc stop"
+  abbrev-alias reload="$_sc reload"
+  abbrev-alias restart="$_sc restart"
+  abbrev-alias status="$_sc status"
+  abbrev-alias ustart="systemctl --user start"
+  abbrev-alias ustop="systemctl --user stop"
+  abbrev-alias ureload="systemctl --user reload"
+  abbrev-alias urestart="systemctl --user restart"
+  abbrev-alias ustatus="systemctl --user status"
+  unset _sc
+fi
 
-  if [[ -d /run/systemd/system ]]; then
-    for cmd ($cmds) {
-      abbrev-alias $cmd="${(%):-%(#..sudo )}systemctl $cmd"
-      abbrev-alias u$cmd="systemctl --user $cmd"
-    }
-  else
-    for cmd ($cmds) {
-      function $cmd() {
-        name=$1 ; shift
-        ${(%):-%(#..sudo)} service $name $0 "$@"
-      }
-      (( $+functions[compdef] )) && compdef _services $cmd
-    }
-  fi
-}
-
-# grep aliases
-() {
-  local grep=grep
-  (( $+commands[ggrep] )) && grep=ggrep
-  local colors="--color=auto"
-  $grep -q $colors . <<< yes 2>/dev/null || colors=""
-  alias grep="command ${grep} ${colors}"
-  abbrev-alias rgrep="grep -r"
-  abbrev-alias egrep="grep -E"
-  abbrev-alias fgrep="grep -F"
-  (( $+commands[zgrep] )) && alias zgrep="GREP=${grep} command zgrep ${colors}"
-}
+# Grep aliases (inlined, no anonymous function or fork)
+alias grep="command grep --color=auto"
+abbrev-alias rgrep="grep -r"
+abbrev-alias egrep="grep -E"
+abbrev-alias fgrep="grep -F"
+(( $+commands[zgrep] )) && alias zgrep="GREP=grep command zgrep --color=auto"
 
 # nixpkgs runner
 (( $+commands[nix] )) && nixpkgs() {
@@ -87,8 +72,6 @@ v() {
     fi
   elif (( $+commands[less] )); then
     gzip -cdfq -- "$@" | less -FX
-  elif (( $+commands[zmore] )); then
-    zmore "$@"
   elif (( $+commands[more] )); then
     gzip -cdfq -- "$@" | more
   else
@@ -97,6 +80,5 @@ v() {
 }
 
 # jayrah
-if [[ -d ${HOME}/src/github.com/chmouel/jayrah ]]; then
+[[ -d ${HOME}/src/github.com/chmouel/jayrah ]] && \
   alias jayrah="uv --directory=${HOME}/src/github.com/chmouel/jayrah run jayrah"
-fi
dots/config/zsh/tools/autosuggestions.zsh
@@ -1,12 +0,0 @@
-# Zsh autosuggestions
-local plugin
-for plugin in \
-  /etc/profiles/per-user/$USER/share/zsh-autosuggestions/zsh-autosuggestions.zsh \
-  /run/current-system/sw/share/zsh-autosuggestions/zsh-autosuggestions.zsh \
-  /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh; do
-  if [[ -f "$plugin" ]]; then
-    source "$plugin"
-    ZSH_AUTOSUGGEST_STRATEGY=(history)
-    break
-  fi
-done
home/common/shell/zsh.nix
@@ -2,26 +2,25 @@
 {
   # Plugins: fetched by Nix, placed in ZDOTDIR/plugins, sourced by dots/config/zsh/tools/
   home.file."${config.programs.zsh.dotDir}/plugins/kubectl-config-switcher".source =
-    pkgs.fetchFromGitHub {
-      owner = "chmouel";
-      repo = "kubectl-config-switcher";
-      rev = "5679aa70383cee93fc15351dd4895c29c90b78a5";
-      sha256 = "sha256-Aifa5ms2p/l0FkZE8Tep8QiDWUdfFfdKrTIbJNurxw4=";
-    };
-  home.file."${config.programs.zsh.dotDir}/plugins/zsh-z".source =
-    pkgs.fetchFromGitHub {
-      owner = "agkozak";
-      repo = "zsh-z";
-      rev = "aaafebcd97424c570ee247e2aeb3da30444299cd";
-      sha256 = "sha256-9Wr4uZLk2CvINJilg4o72x0NEAl043lP30D3YnHk+ZA=";
-    };
-  home.file."${config.programs.zsh.dotDir}/plugins/zsh-nix-shell".source =
-    pkgs.fetchFromGitHub {
-      owner = "chisui";
-      repo = "zsh-nix-shell";
-      rev = "v0.8.0";
-      sha256 = "sha256-Z6EYQdasvpl1P78poj9efnnLj7QQg13Me8x1Ryyw+dM=";
-    };
+    pkgs.fetchFromGitHub
+      {
+        owner = "chmouel";
+        repo = "kubectl-config-switcher";
+        rev = "5679aa70383cee93fc15351dd4895c29c90b78a5";
+        sha256 = "sha256-Aifa5ms2p/l0FkZE8Tep8QiDWUdfFfdKrTIbJNurxw4=";
+      };
+  home.file."${config.programs.zsh.dotDir}/plugins/zsh-z".source = pkgs.fetchFromGitHub {
+    owner = "agkozak";
+    repo = "zsh-z";
+    rev = "aaafebcd97424c570ee247e2aeb3da30444299cd";
+    sha256 = "sha256-9Wr4uZLk2CvINJilg4o72x0NEAl043lP30D3YnHk+ZA=";
+  };
+  home.file."${config.programs.zsh.dotDir}/plugins/zsh-nix-shell".source = pkgs.fetchFromGitHub {
+    owner = "chisui";
+    repo = "zsh-nix-shell";
+    rev = "v0.8.0";
+    sha256 = "sha256-Z6EYQdasvpl1P78poj9efnnLj7QQg13Me8x1Ryyw+dM=";
+  };
 
   home.packages = with pkgs; [
     nix-zsh-completions
@@ -33,7 +32,7 @@
     # Completion is deferred in our own init.zsh (precmd hook)
     completionInit = "";
     enableCompletion = false;
-    autosuggestion.enable = false; # handled in dots/config/zsh/tools/autosuggestions.zsh
+    autosuggestion.enable = true; # home-manager handles sourcing + keybindings
     autocd = true;
     dotDir = "${config.xdg.configHome}/zsh";
     defaultKeymap = "emacs";
flake.nix
@@ -232,7 +232,10 @@
             # python
             ruff.enable = true;
             # shell
-            shellcheck.enable = true;
+            shellcheck = {
+              enable = true;
+              excludes = [ "dots/config/zsh/.*" ]; # zsh files use zsh-specific syntax
+            };
             # emacs lisp - basic syntax checking
             elisp-byte-compile = {
               enable = false; # Disabled - causes issues with missing packages in pre-push hook