Skip to content
Open
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
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ RUN set -eux; \
rm -f "/tmp/${f}"

# ---- Shell experience -------------------------------------------------------
# kubectl completion is generated once at build time (not on every shell start).
RUN kubectl completion bash > /usr/share/bash-completion/completions/kubectl

COPY motd.txt /etc/motd
COPY bashrc /root/.bashrc
# /etc/bash.bashrc applies to any HOME/UID; /root/.bashrc (Ubuntu's skel copy,
# which would reset PS1 afterwards) is replaced with a stub.
COPY bashrc /etc/bash.bashrc
RUN echo '# see /etc/bash.bashrc' > /root/.bashrc

WORKDIR /root
ENTRYPOINT ["/bin/bash"]
21 changes: 17 additions & 4 deletions bashrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# k8s-debug shell config
# k8s-debug shell config. Installed as /etc/bash.bashrc so it applies whatever
# HOME / UID the pod runs the debug container with (not just root's ~/.bashrc).

# Interactive shells only (previously the guard tested $PS1, which was always
# set by this very file, so it never guarded anything).
[[ $- == *i* ]] || return 0

[ -f /etc/bash_completion ] && . /etc/bash_completion

export PS1='\[\e[1;36m\][debug]\[\e[0m\] \h:\w \$ '
Expand All @@ -10,11 +16,18 @@ alias ll='ls -alF --color=auto'
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias k=kubectl
command -v kubectl >/dev/null && source <(kubectl completion bash) && complete -o default -F __start_kubectl k
# Completion is generated at image build time (see Dockerfile); running
# `kubectl completion bash` here would fork kubectl on every shell start.
_kc=/usr/share/bash-completion/completions/kubectl
[ -r "$_kc" ] && . "$_kc" && complete -o default -F __start_kubectl k
unset _kc

# Helper: list the target container's filesystem root.
# troot <pid> -> /proc/<pid>/root (use with --target / shared PID namespace)
troot() { echo "/proc/${1:?usage: troot <pid>}/root"; }

# Show the banner once, for interactive shells only.
[ -n "$PS1" ] && [ -z "$DEBUG_MOTD_SHOWN" ] && export DEBUG_MOTD_SHOWN=1 && cat /etc/motd
# Show the banner once per shell tree.
if [ -z "$DEBUG_MOTD_SHOWN" ]; then
export DEBUG_MOTD_SHOWN=1
cat /etc/motd
fi
Loading