summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/co/cope/package.nix
blob: 90e296b853c7b0cca713756ac1dc3342141687fb (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
{
  lib,
  fetchFromGitHub,
  perlPackages,
  makeWrapper,
}:
perlPackages.buildPerlPackage {
  pname = "cope";
  version = "0-unstable-2025-06-20";

  src = fetchFromGitHub {
    owner = "deftdawg";
    repo = "cope";
    rev = "6d0322a8493361ad32e454b97998df715dbe7b97";
    hash = "sha256-VQveV7avM/4nbLroyujJaSoVAP3pXhwrzqzI3eMzxVo=";
  };

  postPatch = ''
    substituteInPlace lib/App/Cope.pm \
      --replace-warn "feature->import( ':5.10' );" "require feature; feature->import( ':5.10' );"
  '';

  nativeBuildInputs = [ makeWrapper ];

  buildInputs = with perlPackages; [
    EnvPath
    ExporterTiny
    FileShareDir
    IOTty
    IOStty
    ListMoreUtils
    RegexpCommon
    RegexpIPv6
  ];

  postInstall =
    let
      perlDeps = with perlPackages; [
        EnvPath
        ExporterTiny
        FileShareDir
        IOTty
        IOStty
        ListMoreUtils
        RegexpCommon
        RegexpIPv6
      ];
      perlPath = perlPackages.makePerlPath perlDeps;
    in
    ''
      mkdir -p $out/bin # $out/libexec
      mv $out/${perlPackages.perl.libPrefix}/${perlPackages.perl.version}/auto/share/dist/Cope $out/libexec
      # Wrap all Perl scripts in the Cope directory before moving them
      for script in $out/libexec/*; do
        if [[ -f "$script" && -x "$script" ]]; then
          wrapProgram "$script" \
            --set PERL5LIB "${perlPath}:$out/lib/perl5/site_perl"
          sed -i "1s|^#!.*perl|#!${perlPackages.perl}/bin/perl|" "$out/libexec/.''${script##*/}-wrapped"
        fi
      done
      rm -r $out/${perlPackages.perl.libPrefix}/${perlPackages.perl.version}/auto

      # replace cope with a new cope, new-cope is a bash script which doesn't need to be wrapped
      cp $src/new-cope $out/bin/cope
      cp -f $src/new-cope $out/libexec/cope
    '';

  meta = {
    description = "Colourful wrapper for terminal programs";
    homepage = "https://github.com/deftdawg/cope";
    license = with lib.licenses; [
      artistic1
      gpl1Plus
    ];
    maintainers = with lib.maintainers; [ deftdawg ];
  };
}