aboutsummaryrefslogtreecommitdiffstats
path: root/modules/terminal/zsh/default.nix
blob: bd0fee6c00f56651c8fcf72989b992f23caba9cf (plain)
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
# Zsh - Z shell, extended bash with additional features and plugins
{
  config,
  lib,
  pkgs,
  ...
}:
{
  options.terminal.zsh = {
    enable = lib.mkEnableOption "Enables zsh.";
    package = lib.mkPackageOption pkgs "zsh" { };
  };

  config =
    let
      nixCommandWrappers = builtins.readFile ./nix-aliases.sh;
    in
    lib.mkIf config.terminal.zsh.enable {
      programs.zsh = {
        enable = true;
        package = config.terminal.zsh.package;
        dotDir = "${config.xdg.configHome}/zsh";
        history.path = "${config.xdg.cacheHome}/zsh/history";
        enableCompletion = true;
        initContent = ''
          setopt PROMPT_SUBST

          # Vi insert/command modes for command-line editing. Escape enters normal mode.
          bindkey -v
          KEYTIMEOUT=1

          autoload -U colors && colors

          export GPG_TTY="$(tty)"
          gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1

          bindkey "^[[3~" delete-char
          bindkey "^?" backward-delete-char
          ${nixCommandWrappers}
        '';
      };

      programs.bash.initExtra = lib.mkIf config.terminal.bash.enable (lib.mkAfter nixCommandWrappers);

      home.sessionVariables.SHELL = "${lib.getExe config.terminal.zsh.package}";
    };
}