Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [bat warning]: Unknown theme 'Monokai Extended' #1075

Closed
mckellygit opened this issue May 10, 2022 · 32 comments
Closed

🐛 [bat warning]: Unknown theme 'Monokai Extended' #1075

mckellygit opened this issue May 10, 2022 · 32 comments

Comments

@mckellygit
Copy link

Thank you for delta.
It was working fine for me for a long time and then recently it stopped working.
Perhaps some update with bat or something on my end.
Running delta on any two files now reports -

% delta file1 file2
[bat warning]: Unknown theme 'Monokai Extended', using default.
thread 'main' panicked at 'something is very wrong if the default theme is missing', /home/kellma02/.cargo/registry/src/github.com-1ecc6299db9ec823/bat-0.20.0/src/assets.rs:204:22

% delta --version
delta 0.12.2 - latest ToT built - commit a53dc02

% bat --version
bat 0.20.0 (dc7d5a8) - also latest ToT built

OS:
linux 5.13.0-41 (ubuntu 20.04 + hwe)

ok, seems like a bat problem. But bat alone for me seems ok.
I cannot get bat by itself to fail like this. Should I submit this to bat ?

% bat --theme "Monokai Extended" file1

works ok.

% bat --list-themes shows the theme is present -

Theme: Monokai Extended

A full stack trace from the delta cmdline is -

stack backtrace:
0: 0x5614e7351b7d - std::backtrace_rs::backtrace::libunwind::trace::hee598835bc88d35b
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x5614e7351b7d - std::backtrace_rs::backtrace::trace_unsynchronized::h9cdc730ba5cf5d72
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x5614e7351b7d - std::sys_common::backtrace::_print_fmt::h75aeaf7ed30e43fa
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/sys_common/backtrace.rs:66:5
3: 0x5614e7351b7d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h606862f787600875
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/sys_common/backtrace.rs:45:22
4: 0x5614e737902c - core::fmt::write::he803f0f418caf762
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/fmt/mod.rs:1190:17
5: 0x5614e734cc28 - std::io::Write::write_fmt::h70bc45872f37e7bb
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/io/mod.rs:1657:15
6: 0x5614e7353ee7 - std::sys_common::backtrace::_print::h64d038cf8ac3e13e
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/sys_common/backtrace.rs:48:5
7: 0x5614e7353ee7 - std::sys_common::backtrace::print::h359300b4a7fccf65
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/sys_common/backtrace.rs:35:9
8: 0x5614e7353ee7 - std::panicking::default_hook::{{closure}}::hf51be35e2f510149
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:295:22
9: 0x5614e7353bb0 - std::panicking::default_hook::h03ca0f22e1d2d25e
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:314:9
10: 0x5614e7354639 - std::panicking::rust_panic_with_hook::h3b7380e99b825b63
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:698:17
11: 0x5614e7354327 - std::panicking::begin_panic_handler::{{closure}}::h8e849d0710154ce0
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:588:13
12: 0x5614e7352044 - std::sys_common::backtrace::__rust_end_short_backtrace::hedcdaddbd4c46cc5
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/sys_common/backtrace.rs:138:18
13: 0x5614e7354039 - rust_begin_unwind
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:584:5
14: 0x5614e7092cf3 - core::panicking::panic_fmt::he1bbc7336d49a357
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:143:14
15: 0x5614e7377ad1 - core::panicking::panic_display::hb184394d54dc8360
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:73:5
16: 0x5614e7377a7b - core::panicking::panic_str::ha42887cd972750c9
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:56:5
17: 0x5614e7092b66 - core::option::expect_failed::h9159c9d16ed9fb7c
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/option.rs:1852:5
18: 0x5614e7203cce - bat::assets::HighlightingAssets::get_theme::hc7467125c4edc0ea
19: 0x5614e70dc4a8 - delta::options::theme::set__is_light_mode__syntax_theme__syntax_set::h677759c10e43ad69
20: 0x5614e715b390 - delta::options::set::set_options::h8d58af2bf0c84dcf
21: 0x5614e7095c1f - delta::cli::Opt::from_clap_and_git_config::h61c2a01edb15a7ff
22: 0x5614e709599f - delta::cli::Opt::from_args_and_git_config::hdbf699dc115ec9e4
23: 0x5614e7175084 - delta::main::hf4df0a35130e1bc7
24: 0x5614e71291c3 - std::sys_common::backtrace::__rust_begin_short_backtrace::h62d7051c2c241ccc
25: 0x5614e717791d - std::rt::lang_start::{{closure}}::hcdf5d85a768ff03e
26: 0x5614e7351261 - core::ops::function::impls::<impl core::ops::function::FnOnce for &F>::call_once::hb7014f43484a8b4e
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/ops/function.rs:259:13
27: 0x5614e7351261 - std::panicking::try::do_call::h7bc9dc436daeb8c7
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:492:40
28: 0x5614e7351261 - std::panicking::try::h653d68a27ff5f175
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:456:19
29: 0x5614e7351261 - std::panic::catch_unwind::h9d739f9f59895e68
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panic.rs:137:14
30: 0x5614e7351261 - std::rt::lang_start_internal::{{closure}}::hf006f2bc7ce22bbe
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/rt.rs:128:48
31: 0x5614e7351261 - std::panicking::try::do_call::hfb39d6df61a2e69f
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:492:40
32: 0x5614e7351261 - std::panicking::try::h13e2d225134958ac
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:456:19
33: 0x5614e7351261 - std::panic::catch_unwind::h3bd49b5a5dfb1a50
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panic.rs:137:14
34: 0x5614e7351261 - std::rt::lang_start_internal::h2ba92edce36c035e
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/rt.rs:128:20
35: 0x5614e71787c2 - main
36: 0x14d5f048b0b3 - __libc_start_main
at /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:308:16
37: 0x5614e709352e - _start

Is there anything else I can provide ?

thx,
-m

@kidonng
Copy link

kidonng commented May 13, 2022

Probably a reincarnation of #895.

@Reinis
Copy link

Reinis commented May 13, 2022

Similar issue also with bat 0.21.0.
https://github.com/sharkdp/bat/releases/tag/v0.21.0

Probably due to this:

@rashil2000
Copy link
Contributor

Facing the same error when running git diff on a git repo:

[bat warning]: Unknown theme 'GitHub', using default.
thread 'main' panicked at 'something is very wrong if the default theme is missing', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\bat-0.20.0\src\assets.rs:204:22
stack backtrace:
   0:     0x7ff6ffce31df - git_filter_source_path
   1:     0x7ff6ffd0256a - git_filter_source_path
   2:     0x7ff6ffcdca88 - git_filter_source_path
   3:     0x7ff6ffce5f6b - git_filter_source_path
   4:     0x7ff6ffce5a64 - git_filter_source_path
   5:     0x7ff6ffce646c - git_filter_source_path
   6:     0x7ff6ffce632b - git_filter_source_path
   7:     0x7ff6ffce3b27 - git_filter_source_path
   8:     0x7ff6ffce6029 - git_filter_source_path
   9:     0x7ff6ffe12000 - onig_unicode_define_user_property
  10:     0x7ff6ffd00f40 - git_filter_source_path
  11:     0x7ff6ffd00eeb - git_filter_source_path
  12:     0x7ff6ffe11ef9 - onig_unicode_define_user_property
  13:     0x7ff6ffc0a65a - git_filter_source_repo
  14:     0x7ff6ffaed246 - <unknown>
  15:     0x7ff6ffb78c3b - <unknown>
  16:     0x7ff6ffa96adc - <unknown>
  17:     0x7ff6ffa96768 - <unknown>
  18:     0x7ff6ffb95313 - <unknown>
  19:     0x7ff6ffb49186 - <unknown>
  20:     0x7ff6ffb87520 - <unknown>
  21:     0x7ff6ffce2a3f - git_filter_source_path
  22:     0x7ff6ffb97ea7 - <unknown>
  23:     0x7ff6ffe022bc - onig_unicode_define_user_property
  24:     0x7ffab508244d - BaseThreadInitThunk
  25:     0x7ffab596df88 - RtlUserThreadStart

I temporarily fixed it by:

> scoop uninstall bat
> scoop install bat@0.20.0
> bat cache --build

@dandavison
Copy link
Owner

Hi all, I think these errors are related to the bat cache and that @rashil2000 has the right fix: can you try installing a recent version of bat and running bat cache --build.

To be clear, delta does not use the bat executable, but it does share the same on-disk cache of language grammars and syntax-highlighting themes.

@rbpatt2019
Copy link

So rebuilding the bat cache doesn't quite fix things for me (Mac Monterrey, all installed using macports). Though that fixes bat, delta still fails with

[bat warning]: Unknown theme 'gruvbox-dark', using default.
thread 'main' panicked at 'something is very wrong if the default theme is missing', /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_textproc_git-delta/git-delta/work/.home/.cargo/macports/bat-0.20.0/src/assets.rs:204:22

Took me a minute, but it's looking for bat v0.20.0 which isn't installed any more, as I updated. You can actually see the same in @rashil2000 error - delta is looking for/using files from bat 0.20.0. Any ideas why delta would be looking for components of bat 0.20.0?

@rashil2000
Copy link
Contributor

It seems like the cache that delta utilized only worked till bat v0.20.0. bat v0.21.0's cache is incompatible with delta.

@dandavison
Copy link
Owner

dandavison commented May 13, 2022

Hm, thanks, maybe I need to update the bat Rust library used by delta. (It's not bat's fault btw -- delta is using their on-disk cache, which is not a public API! So delta is getting what it deserves in the form of these backwards-incompatibility problems. On the plus side, the bat developers have told me informally that such breaking changes will be rare; and delta gets a lot of utility from sharing that cache. I believe they did warn me earlier this year that this second breaking change was coming up.)

Took me a minute, but it's looking for bat v0.20.0 which isn't installed any more, as I updated.

Just to make sure we're all on the same page, delta does not have any run time dependency on bat: the delta executable works without bat being installed. But delta does use bat as a Rust library, and indeed, it uses v0.20.0 of that Rust library:

bat = "0.20.0"

I assume MacPorts is compiling the Rust code on your machine? In that case I think it's all fine and proper that MacPorts has v0.20.0 of that Rust library on your system: it's just some Rust library it needs privately to build delta, and is unrelated to any bat executable you may or may not have.

@dandavison
Copy link
Owner

I've pushed an update to master which updates the bat library that delta uses. I'll try to release it shortly. So, if you are able to install from master, then it will work with latest bat (v0.21) after running bat cache --build.

@Kr1ss-XD
Copy link
Contributor

Thx @dandavison - I've encountered this problem since my bat cache is v0.21.

After rebuilding delta from master, this is fixed.

@mckellygit
Copy link
Author

Yes, thanks so much, latest build works great.

@michaelblyons
Copy link

Homebrew waiting on Homebrew/homebrew-core#101419

@dandavison
Copy link
Owner

dandavison commented May 14, 2022

This is fixed in the latest release (which is now available in homebrew). Thanks everyone for the help here.

@kschat
Copy link

kschat commented May 16, 2022

It's not bat's fault btw -- delta is using their on-disk cache, which is not a public API! So delta is getting what it deserves in the form of these backwards-incompatibility problems. On the plus side, the bat developers have told me informally that such breaking changes will be rare; and delta gets a lot of utility from sharing that cache.

Is it possible to reconsider this strategy? Because of this implicit, runtime dependency it makes it so anyone using delta v0.12.2 - ??? can only have bat v0.20 installed on their system. If you want to use delta v0.13.0 you need to make sure you also update bat at the same time. Needing to update these utilities in lockstep isn't ideal, and when you don't, there isn't a very helpful error message telling you why delta suddenly doesn't work. The cache created by bat is data owned by bat and as we've seen, depending on it to be stable can be dangerous. Is it possible for detla to create its own cache?

If the utility provided by using a single cache for bat and delta is too high, would it be possible to add a runtime check for the version of bat installed and provide a detailed error message for this issue?

@dandavison
Copy link
Owner

Hi @kschat,

Is it possible for delta to create its own cache?

Certainly possible. A downside is that it would be (semantically, if not in bytes) identical to the bat cache -- a user wanting to create a custom syntax theme or language grammar would have to do it in both places (the chances are that such a user would be using both applications).

Needing to update these utilities in lockstep isn't ideal

I honestly think there may be good news there -- I believe that bat is not planning to make more backwards incompatible changes to their cache format. There have only been two during delta's existence, and both recent since there was a pulse of bat development aimed at lazy-loading assets (from which delta benefits!).

would it be possible to add a runtime check for the version of bat installed and provide a detailed error message for this issue?

Yes, and I'd be happy to receive PRs in this area. I don't think I'd want to try to start a bat process on every delta startup, but maybe we could simply improve the error message that results?

@kschat
Copy link

kschat commented May 16, 2022

A downside is that it would be (semantically, if not in bytes) identical to the bat cache -- a user wanting to create a custom syntax theme or language grammar would have to do it in both places (the chances are that such a user would be using both applications).

I personally don't think that's a con (but others likely disagree). I actually find it surprising that upgrading the cache of one disparate application affects another, seemingly unrelated application. I understand that under the hood delta uses bat as a library for things related to theming, but that's an implementation detail and not something users should be privy to (IMO).

I honestly think there may be good news there -- I believe that bat is not planning to make more backwards incompatible changes to their cache format.

That is good news, and perhaps I'm making a bigger deal out of this than needed.

Yes, and I'd be happy to receive PRs in this area.

Great! I won't make any promises of being able to do this soon, but it's something I'm happy to contribute when I find the time. Speaking of time, thanks for yours and delta! It's appreciated.

I don't think I'd want to try to start a bat process on every delta startup, but maybe we could simply improve the error message that results?

Yeah, totally. Perhaps it could be a first time check that is cached? Or maybe there's a heuristic that can be used to determine the current version of bat based on the cache?

@dandavison
Copy link
Owner

dandavison commented May 16, 2022

I personally don't think that's a con (but others likely disagree). I actually find it surprising that upgrading the cache of one disparate application affects another, seemingly unrelated application. I understand that under the hood delta uses bat as a library for things related to theming, but that's an implementation detail and not something users should be privy to (IMO).

Yes, I don't disagree with you. I don't want to give the impression that this is really by design. It's more that, to recreate the cache lifecycle management functionality, I'd have to vendor a bunch of code from bat (or help them move it into the bat library, if that made sense). And while there is some vendored bat code, it's very little now due to the bat Rust library. But I think possibly I, and maybe the bat devs, feel that a separate library dedicated to managing the syntax highlighting assets could make more sense ultimately than that being in the bat crate. So all in all, as you can imagine, it's easier, for a side project, to leave it be and try to deal with the backwards incompatible upgrades with minimal disruption to my users!

@Enselic
Copy link

Enselic commented May 16, 2022

There is a metadata.yml file in the cache that you could use. See here:

https://github.com/sharkdp/bat/blob/5f139e5ec2ed0e7745ebaf00f354400aa4ad7943/src/bin/bat/assets.rs#L30

for the bat code for this check.

Disclaimer: This is not a commitment to keep the format of that file stable over time (see e.g. sharkdp/bat#2085). But it should work for the foreseeable future.

@kschat
Copy link

kschat commented May 16, 2022

So all in all, as you can imagine, it's easier, for a side project, to leave it be and try to deal with the backwards incompatible upgrades with minimal disruption to my users!

Sure, I understand and empathize with that stance.

I had some downtime at work today, so I took a quick stab at it. @Enselic the code you linked was very helpful, thanks for it. Unfortunately I'm stuck on getting the current built version of bat. When bat is used as a lib, does it expose the current version anywhere? I had a cursory look, but came up short.

@dandavison if there isn't a programmatic way of getting the current built version of bat, I'll have to parse the Cargo.toml/Cargo.lock file with a build script. Is this something you're open to? I know some projects are (understandably) opposed to adding build complexity, so I want to confirm before committing time to that strategy.

@dandavison
Copy link
Owner

@kschat the main thing I am reluctant to do is read files at delta start time.

@dandavison
Copy link
Owner

Can you explain what you would be reading from a Cargo.{toml,lock} file? How does that tell us about the user's bat installation? I am feeling a bit reluctant to increasing delta build complexity to address this issue as

(a) I'm not convinced that it's going to happen frequently
(b) Not all delta users are bat users
(c) It's quite easy to upgrade both bat and delta

But I would like to make error messages as helpful as possible.

@kschat
Copy link

kschat commented May 16, 2022

Sure. In order to use the is_compatible_with method on AssetsMetadata, the current version of bat being used needs to be passed. It doesn't look like bat provides the current version when being used as a lib. If that's the case, then the current version needs to be extract from the Cargo.lock file at built time so it can be used by delta when checking if the cache is compatible.

If you're opposed to a build script, I can open a PR against bat to expose the current version.

@dandavison
Copy link
Owner

I see, thanks. Right, this change does seem quite attractive then seeing as bat has the is_compatible_with API and it would not involve any disk access at runtime AIUI (other than what we are obliged to do already to load assets).

If you're opposed to a build script, I can open a PR against bat to expose the current version.

Unless @Enselic says in this thread that they would not be interested in that change, could you look into that possibility? I see that bat has a build script already and that it might be a relatively small change (though of course, only really justified if it might be useful to other bat crate users).

@Enselic
Copy link

Enselic commented May 17, 2022

I'm not sure exposing the version from bat would help much, because the version is for bat-as-a-library, and not for binary assets. In other words, we can expect the bat 0.x.0 version to be increased without binary assets becoming incompatible.

My thinking goes like this:

  • delta knows what version of bat that it uses
  • delta knows for what bat version that assets are incompatible
  • delta knows what bat version that was used to generate bat assets by looking inside metadata.yml

Based on the above, delta could have a user-friendly check of compatibility. So the way I see it, there is no need for new APIs in bat.

@chmanie
Copy link

chmanie commented May 17, 2022

Hey sorry to hijack this as it should be solved but I'm running bat 0.20.0 (just noting even though apparently it doesn't matter) and delta 0.13.0 and I still get the message:

[bat warning]: Unknown theme 'Monokai Extended', using default.
thread 'main' panicked at 'something is very wrong if the default theme is missing', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/bat-0.21.0/src/assets.rs:205:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

| bat --version    
bat 0.20.0 (0655ecf2)

| delta --version
delta 0.13.0

I'm running Arch and installed both from the community repo (bat@0.20.0-2 and git-delta@0.13.0-1)
I already did a bat cache --build. Is there anything else I need to do?

@Frederick888
Copy link

I'm running bat 0.20.0 (just noting even though apparently it doesn't matter) and delta 0.13.0 and I still get the message:

Exactly. @chmanie

@chmanie
Copy link

chmanie commented May 17, 2022

@Frederick888 I'm not sure what you mean. Can you elaborate?

@Frederick888
Copy link

@Frederick888 I'm not sure what you mean. Can you elaborate?

You need to either update bat to 0.21.0 or roll delta back to 0.12.1.

@chmanie
Copy link

chmanie commented May 17, 2022

Ah yeah, thanks! Sorry I got lost in this thread somehow. So just to clarify (also for others):

The issue is not your installed bat version or whether it is installed at all. The issue only comes up only when there's a bat cache folder (for me it was ~/.cache/bat) that was created with bat version 0.20.0.

As 0.21.0 of bat was not available in the Arch repos at the time of writing I resolved to installing it using cargo directly.

@Frederick888
Copy link

The issue is not your installed bat version or whether it is installed at all. The issue only comes up only when there's a bat cache folder (for me it was ~/.cache/bat) that was created with bat version 0.20.0.

AFAIU to be accurate it happens when there's some breaking change in bat's cache format and delta's dependent bat (as library) version mismatches. Correct me if I'm wrong tho.

@kschat
Copy link

kschat commented May 17, 2022

@Enselic I might be misunderstanding what is_compatible_with does, then. I was under the impression that this method told the caller whether the passed in version of bat is compatible with the loaded cache data. If that's true, then delta would need to pass in the current bat-as-a-library version to this method. It's true that delta knows what version of bat it's using, but it's unfortunately not very straight forward to get this info at runtime. If bat exposed a version const, it'd be much easier for bat-as-a-library users to use the is_compatible_with method.

@Enselic
Copy link

Enselic commented May 17, 2022

The problem with is_compatible_with is that it is buggy. It will return false even though binary files are compatible with the version of the software that makes the check. This is because the check uses the bat-as-a-library version. It simply checks if 0.x.0 has changed. If it has, it assumes that binary files are not compatible anymore. But this is wrong. So exposing the bat-as-a-library version is not a long term fix.

I'm thinking the best short-term fix for delta is to parse the yml yourself (which is close to trivial) and then simply add a check "if binary assets come from bat v0.20.0, then print an error message", since we know that the latest version of delta is incompatible with bat v0.20.0 assets. It is not possible today to say if bat v0.22.0 assets will be compatible or not with bat v0.21.0 assets. But right now it looks like they will be compatible.

The right long-term fix here seems to me to be to make bat properly version its binary files format separately from the bat-as-a-library version, and expose the necessary API for clients to make their own checks. Assuming we want binary files to be part of the API at all, which is not self-evident.

This is all my personal opinions and thoughts. I have not synced with other bat maintainers about this yet.

@The-Compiler
Copy link

As 0.21.0 of bat was not available in the Arch repos at the time of writing I resolved to installing it using cargo directly.

FWIW, here is an updated PKGBUILD you can install with makepkg -si:

# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Wesley Moore <wes@wezm.net>

pkgname=bat
pkgver=0.21.0
pkgrel=1
pkgdesc='Cat clone with syntax highlighting and git integration'
arch=(x86_64)
url='https://github.com/sharkdp/bat'
license=(APACHE MIT)
depends=(gcc-libs libgit2 oniguruma)
makedepends=(clang cmake git rust)
source=("git+$url#commit=405e5f7") # tag: v0.21.0
b2sums=('SKIP')

prepare() {
  cargo fetch \
    --locked \
    --manifest-path "$srcdir/$pkgname/Cargo.toml"
}

build() {
  export CFLAGS+=' -ffat-lto-objects -w'
  cargo build \
    --locked \
    --manifest-path "$srcdir/$pkgname/Cargo.toml" \
    --release
}

# check() {
#   cargo test \
#     --locked \
#     --manifest-path "$srcdir/$pkgname/Cargo.toml"
# }

package() {
  install -Dm755 $pkgname/target/release/$pkgname "$pkgdir/usr/bin/$pkgname"

  # Package licenses
  install -Dm644 $pkgname/LICENSE-APACHE \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE-APACHE"
  install -Dm644 $pkgname/LICENSE-MIT \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE-MIT"

  cd $pkgname/target/release/build

  # Find and package the man page (because cargo --out-dir is too new)
  find . -name bat.1 -type f -exec install -Dm644 {} \
    "$pkgdir/usr/share/man/man1/bat.1" \;

  # Find and package the zsh completion file (not in zsh-completions yet)
  find . -name bat.zsh -type f -exec install -Dm644 {} \
    "$pkgdir/usr/share/zsh/site-functions/_bat" \;

  # Find and package the fish completion file
  find . -name bat.fish -type f -exec install -Dm644 {} \
    "$pkgdir/usr/share/fish/vendor_completions.d/bat.fish" \;
}

(I had to disable the tests as they were failing for me, didn't feel like investigating in detail)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests