Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion .devcontainer/zsh/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions .devcontainer/zsh/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions .devcontainer/zsh/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 4 additions & 8 deletions src/zsh/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/zsh/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/zsh/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"features": {
"zsh": {
"theme": "agnoster",
"defaultUser": "vscode"
"defaultUser": "true"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions test/zsh/test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down