aboutsummaryrefslogtreecommitdiff
path: root/users/tdback/modules/shell/default.nix
blob: 325b8711fb7098e0063d72886ab45af20224e746 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# users/tdback/modules/shell/default.nix
#
# My shell environment. I opt to use bash since it comes installed by default
# on most distributions, including NixOS, and I spend a lot of time remoting
# onto servers at work.

{
  headless,
  ...
}:
{
  programs.bash = {
    enable = true;
    historyControl = [
      "ignoredups"
      "ignorespace"
    ];
    shellOptions = [ "histappend" ];
    initExtra = ''
      # Shell prompt.
      PS1="${if headless then ''\[\e[31m\][\h] '' else ""}\[\e[34m\]\w \[\e[33m\]λ\[\e[0m\] "

      # Sane options.
      set -o noclobber
      bind "\C-l":clear-screen
      bind "\C-p":previous-history
      bind "\C-n":next-history
    '';

    profileExtra = ''
      # Add script directories to PATH.
      PATH=$PATH:$HOME/scripts
      PATH=$PATH:$HOME/.local/bin

      # Clean up duplicate entries in PATH while preserving directory order.
      PATH="$(echo $PATH | tr ':' '\n' | awk '!a[$0]++' | tr '\n' ':' | sed 's/:$//')"
    '';

    sessionVariables = {
      BROWSER = "firefox";
      KEYTIMEOUT = 1;
      LC_ALL = "en_US.UTF-8";
      LEDGER_FILE = "$HOME/Documents/finance/2025.journal";
      LESSHISTFILE = "-";
      MANPAGER = "less -R --use-color -Dd+r -Du+b";
    };

    shellAliases = {
      cp = "cp -i";
      mv = "mv -i";
      rm = "rm -I";
      ls = "ls --color=auto";
      cat = "bat -pp";
      grep = "grep --color=auto";
      diff = "diff --color=auto";
      mkdir = "mkdir -p";
    };
  };

  # Automatically use flake environments in the editor and shell.
  programs.direnv = {
    enable = true;
    enableBashIntegration = true;
    nix-direnv.enable = true;
  };

  programs.zoxide = {
    enable = true;
    options = [ "--cmd cd" ];
  };
}