Unverified Commit aae9de7e authored by Jacob Woffenden's avatar Jacob Woffenden Committed by GitHub

Change default shell if installing ZSH (#325)

* Added new option to configure zsh as default shell
Added test scenario
Bumped feature version

* Update test/common-utils/scenarios.json
Co-authored-by: 's avatarSamruddhi Khandale <skhandale@microsoft.com>

* Update src/common-utils/devcontainer-feature.json
Co-authored-by: 's avatarSamruddhi Khandale <skhandale@microsoft.com>

* Update test/common-utils/configure_zsh_as_default_shell.sh
Co-authored-by: 's avatarSamruddhi Khandale <skhandale@microsoft.com>
Co-authored-by: 's avatarSamruddhi Khandale <skhandale@microsoft.com>
parent e28358e3
{ {
"id": "common-utils", "id": "common-utils",
"version": "1.1.6", "version": "1.2.0",
"name": "Common Debian Utilities", "name": "Common Debian Utilities",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.", "description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
"default": true, "default": true,
"description": "Install ZSH?" "description": "Install ZSH?"
}, },
"configureZshAsDefaultShell": {
"type": "boolean",
"default": false,
"description": "Change default shell to ZSH?"
},
"installOhMyZsh": { "installOhMyZsh": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
......
...@@ -13,6 +13,7 @@ set -e ...@@ -13,6 +13,7 @@ set -e
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
INSTALL_ZSH="${INSTALLZSH:-"true"}" INSTALL_ZSH="${INSTALLZSH:-"true"}"
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}" INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}" UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
...@@ -378,6 +379,12 @@ if [ "${INSTALL_ZSH}" = "true" ]; then ...@@ -378,6 +379,12 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
ZSH_ALREADY_INSTALLED="true" ZSH_ALREADY_INSTALLED="true"
fi fi
# Change shell of determined user
if [[ "${CONFIGURE_ZSH_AS_DEFAULT_SHELL}" == "true" ]]; then
chsh --shell /bin/zsh ${USERNAME}
fi
# Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme. # Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme.
# See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script. # See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script.
oh_my_install_dir="${user_rc_path}/.oh-my-zsh" oh_my_install_dir="${user_rc_path}/.oh-my-zsh"
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "default-shell-is-zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print $7 }' | grep '/bin/zsh'"
# Report result
reportResults
{
"configure_zsh_as_default_shell": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"common-utils": {
"configureZshAsDefaultShell": true
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment