Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@
| [yoctoproject.org/bitbake](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/yoctoproject.org-bitbake) | `bitbake` — build tool for the Yocto Project | curl | 1.0.2 |
| [yq](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/yq) | `yq` — command-line YAML/JSON/XML processor | gh release | 1.0.3 |
| [zellij.dev](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/zellij.dev) | `zellij` — terminal workspace with multiplexer and layouts | gh release | 1.0.4 |
| [zmx.sh](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/zmx.sh) | `zmx` — persistent terminal sessions with native scrollback | gh release | 1.0.0 |
| [zyedidia/eget](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/zyedidia-eget) | `eget` — easily install prebuilt binaries from GitHub releases | gh release | 1.0.4 |
17 changes: 17 additions & 0 deletions src/zmx.sh/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# zmx.sh

## Project

- [zmx](https://zmx.sh)

## Description

`zmx` persists terminal sessions so you can detach and reattach without stopping their processes. It preserves native terminal scrollback and leaves window management to your terminal or operating system.

## Installation Method

Downloaded as a pre-compiled binary from the [GitHub releases page](https://github.com/neurosnap/zmx/releases) and placed in `/usr/local/bin`.

## Other Notes

_No additional notes._
20 changes: 20 additions & 0 deletions src/zmx.sh/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "zmx.sh",
"id": "zmx.sh",
"version": "1.0.0",
"description": "Install \"zmx\" binary",
"documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/zmx.sh",
"options": {
"version": {
"type": "string",
"default": "latest",
"proposals": [
"latest"
],
"description": "Version of \"zmx\" to install."
}
},
"installsAfter": [
"ghcr.io/devcontainer-community/devcontainer-features/ca-certificates:latest"
]
}
163 changes: 163 additions & 0 deletions src/zmx.sh/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
set -o allexport
readonly githubRepository='neurosnap/zmx'
readonly binaryName='zmx'
readonly versionArgument='version'
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() {
echo "$(dpkg --print-architecture)"
}
debian_get_target_arch() {
case $(debian_get_arch) in
amd64) echo 'x86_64' ;;
arm64) echo 'aarch64' ;;
*) echo 'unknown' ;;
esac
}
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
}
github_get_tag_for_version() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: github_get_tag_for_version <owner/repo> <version>"
return 1
fi
local repo="$1"
local _version="$2"
local url="https://api.github.com/repos/$repo/releases"
local escaped_version
escaped_version="$(printf '%s' "$_version" | sed 's/\./\\./g')"
curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E "^v?${escaped_version}$" | 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_target_arch)"
if [ "$architecture" == 'unknown' ]; then
printf >&2 '=== [ERROR] Unsupported architecture "%s"!\n' "$(debian_get_arch)"
exit 1
fi
readonly binaryTargetPathTemplate='${binaryTargetFolder}/${binaryName}'
if [ "$VERSION" == 'latest' ] || [ -z "$VERSION" ]; then
VERSION=$(github_get_latest_release "$githubRepository")
fi
readonly version="${VERSION:?}"
readonly releaseTag="$(github_get_tag_for_version "$githubRepository" "$version")"
if [ -z "$releaseTag" ]; then
printf >&2 '=== [ERROR] Could not find release tag for version "%s" in "%s"!\n' "$version" "$githubRepository"
exit 1
fi
readonly downloadUrlTemplate='https://github.com/${githubRepository}/releases/download/${releaseTag}/zmx-${version}-linux-${architecture}.tar.gz'
readonly downloadUrl="$(echo -n "$downloadUrlTemplate" | envsubst)"
curl_check_url "$downloadUrl"
readonly binaryPathInArchive="$binaryName"
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!"
10 changes: 10 additions & 0 deletions test/zmx.sh/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"test-version": {
"image": "debian:latest",
"features": {
"zmx.sh": {
"version": "0.6.0"
}
}
}
}
9 changes: 9 additions & 0 deletions test/zmx.sh/test-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

check "specified zmx version is installed" bash -c "zmx version | grep -F '0.6.0'"

reportResults
9 changes: 9 additions & 0 deletions test/zmx.sh/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

check "execute command" bash -c "zmx version | grep 'zmx'"

reportResults