aboutsummaryrefslogtreecommitdiff
path: root/pkgs.nix
blob: a62e8b2b3efcbbb03e0337dc0bf1bbf65e8b3fc1 (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
{pkgs}: let
  shellrcPkgs = {
    shellrc-bash = pkgs.stdenvNoCC.mkDerivation {
      name = "shellrc-bash";
      src = ./.;
      nativeBuildInputs = [pkgs.installShellFiles];
      installPhase = ''
        mkdir -p "$out/bin"
        cat >"$out/bin/shellrc-bash" <<"EOF"
        #!/usr/bin/env bash
        for file in ${./bashrc.d}/* ${./shellrc.d}/*; do
          echo "source $file;"
        done
        EOF
        chmod +x "$out/bin/shellrc-bash"
        for comp in bash-completion/*; do
          installShellCompletion --bash --name "''${comp##*/}.bash" "$comp"
        done
      '';
    };
    shellrc-zsh = pkgs.stdenvNoCC.mkDerivation {
      name = "shellrc-zsh";
      src = ./.;
      nativeBuildInputs = [pkgs.installShellFiles];
      installPhase = ''
        mkdir -p "$out/bin"
        cat >"$out/bin/shellrc-zsh" <<"EOF"
        #!/usr/bin/env zsh
        for file in ${./zshrc.d}/* ${./shellrc.d}/*; do
          echo "source $file;"
        done
        EOF
        chmod +x "$out/bin/shellrc-zsh"
        for comp in zsh-completion/*; do
          installShellCompletion --zsh --name "''${comp##*/}" "$comp"
        done
      '';
    };
    shellrc-user-setup = pkgs.writeScriptBin "shellrc-user-setup" ''
      #!/usr/bin/env bash
      cmdbash='eval $(shellrc-bash)'
      cmdzsh='eval $(shellrc-zsh)'
      if command -v shellrc-bash 2>/dev/null >&2 \
          && ! grep -qxF "$cmdbash" ~/.profile 2>/dev/null; then
        echo "$cmdbash" >>~/.profile
      fi
      if command -v shellrc-zsh 2>/dev/null >&2 \
          && ! grep -qxF "$cmdzsh" ~/.zprofile 2>/dev/null; then
          echo "$cmdzsh" >>~/.zprofile
      fi
    '';
  };
in
  shellrcPkgs