Skip to content

Change default shell if installing ZSH #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 9, 2022
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
7 changes: 6 additions & 1 deletion src/common-utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "common-utils",
"version": "1.1.6",
"version": "1.2.0",
"name": "Common Debian Utilities",
"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.",
Expand All @@ -10,6 +10,11 @@
"default": true,
"description": "Install ZSH?"
},
"configureZshAsDefaultShell": {
"type": "boolean",
"default": false,
"description": "Change default shell to ZSH?"
},
"installOhMyZsh": {
"type": "boolean",
"default": true,
Expand Down
7 changes: 7 additions & 0 deletions src/common-utils/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set -e
rm -rf /var/lib/apt/lists/*

INSTALL_ZSH="${INSTALLZSH:-"true"}"
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
Expand Down Expand Up @@ -378,6 +379,12 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
ZSH_ALREADY_INSTALLED="true"
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.
# See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script.
oh_my_install_dir="${user_rc_path}/.oh-my-zsh"
Expand Down
12 changes: 12 additions & 0 deletions test/common-utils/configure_zsh_as_default_shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/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
10 changes: 10 additions & 0 deletions test/common-utils/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"configure_zsh_as_default_shell": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"common-utils": {
"configureZshAsDefaultShell": true
}
}
}
}