Skip to content

Fix bashrc interactive guard, bake kubectl completion, load for any HOME - #3

Open
ngpayyappilly wants to merge 2 commits into
mainfrom
claude/shell-fixes
Open

ngpayyappilly wants to merge 2 commits into
mainfrom
claude/shell-fixes

Conversation

@ngpayyappilly

Copy link
Copy Markdown
Owner

Summary

Three shell-experience fixes found in the SRE review:

  1. Broken interactive guard. The banner was guarded by [ -n "$PS1" ], but PS1 is exported earlier in the same file, so the guard was always true. Now [[ $- == *i* ]] || return 0 at the top.
  2. Slow shell start. source <(kubectl completion bash) forked kubectl on every shell start. The completion file is now generated once at build time into /usr/share/bash-completion/completions/kubectl and sourced from there.
  3. Config only loaded for root's HOME. It was installed as /root/.bashrc, so a pod running the container with another UID/HOME got a bare shell. It is now installed as /etc/bash.bashrc; /root/.bashrc becomes a stub so Ubuntu's skel copy cannot reset PS1 afterwards.

Testing

No Docker daemon was available, so the image was not built locally. Checked the bashrc itself in a shell:

  • Sourcing non-interactively prints nothing.
  • Interactive: k alias, PS1 and banner path work.
  • Completion wiring: complete -p k gives complete -o default -F __start_kubectl k.

The PR workflow's build and smoke test (which checks type k) will exercise the image end to end. The RUN kubectl completion bash step runs after kubectl is installed (the Shell experience section is last).

Part of an SRE review series (operability).


Generated by Claude Code

- The banner guard tested $PS1, which the file exports two lines earlier,
  so it was always true. Use [[ $- == *i* ]] and return early for
  non-interactive shells.
- `source <(kubectl completion bash)` forked kubectl on every shell start.
  Generate the completion file once at image build time and source it.
- Install the config as /etc/bash.bashrc instead of /root/.bashrc so it
  applies when the pod runs the debug container with a different UID/HOME;
  stub out /root/.bashrc so Ubuntu's skel copy cannot reset PS1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014iDTyB5N8EdZyyZo4ymUVR

This branch has not been deployed

No deployments
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