From fa01167c6eac600d1efe4ebbfd91b8b4a9b9859b Mon Sep 17 00:00:00 2001 From: Tim Perkins Date: Fri, 5 Jun 2026 22:14:57 -0400 Subject: [PATCH] Add ~/.bashrc.d pattern support Any `*.sh` or `*.bash` files placed in `~/.bashrc.d` will be sourced as if it were part of `~/.bashrc`. Additionally, if `BASHRC_D_PROFILE` is set to non-zero, then profiling information will be printed. --- containers/base/Containerfile | 5 +++++ containers/base/bashrcd_fragment.bash | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 containers/base/bashrcd_fragment.bash diff --git a/containers/base/Containerfile b/containers/base/Containerfile index a62e1d6..d04c59e 100644 --- a/containers/base/Containerfile +++ b/containers/base/Containerfile @@ -178,6 +178,11 @@ COPY entrypoint.sh /entrypoint.sh COPY fix_user.sh $ENTRYPOINT_DIR/00_fix_user.sh COPY login_shim.sh $ENTRYPOINT_DIR/01_login_shim.sh +# Add ~/.bashrc.d support to the user's ~/.bashrc +COPY bashrcd_fragment.bash /tmp/bashrcd_fragment.bash +RUN cat /tmp/bashrcd_fragment.bash >> $DEV_USER_HOME/.bashrc \ + && sudo -u $DEV_USER mkdir -m 755 $DEV_USER_HOME/.bashrc.d + # Here we set the entry point to the main entry point script. This script in # turn execs a chain of other entry points. This allows other images to layer # their own entry points onto the original entry point. diff --git a/containers/base/bashrcd_fragment.bash b/containers/base/bashrcd_fragment.bash new file mode 100644 index 0000000..80ff9b3 --- /dev/null +++ b/containers/base/bashrcd_fragment.bash @@ -0,0 +1,25 @@ + +########## BASHRC.D BEGIN ########## +declare -a brc_files +bashrc_d="$HOME/.bashrc.d" +if [[ -d $bashrc_d ]]; then + readarray -t -d '' brc_files < \ + <(find $bashrc_d -type f -regex '.*\.\(ba\)?sh$' -print0 | LC_ALL=C sort -z) +fi +declare -A brc_elapsed +for brc_file in "${brc_files[@]}"; do + start_time=$EPOCHREALTIME + source "$brc_file" + end_time=$EPOCHREALTIME + brc_elapsed["$brc_file"]=$(awk 'BEGIN {printf "%.2f", '"($end_time - $start_time)}") +done +: "${BASHRC_D_PROFILE:=0}" +if [[ $BASHRC_D_PROFILE -ne 0 ]] && [[ ${#brc_elapsed[@]} -gt 0 ]]; then + echo "Elapsed time to source '.bashrc.d':" + for brc_file in "${!brc_elapsed[@]}"; do + printf "%s %s\n" "${brc_elapsed[$brc_file]}" "$(basename "$brc_file")" + done | sort -rn | while read -r time name; do + printf " - %-20s %10s seconds\n" "$name" "$time" + done +fi +########### BASHRC.D END ###########