diff --git a/debian/Dockerfile b/debian/Dockerfile index 96fbe63..5717d64 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -51,3 +51,6 @@ COPY --chown=${USERNAME}:${USERNAME} assets/.bashrc /home/${USERNAME}/.bashrc USER ${USERNAME} WORKDIR /workspaces + +ENV HISTFILE=/home/${USERNAME}/.local/state/bash/history +RUN mkdir -p "${HISTFILE%/*}" diff --git a/debian/README.md b/debian/README.md index 1771a99..81a7ec9 100644 --- a/debian/README.md +++ b/debian/README.md @@ -55,6 +55,12 @@ The image runs as the non-root user `dev` (UID/GID 1000) and its working directo Container clients pick up the user without extra configuration. Every image built on this one inherits that label. +`dev`'s login shell is bash, which appends each command to `$HISTFILE` as it is entered rather +than at exit. `HISTFILE` is `/home/dev/.local/state/bash/history` rather than the default +`~/.bash_history`, and that directory is created in the image, so mounting a volume on it keeps +the shell history across container rebuilds, which is what the +[Dev Container template](#dev-container-template) does. + ## Not installed - **No development headers beyond libc.** `build-essential` covers the compiler, linker, and diff --git a/debian/assets/.bashrc b/debian/assets/.bashrc index 9ac42fb..33ccd5c 100644 --- a/debian/assets/.bashrc +++ b/debian/assets/.bashrc @@ -9,6 +9,9 @@ HISTCONTROL=ignoreboth HISTSIZE=${HISTSIZE:-10000} HISTFILESIZE=${HISTFILESIZE:-20000} shopt -s histappend +# Append each command to HISTFILE as it is entered. Waiting for the shell to exit +# loses the session when the container is stopped before bash gets to write it. +PROMPT_COMMAND=${PROMPT_COMMAND:+${PROMPT_COMMAND}$'\n'}'history -a' # Check terminal size after each command. shopt -s checkwinsize diff --git a/debian/smoke-test.sh b/debian/smoke-test.sh index 7f45bc8..5b41fa7 100755 --- a/debian/smoke-test.sh +++ b/debian/smoke-test.sh @@ -7,6 +7,9 @@ git --version cc --version make --version +echo "=== Verifying the shell history directory is writable ===" +[ -w "${HISTFILE%/*}" ] + echo "=== Verifying the C toolchain compiles and links ===" TMPDIR=$(mktemp -d) trap 'rm -rf "$TMPDIR"' EXIT