Skip to content

Commit 33e9f6f

Browse files
Copilotjsburckhardt
andcommitted
feat: add BAT feature with Ubuntu/Debian package installation
Co-authored-by: jsburckhardt <[email protected]>
1 parent acfeb03 commit 33e9f6f

5 files changed

Lines changed: 111 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This repository contains a _collection_ of Features.
88

99
| Name | URL | Description |
1010
| --- | --- | --- |
11+
| bat | https://github.com/sharkdp/bat | A cat(1) clone with syntax highlighting and Git integration. |
1112
| flux | https://fluxcd.io/flux/installation/ | Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration |
1213
| notation | https://notaryproject.dev/ | Notation is a CLI project to add signatures as standard items in the registry ecosystem, and to build a set of simple tooling for signing and verifying these signatures. This should be viewed as similar security to checking git commit signatures, although the signatures are generic and can be used for additional purposes. Notation is an implementation of the Notary v2 specifications.|
1314
| crane | https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md | crane is a tool for interacting with remote images and registries.|
@@ -26,6 +27,23 @@ This repository contains a _collection_ of Features.
2627

2728

2829

30+
### `bat`
31+
32+
Running `bat` inside the built container will print the help menu of bat.
33+
34+
```jsonc
35+
{
36+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
37+
"features": {
38+
"ghcr.io/jsburckhardt/devcontainer-features/bat:1": {}
39+
}
40+
}
41+
```
42+
43+
```bash
44+
bat --version
45+
```
46+
2947
### `flux`
3048

3149
Running `flux` inside the built container will print the help menu of flux.

src/bat/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# bat (bat)
2+
3+
A cat(1) clone with syntax highlighting and Git integration.
4+
5+
## Example Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/jsburckhardt/devcontainer-features/bat:1": {}
10+
}
11+
```
12+
13+
## Options
14+
15+
| Options Id | Description | Type | Default Value |
16+
|-----|-----|-----|-----|
17+
| version | Version of bat to install (currently installs from Ubuntu package repository). | string | latest |
18+
19+
20+
21+
---
22+
23+
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/jsburckhardt/devcontainer-features/blob/main/src/bat/devcontainer-feature.json). Add additional notes to a `NOTES.md`._

src/bat/devcontainer-feature.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "bat",
3+
"id": "bat",
4+
"version": "1.0.0",
5+
"description": "A cat(1) clone with syntax highlighting and Git integration.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"default": "latest",
10+
"description": "Version of bat to install (currently installs from Ubuntu package repository)."
11+
}
12+
}
13+
}

src/bat/install.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
BAT_VERSION="${VERSION:-"latest"}"
4+
5+
set -e
6+
7+
if [ "$(id -u)" -ne 0 ]; then
8+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
9+
exit 1
10+
fi
11+
12+
# Checks if packages are installed and installs them if not
13+
check_packages() {
14+
if ! dpkg -s "$@" >/dev/null 2>&1; then
15+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
16+
echo "Running apt-get update..."
17+
apt-get update -y
18+
fi
19+
apt-get -y install --no-install-recommends "$@"
20+
fi
21+
}
22+
23+
echo "Installing bat..."
24+
25+
# For simplicity and reliability, install bat from Ubuntu repositories
26+
# This provides a stable version that works well in devcontainer environments
27+
check_packages bat
28+
29+
# Verify installation
30+
echo "Verifying bat installation..."
31+
32+
# In Ubuntu, bat is installed as 'batcat' to avoid conflicts
33+
if command -v batcat >/dev/null 2>&1; then
34+
echo "batcat installed successfully!"
35+
batcat --version
36+
# Create a symlink so users can use 'bat' command
37+
ln -sf /usr/bin/batcat /usr/local/bin/bat
38+
echo "Created symlink: /usr/local/bin/bat -> /usr/bin/batcat"
39+
elif command -v bat >/dev/null 2>&1; then
40+
echo "bat installed successfully!"
41+
bat --version
42+
else
43+
echo "ERROR: bat installation failed - neither bat nor batcat found"
44+
exit 1
45+
fi
46+
47+
# Clean up
48+
rm -rf /var/lib/apt/lists/*
49+
50+
echo "Done!"

test/bat/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
check "bat" bat --version
7+
reportResults

0 commit comments

Comments
 (0)