Skip to content

Commit 96d83bb

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

8 files changed

Lines changed: 174 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+
- glow
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+
| Glow | https://github.com/charmbracelet/glow | Render markdown on the CLI, with pizzazz! 💅🏻 |
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+
### `glow`
397+
398+
Running `glow --version` inside the built container will print the version of glow.
399+
400+
```jsonc
401+
{
402+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
403+
"features": {
404+
"ghcr.io/jsburckhardt/devcontainer-features/glow:1": {}
405+
}
406+
}
407+
```
408+
409+
```bash
410+
glow --version
411+
```

src/glow/devcontainer-feature.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "Glow",
3+
"id": "glow",
4+
"version": "1.0.0",
5+
"description": "Render markdown on the CLI, with pizzazz! 💅🏻",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"default": "latest",
10+
"description": "Version of glow to install from GitHub releases e.g. v2.1.2"
11+
}
12+
}
13+
}

src/glow/install.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env bash
2+
3+
# Variables
4+
REPO_OWNER="charmbracelet"
5+
REPO_NAME="glow"
6+
BINARY_NAME="glow"
7+
GLOW_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 "$GLOW_VERSION" ] || [ "$GLOW_VERSION" == "latest" ]; then
41+
# No version provided, get the latest version
42+
GLOW_VERSION=$(get_latest_version)
43+
echo "No version provided or 'latest' specified, installing the latest version: $GLOW_VERSION"
44+
else
45+
echo "Installing version from environment variable: $GLOW_VERSION"
46+
fi
47+
48+
# Strip the leading 'v' for the download URL filename
49+
VERSION_NO_V="${GLOW_VERSION#v}"
50+
51+
# Determine the OS and architecture
52+
OS=$(uname -s)
53+
ARCH=$(uname -m)
54+
55+
case "$ARCH" in
56+
x86_64)
57+
ARCH="x86_64"
58+
;;
59+
i686 | i386)
60+
ARCH="i386"
61+
;;
62+
aarch64 | arm64)
63+
ARCH="arm64"
64+
;;
65+
armv7l)
66+
ARCH="arm"
67+
;;
68+
*)
69+
echo "Unsupported architecture: $ARCH"
70+
exit 1
71+
;;
72+
esac
73+
74+
case "$OS" in
75+
Linux)
76+
OS="Linux"
77+
;;
78+
Darwin)
79+
OS="Darwin"
80+
;;
81+
*)
82+
echo "Unsupported OS: $OS"
83+
exit 1
84+
;;
85+
esac
86+
87+
# Construct the download URL
88+
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${GLOW_VERSION}/glow_${VERSION_NO_V}_${OS}_${ARCH}.tar.gz"
89+
90+
# Create a temporary directory for the download
91+
TMP_DIR=$(mktemp -d)
92+
cd "$TMP_DIR" || exit
93+
94+
echo "Downloading glow from $DOWNLOAD_URL"
95+
curl -sSL "$DOWNLOAD_URL" -o "glow.tar.gz"
96+
97+
# Extract the tarball
98+
echo "Extracting glow..."
99+
tar -xzf "glow.tar.gz"
100+
101+
# Move the binary to /usr/local/bin
102+
echo "Installing glow..."
103+
mv glow /usr/local/bin/
104+
chmod +x /usr/local/bin/glow
105+
106+
# Cleanup
107+
cd - || exit
108+
rm -rf "$TMP_DIR"
109+
110+
# Clean up
111+
rm -rf /var/lib/apt/lists/*
112+
113+
# Verify installation
114+
echo "Verifying installation..."
115+
glow --version
116+
117+
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 "glow" glow --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 "glow with specific version" /bin/bash -c "glow --version | grep '2.1.2'"
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+
"glow": {}
2627
}
2728
},
2829
"flux-specific-version": {
@@ -172,5 +173,13 @@
172173
"features": {
173174
"tmux": {}
174175
}
176+
},
177+
"glow-specific-version": {
178+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
179+
"features": {
180+
"glow": {
181+
"version": "v2.1.2"
182+
}
183+
}
175184
}
176185
}

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

0 commit comments

Comments
 (0)