Skip to content

Commit 719901a

Browse files
[common-utils] Bug fix: zsh missing rc snippet (#736)
* [common-utils] Bug fix: zsp missing rc snippet * condion rc snippet * fix bug * remove debugging step
1 parent 4c2c9f7 commit 719901a

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/common-utils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "common-utils",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"name": "Common Utilities",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
66
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",

src/common-utils/main.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ fi
421421
# Restore user .bashrc / .profile / .zshrc defaults from skeleton file if it doesn't exist or is empty
422422
possible_rc_files=( ".bashrc" ".profile" )
423423
[ "$INSTALL_OH_MY_ZSH_CONFIG" == "true" ] && possible_rc_files+=('.zshrc')
424+
[ "$INSTALL_ZSH" == "true" ] && possible_rc_files+=('.zprofile')
424425
for rc_file in "${possible_rc_files[@]}"; do
425426
if [ -f "/etc/skel/${rc_file}" ]; then
426427
if [ ! -e "${user_home}/${rc_file}" ] || [ ! -s "${user_home}/${rc_file}" ]; then
@@ -456,13 +457,17 @@ fi
456457

457458
# Optionally configure zsh and Oh My Zsh!
458459
if [ "${INSTALL_ZSH}" = "true" ]; then
460+
if [ ! -f "${user_home}/.zprofile" ] || ! grep -Fxq 'source $HOME/.profile' "${user_home}/.zprofile" ; then
461+
echo 'source $HOME/.profile' >> "${user_home}/.zprofile"
462+
fi
463+
459464
if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then
460465
if [ "${ADJUSTED_ID}" = "rhel" ]; then
461466
global_rc_path="/etc/zshrc"
462467
else
463468
global_rc_path="/etc/zsh/zshrc"
464469
fi
465-
cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> /etc/zshrc
470+
cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${global_rc_path}
466471
ZSH_ALREADY_INSTALLED="true"
467472
fi
468473

test/common-utils/configure_zsh_as_default_shell.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source dev-container-features-test-lib
99
check "default-shell-is-zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print $7 }' | grep '/bin/zsh'"
1010
# check it overrides the ~/.zshrc with default dev containers template
1111
check "default-zshrc-is-dev-container-template" bash -c "cat ~/.zshrc | grep ZSH_THEME | grep devcontainers"
12+
check "zsh-path-contains-local-bin" zsh -l -c "echo $PATH | grep '/home/devcontainer/.local/bin'"
1213

1314
# Report result
1415
reportResults

test/common-utils/scenarios.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@
108108
}
109109
},
110110
"configure_zsh_as_default_shell": {
111-
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
111+
"image": "ubuntu",
112112
"features": {
113113
"common-utils": {
114+
"installZsh": true,
114115
"configureZshAsDefaultShell": true
115116
}
116-
}
117+
},
118+
"remoteUser": "devcontainer"
117119
},
118120
"configure_zsh_no_template_second_step": {
119121
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",

0 commit comments

Comments
 (0)