Skip to content

Commit e34adf2

Browse files
committed
Backward-compatible approach, with functions still added to targetFiles
1 parent 12248b7 commit e34adf2

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/artifacts-helper/devcontainer-feature.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,27 @@
5151
},
5252
"shimDirectory": {
5353
"type": "string",
54-
"default": "/usr/local/bin",
54+
"default": "/usr/local/share/codespace-shims",
5555
"description": "Directory where the shims will be installed. This must be in $PATH, and needs to be as early as possible in priority for the scripts to override the base executables."
5656
},
57+
"targetFiles": {
58+
"type": "string",
59+
"default": "DEFAULT",
60+
"description": "Comma separated list of files to write to. Default is '/etc/bash.bashrc,/etc/zsh/zshrc' for root and '~/.bashrc,~/.zshrc' for non-root"
61+
},
5762
"python": {
5863
"type": "boolean",
5964
"default": false,
6065
"description": "Install Python keyring helper for pip"
6166
}
6267
},
68+
"containerEnv": {
69+
"PATH": "${shimDirectory}:${PATH}"
70+
},
6371
"installsAfter": [
6472
"ghcr.io/devcontainers/features/common-utils",
65-
"ghcr.io/devcontainers/features/python"
73+
"ghcr.io/devcontainers/features/python",
74+
"ghcr.io/devcontainers/features/node"
6675
],
6776
"customizations": {
6877
"vscode": {

src/artifacts-helper/install.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ALIAS_NPX="${NPXALIAS:-"true"}"
1212
ALIAS_RUSH="${RUSHALIAS:-"true"}"
1313
ALIAS_PNPM="${PNPMALIAS:-"true"}"
1414
INSTALL_PIP_HELPER="${PYTHON:-"false"}"
15-
SHIM_DIRECTORY="${SHIMDIRECTORY:-"/usr/local/bin"}"
15+
SHIM_DIRECTORY="${SHIMDIRECTORY:-"/usr/local/share/codespace-shims"}"
1616

1717
ALIASES_ARR=()
1818

@@ -108,6 +108,29 @@ if command -v sudo >/dev/null 2>&1; then
108108
fi
109109
fi
110110

111+
if [ "${COMMA_SEP_TARGET_FILES}" = "DEFAULT" ]; then
112+
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
113+
COMMA_SEP_TARGET_FILES="~/.bashrc,~/.zshrc"
114+
else
115+
COMMA_SEP_TARGET_FILES="/etc/bash.bashrc,/etc/zsh/zshrc"
116+
fi
117+
fi
118+
119+
IFS=',' read -r -a TARGET_FILES_ARR <<< "$COMMA_SEP_TARGET_FILES"
120+
121+
ALIASES_BLOCK=""
122+
for ALIAS in "${ALIASES_ARR[@]}"; do
123+
ALIASES_BLOCK+="$ALIAS() { \"${SHIM_DIRECTORY}/$ALIAS\" \"\$@\"; }\n"
124+
done
125+
126+
for TARGET_FILE in "${TARGET_FILES_ARR[@]}"; do
127+
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
128+
sudo -u ${_REMOTE_USER} bash -c "printf '%s' \"$ALIASES_BLOCK\" >> $TARGET_FILE"
129+
else
130+
printf '%s' "$ALIASES_BLOCK" >> "$TARGET_FILE" || true
131+
fi
132+
done
133+
111134
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
112135
sudo -u ${_REMOTE_USER} bash -c "/tmp/install-provider.sh ${USENET6}"
113136
fi

0 commit comments

Comments
 (0)