btw i use nix
1{
2 pkgs,
3 config,
4 lib,
5 ...
6}:
7
8let
9 tmux-sessionizer = pkgs.writeScriptBin "tmux-sessionizer" ''
10 #!/usr/bin/env bash
11
12 hist_file=~/.cache/sessionizer.hist
13
14 if [[ $# -eq 1 ]]; then
15 selected=$1
16 else
17 selected=$((tac "$hist_file"; find ~/ ~/projects -mindepth 1 -maxdepth 1 -type d -not -path '*/[.]*'; echo /etc/nixos) | awk '!seen[$0]++' | fzf --print-query | tail -n 1)
18 fi
19
20 if [[ -z $selected ]]; then
21 exit 0
22 fi
23
24 echo "$selected" >> $hist_file
25
26 selected_name=$(basename "$selected" | tr . _)
27 tmux_running=$(pgrep tmux)
28
29 if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
30 tmux new-session -s $selected_name -c $selected
31 exit 0
32 fi
33
34 if ! tmux has-session -t=$selected_name 2> /dev/null; then
35 tmux new-session -ds $selected_name -c $selected
36 fi
37
38 tmux switch-client -t $selected_name
39 '';
40in
41{
42 imports = [
43 ./mail.nix
44 ./calendar.nix
45 ./gui/default.nix
46 ./nvim/default.nix
47 ./emacs/default.nix
48 ./battery.nix
49 ];
50
51 options.custom.machineColour = lib.mkOption {
52 type = lib.types.str;
53 default = "cyan";
54 };
55
56 config = {
57 home.sessionVariables = {
58 EDITOR = "nvim";
59 NIX_AUTO_RUN = "y";
60 NIX_AUTO_RUN_INTERACTIVE = "y";
61 GOPATH = "$HOME/.go";
62 };
63 home.packages = with pkgs; [
64 htop
65 gnumake
66 inetutils
67 dig
68 fzf
69 jq
70 bc
71 openssh
72 # multicore rust command line utils
73 dua
74 fd
75 ripgrep
76 tmux-sessionizer
77 ];
78
79 home.shellAliases = {
80 ls = "ls -p --color=auto";
81 pls = "sudo $(fc -ln -1)";
82 o = "xdg-open";
83 se = "sudoedit";
84 su = "su -p";
85 ssh = "TERM=xterm ssh";
86 nix-shell = "nix-shell --command zsh";
87 inhibit-lid = "systemd-inhibit --what=handle-lid-switch sleep 1d";
88 tmux = "tmux -2";
89 feh = "feh --scale-down --auto-zoom";
90 nix-stray-roots = "nix-store --gc --print-roots | egrep -v '^(/nix/var|/run|/proc|{censored})'";
91 };
92
93 # https://github.com/nix-community/home-manager/issues/1439#issuecomment-1106208294
94 home.activation = {
95 linkDesktopApplications = {
96 after = [
97 "writeBoundary"
98 "createXdgUserDirectories"
99 ];
100 before = [ ];
101 data = ''
102 rm -rf ${config.xdg.dataHome}/"applications/home-manager"
103 mkdir -p ${config.xdg.dataHome}/"applications/home-manager"
104 cp -Lr ${config.home.homeDirectory}/.nix-profile/share/applications/* ${config.xdg.dataHome}/"applications/home-manager/"
105 '';
106 };
107 };
108
109 programs.zsh = {
110 enable = true;
111 history = {
112 size = 1000000;
113 path = "$HOME/.histfile";
114 share = false;
115 };
116 autosuggestion.enable = true;
117 syntaxHighlighting.enable = true;
118 enableCompletion = true;
119 initExtraFirst = ''
120 export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd completion history)
121 export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=5"
122 PROMPT='%(?..%F{red}%3?%f )%F{${config.custom.machineColour}}%n@%m%f:%~ %#'$'\n'
123 '';
124 initExtra = builtins.readFile ./zsh.cfg;
125 };
126
127 programs.bash.initExtra = ''
128 PS1='\[\e[36m\]\u@\h:\W\[\e[0m\] $ '
129 '';
130
131 programs.gpg = {
132 enable = true;
133 publicKeys = [
134 {
135 text = ''
136 -----BEGIN PGP PUBLIC KEY BLOCK-----
137
138 mDMEZZ1zrBYJKwYBBAHaRw8BAQdA8Zeb1OFbzEWx3tM7ylO0ILCnDCG2JoA/iay6
139 iWXmB7G0G1J5YW4gR2liYiA8cnlhbkBmcmV1bWgub3JnPoiUBBMWCgA8FiEE67lV
140 Y2amyVrqUoWjGfnbY35Mq3QFAmWdc6wCGwMFCQPCZwAECwkIBwQVCgkIBRYCAwEA
141 Ah4FAheAAAoJEBn522N+TKt0mwcA/AvuKD4dTPj4hJ/cezEWDOFELMaVYZqDS3V1
142 LmRJrdIHAQDYgST8awabyd2Y3PRTFf9ZcWRRompeg0v7c2hCc9/3A7g4BGWdc6wS
143 CisGAQQBl1UBBQEBB0AdJP8T3mGR7SUp9DBlIaVU1ESRC7sLWbm4QFCR1JTfSgMB
144 CAeIfgQYFgoAJhYhBOu5VWNmpsla6lKFoxn522N+TKt0BQJlnXOsAhsMBQkDwmcA
145 AAoJEBn522N+TKt07KwA/10R+ejRZeW0cYScowHAsnDZ09A43bZvdp1X7KeQHMl+
146 AQD+TbceHh393VFc4tkl5pYHfrmkCXMdN0faVWolkc7GCA==
147 =EfP/
148 -----END PGP PUBLIC KEY BLOCK-----
149 '';
150 trust = "ultimate";
151 }
152 ];
153 };
154 services.gpg-agent.pinentryPackage = pkgs.pinentry-qt;
155
156 programs.git = {
157 enable = true;
158 extraConfig = {
159 init = {
160 defaultBranch = "main";
161 };
162 user = {
163 email = "ryan@freumh.org";
164 name = "Ryan Gibb";
165 signingKey = "19F9DB637E4CAB74";
166 };
167 alias = {
168 s = "status";
169 c = "commit";
170 cm = "commit --message";
171 ca = "commit --amend";
172 cu = "commit --message update";
173 ci = "commit --message initial";
174 br = "branch";
175 co = "checkout";
176 df = "diff";
177 l = "log";
178 lg = "log -p";
179 lol = "log --graph --decorate --pretty=oneline --abbrev-commit";
180 lola = "log --graph --decorate --pretty=oneline --abbrev-commit --all";
181 ls = "ls-files";
182 a = "add";
183 aa = "add --all";
184 au = "add -u";
185 ap = "add --patch";
186 ai = "add -i";
187 ps = "push";
188 pf = "push --force";
189 pu = "push --set-upstream";
190 pl = "pull";
191 pr = "pull --rebase";
192 acp = "!git add --all && git commit --message update && git push";
193 d = "diff";
194 dc = "diff --cached";
195 };
196 };
197 };
198
199 programs.tmux = {
200 enable = true;
201 extraConfig =
202 let
203 toggle-status-bar = pkgs.writeScript "toggle-status-bar.sh" ''
204 #!/usr/bin/env bash
205 window_count=$(tmux list-windows | wc -l)
206 if [ "$window_count" -ge "2" ]; then
207 tmux set-option status on
208 else
209 tmux set-option status off
210 fi
211 '';
212 in
213 # https://github.com/ThePrimeagen/.dotfiles/blob/master/bin/.local/scripts/tmux-sessionizer
214 ''
215 # alternative modifier
216 unbind C-b
217 set-option -g prefix C-a
218 bind-key C-a send-prefix
219
220 set-window-option -g mode-keys vi
221 set-option -g mouse on
222 set-option -g set-titles on
223 set-option -g set-titles-string "#T"
224 bind-key t capture-pane -S -\; new-window '(tmux show-buffer; tmux delete-buffer) | nvim -c $'
225 bind-key u capture-pane\; new-window '(tmux show-buffer; tmux delete-buffer) | ${pkgs.urlscan}/bin/urlscan'
226 set-hook -g session-window-changed 'run-shell ${toggle-status-bar}'
227 set-hook -g session-created 'run-shell ${toggle-status-bar}'
228 # Fixes C-Up/Down in TUIs
229 set-option default-terminal tmux
230 # https://stackoverflow.com/questions/62182401/neovim-screen-lagging-when-switching-mode-from-insert-to-normal
231 # locking
232 set -s escape-time 0
233 set -g lock-command ${pkgs.vlock}/bin/vlock
234 set -g lock-after-time 0 # Seconds; 0 = never
235 bind L lock-session
236 # for .zprofile display environment starting https://github.com/tmux/tmux/issues/3483
237 set-option -g update-environment XDG_VTNR
238 # Allow clipboard with OSC-52 work
239 set -s set-clipboard on
240 # toggle
241 bind -r ^ last-window
242 # vim copy
243 bind -T copy-mode-vi v send-keys -X begin-selection
244 bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
245 # find
246 bind-key -r f run-shell "tmux neww tmux-sessionizer"
247 # reload
248 bind-key r source-file ~/.config/tmux/tmux.conf
249 # kill unattached
250 bind-key K run-shell 'tmux ls | grep -v attached | cut -d: -f1 | xargs -I {} tmux kill-window -t {}'
251 '';
252 };
253
254 programs.less = {
255 enable = true;
256 keys = ''
257 #line-edit
258 \e[1;5D word-left
259 \e[1;5C word-right
260 '';
261 };
262
263 programs.go.goPath = "~/.go";
264
265 home.stateVersion = "22.05";
266 };
267}