Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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 src/common-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-r
| configureZshAsDefaultShell | Change default shell to ZSH? | boolean | false |
| installOhMyZsh | Install Oh My Zsh!? | boolean | true |
| installOhMyZshConfig | Allow installing the default dev container .zshrc templates? | boolean | true |
| ohMyZshTheme | Oh My Zsh theme to use (e.g., 'robbyrussell', 'agnoster', 'fino'). Default is 'devcontainers'. | string | devcontainers |
| upgradePackages | Upgrade OS packages? | boolean | true |
| username | Enter name of a non-root user to configure or none to skip | string | automatic |
| userUid | Enter UID for non-root user | string | automatic |
Expand Down
5 changes: 5 additions & 0 deletions src/common-utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"default": true,
"description": "Allow installing the default dev container .zshrc templates?"
},
"ohMyZshTheme": {
"type": "string",
"default": "devcontainers",
"description": "Oh My Zsh theme to use (e.g., 'robbyrussell', 'agnoster', 'fino'). Default is 'devcontainers'."
},
"upgradePackages": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions src/common-utils/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ INSTALL_ZSH="${INSTALLZSH:-"true"}"
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
INSTALL_OH_MY_ZSH_CONFIG="${INSTALLOHMYZSHCONFIG:-"true"}"
OH_MY_ZSH_THEME="${OHMYZSHTHEME:-"devcontainers"}"
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
USERNAME="${USERNAME:-"automatic"}"
USER_UID="${UID:-"automatic"}"
Expand Down
9 changes: 8 additions & 1 deletion src/common-utils/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ INSTALL_ZSH="${INSTALLZSH:-"true"}"
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
INSTALL_OH_MY_ZSH_CONFIG="${INSTALLOHMYZSHCONFIG:-"true"}"
OH_MY_ZSH_THEME="${OHMYZSHTHEME:-"devcontainers"}"
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
USERNAME="${USERNAME:-"automatic"}"
USER_UID="${USERUID:-"automatic"}"
Expand Down Expand Up @@ -570,7 +571,13 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
if ! [ -f "${template_path}" ] || ! grep -qF "$(head -n 1 "${template_path}")" "${user_rc_file}"; then
echo -e "$(cat "${template_path}")\nzstyle ':omz:update' mode disabled" > ${user_rc_file}
fi
sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file}
# Validate theme name to prevent injection (allow alphanumeric, hyphens, underscores, and dots)
if echo "${OH_MY_ZSH_THEME}" | grep -qE '^[a-zA-Z0-9_.-]+$'; then
sed -i -e "s/ZSH_THEME=.*/ZSH_THEME=\"${OH_MY_ZSH_THEME}\"/g" ${user_rc_file}
else
echo "Warning: Invalid theme name '${OH_MY_ZSH_THEME}'. Using default 'devcontainers' theme."
sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file}
fi
fi

# Copy to non-root user if one is specified
Expand Down
15 changes: 15 additions & 0 deletions test/common-utils/custom-zsh-theme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "zsh" zsh --version
check "oh-my-zsh installed" test -d $HOME/.oh-my-zsh
check "zsh theme is fino" grep 'ZSH_THEME="fino"' ~/.zshrc
check "default shell is zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print \$7 }' | grep '/bin/zsh'"

# Report result
reportResults
12 changes: 12 additions & 0 deletions test/common-utils/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,17 @@
"features": {
"common-utils": {}
}
},
"custom-zsh-theme": {
"image": "ubuntu:jammy",
"remoteUser": "devcontainer",
"features": {
"common-utils": {
"installZsh": true,
"installOhMyZsh": true,
"ohMyZshTheme": "fino",
"configureZshAsDefaultShell": true
}
}
}
}