Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- atuin.sh
- btop
- bun.sh
- charmbracelet-gum
- chezmoi.io
- deno.com
- feature-installer
Expand Down
17 changes: 17 additions & 0 deletions src/charmbracelet-gum/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "charmbracelet/gum",
"id": "gum",
"version": "1.0.0",
"description": "Install \"gum\" binary",
"documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/charmbracelet-gum",
"options": {
"version": {
"type": "string",
"default": "latest",
"proposals": [
"latest"
],
"description": "Version of \"gum\" to install."
}
}
}
143 changes: 143 additions & 0 deletions src/charmbracelet-gum/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
set -o allexport
readonly githubRepository='charmbracelet/gum'
readonly binaryName='gum'
readonly versionArgument='--version'
readonly downloadUrlTemplate='https://github.com/${githubRepository}/releases/download/v${version}/${name}_${version}_Linux_${architecture}.tar.gz'
readonly binaryPathInArchiveTemplate='${name}_${version}_Linux_${architecture}/${binaryName}'
readonly binaryTargetFolder='/usr/local/bin'
readonly name="${githubRepository##*/}"
apt_get_update() {
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
apt_get_checkinstall() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
apt_get_update
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@"
fi
}
apt_get_cleanup() {
apt-get clean
rm -rf /var/lib/apt/lists/*
}
check_curl_envsubst_file_tar_installed() {
declare -a requiredAptPackagesMissing=()
if ! [ -r '/etc/ssl/certs/ca-certificates.crt' ]; then
requiredAptPackagesMissing+=('ca-certificates')
fi
if ! command -v curl >/dev/null 2>&1; then
requiredAptPackagesMissing+=('curl')
fi
if ! command -v envsubst >/dev/null 2>&1; then
requiredAptPackagesMissing+=('gettext-base')
fi
if ! command -v file >/dev/null 2>&1; then
requiredAptPackagesMissing+=('file')
fi
if ! command -v tar >/dev/null 2>&1; then
requiredAptPackagesMissing+=('tar')
fi
declare -i requiredAptPackagesMissingCount=${#requiredAptPackagesMissing[@]}
if [ $requiredAptPackagesMissingCount -gt 0 ]; then
apt_get_update
apt_get_checkinstall "${requiredAptPackagesMissing[@]}"
apt_get_cleanup
fi
}
curl_check_url() {
local url=$1
local status_code
status_code=$(curl -s -o /dev/null -w '%{http_code}' "$url")
if [ "$status_code" -ne 200 ] && [ "$status_code" -ne 302 ]; then
echo "Failed to download '$url'. Status code: $status_code."
return 1
fi
}
curl_download_stdout() {
local url=$1
curl \
--silent \
--location \
--output '-' \
--connect-timeout 5 \
"$url"
}
curl_download_untar() {
local url=$1
local strip=$2
local target=$3
local bin_path=$4
curl_download_stdout "$url" | tar \
-xz \
-f '-' \
--strip-components="$strip" \
-C "$target" \
"$bin_path"
}
debian_get_arch() {
arch=$(uname -m)
# if [[ "$arch" == "aarch64" ]]; then
# arch="arm64"
# elif [[ "$arch" == "x86_64" ]]; then
# arch="x64"
# fi
Comment on lines +86 to +90
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out code for architecture mapping should be removed or implemented. The current implementation returns uname -m output directly (e.g., 'x86_64', 'aarch64'), which must match the naming convention used in the gum release archives. If the releases use different architecture names, this mapping logic should be uncommented and corrected.

Suggested change
# if [[ "$arch" == "aarch64" ]]; then
# arch="arm64"
# elif [[ "$arch" == "x86_64" ]]; then
# arch="x64"
# fi
if [[ "$arch" == "aarch64" ]]; then
arch="arm64"
elif [[ "$arch" == "x86_64" ]]; then
arch="x64"
fi

Copilot uses AI. Check for mistakes.
echo "$arch"
# echo "$(dpkg --print-architecture)" --- IGNORE ---
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented-out line with '--- IGNORE ---' should be removed as it serves no purpose and clutters the code.

Suggested change
# echo "$(dpkg --print-architecture)" --- IGNORE ---

Copilot uses AI. Check for mistakes.
}
echo_banner() {
local text="$1"
echo -e "\e[1m\e[97m\e[41m$text\e[0m"
}
github_list_releases() {
if [ -z "$1" ]; then
echo "Usage: list_github_releases <owner/repo>"
return 1
fi
local repo="$1"
local url="https://api.github.com/repos/$repo/releases"
curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//'
}
github_get_latest_release() {
if [ -z "$1" ]; then
echo "Usage: get_latest_github_release <owner/repo>"
return 1
fi
github_list_releases "$1" | head -n 1
}
utils_check_version() {
local version=$1
if ! [[ "${version:-}" =~ ^(latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
printf >&2 '=== [ERROR] Option "version" (value: "%s") is not "latest" or valid semantic version format "X.Y.Z" !\n' \
"$version"
exit 1
fi
}
install() {
utils_check_version "$VERSION"
check_curl_envsubst_file_tar_installed
readonly architecture="$(debian_get_arch)"
readonly binaryTargetPathTemplate='${binaryTargetFolder}/${binaryName}'
if [ "$VERSION" == 'latest' ] || [ -z "$VERSION" ]; then
VERSION=$(github_get_latest_release "$githubRepository")
fi
readonly version="${VERSION:?}"
readonly downloadUrl="$(echo -n "$downloadUrlTemplate" | envsubst)"
curl_check_url "$downloadUrl"
readonly binaryPathInArchive="$(echo -n "$binaryPathInArchiveTemplate" | envsubst)"
readonly stripComponents="$(echo -n "$binaryPathInArchive" | awk -F'/' '{print NF-1}')"
readonly binaryTargetPath="$(echo -n "$binaryTargetPathTemplate" | envsubst)"
curl_download_untar "$downloadUrl" "$stripComponents" "$binaryTargetFolder" "$binaryPathInArchive"
chmod 755 "$binaryTargetPath"
apt_get_cleanup
}
echo_banner "devcontainer.community"
echo "Installing $name..."
install "$@"
echo "(*) Done!"
18 changes: 18 additions & 0 deletions test/charmbracelet-gum/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash


set -e

# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "execute command" bash -c "gum --version | grep 'gum'"

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults