diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 44126b813..74b64738a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -26,7 +26,8 @@ "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "./zsh": { "theme": "agnoster", - "plugins": "git docker" + "plugins": "git docker", + "defaultUser": "true" } }, "remoteUser": "node", diff --git a/.devcontainer/zsh/devcontainer-feature.json b/.devcontainer/zsh/devcontainer-feature.json index 1cbf9d8c1..22762be42 100644 --- a/.devcontainer/zsh/devcontainer-feature.json +++ b/.devcontainer/zsh/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "zsh", "id": "zsh", - "version": "0.0.5", + "version": "0.0.6", "description": "A feature to install and configure zsh with OhMyZsh", "licenseURL": "https://github.com/nils-geistmann/devcontainers-features/blob/main/LICENSE", "options": { @@ -14,6 +14,15 @@ "agnoster" ] }, + "defaultUser": { + "description": "The defaultUser to set in .zshrc", + "type": "string", + "default": "", + "proposals": [ + "vscode", + "root" + ] + }, "plugins": { "description": "A space separated list of plugins to activate", "type": "string", diff --git a/.devcontainer/zsh/functions.sh b/.devcontainer/zsh/functions.sh index 6ba0c325f..3de6add07 100644 --- a/.devcontainer/zsh/functions.sh +++ b/.devcontainer/zsh/functions.sh @@ -14,6 +14,11 @@ check_and_install() { done } +# Cleans APT's cache to keep devcontainer layers small +clean_package_cache() { + apt-get clean +} + upsert_config_option() { if grep -E -q "$1" "$3"; then sed -i -e "s/$1/$2/" "$3" diff --git a/.devcontainer/zsh/install.sh b/.devcontainer/zsh/install.sh index c50865050..569b4342e 100755 --- a/.devcontainer/zsh/install.sh +++ b/.devcontainer/zsh/install.sh @@ -43,5 +43,12 @@ fi # set the theme upsert_config_option "^ZSH_THEME=.*$" "ZSH_THEME=\"$THEME\"" "$ZSH_RC_FILE" +# set the default user +if [ "$DEFAULTUSER" = "true" ]; then + upsert_config_option "^DEFAULT_USER=.*$" "DEFAULT_USER=\"$_REMOTE_USER\"" "$ZSH_RC_FILE" +fi + # configure the plugins upsert_config_option "^plugins=\\(.*\\)$" "plugins=($PLUGINS)" "$ZSH_RC_FILE" + +clean_package_cache diff --git a/src/zsh/devcontainer-feature.json b/src/zsh/devcontainer-feature.json index 22762be42..3b84d918a 100644 --- a/src/zsh/devcontainer-feature.json +++ b/src/zsh/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "zsh", "id": "zsh", - "version": "0.0.6", + "version": "0.0.7", "description": "A feature to install and configure zsh with OhMyZsh", "licenseURL": "https://github.com/nils-geistmann/devcontainers-features/blob/main/LICENSE", "options": { @@ -15,13 +15,9 @@ ] }, "defaultUser": { - "description": "The defaultUser to set in .zshrc", - "type": "string", - "default": "", - "proposals": [ - "vscode", - "root" - ] + "description": "When set to true the ZSH default user will be set to the remote user", + "type": "boolean", + "default": false }, "plugins": { "description": "A space separated list of plugins to activate", diff --git a/src/zsh/install.sh b/src/zsh/install.sh index fa32d7fdd..569b4342e 100755 --- a/src/zsh/install.sh +++ b/src/zsh/install.sh @@ -44,8 +44,8 @@ fi upsert_config_option "^ZSH_THEME=.*$" "ZSH_THEME=\"$THEME\"" "$ZSH_RC_FILE" # set the default user -if [[ -n "$DEFAULTUSER" ]]; then - upsert_config_option "^DEFAULT_USER=.*$" "DEFAULT_USER=\"$DEFAULTUSER\"" "$ZSH_RC_FILE" +if [ "$DEFAULTUSER" = "true" ]; then + upsert_config_option "^DEFAULT_USER=.*$" "DEFAULT_USER=\"$_REMOTE_USER\"" "$ZSH_RC_FILE" fi # configure the plugins diff --git a/test/zsh/scenarios.json b/test/zsh/scenarios.json index d3c1fb364..2ab9f56e3 100644 --- a/test/zsh/scenarios.json +++ b/test/zsh/scenarios.json @@ -20,7 +20,7 @@ "features": { "zsh": { "theme": "agnoster", - "defaultUser": "vscode" + "defaultUser": "true" } } }, diff --git a/test/zsh/test_functions.sh b/test/zsh/test_functions.sh index 40c97f834..b087c1e5f 100644 --- a/test/zsh/test_functions.sh +++ b/test/zsh/test_functions.sh @@ -37,8 +37,8 @@ assert_configured_theme_is() { } assert_configured_default_user_is() { - theme=$1 - if ! grep -E -q "^DEFAULT_USER=\"$theme\"" ~/.zshrc; then + userName=$1 + if ! grep -E -q "^DEFAULT_USER=\"$userName\"" ~/.zshrc; then exit 1 fi }