about summary refs log tree commit diff
path: root/pkgs/tools/misc/lesspipe/default.nix
blob: b2c310bc5f40ec6a57f787cb6ab7ebc058427b15 (plain) (blame)
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
{ lib
, stdenv
, fetchFromGitHub
, makeWrapper
, perl
, procps
, bash

# shell referenced dependencies
, resholve
, binutils-unwrapped
, file
, gnugrep
, coreutils
, gnused
, gnutar
, iconv
, ncurses
}:

stdenv.mkDerivation rec {
  pname = "lesspipe";
  version = "2.11";

  src = fetchFromGitHub {
    owner = "wofr06";
    repo = "lesspipe";
    rev = "v${version}";
    hash = "sha256-jJrKiRdrargk0JzcPWxBZGyOpMfTIONHG8HNRecazVo=";
  };

  nativeBuildInputs = [ perl makeWrapper ];
  buildInputs = [ perl bash ];
  strictDeps = true;

  postPatch = ''
    patchShebangs --build configure
    substituteInPlace configure --replace '/etc/bash_completion.d' '/share/bash-completion/completions'
  '';

  configureFlags = [ "--shell=${bash}/bin/bash" "--prefix=/" ];
  configurePlatforms = [ ];

  dontBuild = true;

  installFlags = [ "DESTDIR=$(out)" ];

  postInstall = ''
    # resholve doesn't see strings in an array definition
    substituteInPlace $out/bin/lesspipe.sh --replace 'nodash strings' "nodash ${binutils-unwrapped}/bin/strings"

    ${resholve.phraseSolution "lesspipe.sh" {
      scripts = [ "bin/lesspipe.sh" ];
      interpreter = "${bash}/bin/bash";
      inputs = [
        coreutils
        file
        gnugrep
        gnused
        gnutar
        iconv
        procps
        ncurses
      ];
      keep = [ "$prog" "$c1" "$c2" "$c3" "$c4" "$c5" "$cmd" "$colorizer" "$HOME" ];
      fake = {
        # script guards usage behind has_cmd test function, it's safe to leave these external and optional
        external = [
          "cpio" "isoinfo" "cabextract" "bsdtar" "rpm2cpio" "bsdtar" "unzip" "ar" "unrar" "rar" "7zr" "7za" "isoinfo"
          "gzip" "bzip2" "lzip" "lzma" "xz" "brotli" "compress" "zstd" "lz4"
          "archive_color" "bat" "batcat" "pygmentize" "source-highlight" "vimcolor" "code2color"

          "w3m" "lynx" "elinks" "html2text" "dtc" "pdftotext" "pdftohtml" "pdfinfo" "ps2ascii" "procyon" "ccze"
          "mdcat" "pandoc" "docx2txt" "libreoffice" "pptx2md" "mdcat" "xlscat" "odt2txt" "wvText" "antiword" "catdoc"
          "broken_catppt" "sxw2txt" "groff" "mandoc" "unrtf" "dvi2tty" "pod2text" "perldoc" "h5dump" "ncdump" "matdump"
          "djvutxt" "openssl" "gpg" "plistutil" "plutil" "id3v2" "csvlook" "jq" "zlib-flate" "lessfilter"
        ] ++ lib.optional (stdenv.isDarwin || stdenv.isFreeBSD) [
          # resholve only identifies this on darwin/bsd
          # call site is guarded by || so it's safe to leave dynamic
          "locale"
        ];
        builtin = [ "setopt" ];
      };
      execer = [
        "cannot:${iconv}/bin/iconv"
      ];
    }}
    ${resholve.phraseSolution "lesscomplete" {
      scripts = [ "bin/lesscomplete" ];
      interpreter = "${bash}/bin/bash";
      inputs = [
        coreutils
        file
        gnugrep
        gnused
        gnutar
      ];
      keep = [ "$prog" "$c1" "$c2" "$c3" "$c4" "$c5" "$cmd" ];
      fake = {
        # script guards usage behind has_cmd test function, it's safe to leave these external and optional
        external = [
          "cpio" "isoinfo" "cabextract" "bsdtar" "rpm2cpio" "bsdtar" "unzip" "ar" "unrar" "rar" "7zr" "7za" "isoinfo"
          "gzip" "bzip2" "lzip" "lzma" "xz" "brotli" "compress" "zstd" "lz4"
        ];
        builtin = [ "setopt" ];
      };
    }}
  '';

  meta = with lib; {
    description = "Preprocessor for less";
    longDescription = ''
      Usually lesspipe.sh is called as an input filter to less. With the help
      of that filter less will display the uncompressed contents of compressed
      (gzip, bzip2, compress, rar, 7-zip, lzip, xz or lzma) files. For files
      containing archives and directories, a table of contents will be
      displayed (e.g tar, ar, rar, jar, rpm and deb formats). Other supported
      formats include nroff, pdf, ps, dvi, shared library, MS word, OASIS
      (e.g. Openoffice), NetCDF, html, mp3, jpg, png, iso images, MacOSX bom,
      plist and archive formats, perl storable data and gpg encrypted files.
      This does require additional helper programs being installed.
    '';
    homepage = "https://github.com/wofr06/lesspipe";
    platforms = platforms.all;
    license = licenses.gpl2Only;
    maintainers = [ maintainers.martijnvermaat ];
  };
}