blob: 8cd2ee87cfb159aed7935139d8b2c3aba0cdb11f [file] [log] [blame]
Samuel Shuert02ffd1e2024-02-13 21:37:15 -05001{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7{
8 options.chimera.shell = {
9 rebuildFlakePath = lib.mkOption {
10 type = lib.types.nullOr lib.types.str;
11 description = "Full path to where you store your flake locally";
12 default = null;
13 };
14 defaultAliases.enable = lib.mkEnableOption "Use sensible custom aliases";
15 usefulPackages.enable = lib.mkEnableOption "Enable useful shell packages (ripgrep, wget, etc)";
Skyler Greyb0700382024-06-30 23:16:17 +000016
17 tsStatus.enable = lib.mkEnableOption "Enable ts-status alias for better viewing of tailscale status.";
18
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050019 replacements = {
Samuel Shuertf51d0492024-02-21 21:52:27 +000020 defaultEnable = lib.mkEnableOption "Enable replacing everything by default";
21
Samuel Shuertae46a692024-03-03 10:47:35 -050022 atuin = {
23 enable = lib.mkOption {
24 description = "Use atuin instead of bkd-i-search";
25 type = lib.types.bool;
26 default = config.chimera.shell.replacements.defaultEnable;
27 example = true;
28 };
29 enableUpArrow = lib.mkEnableOption "Pressing up arrow will enter atuin instead of scrolling back through history";
30 };
31
Samuel Shuertf51d0492024-02-21 21:52:27 +000032 eza.enable = lib.mkOption {
33 description = "Use eza instead of ls";
34 type = lib.types.bool;
35 default = config.chimera.shell.replacements.defaultEnable;
36 example = true;
37 };
38 bfs.enable = lib.mkOption {
39 description = "Use bfs instead of find";
40 type = lib.types.bool;
41 default = config.chimera.shell.replacements.defaultEnable;
42 example = true;
43 };
44 ripgrep.enable = lib.mkOption {
45 description = "Use ripgrep instead of grep";
46 type = lib.types.bool;
47 default = config.chimera.shell.replacements.defaultEnable;
48 example = true;
49 };
50 htop.enable = lib.mkOption {
51 description = "Use htop instead of top";
52 type = lib.types.bool;
53 default = config.chimera.shell.replacements.defaultEnable;
54 example = true;
55 };
56 erdtree.enable = lib.mkOption {
57 description = "Use erdtree instead of tree";
58 type = lib.types.bool;
59 default = config.chimera.shell.replacements.defaultEnable;
60 example = true;
61 };
62 dust.enable = lib.mkOption {
63 description = "Use dust instead of du";
64 type = lib.types.bool;
65 default = config.chimera.shell.replacements.defaultEnable;
66 example = true;
67 };
68 bat.enable = lib.mkOption {
69 description = "Use bat instead of cat";
70 type = lib.types.bool;
71 default = config.chimera.shell.replacements.defaultEnable;
72 example = true;
73 };
74 zoxide.enable = lib.mkOption {
75 description = "Use zoxide instead of cd";
76 type = lib.types.bool;
77 default = config.chimera.shell.replacements.defaultEnable;
78 example = true;
79 };
Samuel Shuertb652b362024-06-20 21:37:38 -040080 glow.enable = lib.mkOption {
81 description = "Use glow for cat-ing .md files";
82 type = lib.types.bool;
83 default = config.chimera.shell.replacements.defaultEnable;
84 example = true;
85 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050086 };
87 };
88
89 config = {
Samuel Shuertb652b362024-06-20 21:37:38 -040090 home.shellAliases = lib.mkIf config.chimera.shell.defaultAliases.enable (
91 let
92 any_cat_replacement = config.chimera.shell.replacements.glow.enable || config.chimera.shell.replacements.bat.enable;
93 cat_or_bat = if config.chimera.shell.replacements.bat.enable then "${pkgs.bat}/bin/bat" else "${pkgs.coreutils}/bin/cat";
94 glow_or_cat_or_bat = if config.chimera.shell.replacements.glow.enable
95 then builtins.toString (pkgs.writeScript "glow_or_cat_or_bat" ''
96 if [[ "$1" == *.md ]]; then
97 ${pkgs.glow}/bin/glow "$@"
98 else
99 ${cat_or_bat} "$@"
100 fi
101 '')
102 else cat_or_bat;
103 in {
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500104 rebuild =
105 lib.mkIf (config.chimera.shell.rebuildFlakePath != null)
106 "sudo nixos-rebuild switch --flake ${config.chimera.shell.rebuildFlakePath}";
107 clr = "clear";
Skyler Grey1dea6b62024-03-12 11:41:15 +0000108 edit = builtins.toString config.home.sessionVariables.EDITOR;
Skyler Greye3f77dc2024-02-25 13:17:34 +0000109 find = lib.mkIf config.chimera.shell.replacements.bfs.enable "${pkgs.bfs}/bin/bfs";
Skyler Grey1ab2c1a2024-05-24 23:29:22 +0000110 grep = lib.mkIf config.chimera.shell.replacements.ripgrep.enable "${config.programs.ripgrep.package}/bin/rg --include-zero";
Skyler Greye3f77dc2024-02-25 13:17:34 +0000111 top = lib.mkIf config.chimera.shell.replacements.htop.enable "${config.programs.htop.package}/bin/htop";
112 tree = lib.mkIf config.chimera.shell.replacements.erdtree.enable "${pkgs.erdtree}/bin/erdtree";
113 du = lib.mkIf config.chimera.shell.replacements.dust.enable "${pkgs.dust}/bin/dust";
Samuel Shuertb652b362024-06-20 21:37:38 -0400114 cat = lib.mkIf any_cat_replacement glow_or_cat_or_bat;
Skyler Grey55d3edc2024-05-25 12:22:30 +0000115 lix = "${config.nix.package}/bin/nix"; # Lix, like nix
Skyler Greyb0700382024-06-30 23:16:17 +0000116
117 ts-status = lib.mkIf config.chimera.shell.tsStatus.enable ''${pkgs.tailscale}/bin/tailscale status | column -t -N "ADDRESS,DOMAIN,USER,OS,STATUS,CONNECTION" -l 6 -o " | "'';
Samuel Shuertb652b362024-06-20 21:37:38 -0400118 });
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500119
Skyler Greyb9fc2cd2024-04-05 09:10:39 +0000120 home.sessionVariables = lib.mkIf (config.chimera.shell.usefulPackages.enable && config.chimera.theme.style == "Light") {
121 BAT_THEME = "OneHalfLight";
122 };
123
Samuel Shuertae46a692024-03-03 10:47:35 -0500124 programs.atuin = lib.mkIf config.chimera.shell.replacements.atuin.enable {
125 enable = true;
126 enableZshIntegration = config.chimera.shell.zsh.enable;
127 enableBashIntegration = config.chimera.shell.bash.enable;
128 flags = lib.mkIf (!config.chimera.shell.replacements.atuin.enableUpArrow) [ "--disable-up-arrow" ];
129 };
130
Samuel Shuertf51d0492024-02-21 21:52:27 +0000131 programs.eza = lib.mkIf config.chimera.shell.replacements.eza.enable {
132 enable = true;
Skyler Grey6b8b30c2024-04-20 22:20:37 +0000133 enableZshIntegration = config.chimera.shell.zsh.enable;
134 enableBashIntegration = config.chimera.shell.bash.enable;
Samuel Shuertf51d0492024-02-21 21:52:27 +0000135 };
136
137 programs.ripgrep = lib.mkIf config.chimera.shell.replacements.ripgrep.enable {
138 enable = true;
139 arguments = [ "--smart-case" ];
140 };
141
Samuel Shuert659b5642024-02-23 20:47:43 +0000142 programs.htop = lib.mkIf config.chimera.shell.replacements.htop.enable { enable = true; };
Samuel Shuertf51d0492024-02-21 21:52:27 +0000143
144 programs.zoxide = lib.mkIf config.chimera.shell.replacements.zoxide.enable {
145 enable = true;
146 enableZshIntegration = config.chimera.shell.zsh.enable;
147 enableBashIntegration = config.chimera.shell.bash.enable;
148 options = [ "--cmd cd" ];
149 };
150
151 programs.tealdeer = lib.mkIf config.chimera.shell.usefulPackages.enable {
Samuel Shuertf51d0492024-02-21 21:52:27 +0000152 enable = true;
Samuel Shuert32887872024-03-02 12:18:33 -0500153 settings.updates = {
154 auto_update = true;
155 auto_update_interval_hours = 72;
156 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500157 };
Samuel Shuert659b5642024-02-23 20:47:43 +0000158 programs.jq = lib.mkIf config.chimera.shell.usefulPackages.enable { enable = true; };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500159
160 home.packages =
161 (
162 if config.chimera.shell.usefulPackages.enable then
163 [
164 pkgs.wget
Skyler Greyb9fc2cd2024-04-05 09:10:39 +0000165 pkgs.bat
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500166 pkgs.curl
167 pkgs.curlie
168 pkgs.pv
169 pkgs.sd
170 pkgs.tokei
171 pkgs.hyperfine
Samuel Shuertf51d0492024-02-21 21:52:27 +0000172 pkgs.tmux
Samuel Shuertb652b362024-06-20 21:37:38 -0400173 pkgs.glow
Samuel Shuert8b49c022024-09-14 19:13:52 -0400174 pkgs.difftastic
175 pkgs.meld
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500176 ]
177 else
178 [ ]
179 )
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500180 ++ (if config.chimera.shell.replacements.bfs.enable then [ pkgs.bfs ] else [ ])
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500181 ++ (if config.chimera.shell.replacements.htop.enable then [ pkgs.htop ] else [ ])
182 ++ (if config.chimera.shell.replacements.erdtree.enable then [ pkgs.erdtree ] else [ ])
Skyler Greyb9fc2cd2024-04-05 09:10:39 +0000183 ++ (if config.chimera.shell.replacements.dust.enable then [ pkgs.dust ] else [ ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500184 };
185}