Skip to content

Conversation

Copy link

Copilot AI commented Dec 2, 2025

Configures Codespaces to use \W\$ prompt (current directory only) instead of the full path, improving terminal readability in workshop settings.

Changes

  • .devcontainer/devcontainer.json: Add idempotent postStartCommand that appends PS1 export to ~/.bashrc only if not already present
  • .devcontainer/README.md: Document the change and override options (edit ~/.bashrc or use custom dotfiles repo)

Implementation

"postStartCommand": "grep -qxF \"export PS1='\\\\W\\\\$ '\" ~/.bashrc || echo \"export PS1='\\\\W\\\\$ '\" >> ~/.bashrc"

The grep -qxF ensures exact line matching, preventing duplicate entries on repeated Codespace starts.

Revert

Delete the postStartCommand line from devcontainer.json.

Original prompt

Make Codespaces open terminals with a shorter prompt by setting PS1='\W$ '. Implement an idempotent change via the repository's devcontainer so that when a Codespace is created or started the user's bash configuration will include this prompt setting without adding duplicate lines on repeated starts.

Specific changes to make:

  • Update or create .devcontainer/devcontainer.json to include a postStartCommand that checks for the export line and appends it to ~/.bashrc only if not present. Use a shell-safe, idempotent command such as:
    grep -qxF "export PS1='\W\$ '" ~/.bashrc || echo "export PS1='\W\$ '" >> ~/.bashrc
  • If the repo does not have a .devcontainer/devcontainer.json, add one using the repo's default container configuration and include the postStartCommand.
  • Add a short developer note at .devcontainer/README.md explaining why this change was made and how to override it (e.g., by editing ~/.bashrc or using a custom dotfiles repo).

Requirements:

  • Do not affect other devcontainer settings (keep existing fields intact if devcontainer.json already exists).
  • Ensure the change is safe to run multiple times (idempotent) and will not create duplicate lines.
  • Keep commits small and include a clear commit message.

Deliverable: open a pull request in pyOpenSci/pyopensci-workshop-create-python-package that implements the above changes and includes a short description in the PR body explaining the approach and how to revert if necessary.

This pull request was created as a result of the following prompt from Copilot chat.

Make Codespaces open terminals with a shorter prompt by setting PS1='\W$ '. Implement an idempotent change via the repository's devcontainer so that when a Codespace is created or started the user's bash configuration will include this prompt setting without adding duplicate lines on repeated starts.

Specific changes to make:

  • Update or create .devcontainer/devcontainer.json to include a postStartCommand that checks for the export line and appends it to ~/.bashrc only if not present. Use a shell-safe, idempotent command such as:
    grep -qxF "export PS1='\W\$ '" ~/.bashrc || echo "export PS1='\W\$ '" >> ~/.bashrc
  • If the repo does not have a .devcontainer/devcontainer.json, add one using the repo's default container configuration and include the postStartCommand.
  • Add a short developer note at .devcontainer/README.md explaining why this change was made and how to override it (e.g., by editing ~/.bashrc or using a custom dotfiles repo).

Requirements:

  • Do not affect other devcontainer settings (keep existing fields intact if devcontainer.json already exists).
  • Ensure the change is safe to run multiple times (idempotent) and will not create duplicate lines.
  • Keep commits small and include a clear commit message.

Deliverable: open a pull request in pyOpenSci/pyopensci-workshop-create-python-package that implements the above changes and includes a short description in the PR body explaining the approach and how to revert if necessary.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add postStartCommand to devcontainer.json that sets PS1='\W\$ '
- Command is idempotent: only adds to ~/.bashrc if not already present
- Add .devcontainer/README.md explaining the change and how to override

Co-authored-by: lwasser <[email protected]>
Copilot AI changed the title [WIP] Update Codespaces to set shorter Bash prompt Add shorter terminal prompt (PS1) for Codespaces Dec 2, 2025
Copilot AI requested a review from lwasser December 2, 2025 16:05
Copilot finished work on behalf of lwasser December 2, 2025 16:05
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.

2 participants