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

Commit 4b58c70

Browse files
author
Olivier SECHET
committed
feat: add zoxide feature
1 parent 9a1d24b commit 4b58c70

File tree

6 files changed

+137
-0
lines changed

6 files changed

+137
-0
lines changed

src/zoxide/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# zoxide
3+
4+
Install [zoxide](https://github.com/ajeetdsouza/zoxide)
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/devcontainers-contrib/features/zoxide:0": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
| replaceCd | Use zoxide when calling cd (see ZOXIDE_CMD_OVERRIDE) | bool | true |
19+
| username | For which user to setup zoxide, by default uses 'remoteUser' or 'containerUser' from config | string | - |

src/zoxide/devcontainer-feature.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "zoxide",
3+
"id": "zoxide",
4+
"version": "0.1.0",
5+
"description": "Install zoxide",
6+
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/zoxide",
7+
"installsAfter": [],
8+
"options": {
9+
"replaceCd": {
10+
"type": "bool",
11+
"default": "true",
12+
"proposals": [],
13+
"description": "Use zoxide when calling cd (see ZOXIDE_CMD_OVERRIDE)"
14+
},
15+
"username": {
16+
"type": "string",
17+
"default": "",
18+
"proposals": [
19+
"root",
20+
"node",
21+
"vscode"
22+
],
23+
"description": "For which user to setup zoxide, by default uses 'remoteUser' or 'containerUser' from config"
24+
}
25+
}
26+
}

src/zoxide/install.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
REPLACE_CD=${REPLACECD:-""}
4+
USERNAME=${USERNAME:-$_REMOTE_USER}
5+
6+
prefix=/usr/local
7+
shells="bash zsh"
8+
9+
install_zoxide() {
10+
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh -s -- --bin-dir ${prefix}/bin --man-dir ${prefix}/share/man
11+
}
12+
13+
# Install zoxide
14+
install_zoxide
15+
16+
if [ "$USERNAME" = "root" ]; then
17+
USER_LOCATION="/root"
18+
else
19+
USER_LOCATION="/home/$USERNAME"
20+
fi
21+
22+
# Check available shells
23+
for s in $shells; do
24+
if ! command -v "$s" > /dev/null; then
25+
shells=${shells/$s/}
26+
fi
27+
done
28+
29+
# Configure available shells
30+
for shell in $shells; do
31+
[ $shell = zsh ] && dest=${ZDOTDIR:-$USER_LOCATION}/.zshrc || dest=$USER_LOCATION/.bashrc
32+
# Set ZOXIDE_CMD_OVERRIDE
33+
if [ "${REPLACE_CD}" = "true" ]; then
34+
echo -e '\n# Replace cd with zoxide\nexport ZOXIDE_CMD_OVERRIDE="cd"' >> $dest
35+
fi
36+
37+
echo -e "\n# Enable zoxide\neval \"\$(zoxide init $shell)\"" >> $dest
38+
done

test/zoxide/scenarios.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"test": {
3+
"image": "mcr.microsoft.com/devcontainers/base:debian",
4+
"features": {
5+
"zoxide": {
6+
"replaceCd": true
7+
}
8+
}
9+
},
10+
"test_no_cd": {
11+
"image": "mcr.microsoft.com/devcontainers/base:debian",
12+
"features": {
13+
"zoxide": {
14+
"replaceCd": false
15+
}
16+
}
17+
}
18+
}

test/zoxide/test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
7+
# Test zoxide installed
8+
check "zoxide installed" command -v zoxide &>/dev/null
9+
10+
# Test zsh shell configured
11+
check "ZOXIDE_CMD_OVERRIDE is set" zsh -i -c "[[ -n \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
12+
check "zoxide is enabled" zsh -i -c "command -v z &>/dev/null"
13+
14+
# Test bash shell configured
15+
check "ZOXIDE_CMD_OVERRIDE is set" bash -i -c "[[ -n \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
16+
check "zoxide is enabled" bash -i -c "command -v z &>/dev/null"
17+
18+
reportResults

test/zoxide/test_no_cd.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
7+
# Test zoxide installed
8+
check "zoxide installed" command -v zoxide
9+
10+
# Test zsh shell configured
11+
check "ZOXIDE_CMD_OVERRIDE is set" zsh -i -c "[[ -z \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
12+
check "zoxide is enabled" zsh -i -c "command -v z &>/dev/null"
13+
14+
# Test bash shell configured
15+
check "ZOXIDE_CMD_OVERRIDE is set" bash -i -c "[[ -z \"\${ZOXIDE_CMD_OVERRIDE+1}\" ]]"
16+
check "zoxide is enabled" bash -i -c "command -v z &>/dev/null"
17+
18+
reportResults

0 commit comments

Comments
 (0)