dotfiles

My PC Dotfiles & Website

modules/shell/shell.nix (4341B)


  1## Shell Configuration ##
  2{config, ...}: let
  3  inherit (config.flake) files modules;
  4
  5  editor = {
  6    autoindent = true;
  7    backup = true;
  8    clipboard = "external";
  9    cursorline = true;
 10    eofnewline = false;
 11    helpsplit = "vsplit";
 12    hltrailingws = true;
 13    infobar = true;
 14    matchbrace = true;
 15    keymenu = true;
 16    mouse = true;
 17    reload = "prompt";
 18    ruler = true;
 19    saveundo = true;
 20    scrollbar = true;
 21    smartpaste = true;
 22    statusline = true;
 23    syntax = true;
 24  };
 25in {
 26  flake.modules = {
 27    nixos.shell = {
 28      imports = [modules.nixos.shell-cli];
 29      programs = {
 30        bash.vteIntegration = true;
 31        zsh.vteIntegration = true;
 32      };
 33    };
 34
 35    nixos.shell-cli = {pkgs, ...}: {
 36      config = {
 37        environment = {
 38          shells = [pkgs.bashInteractive];
 39
 40          # Text Editor
 41          variables."EDITOR" = "micro";
 42          systemPackages = [pkgs.micro];
 43          interactiveShellInit = ''
 44            e() { "''${EDITOR:-nano}" "$@"; }
 45          '';
 46        };
 47
 48        systemd.tmpfiles.rules = let
 49          settings = pkgs.writeText "micro-settings.json" (builtins.toJSON editor);
 50        in [
 51          "d /root/.config 0700 root root -"
 52          "d /root/.config/micro 0700 root root -"
 53          "L+ /root/.config/micro/settings.json - - - - ${settings}"
 54        ];
 55
 56        programs = {
 57          nano = {
 58            enable = true;
 59            syntaxHighlight = true;
 60            nanorc = files.nano;
 61          };
 62
 63          # Bourne Shell
 64          bash.promptInit = ''
 65            shopt -s autocd
 66            shopt -s cdspell
 67            shopt -s checkjobs
 68            shopt -s checkwinsize
 69            shopt -s cmdhist
 70            shopt -s extglob
 71            shopt -s globstar
 72            shopt -s histappend
 73
 74            HISTCONTROL=erasedups:ignoredups:ignorespace
 75            HISTFILESIZE=100000
 76            HISTIGNORE=rm:killall
 77            HISTSIZE=100000
 78          '';
 79
 80          # Z Shell
 81          zsh = {
 82            enable = true;
 83            autosuggestions.enable = true;
 84            enableCompletion = false;
 85            syntaxHighlighting.enable = true;
 86            setOptions = [
 87              "autocd"
 88              "EXTENDED_HISTORY"
 89              "HIST_EXPIRE_DUPS_FIRST"
 90            ];
 91
 92            promptInit = ''
 93              bindkey '^[[1;5C' forward-word
 94              bindkey '^[[1;5D' backward-word
 95              bindkey '^[[3;5~' kill-word
 96              bindkey '^[[3~'   delete-char
 97              bindkey '^[[5~'   beginning-of-history
 98              bindkey '^[[6~'   end-of-history
 99              bindkey '^[[A'    up-line-or-search
100              bindkey '^[[B'    down-line-or-search
101              bindkey '^[[C'    forward-char
102              bindkey '^[[D'    backward-char
103              bindkey '^[[F'    end-of-linegestures
104              bindkey '^[[H'    beginning-of-line
105              bindkey '^H'      backward-kill-word
106              bindkey '^J'      backward-kill-line
107            '';
108
109            interactiveShellInit = ''
110              source ${pkgs.zsh-autopair}/share/zsh/zsh-autopair/autopair.zsh
111            '';
112          };
113        };
114        system.userActivationScripts.zshrc = "touch .zshrc";
115      };
116    };
117
118    homeManager.shell = {config, ...}: {
119      home.persist = {
120        files = [
121          ".bash_history"
122          ".zsh_history"
123        ];
124        directories = [
125          ".config/micro"
126          ".local/share/bash"
127          ".cache/zsh"
128        ];
129      };
130
131      programs = {
132        bash = {
133          enable = true;
134          historySize = 100000;
135          historyFileSize = 100000;
136          historyControl = [
137            "erasedups"
138            "ignoredups"
139            "ignorespace"
140          ];
141          historyIgnore = [
142            "rm"
143            "killall"
144          ];
145        };
146
147        zsh = {
148          enable = true;
149          history = {
150            path = "${config.home.homeDirectory}/.zsh_history";
151            size = 100000;
152            save = 100000;
153            extended = true;
154            expireDuplicatesFirst = true;
155            ignoreDups = true;
156            ignoreSpace = true;
157            share = true;
158          };
159        };
160
161        # Text Editor
162        micro = {
163          enable = true;
164          settings = editor;
165        };
166      };
167    };
168  };
169}