1{
2 lib,
3 stdenv,
4 buildGoModule,
5 fetchFromGitHub,
6 installShellFiles,
7 buildPackages,
8 versionCheckHook,
9 nix-update-script,
10}:
11buildGoModule rec {
12 pname = "guesswidth";
13 version = "0.4.0";
14
15 src = fetchFromGitHub {
16 owner = "noborus";
17 repo = "guesswidth";
18 tag = "v${version}";
19 hash = "sha256-afZYegG4q+KmvNP2yy/HGvP4V1mpOUCxRLWLTUHAK0M=";
20 };
21
22 vendorHash = "sha256-IGb+fM3ZOlGrLGFSUeUhZ9wDMKOBofDBYByAQlvXY14=";
23
24 ldflags = [
25 "-X github.com/noborus/guesswidth.version=v${version}"
26 "-X github.com/noborus/guesswidth.revision=${src.rev}"
27 ];
28
29 nativeBuildInputs = [
30 installShellFiles
31 ];
32
33 postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) (
34 let
35 emulator = stdenv.hostPlatform.emulator buildPackages;
36 in
37 ''
38 installShellCompletion --cmd guesswidth \
39 --bash <(${emulator} $out/bin/guesswidth completion bash) \
40 --fish <(${emulator} $out/bin/guesswidth completion fish) \
41 --zsh <(${emulator} $out/bin/guesswidth completion zsh)
42 ''
43 );
44
45 nativeInstallCheckInputs = [
46 versionCheckHook
47 ];
48 versionCheckProgramArg = "--version";
49 doInstallCheck = true;
50
51 passthru.updateScript = nix-update-script { };
52
53 meta = {
54 description = "Guess the width (fwf) output without delimiters in commands that output to the terminal";
55 homepage = "https://github.com/noborus/guesswidth";
56 changelog = "https://github.com/noborus/guesswidth/releases/tag/v${version}";
57 license = lib.licenses.mit;
58 maintainers = with lib.maintainers; [ xiaoxiangmoe ];
59 mainProgram = "guesswidth";
60 };
61}