Skip to content

Switch Codespaces login shell to zsh - #4

Merged
mahata merged 3 commits into
mainfrom
mahata/codespaces-zsh-login-shell
May 8, 2026
Merged

Switch Codespaces login shell to zsh#4
mahata merged 3 commits into
mainfrom
mahata/codespaces-zsh-login-shell

Conversation

@mahata

@mahata mahata commented May 8, 2026

Copy link
Copy Markdown
Owner

Summary

Codespaces ships with bash as the default login shell, so even after install-codespaces.sh symlinks .zshrc, new terminals still start in bash. This change makes the dotfiles installer flip the login shell to zsh so a fresh Codespace drops you straight into zsh.

Changes

  • Add a configure_login_shell step to install-codespaces.sh:
    • Resolve zsh via command -v zsh; skip with a message if it isn't installed.
    • Read the current login shell from getent passwd "$USER"; skip if it's already zsh (idempotent).
    • Otherwise run sudo chsh -s "$zsh_path" "$USER" to update /etc/passwd.
  • Wire it into the run_step list so a failure is logged but doesn't abort the rest of the install.
  • Mention the behavior in the Codespaces section of README.md.

Notes

  • zsh is preinstalled in the default Codespaces image, so no extra apt install is needed.
  • chsh only takes effect for new login sessions, which is fine for Codespaces (next terminal / next start).
  • Verified with bash -n install-codespaces.sh. shellcheck only reports the pre-existing SC1091 info about lib.sh.

Add a configure_login_shell step to install-codespaces.sh that runs
sudo chsh against $USER so new terminals in a Codespace start in zsh.
Skip when zsh is missing or already the login shell.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 8, 2026 03:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Codespaces dotfiles installer so that Codespaces sessions start in zsh by changing the user’s login shell, aligning the actual shell experience with the repo’s zsh configuration.

Changes:

  • Add a configure_login_shell step that discovers zsh, checks the current login shell, and runs sudo chsh when needed.
  • Wire the new step into the Codespaces install sequence via run_step so failures are logged but don’t stop the rest of setup.
  • Document the new behavior in the Codespaces section of README.md.
Show a summary per file
File Description
README.md Documents that Codespaces setup updates the login shell to zsh.
install-codespaces.sh Adds an install step to switch the login shell to zsh and runs it during Codespaces setup.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread install-codespaces.sh
Comment on lines +40 to +47
local current_shell
current_shell="$(getent passwd "$USER" | cut -d: -f7)"
if [[ "$current_shell" == "$zsh_path" ]]; then
echo "Login shell is already $zsh_path, skipping"
return 0
fi

sudo chsh -s "$zsh_path" "$USER"
mahata and others added 2 commits May 8, 2026 13:07
- Refactor install-codespaces.sh with a main() guard so functions can be
  sourced safely from tests.
- Add bats unit tests for configure_login_shell that stub out command,
  getent, and sudo.
- Add a GitHub Actions workflow that runs shellcheck, bats, and a
  Docker-based integration test against the Codespaces universal image.
- Drop unused SCRIPT_DIR vars flagged by shellcheck in lib.sh and
  install-local.sh.
- Document tests in README.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`su - codespace -c` starts a login shell which clears the inherited
CODESPACES environment variable, so install.sh fell through to
install-local.sh and never ran configure_login_shell. Pass CODESPACES
inline so install.sh dispatches to install-codespaces.sh.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI commented May 8, 2026

Copy link
Copy Markdown

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED git conf�� get --global nfig/composer/vendor/bin/git gpg.program (dns block)
  • dl.google.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https tcp -m conntrack --ctstate INVALID,NEW -j DROP (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of mahata May 8, 2026 07:48
@mahata
mahata merged commit 1711a78 into main May 8, 2026
4 checks passed
@mahata
mahata deleted the mahata/codespaces-zsh-login-shell branch May 8, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants