shell-base/modules/shell-process-directory.mod

94 lines
3.7 KiB
Bash

#!/bin/bash
shell_source_subdirs () {
# default processing
[[ ! -d $1 ]] && echo no directory $1 from which to process subdirectories && return 1
local DIR
local SUBDIRS
local IGNORE_FILE
DIR=$1
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
# must quote all globs to avoid bash glob expansion which is likely on
# TODO have default set of ignores plus check for shell-ignore
# source_dir -p "archive" -x '"*.off" "*.md" "*TODO*" "LICENSE" "*.sample"' -d 0 $DIR/$SUBDIR
# source_dir -p "archive" -x "$excludes" -d 0 $DIR/$SUBDIR
source_dir -f "$IGNORE_FILE" -d 0 $DIR/$SUBDIR
# else
# echo no subdirectory $DIR/$SUBDIR to process, ignorning
fi
done
}
function shell_process_directory () {
local SUBDIRS
local DIR
module_load file
[[ $? -ne 0 ]] && echo unable to access the file module, aborting load && return 1
DIR=${1:-$BASH_SHELL_BASE}
# echo sourcing directory $DIR
# if [[ $DIR = "$BASH_SHELL_BASE" ]]; then
# BASH_SHELL_IGNORE=$(shell_get_ignores)
# excludes=$BASH_SHELL_IGNORE
# else
# excludes=$(shell_get_ignores $DIR)
# [[ $? -ne 0 ]] && excludes=$BASH_SHELL_IGNORE
# fi
if [ -d "$DIR" ]; then
if [ "$DIR" = "$BASH_SHELL_BASE" ] && [ "$BASH_SHELL_BASE_LOADED" = "true" ]; then
if [ -v PS1 ]; then
echo base directory already sourced
read -p "do you want to re-source the base (not recommended)? " -n 1 -r
echo
[[ ! $REPLY =~ ^[Yy]$ ]] && return 1
# else
# echo non-interactive shell
# return 1
fi
fi
if [[ $DIR != "$BASH_SHELL_BASE" ]] && [[ -f $DIR/load.sh ]]; then
#
echo "$DIR/load.sh" found, running instead of base load.sh script
source "$DIR/load.sh"
else
shell_source_subdirs $DIR
# # default processing
# local SUBDIRS
# local IGNORE_FILE
# 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
# # must quote all globs to avoid bash glob expansion which is likely on
# # TODO have default set of ignores plus check for shell-ignore
# # source_dir -p "archive" -x '"*.off" "*.md" "*TODO*" "LICENSE" "*.sample"' -d 0 $DIR/$SUBDIR
# # source_dir -p "archive" -x "$excludes" -d 0 $DIR/$SUBDIR
# source_dir -f "$IGNORE_FILE" -d 0 $DIR/$SUBDIR
# # else
# # echo no subdirectory $DIR/$SUBDIR to process, ignorning
# fi
# done
fi
# echo "done sourcing directory $DIR"
# else
# echo $DIR does not exist nothing to source
fi
}