Skip to content

Commit

Permalink
lesspipe: fix paths via patch and substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
snaar committed Jul 24, 2018
1 parent c6bc77d commit 9320780
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkgs/tools/misc/lesspipe/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{ stdenv, lib, fetchFromGitHub, makeWrapper, perl, file, ncurses }:
{ stdenv, fetchFromGitHub, substituteAll, perl, file, ncurses }:

stdenv.mkDerivation rec {
name = "lesspipe-${version}";
version = "1.82";

buildInputs = [ makeWrapper perl ];
buildInputs = [ perl ];
preConfigure = "patchShebangs .";
preFixupPhases = ["wrapWithDepsPhase"];

src = fetchFromGitHub {
owner = "wofr06";
Expand All @@ -15,9 +14,13 @@ stdenv.mkDerivation rec {
sha256 = "0vb7bpap8vy003ha10hc7hxl17y47sgdnrjpihgqxkn8k0bfqbbq";
};

wrapWithDepsPhase = ''
wrapProgram $out/bin/lesspipe.sh --prefix PATH ":" ${lib.makeBinPath [ file ncurses ]}
'';
patches = [
(substituteAll {
src = ./fix-paths.patch;
file = "${file}/bin/file";
tput = "${ncurses}/bin/tput";
})
];

meta = with stdenv.lib; {
description = "A preprocessor for less";
Expand Down
22 changes: 22 additions & 0 deletions pkgs/tools/misc/lesspipe/fix-paths.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/lesspipe.sh.in
+++ b/lesspipe.sh.in
@@ -48,8 +48,8 @@ if [[ "$LESS_ADVANCED_PREPROCESSOR" = '' ]]; then
fi

filecmd() {
- file -L -s "$@"
- file -L -s -i "$@" 2> /dev/null | sed -n 's/.*charset=/;/p' | tr a-z A-Z
+ @file@ -L -s "$@"
+ @file@ -L -s -i "$@" 2> /dev/null | sed -n 's/.*charset=/;/p' | tr a-z A-Z
}

sep=: # file name separator
@@ -546,7 +546,7 @@ isfinal() {

# color requires -r or -R when calling less
typeset COLOR
- if [[ $(tput colors) -ge 8 && ("$LESS" = *-*r* || "$LESS" = *-*R*) ]]; then
+ if [[ $(@tput@ colors) -ge 8 && ("$LESS" = *-*r* || "$LESS" = *-*R*) ]]; then
COLOR="--color=always"
fi

0 comments on commit 9320780

Please sign in to comment.