Skip to content

Commit f7503af

Browse files
jsburckhardtCopilot
andcommitted
feat(ripgrep): add ripgrep devcontainer feature
Closes #95 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 40c7450 commit f7503af

8 files changed

Lines changed: 188 additions & 1 deletion

File tree

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- opencode
3333
- ccc
3434
- tmux
35+
- ripgrep
3536
baseImage:
3637
- debian:latest
3738
- ubuntu:latest

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This repository contains a _collection_ of Features.
3131
| ccc | https://github.com/jsburckhardt/co-config | A TUI tool to interactively configure and view GitHub Copilot CLI settings. |
3232
| Yazi | https://github.com/sxyazi/yazi | Blazing fast terminal file manager written in Rust, based on async I/O. |
3333
| tmux | https://github.com/tmux/tmux | tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal. |
34+
| ripgrep | https://github.com/BurntSushi/ripgrep | Recursively searches directories for a regex pattern while respecting your gitignore. |
3435

3536

3637

@@ -391,3 +392,20 @@ Running `tmux -V` inside the built container will print the version of tmux.
391392
```bash
392393
tmux -V
393394
```
395+
396+
### `ripgrep`
397+
398+
Running `rg --version` inside the built container will print the version of ripgrep.
399+
400+
```jsonc
401+
{
402+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
403+
"features": {
404+
"ghcr.io/jsburckhardt/devcontainer-features/ripgrep:1": {}
405+
}
406+
}
407+
```
408+
409+
```bash
410+
rg --version
411+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "ripgrep",
3+
"id": "ripgrep",
4+
"version": "1.0.0",
5+
"description": "Recursively searches directories for a regex pattern while respecting your gitignore.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"default": "latest",
10+
"description": "Version of ripgrep to install from GitHub releases e.g. 14.1.1"
11+
}
12+
}
13+
}

src/ripgrep/install.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env bash
2+
3+
# Variables
4+
REPO_OWNER="BurntSushi"
5+
REPO_NAME="ripgrep"
6+
BINARY_NAME="rg"
7+
RIPGREP_VERSION="${VERSION:-"latest"}"
8+
GITHUB_API_REPO_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases"
9+
10+
set -e
11+
12+
if [ "$(id -u)" -ne 0 ]; then
13+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
14+
exit 1
15+
fi
16+
17+
# Clean up
18+
rm -rf /var/lib/apt/lists/*
19+
20+
# Checks if packages are installed and installs them if not
21+
check_packages() {
22+
if ! dpkg -s "$@" >/dev/null 2>&1; then
23+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
24+
echo "Running apt-get update..."
25+
apt-get update -y
26+
fi
27+
apt-get -y install --no-install-recommends "$@"
28+
fi
29+
}
30+
31+
# Make sure we have curl and jq
32+
check_packages curl jq ca-certificates
33+
34+
# Function to get the latest version from GitHub API
35+
get_latest_version() {
36+
curl -s "${GITHUB_API_REPO_URL}/latest" | jq -r ".tag_name"
37+
}
38+
39+
# Check if a version is passed as an argument
40+
if [ -z "$RIPGREP_VERSION" ] || [ "$RIPGREP_VERSION" == "latest" ]; then
41+
# No version provided, get the latest version
42+
RIPGREP_VERSION=$(get_latest_version)
43+
echo "No version provided or 'latest' specified, installing the latest version: $RIPGREP_VERSION"
44+
else
45+
echo "Installing version from environment variable: $RIPGREP_VERSION"
46+
fi
47+
48+
# Determine the OS and architecture
49+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
50+
ARCH=$(uname -m)
51+
52+
case "$ARCH" in
53+
x86_64)
54+
ARCH_TRIPLE="x86_64-unknown-linux-musl"
55+
;;
56+
i686)
57+
ARCH_TRIPLE="i686-unknown-linux-gnu"
58+
;;
59+
aarch64)
60+
ARCH_TRIPLE="aarch64-unknown-linux-gnu"
61+
;;
62+
armv7l)
63+
ARCH_TRIPLE="armv7-unknown-linux-gnueabihf"
64+
;;
65+
*)
66+
echo "Unsupported architecture: $ARCH"
67+
exit 1
68+
;;
69+
esac
70+
71+
case "$OS" in
72+
linux)
73+
# ARCH_TRIPLE already set above for linux
74+
;;
75+
darwin)
76+
case "$ARCH" in
77+
x86_64)
78+
ARCH_TRIPLE="x86_64-apple-darwin"
79+
;;
80+
aarch64|arm64)
81+
ARCH_TRIPLE="aarch64-apple-darwin"
82+
;;
83+
*)
84+
echo "Unsupported architecture on macOS: $ARCH"
85+
exit 1
86+
;;
87+
esac
88+
;;
89+
*)
90+
echo "Unsupported OS: $OS"
91+
exit 1
92+
;;
93+
esac
94+
95+
# Construct the download URL
96+
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${RIPGREP_VERSION}/ripgrep-${RIPGREP_VERSION}-${ARCH_TRIPLE}.tar.gz"
97+
98+
# Create a temporary directory for the download
99+
TMP_DIR=$(mktemp -d)
100+
cd "$TMP_DIR" || exit
101+
102+
echo "Downloading ripgrep from $DOWNLOAD_URL"
103+
curl -sSL "$DOWNLOAD_URL" -o "ripgrep.tar.gz"
104+
105+
# Extract the tarball
106+
echo "Extracting ripgrep..."
107+
tar -xzf "ripgrep.tar.gz"
108+
109+
# Find the extracted directory
110+
EXTRACTED_DIR=$(find . -name "ripgrep-${RIPGREP_VERSION}-*" -type d | head -1)
111+
if [ -z "$EXTRACTED_DIR" ]; then
112+
echo "ERROR: Could not find extracted ripgrep directory"
113+
exit 1
114+
fi
115+
116+
# Move the binary to /usr/local/bin
117+
echo "Installing ripgrep..."
118+
mv "${EXTRACTED_DIR}/rg" /usr/local/bin/
119+
120+
# Cleanup
121+
cd - || exit
122+
rm -rf "$TMP_DIR"
123+
124+
# Clean up
125+
rm -rf /var/lib/apt/lists/*
126+
127+
# Verify installation
128+
echo "Verifying installation..."
129+
rg --version
130+
131+
echo "Done!"

test/_global/all-tools.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ check "opencode" opencode --version
2121
check "ccc" ccc --version
2222
check "yazi" yazi --version
2323
check "tmux" tmux -V
24+
check "ripgrep" rg --version
2425

2526
reportResults
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+
source dev-container-features-test-lib
5+
check "ripgrep with specific version" /bin/bash -c "rg --version | grep '14.1.1'"
6+
7+
reportResults

test/_global/scenarios.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"opencode": {},
2323
"ccc": {},
2424
"yazi": {},
25-
"tmux": {}
25+
"tmux": {},
26+
"ripgrep": {}
2627
}
2728
},
2829
"flux-specific-version": {
@@ -172,5 +173,13 @@
172173
"features": {
173174
"tmux": {}
174175
}
176+
},
177+
"ripgrep-specific-version": {
178+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
179+
"features": {
180+
"ripgrep": {
181+
"version": "14.1.1"
182+
}
183+
}
175184
}
176185
}

test/ripgrep/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 "ripgrep" rg --version
7+
reportResults

0 commit comments

Comments
 (0)