Skip to content
This repository was archived by the owner on Jan 12, 2025. It is now read-only.

add zoxide feature #633

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
19 changes: 19 additions & 0 deletions src/zoxide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# zoxide

Install [zoxide](https://github.com/ajeetdsouza/zoxide)

## Example Usage

```json
"features": {
"ghcr.io/devcontainers-contrib/features/zoxide:0": {}
}
```

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| replaceCd | Use zoxide when calling cd (see ZOXIDE_CMD_OVERRIDE) | bool | true |
| username | For which user to setup zoxide, by default uses 'remoteUser' or 'containerUser' from config | string | - |
25 changes: 25 additions & 0 deletions src/zoxide/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "zoxide",
"id": "zoxide",
"version": "0.1.0",
"description": "Install zoxide",
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/zoxide",
"installsAfter": [],
"options": {
"replaceCd": {
"type": "boolean",
"default": "true",
"description": "Use zoxide when calling cd (see ZOXIDE_CMD_OVERRIDE)"
},
"username": {
"type": "string",
"default": "",
"proposals": [
"root",
"node",
"vscode"
],
"description": "For which user to setup zoxide, by default uses 'remoteUser' or 'containerUser' from config"
}
}
}
38 changes: 38 additions & 0 deletions src/zoxide/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -x
REPLACE_CD=${REPLACECD:-""}
USERNAME=${USERNAME:-$_REMOTE_USER}

prefix=/usr/local
shells="bash zsh"

install_zoxide() {
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh -s -- --bin-dir ${prefix}/bin --man-dir ${prefix}/share/man
}

# Install zoxide
install_zoxide

if [ "$USERNAME" = "root" ]; then
USER_LOCATION="/root"
else
USER_LOCATION="/home/$USERNAME"
fi

# Check available shells
for s in $shells; do
if ! command -v "$s" > /dev/null; then
shells=${shells/$s/}
fi
done

# Configure available shells
for shell in $shells; do
[ $shell = zsh ] && dest=${ZDOTDIR:-$USER_LOCATION}/.zshrc || dest=$USER_LOCATION/.bashrc
# Set ZOXIDE_CMD_OVERRIDE
if [ "${REPLACE_CD}" = "true" ]; then
echo -e '\n# Replace cd with zoxide\nexport ZOXIDE_CMD_OVERRIDE="cd"' >> $dest
fi

echo -e "\n# Enable zoxide\neval \"\$(zoxide init $shell)\"" >> $dest
done
18 changes: 18 additions & 0 deletions test/zoxide/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"test": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"zoxide": {
"replaceCd": true
}
}
},
"test_no_cd": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"zoxide": {
"replaceCd": false
}
}
}
}
18 changes: 18 additions & 0 deletions test/zoxide/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

# Test zoxide installed
check "zoxide installed" command -v zoxide &>/dev/null

# Test zsh shell configured
check "ZOXIDE_CMD_OVERRIDE is set" zsh -i -c "[[ -n \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
check "zoxide is enabled" zsh -i -c "command -v z &>/dev/null"

# Test bash shell configured
check "ZOXIDE_CMD_OVERRIDE is set" bash -i -c "[[ -n \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
check "zoxide is enabled" bash -i -c "command -v z &>/dev/null"

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

set -e

source dev-container-features-test-lib

# Test zoxide installed
check "zoxide installed" command -v zoxide

# Test zsh shell configured
check "ZOXIDE_CMD_OVERRIDE is set" zsh -i -c "[[ -z \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
check "zoxide is enabled" zsh -i -c "command -v z &>/dev/null"

# Test bash shell configured
check "ZOXIDE_CMD_OVERRIDE is set" bash -i -c "[[ -z \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
check "zoxide is enabled" bash -i -c "command -v z &>/dev/null"

reportResults