summaryrefslogtreecommitdiff
path: root/modules/common/common/shell/default.nix
blob: c3c29de2ce83e1430a48045b0704ae07bed12454 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
  lib,
  pkgs,
  pkgsStable,
  this,
  ...
}:
with lib; {
  hm = {
    programs = {
      bash = {
        enable = true;

        shellOptions = [
          "autocd"
          "cdspell"
          "checkjobs"
          "checkwinsize"
          "dirspell"
          "extglob"
          "globstar"
          "histappend"
          "histreedit"
          "histverify"
        ];

        profileExtra = ''
          export _PROFILE_SOURCED=1
        '';

        initExtra = ''
          set -o notify

          # Apropriated from the default NixOS prompt settings.
          if [ "$TERM" != "dumb" ] || [ -n "$INSIDE_EMACS" ]; then
            PROMPT_COLOR="1;31m"
            ((UID)) && PROMPT_COLOR="1;32m"
            if [ -n "$INSIDE_EMACS" ] || [ "$TERM" = "eterm" ] || [ "$TERM" = "eterm-color" ]; then
              PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
            else
              PS1="\n\[\033[$PROMPT_COLOR\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\\$\[\033[0m\] "
            fi
            if test "$TERM" = "xterm"; then
              PS1="\[\033]2;\h:\u:\w\007\]$PS1"
            fi
          fi

          ${readFile ./functions.bash}

          # Colourise certain programs' outputs.
          GRC_ALIASES=true
          source ${pkgs.grc}/etc/profile.d/grc.sh

          # This makes sure we always source these tweaks for both interactive
          # and login sessions.
          if [ -z "$_PROFILE_SOURCED" ] && [ -f "$HOME/.profile" ]; then
            source "$HOME/.profile"
          fi
        '';

        shellAliases =
          listToAttrs
          (map
            ({
              name,
              value,
            }:
              nameValuePair name (with pkgs; let
                pkg =
                  if this.isHeadful
                  then
                    # FIXME Update this to 9.3 when patches[1] become available
                    #
                    # [1]: https://github.com/jarun/advcpmv
                    (pkgsStable.coreutils.overrideAttrs (_: _: {
                      patches = [
                        (fetchpatch {
                          url = "https://raw.githubusercontent.com/jarun/advcpmv/ea268d870b475edd5960dcd55d5378abc9705958/advcpmv-0.9-9.1.patch";
                          hash = "sha256-d+SRT/R4xmfHLAdOr7m4R3WFiW64P5ZH6iqDvErYCyg=";
                        })
                      ];
                    }))
                  else coreutils;
              in "${pkg}/bin/coreutils --coreutils-prog=${value}"))
            (
              let
                mkAlias = {
                  name ? head command,
                  command,
                }: {
                  inherit name;
                  value = concatStringsSep " " command;
                };

                progressBar = optionalString this.isHeadful "--progress-bar";
              in [
                (mkAlias {command = ["cp" "--interactive" "--recursive" progressBar];})
                (mkAlias {command = ["mv" "--interactive" progressBar];})
                (mkAlias {command = ["rm" "--interactive=once"];})
                (mkAlias {command = ["ln" "--interactive"];})
                (mkAlias {command = ["mkdir" "--parents"];})
                (mkAlias {command = ["rmdir" "--parents"];})
                (mkAlias {
                  name = "lower";
                  command = ["tr" "'[:upper:]'" "'[:lower:]'"];
                })
                (mkAlias {
                  name = "upper";
                  command = ["tr" "'[:lower:]'" "'[:upper:]'"];
                })
              ]
            ))
          // genAttrs ["grep" "egrep" "fgrep"]
          (name: "${pkgs.gnugrep}/bin/${name} --color=always");

        historyControl = ["ignoredups" "ignorespace"];
      };

      command-not-found.enable = false;

      dircolors.enable = true;
    };

    home.packages = with pkgs; [grc];
  };

  environment = {
    etc."grc.conf".source = "${pkgs.grc}/etc/grc.conf";

    systemPackages = with pkgs; [
      bash-completion
      bc
      gawk
      hr
      moreutils
      pv
    ];
  };
}