about summary refs log tree commit diff stats
path: root/modules/by-name/zs/zsh/module.nix
blob: cb1bb086fd4140021554562360fefdf818029b58 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{
  config,
  lib,
  shell_library,
  system,
  ...
}: let
  cfg = config.soispha.programs.zsh;

  zDotDir = ".config/zsh";

  sourceFile = path: "source ${path}\n";
in {
  options.soispha.programs.zsh = {
    enable = lib.mkEnableOption "zsh";
  };

  config = lib.mkIf cfg.enable {
    environment.variables = {
      ZDOTDIR = "${config.home-manager.users.soispha.home.homeDirectory}/${zDotDir}";
    };

    home-manager.users.soispha = {
      home.sessionPath = lib.mkForce [];

      # This just includes a `source ~/.config/zsh/.zshenv`, because home-manger by-default
      # can't access the root `/etc/zshenv`. We can and thus, we can remove this file.
      home.file.".zshenv".enable = false;

      programs.zsh = {
        enable = true;
        enableCompletion = true;
        autosuggestion = {
          enable = true;
          strategy = [];
        };
        syntaxHighlighting.enable = true;

        autocd = true;

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

        # TODO: Remove the whole history and replace it completely with `atuin` <2024-10-21>
        history = {
          path = "/dev/null";
          # save = 0; # number of lines to save
          # size = 0; # number of lines to keep
          # share = false; # share between sessions
        };

        loginExtra =
          # bash
          ''
            setopt AUTO_CD
            setopt AUTO_PUSHD
            setopt CHASE_DOTS

            setopt ALWAYS_TO_END

            setopt EXTENDED_HISTORY
            setopt HIST_ALLOW_CLOBBER
            setopt HIST_VERIFY
            setopt HIST_FCNTL_LOCK
            setopt APPEND_HISTORY

            setopt DVORAK
            setopt CORRECT

            setopt PROMPT_SUBST
            setopt TRANSIENT_RPROMPT # maybe?

            setopt COMBINING_CHARS
            setopt VI
          '';

        initExtraFirst =
          sourceFile ./config/zsh-init.zsh
          + ''
            SHELL_LIBRARY_VERSION="2.1.2" source ${shell_library.rawLib.${system}}
          '';

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

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