From 9d7e07a113574bd8c3f68ca2b5b117eefead2837 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Mon, 2 May 2022 10:46:41 -0700 Subject: [PATCH] load only base and any host when coming from ssh --- load.sh | 28 +++++++++++++++++++++++----- modules/shell-process-directory.sh | 4 +++- setup/user/.bashrc | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/load.sh b/load.sh index c8821cc..6d2dd9f 100755 --- a/load.sh +++ b/load.sh @@ -24,11 +24,29 @@ unset BASH_SHELL_BASE_LOADED unset BASH_SHELL_LOADED module_load shell-process-directory -for dir in ${1:-$BASH_SHELL_DIRS}; do - # echo $dir $BASH_SHELL_BASE - shell_process_directory $dir - [[ "$dir" = "$BASH_SHELL_BASE" ]] && export BASH_SHELL_BASE_LOADED=true -done + +if [[ $SSH_SESSION ]]; then + # ssh session only process base by default + # env | grep SSH + # echo ssh session bash load + # TODO process network dirs if environment variable is set + # process only base, nothing (i.e. BASH_SAFE_MODE, SSH_SHELL_CLEAN) if env variables are set + # see https://stackoverflow.com/a/59461195 + shell_process_directory $BASH_SHELL_BASE + shell_process_directory $BASH_SHELL_ANY_HOST + shell_process_directory $BASH_SHELL_HOST + + export BASH_SHELL_BASE_LOADED=true + + else + # local shell so process all directories + for dir in ${1:-$BASH_SHELL_DIRS}; do + # env | grep BASH + # echo $dir + shell_process_directory $dir + [[ "$dir" = "$BASH_SHELL_BASE" ]] && export BASH_SHELL_BASE_LOADED=true + done +fi export BASH_SHELL_LOADED=true diff --git a/modules/shell-process-directory.sh b/modules/shell-process-directory.sh index 95a9016..5a9a2dc 100644 --- a/modules/shell-process-directory.sh +++ b/modules/shell-process-directory.sh @@ -9,7 +9,7 @@ function shell_process_directory () { DIR=${1:-$BASH_SHELL_BASE} - # echo soucring directory $DIR + # echo sourcing directory $DIR # if [[ $DIR = "$BASH_SHELL_BASE" ]]; then # BASH_SHELL_IGNORE=$(shell_get_ignores) # excludes=$BASH_SHELL_IGNORE @@ -41,6 +41,8 @@ function shell_process_directory () { SUBDIRS=$([[ -f "$DIR/.bash-shell-include" ]] && cat "$DIR/.bash-shell-include" || cat "$BASH_SHELL_BASE/.bash-shell-include") [[ $SSH_SESSION ]] && SUBDIRS+=" ssh/session" IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore" + # echo $DIR + # echo $SUBDIRS for SUBDIR in $SUBDIRS; do if [ -e "$DIR/$SUBDIR" ]; then # echo processing subdirectory $DIR/$SUBDIR diff --git a/setup/user/.bashrc b/setup/user/.bashrc index 76274d2..876596d 100644 --- a/setup/user/.bashrc +++ b/setup/user/.bashrc @@ -10,8 +10,8 @@ if ( [[ $SHELL_INTERACTIVE ]] );then if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then - # echo loading user shell sources export BASH_SHELL_USER=${BASH_SHELL_USER:-"shell"} + # echo loading user $USER shell at $HOME/$BASH_SHELL_USER [[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\ echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template fi