summaryrefslogtreecommitdiff
path: root/modules/nixfiles/common/shell/default.nix
blob: 8ed2e996eea7c97abeba17f01e87e4f8ab8d5d48 (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
{
  lib,
  pkgs,
  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

          ${readFile ./functions.bash}

          GRC_ALIASES=true
          source ${pkgs.grc}/etc/profile.d/grc.sh

          if [ -z $_PROFILE_SOURCED ] && [ -f $HOME/.profile ]; then
            source $HOME/.profile
          fi
        '';

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

      command-not-found.enable = false;

      dircolors.enable = true;
    };

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

  programs.command-not-found.enable = false;

  environment = {
    shellAliases =
      listToAttrs
      (map
        ({
          name,
          value,
        }:
          nameValuePair name (with pkgs; let
            pkg =
              if this.isHeadful
              then
                (coreutils.overrideAttrs (_: super: {
                  patches =
                    super.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:]'"];
            })
            (mkAlias {
              name = "disk";
              command = [
                "df"
                "--human-readable"
                "--exclude-type=tmpfs"
                "--exclude-type=devtmpfs"
                "2>/dev/null"
              ];
            })
          ]
        ))
      // genAttrs ["grep" "egrep" "fgrep"]
      (name: "${pkgs.gnugrep}/bin/${name} --color=always");

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