nixpkgs/pkgs/tools/misc/bat/default.nix

64 lines
1.7 KiB
Nix
Raw Normal View History

2021-07-13 13:03:37 +02:00
{ lib
, stdenv
, rustPlatform
, fetchFromGitHub
, pkg-config
, less
, Security
, libiconv
, installShellFiles
, makeWrapper
2018-09-13 11:56:22 +02:00
}:
2018-04-30 22:12:20 +02:00
rustPlatform.buildRustPackage rec {
pname = "bat";
2021-08-22 20:04:06 +02:00
version = "0.18.3";
2018-04-30 22:12:20 +02:00
src = fetchFromGitHub {
owner = "sharkdp";
repo = pname;
rev = "v${version}";
2021-08-22 20:04:06 +02:00
sha256 = "sha256-3XwnlSPlyEE4oznXK59/rooZLtj1+VbozprXU2W0J5I=";
2018-04-30 22:12:20 +02:00
};
2021-08-22 20:04:06 +02:00
cargoSha256 = "sha256-g5yfE/s1N6EgI2ikiJbypI4iQbXPu6zGNoSVC6ldoWo=";
2020-05-11 22:40:22 +02:00
nativeBuildInputs = [ pkg-config installShellFiles makeWrapper ];
2018-04-30 22:12:20 +02:00
2021-01-15 10:19:50 +01:00
buildInputs = lib.optionals stdenv.isDarwin [ Security libiconv ];
2018-06-05 23:56:17 +02:00
2018-09-21 10:23:26 +02:00
postInstall = ''
installManPage $releaseDir/build/bat-*/out/assets/manual/bat.1
2021-07-13 13:03:37 +02:00
installShellCompletion $releaseDir/build/bat-*/out/assets/completions/bat.{bash,fish,zsh}
2018-09-21 10:23:26 +02:00
'';
# Insert Nix-built `less` into PATH because the system-provided one may be too old to behave as
# expected with certain flag combinations.
postFixup = ''
wrapProgram "$out/bin/bat" \
2021-01-15 10:19:50 +01:00
--prefix PATH : "${lib.makeBinPath [ less ]}"
'';
checkFlags = [ "--skip=pager_more" "--skip=pager_most" ];
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
testFile=$(mktemp /tmp/bat-test.XXXX)
echo -ne 'Foobar\n\n\n42' > $testFile
$out/bin/bat -p $testFile | grep "Foobar"
$out/bin/bat -p $testFile -r 4:4 | grep 42
rm $testFile
runHook postInstallCheck
'';
2020-11-28 19:33:16 +01:00
meta = with lib; {
2018-04-30 22:12:20 +02:00
description = "A cat(1) clone with syntax highlighting and Git integration";
homepage = "https://github.com/sharkdp/bat";
changelog = "https://github.com/sharkdp/bat/raw/v${version}/CHANGELOG.md";
license = with licenses; [ asl20 /* or */ mit ];
2021-08-11 16:55:01 +02:00
maintainers = with maintainers; [ dywedir lilyball zowoq SuperSandro2000 ];
2018-04-30 22:12:20 +02:00
};
}