diff --git a/src/common-utils/README.md b/src/common-utils/README.md index 3d21e8b3f..e5218bdb4 100644 --- a/src/common-utils/README.md +++ b/src/common-utils/README.md @@ -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 | diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index 14056e3a9..790a6d4b4 100644 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -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, diff --git a/src/common-utils/install.sh b/src/common-utils/install.sh index 313271d0a..622d5ea72 100755 --- a/src/common-utils/install.sh +++ b/src/common-utils/install.sh @@ -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"}" diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index b0fd2f3b0..f41da3e59 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -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"}" @@ -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 diff --git a/test/common-utils/custom-zsh-theme.sh b/test/common-utils/custom-zsh-theme.sh new file mode 100755 index 000000000..6d8dd90da --- /dev/null +++ b/test/common-utils/custom-zsh-theme.sh @@ -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 diff --git a/test/common-utils/scenarios.json b/test/common-utils/scenarios.json index ee138ca22..9c5137c20 100644 --- a/test/common-utils/scenarios.json +++ b/test/common-utils/scenarios.json @@ -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 + } + } } } \ No newline at end of file