about summary refs log tree commit diff stats
path: root/modules/by-name/zs/zsh/module.nix
blob: 98e0d28a0fd5977268bc0d2b3b8c79b6a89bdcd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
  config,
  pkgs,
  lib,
  shell_library,
  system,
  ...
}: let
  cfg = config.soispha.programs.zsh;
  homeConfig = config.home-manager.users.soispha;
in {
  options.soispha.programs.zsh = {
    enable = lib.mkEnableOption "zsh";
  };

  config.home-manager.users.soispha = lib.mkIf cfg.enable {
    home.sessionPath = [];

    programs.zsh = {
      enable = true;
      enableCompletion = true;
      autosuggestion.enable = true;
      syntaxHighlighting.enable = true;

      autocd = true;

      # Must be relative to the users home directory (for whatever reason)
      # Thus no `${homeConfig.xdg.configHome}`
      dotDir = ".config/zsh";

      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
      };

      loginExtra =
        "setopt " # The extra space is important
        + lib.concatStringsSep "\nsetopt " [
          "AUTO_CD"
          "AUTO_PUSHD"
          "CHASE_DOTS"

          "ALWAYS_TO_END"

          "EXTENDED_HISTORY"
          "HIST_ALLOW_CLOBBER"
          "HIST_VERIFY"
          "HIST_FCNTL_LOCK"
          "APPEND_HISTORY"

          "DVORAK"
          "CORRECT"

          "PROMPT_SUBST"
          "TRANSIENT_RPROMPT" # maybe?

          "COMBINING_CHARS"
          "VI"
        ];

      initExtraFirst =
        builtins.readFile ./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:

        ''
        # 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";

      shellAliases = {
        ll = ". ll";
        lm = ". lm";

        hisea = "history 0 | grep";
      };
    };
  };
}