about summary refs log tree commit diff stats
path: root/modules/by-name/zs/zsh/module.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/by-name/zs/zsh/module.nix106
1 files changed, 62 insertions, 44 deletions
diff --git a/modules/by-name/zs/zsh/module.nix b/modules/by-name/zs/zsh/module.nix
index 98e0d28a..833da126 100644
--- a/modules/by-name/zs/zsh/module.nix
+++ b/modules/by-name/zs/zsh/module.nix
@@ -1,6 +1,5 @@
 {
   config,
-  pkgs,
   lib,
   shell_library,
   system,
@@ -8,6 +7,8 @@
 }: let
   cfg = config.soispha.programs.zsh;
   homeConfig = config.home-manager.users.soispha;
+
+  sourceFile = path: "source ${path}\n";
 in {
   options.soispha.programs.zsh = {
     enable = lib.mkEnableOption "zsh";
@@ -19,7 +20,10 @@ in {
     programs.zsh = {
       enable = true;
       enableCompletion = true;
-      autosuggestion.enable = true;
+      autosuggestion = {
+        enable = true;
+        strategy = [];
+      };
       syntaxHighlighting.enable = true;
 
       autocd = true;
@@ -28,66 +32,80 @@ in {
       # Thus no `${homeConfig.xdg.configHome}`
       dotDir = ".config/zsh";
 
+      # TODO: Remove the whole history and replace it completely with `atuin` <2024-10-21>
       history = {
-        extended = true;
-        ignoreDups = false;
-        expireDuplicatesFirst = false;
-        ignoreSpace = false;
-
-        path = "${homeConfig.xdg.dataHome}/zsh/history";
-        save = 9000000; # number of lines to save
-        size = 9000000; # number of lines to keep
-        share = false; # share between sessions
-      };
-      historySubstringSearch = {
-        enable = true;
-        searchDownKey = "^[[B"; # DOWN Arrow key
-        searchUpKey = "^[[A"; # UP Arrow key
+        path = "/dev/null";
+        # save = 0; # number of lines to save
+        # size = 0; # number of lines to keep
+        # share = false; # share between sessions
       };
 
       loginExtra =
-        "setopt " # The extra space is important
-        + lib.concatStringsSep "\nsetopt " [
-          "AUTO_CD"
-          "AUTO_PUSHD"
-          "CHASE_DOTS"
+        # bash
+        ''
+          setopt AUTO_CD
+          setopt AUTO_PUSHD
+          setopt CHASE_DOTS
 
-          "ALWAYS_TO_END"
+          setopt ALWAYS_TO_END
 
-          "EXTENDED_HISTORY"
-          "HIST_ALLOW_CLOBBER"
-          "HIST_VERIFY"
-          "HIST_FCNTL_LOCK"
-          "APPEND_HISTORY"
+          setopt EXTENDED_HISTORY
+          setopt HIST_ALLOW_CLOBBER
+          setopt HIST_VERIFY
+          setopt HIST_FCNTL_LOCK
+          setopt APPEND_HISTORY
 
-          "DVORAK"
-          "CORRECT"
+          setopt DVORAK
+          setopt CORRECT
 
-          "PROMPT_SUBST"
-          "TRANSIENT_RPROMPT" # maybe?
+          setopt PROMPT_SUBST
+          setopt TRANSIENT_RPROMPT # maybe?
 
-          "COMBINING_CHARS"
-          "VI"
-        ];
+          setopt COMBINING_CHARS
+          setopt VI
+        '';
 
       initExtraFirst =
-        builtins.readFile ./config/zsh-init.zsh
+        sourceFile ./config/zsh-init.zsh
         + ''
           SHELL_LIBRARY_VERSION="2.1.2" source ${shell_library.rawLib.${system}}
-          # This next line buffers the first line of the following item:
+        '';
+
+      initExtra = let
+        start = lib.modules.mkBefore (
+          # NOTE: This must be before the insult, as we otherwise override the previous handler <2024-02-28>
+          sourceFile ./config/command_not_found/command_not_found.sh
+          + sourceFile ./config/command_not_found/command_not_found_insult.sh
+          + sourceFile ./config/custom_cursor.zsh
+          + sourceFile ./config/edit_command_line.zsh
+          + sourceFile ./plugins/zsh-history-substring-search.zsh
+        );
+        end = lib.modules.mkAfter (
+          sourceFile ./config/keymaps_start.zsh
+          + sourceFile ./config/keymaps/command.zsh
+          + sourceFile ./config/keymaps/emacs.zsh
+          + sourceFile ./config/keymaps/isearch.zsh
+          + sourceFile ./config/keymaps/vicmd.zsh
+          + sourceFile ./config/keymaps/viins.zsh
+          + sourceFile ./config/keymaps/viopp.zsh
+          + sourceFile ./config/keymaps/visual.zsh
+          + sourceFile ./config/keymaps_end.zsh
+        );
+      in
+        lib.modules.mkMerge
+        [
+          start
+          end
+        ];
 
-        ''
-        # NOTE: This must be before the insult, as we otherwise override the previous handler <2024-02-28>
-        + builtins.readFile ./config/command_not_found.sh
-        + builtins.readFile ./config/command_not_found_insult.sh
-        + builtins.readFile ./config/custom_cursor.zsh
-        + builtins.readFile "${pkgs.fzf}/share/fzf/key-bindings.zsh";
+      localVariables = {
+        HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND = "bg=cyan,fg=white";
+        HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND = "fg=red,underline,standout,bold";
+      };
 
       shellAliases = {
         ll = ". ll";
         lm = ". lm";
-
-        hisea = "history 0 | grep";
       };
     };
   };