From 33222b4ad49990fe99be0cbcbc4fd3235a32e95e Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Fri, 22 Nov 2024 10:45:18 -0500 Subject: [PATCH 01/11] renamed BD_AUTOLOAD_* to BD_AUTOLAODER_* --- bd.sh | 82 ++++++++++++++++++++--------------------- doc/bd-completion.md | 2 +- doc/bd.md | 2 +- etc/bash.d/bd-help.sh | 2 +- etc/bash.d/bd-sundry.sh | 8 ++-- example/.bd.conf | 17 ++++----- 6 files changed, 56 insertions(+), 57 deletions(-) diff --git a/bd.sh b/bd.sh index b41d2a2..1e79139 100644 --- a/bd.sh +++ b/bd.sh @@ -42,7 +42,7 @@ if [ "${BASH_SOURCE}" == '' ]; then return 1 &> /dev/null fi -export BD_VERSION=0.45.1 +export BD_VERSION=0.46.0 # # functions @@ -56,8 +56,8 @@ export -f bd # stub _bd_ansi() until bd-ansi.sh is fully loaded (needed for embedded _bd_debug) if ! type -t _bd_ansi &> /dev/null; then - if [ -r "${BD_DIR}/${BD_AUTOLOAD_SUB_DIR}/bd-ansi.sh" ]; then - . "${BD_DIR}/${BD_AUTOLOAD_SUB_DIR}/bd-ansi.sh" + if [ -r "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}/bd-ansi.sh" ]; then + . "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}/bd-ansi.sh" else _bd_ansi() { return @@ -86,7 +86,7 @@ _bd_autoload() { # autoload directory array - _bd_autoload_execute_array "${BD_AUTOLOAD_DIRS[@]}" + _bd_autoload_execute_array "${BD_AUTOLOADER_DIRS[@]}" return $? } @@ -181,10 +181,10 @@ export -f _bd_autoload_execute_array _bd_bootstrap() { _bd_caller || return 1 - export BD_AUTOLOAD_SUB_DIR='etc/bash.d' + export BD_AUTOLOADER_SUB_DIR='etc/bash.d' export BD_CONFIG_FILE='.bd.conf' export BD_DEBUG=${BD_DEBUG:-0} # level >0 enables debugging - export BD_BITS_DIR="${BD_BITS_DIR:-${BD_DIR}/${BD_AUTOLOAD_SUB_DIR}/bits}" + export BD_BITS_DIR="${BD_BITS_DIR:-${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}/bits}" export BD_SOURCE="$(_bd_realpath "${BASH_SOURCE}")" _bd_debug "BD_SOURCE = ${BD_SOURCE} (${FUNCNAME})" 2 @@ -287,7 +287,7 @@ _bd_debug_ms() { } export -f _bd_debug_ms -# add only unique, existing directories to the BD_AUTOLOAD_DIRS array (& prevent dupes & preserve the given order) +# add only unique, existing directories to the BD_AUTOLOADER_DIRS array (& prevent dupes & preserve the given order) _bd_autoload_dir() { _bd_debug "${FUNCNAME}(${@})" 55 @@ -306,17 +306,17 @@ _bd_autoload_dir() { _bd_debug "2 bd_dir_name = ${bd_dir_name}" 6 - [ ${#BD_AUTOLOAD_DIRS} -eq 0 ] && export BD_AUTOLOAD_DIRS=() + [ ${#BD_AUTOLOADER_DIRS} -eq 0 ] && export BD_AUTOLOADER_DIRS=() local bd_dir_exists=0 # false local bd_autoload_dir - for bd_autoload_dir in ${BD_AUTOLOAD_DIRS[@]}; do + for bd_autoload_dir in ${BD_AUTOLOADER_DIRS[@]}; do [ ${bd_dir_exists} -eq 1 ] && break [ "${bd_autoload_dir}" == "${bd_dir_name}" ] && bd_dir_exists=1 done - [ ${bd_dir_exists} -eq 0 ] && BD_AUTOLOAD_DIRS+=("${bd_dir_name}") && _bd_debug "bd_dir_name = ${bd_dir_name}" 2 + [ ${bd_dir_exists} -eq 0 ] && BD_AUTOLOADER_DIRS+=("${bd_dir_name}") && _bd_debug "bd_dir_name = ${bd_dir_name}" 2 } export -f _bd_autoload_dir @@ -332,25 +332,25 @@ _bd_load_config() { fi # ${BD_DIR} - if [ ${#BD_DIR} -gt 0 ] && [ ${#BD_AUTOLOAD_SUB_DIR} -gt 0 ]; then + if [ ${#BD_DIR} -gt 0 ] && [ ${#BD_AUTOLOADER_SUB_DIR} -gt 0 ]; then [ -f "${BD_DIR}/${BD_CONFIG_FILE}" ] && [ -r "${BD_DIR}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${BD_DIR}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${BD_DIR}/${BD_AUTOLOAD_SUB_DIR}" ] && [ -r "${BD_DIR}/${BD_AUTOLOAD_SUB_DIR}" ]; then - _bd_autoload_dir "${BD_DIR}/${BD_AUTOLOAD_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" ]; then + _bd_autoload_dir "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" _bd_load_config_dir "${BD_DIR}" fi fi - # /${BD_AUTOLOAD_SUB_DIR}/.. (/etc) - if [ ${#BD_AUTOLOAD_SUB_DIR} -gt 0 ] && [ "/${BD_AUTOLOAD_SUB_DIR}/.." != "//.." ]; then - [ -f "/${BD_AUTOLOAD_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && [ -r "/${BD_AUTOLOAD_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && _bd_load_config_file "/${BD_AUTOLOAD_SUB_DIR}/../${BD_CONFIG_FILE/./}" ${1} + # /${BD_AUTOLOADER_SUB_DIR}/.. (/etc) + if [ ${#BD_AUTOLOADER_SUB_DIR} -gt 0 ] && [ "/${BD_AUTOLOADER_SUB_DIR}/.." != "//.." ]; then + [ -f "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && [ -r "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && _bd_load_config_file "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ${1} - if [ "${1}" != 'preload' ] && [ -d "/${BD_AUTOLOAD_SUB_DIR}" ] && [ -r "/${BD_AUTOLOAD_SUB_DIR}" ]; then - _bd_autoload_dir "/${BD_AUTOLOAD_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "/${BD_AUTOLOADER_SUB_DIR}" ]; then + _bd_autoload_dir "/${BD_AUTOLOADER_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "/${BD_AUTOLOAD_SUB_DIR}"/*; do + for bd_load_config_dir_name in "/${BD_AUTOLOADER_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" done @@ -362,11 +362,11 @@ _bd_load_config() { if [ ${#HOME} -gt 0 ] && [ "${HOME}" != "/" ]; then [ -f "${HOME}/${BD_CONFIG_FILE}" ] && [ -r "${HOME}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${HOME}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${HOME}/${BD_AUTOLOAD_SUB_DIR}" ] && [ -r "${HOME}/${BD_AUTOLOAD_SUB_DIR}" ]; then - _bd_autoload_dir "${HOME}/${BD_AUTOLOAD_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${HOME}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${HOME}/${BD_AUTOLOADER_SUB_DIR}" ]; then + _bd_autoload_dir "${HOME}/${BD_AUTOLOADER_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "${HOME}/${BD_AUTOLOAD_SUB_DIR}"/*; do + for bd_load_config_dir_name in "${HOME}/${BD_AUTOLOADER_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" done @@ -378,11 +378,11 @@ _bd_load_config() { if [ ${#BD_HOME} -gt 0 ] && [ "${BD_HOME}" != "/" ] && [ "${BD_HOME}" != "${HOME}" ]; then [ -f "${BD_HOME}/${BD_CONFIG_FILE}" ] && [ -r "${BD_HOME}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${BD_HOME}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${BD_HOME}/${BD_AUTOLOAD_SUB_DIR}" ] && [ -r "${BD_HOME}/${BD_AUTOLOAD_SUB_DIR}" ]; then - _bd_autoload_dir "${BD_HOME}/${BD_AUTOLOAD_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" ]; then + _bd_autoload_dir "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "${BD_HOME}/${BD_AUTOLOAD_SUB_DIR}"/*; do + for bd_load_config_dir_name in "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" done @@ -394,11 +394,11 @@ _bd_load_config() { if [ ${#PWD} -gt 0 ] && [ "${PWD}" != "/etc" ] && [ "${PWD}" != "${BD_HOME}" ] && [ "${PWD}" != "${HOME}" ]; then [ -f "${PWD}/${BD_CONFIG_FILE}" ] && [ -r "${PWD}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${PWD}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${PWD}/${BD_AUTOLOAD_SUB_DIR}" ] && [ -r "${PWD}/${BD_AUTOLOAD_SUB_DIR}" ]; then - _bd_autoload_dir "${PWD}/${BD_AUTOLOAD_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${PWD}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${PWD}/${BD_AUTOLOADER_SUB_DIR}" ]; then + _bd_autoload_dir "${PWD}/${BD_AUTOLOADER_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "${PWD}/${BD_AUTOLOAD_SUB_DIR}"/*; do + for bd_load_config_dir_name in "${PWD}/${BD_AUTOLOADER_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" done @@ -410,7 +410,7 @@ _bd_load_config() { } export -f _bd_load_config -# process BD_AUTOLOAD_CONFIG_DIRS with _bd_autoload_dir(); i.e. look for etc/bash.d in other/specific locations +# process BD_AUTOLOADER_CONFIG_DIRS with _bd_autoload_dir(); i.e. look for etc/bash.d in other/specific locations _bd_load_config_dir() { _bd_debug "${FUNCNAME}(${@})" 55 @@ -418,9 +418,9 @@ _bd_load_config_dir() { _bd_debug "bd_load_config_dir_name = ${bd_load_config_dir_name}" 10 - if [ ${#BD_AUTOLOAD_CONFIG_DIRS} -gt 0 ]; then + if [ ${#BD_AUTOLOADER_CONFIG_DIRS} -gt 0 ]; then local bd_load_config_dirs - for bd_load_config_dirs in "${BD_AUTOLOAD_CONFIG_DIRS[@]}"; do + for bd_load_config_dirs in "${BD_AUTOLOADER_CONFIG_DIRS[@]}"; do if [ "${bd_load_config_dirs:0:1}" == "/" ]; then # qualified path [ -d "${bd_load_config_dirs}" ] && [ -r "${bd_load_config_dirs}" ] && _bd_autoload_dir "${bd_load_config_dirs}" @@ -430,7 +430,7 @@ _bd_load_config_dir() { fi done fi - unset -v BD_AUTOLOAD_CONFIG_DIRS + unset -v BD_AUTOLOADER_CONFIG_DIRS } export -f _bd_load_config_dir @@ -470,10 +470,10 @@ _bd_load_config_file() { _bd_debug "bd_config_file_variable_value=${bd_config_file_variable_value}" 11 # 0.44.0, note BD_BAG_DIR is deprecated & will be removed in 1.0 - if [ "${bd_config_file_variable_name}" == 'BD_AUTOLOAD_DIR' ] || [ "${bd_config_file_variable_name}" == 'BD_BAG_DIR' ]; then + if [ "${bd_config_file_variable_name}" == 'BD_AUTOLOADER_DIR' ] || [ "${bd_config_file_variable_name}" == 'BD_BAG_DIR' ]; then [ "${bd_config_file_preload}" == "preload" ] && continue - _bd_debug "export BD_AUTOLOAD_CONFIG_DIRS+=(\"${bd_config_file_variable_value}\")" 15 - export BD_AUTOLOAD_CONFIG_DIRS+=("${bd_config_file_variable_value}") + _bd_debug "export BD_AUTOLOADER_CONFIG_DIRS+=(\"${bd_config_file_variable_value}\")" 15 + export BD_AUTOLOADER_CONFIG_DIRS+=("${bd_config_file_variable_value}") else [ "${bd_config_file_preload}" != "preload" ] && continue _bd_debug "export ${bd_config_file_variable_name}=\"${bd_config_file_variable_value}\"" 15 @@ -599,12 +599,12 @@ _bd_namespace_init() { _bd_os - # ensure BD_AUTOLOAD_DIRS, BD_AUTOLOAD_CONFIG_DIRS, BD_BASH_INIT_FILE, BD_HOME, BD_USER, & USER + # ensure BD_AUTOLOADER_DIRS, BD_AUTOLOADER_CONFIG_DIRS, BD_BASH_INIT_FILE, BD_HOME, BD_USER, & USER - unset -v BD_AUTOLOAD_CONFIG_DIRS + unset -v BD_AUTOLOADER_CONFIG_DIRS # TODO: learn requires more testing - _bd_true ${BD_LEARN} || export BD_AUTOLOAD_DIRS=() + _bd_true ${BD_LEARN} || export BD_AUTOLOADER_DIRS=() [ "${EUID}" == '0' ] && USER=root @@ -647,7 +647,7 @@ _bd_namespace_init() { _bd_load_config - _bd_debug "BD_AUTOLOAD_DIRS = ${BD_AUTOLOAD_DIRS[@]} # (after _bd_load_config)" 1 + _bd_debug "BD_AUTOLOADER_DIRS = ${BD_AUTOLOADER_DIRS[@]} # (after _bd_load_config)" 1 } export -f _bd_namespace_init @@ -715,7 +715,7 @@ _bd_namespace_reset() { [[ "${bd_variable_name}" == 'BD_'*'_EXPORT' ]] && continue - if [ "${bd_variable_name}" == 'BD_AUTOLOAD_DIRS' ]; then + if [ "${bd_variable_name}" == 'BD_AUTOLOADER_DIRS' ]; then if ! _bd_true ${BD_LEARN}; then bd_variable_names+=("${bd_variable_name}") fi @@ -812,7 +812,7 @@ _bd_private() { bd_private_variable_names=() - bd_private_variable_names+=('BD_AUTOLOAD_SUB_DIR') + bd_private_variable_names+=('BD_AUTOLOADER_SUB_DIR') bd_private_variable_names+=('BD_CONFIG_FILE') bd_private_variable_names+=('BD_DECLARE') bd_private_variable_names+=('BD_OIFS') diff --git a/doc/bd-completion.md b/doc/bd-completion.md index 346ffac..641c134 100644 --- a/doc/bd-completion.md +++ b/doc/bd-completion.md @@ -20,7 +20,7 @@ This script significantly boosts the usability of the `bash-d` system by making ## Integration with `bd.sh` -* Relies on the presence of the `bd` environment and directory structure (e.g., BD_AUTOLOAD_DIR) for proper operation. +* Relies on the presence of the `bd` environment and directory structure (e.g., BD_AUTOLOADER_DIR) for proper operation. * Complements other `bd` components by making their functionality more accessible and user-friendly. ## Key Features diff --git a/doc/bd.md b/doc/bd.md index 4f9a272..a86add7 100644 --- a/doc/bd.md +++ b/doc/bd.md @@ -55,7 +55,7 @@ The Bash script, `bd.sh`, implements a sophisticated directory autoloader for ma ### Bootstrap and Initialization -* Sets up essential environment variables, including `BD_AUTOLOAD_DIRS`, `BD_HOME`, and `BD_USER`. +* Sets up essential environment variables, including `BD_AUTOLOADER_DIRS`, `BD_HOME`, and `BD_USER`. * Detects and initializes the appropriate directories and configurations based on the current shell environment. ### Error Handling and Safety diff --git a/etc/bash.d/bd-help.sh b/etc/bash.d/bd-help.sh index b31b2b5..ea11244 100644 --- a/etc/bash.d/bd-help.sh +++ b/etc/bash.d/bd-help.sh @@ -50,7 +50,7 @@ _bd_help() { bd_help+=" ['' | *] - (default) invoke autoloader\n" bd_help+="\n" bd_help+=" env [BD_* variable] - display BD_* environment variables & values, and optionally the value of a single variable\n" - bd_help+=" dir [hash | ls] - display only BD_AUTOLOAD_DIRS array values, and optionally hash or list them\n" + bd_help+=" dir [hash | ls] - display only BD_AUTOLOADER_DIRS array values, and optionally hash or list them\n" bd_help+="\n" bd_help+=" license - display MIT license\n" bd_help+=" version - display version\n" diff --git a/etc/bash.d/bd-sundry.sh b/etc/bash.d/bd-sundry.sh index fcf34d7..ede9e4e 100644 --- a/etc/bash.d/bd-sundry.sh +++ b/etc/bash.d/bd-sundry.sh @@ -63,7 +63,7 @@ _bd_autoload_dirs() { if [ ${#2} -gt 0 ]; then if [ "${2}" == 'hash' ] || [ "${2}" == 'ls' ]; then local bd_autoload_dir bd_autoload_file - for bd_autoload_dir in "${BD_AUTOLOAD_DIRS[@]}"; do + for bd_autoload_dir in "${BD_AUTOLOADER_DIRS[@]}"; do if [ -d "${bd_autoload_dir}" ]; then echo "# ${bd_autoload_dir}" echo @@ -85,7 +85,7 @@ _bd_autoload_dirs() { fi fi - echo "${BD_AUTOLOAD_DIRS[@]}" + echo "${BD_AUTOLOADER_DIRS[@]}" } # env option @@ -114,8 +114,8 @@ _bd_environment() { printf "%-30s" "${bd_variable_name}" printf " = " - if [ "${bd_variable_name}" == 'BD_AUTOLOAD_DIRS' ]; then - echo "${BD_AUTOLOAD_DIRS[@]}" + if [ "${bd_variable_name}" == 'BD_AUTOLOADER_DIRS' ]; then + echo "${BD_AUTOLOADER_DIRS[@]}" else echo "${!bd_variable_name}" fi diff --git a/example/.bd.conf b/example/.bd.conf index cc3d700..c76d307 100644 --- a/example/.bd.conf +++ b/example/.bd.conf @@ -1,17 +1,16 @@ # -# use ~/.bd/.bd.conf for system specific (user) variables, e.g. BD_AUTOLOAD_DIR +# use ~/.bd/.bd.conf for system specific (user) variables, e.g. BD_AUTOLOADER_DIR # -#BD_LEARN=1 # don't unset BD_AUTOLOAD_DIRS (et al) +#BD_LEARN=1 # don't unset BD_AUTOLOADER_DIRS (et al) # additional directories and/or bash.d directories to source *.sh files ... -#BD_AUTOLOAD_DIR=~/tmp/1 # an inline comment to a directory that doesn't exist -#BD_AUTOLOAD_DIR=~/base/etc/bash.d -#BD_AUTOLOAD_DIR=~/src/sre/etc/bash.d -#BD_AUTOLOAD_DIR=./base/etc/bash.d -BD_AUTOLOAD_DIR=./base/etc/bash.d -#BD_AUTOLOAD_DIR=./src/sre/etc/bash.d -BD_AUTOLOAD_DIR=./src/entala/etc/bash.d +#BD_AUTOLOADER_DIR=~/tmp/1 # an inline comment to a directory that doesn't exist +#BD_AUTOLOADER_DIR=~/base/etc/bash.d +#BD_AUTOLOADER_DIR=~/src/myapp/etc/bash.d +#BD_AUTOLOADER_DIR=./base/etc/bash.d +BD_AUTOLOADER_DIR=./base/etc/bash.d +#BD_AUTOLOADER_DIR=./src/myapp/etc/bash.d # other BD_ namespace scripts may have values that should work here, too #BD_ROOT_SUDO_PRESERVE_ENV="SSH_AUTH_SOCK" # comma separated list From 3562576918a336c68aa0b1bf12c6e0b0b34aa25a Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Fri, 22 Nov 2024 10:57:49 -0500 Subject: [PATCH 02/11] renamed bd_autoload* to bd_autoloader* --- bd.sh | 130 ++++++++++++++++++++-------------------- doc/bd.md | 2 +- etc/bash.d/bd-bits.sh | 8 +-- etc/bash.d/bd-sundry.sh | 24 ++++---- 4 files changed, 82 insertions(+), 82 deletions(-) diff --git a/bd.sh b/bd.sh index 1e79139..f059bb8 100644 --- a/bd.sh +++ b/bd.sh @@ -66,8 +66,8 @@ if ! type -t _bd_ansi &> /dev/null; then fi fi -# start the autoload procedure -_bd_autoload() { +# start the autoloader procedure +_bd_autoloader() { _bd_debug "${FUNCNAME}(${@})" 55 local bd_start_arg="${1}" @@ -84,98 +84,98 @@ _bd_autoload() { return 1 fi - # autoload directory array + # directory autoloader array - _bd_autoload_execute_array "${BD_AUTOLOADER_DIRS[@]}" + _bd_autoloader_execute_array "${BD_AUTOLOADER_DIRS[@]}" return $? } -export -f _bd_autoload +export -f _bd_autoloader -# predictably execute commands from every (.bash or .sh) file in the current shell (autoload) a given directory -_bd_autoload_execute() { +# predictably execute commands from every (.bash or .sh) file into the current shell +_bd_autoloader_execute() { _bd_debug "${FUNCNAME}(${@})" 55 - local bd_autoload_execute_dir="${1}" + local bd_autoloader_execute_dir="${1}" - if [ -d "${bd_autoload_execute_dir}" ] && [ -r "${bd_autoload_execute_dir}" ]; then - local bd_autoload_execute_file - local bd_autoload_execute_files=() + if [ -d "${bd_autoloader_execute_dir}" ] && [ -r "${bd_autoloader_execute_dir}" ]; then + local bd_autoloader_execute_file + local bd_autoloader_execute_files=() # LC_COLLATE consistency hack (due to bsd/darwin differences) # https://collation-charts.org/fbsd54/ - local bd_autoload_execute_collate="${LC_COLLATE}" + local bd_autoloader_execute_collate="${LC_COLLATE}" LC_COLLATE=POSIX # required for consistent collation across operating systems - for bd_autoload_execute_file in "${bd_autoload_execute_dir}"/*\.{bash,sh}; do - bd_autoload_execute_files+=("${bd_autoload_execute_file}") + for bd_autoloader_execute_file in "${bd_autoloader_execute_dir}"/*\.{bash,sh}; do + bd_autoloader_execute_files+=("${bd_autoloader_execute_file}") done - [ ${#bd_autoload_execute_collate} -gt 0 ] && LC_COLLATE="${bd_autoload_execute_collate}" || unset -v LC_COLLATE + [ ${#bd_autoloader_execute_collate} -gt 0 ] && LC_COLLATE="${bd_autoloader_execute_collate}" || unset -v LC_COLLATE - for bd_autoload_execute_file in "${bd_autoload_execute_files[@]}"; do + for bd_autoloader_execute_file in "${bd_autoloader_execute_files[@]}"; do - if [ "${bd_autoload_execute_file}" == "${BD_SOURCE}" ]; then + if [ "${bd_autoloader_execute_file}" == "${BD_SOURCE}" ]; then # relative location - _bd_debug "${FUNCNAME} ${bd_autoload_execute_file} matches relative path" 13 + _bd_debug "${FUNCNAME} ${bd_autoloader_execute_file} matches relative path" 13 continue fi - if [ "${bd_autoload_execute_file}" == "${BD_SOURCE##*/}" ]; then + if [ "${bd_autoloader_execute_file}" == "${BD_SOURCE##*/}" ]; then # basename - _bd_debug "${FUNCNAME}) ${bd_autoload_execute_file} matches basename" 13 + _bd_debug "${FUNCNAME}) ${bd_autoloader_execute_file} matches basename" 13 continue fi - if [ -r "${bd_autoload_execute_file}" ]; then - local bd_autoload_execute_begin_time + if [ -r "${bd_autoloader_execute_file}" ]; then + local bd_autoloader_execute_begin_time if [ ${#BD_DEBUG} -gt 0 ]; then - bd_autoload_execute_begin_time=$(_bd_uptime) + bd_autoloader_execute_begin_time=$(_bd_uptime) fi - _bd_debug "source ${bd_autoload_execute_file} ..." 4 + _bd_debug "source ${bd_autoloader_execute_file} ..." 4 # execute commands in the current shell - . "${bd_autoload_execute_file}" '' # pass an empty arg to ${1} + . "${bd_autoloader_execute_file}" '' # pass an empty arg to ${1} if [ ${#BD_DEBUG} -gt 0 ]; then - local bd_autoload_execute_end_time bd_autoload_execute_total_time bd_autoload_execute_total_ms + local bd_autoloader_execute_end_time bd_autoloader_execute_total_time bd_autoloader_execute_total_ms - bd_autoload_execute_end_time=$(_bd_uptime) - bd_autoload_execute_total_time=$((${bd_autoload_execute_end_time}-${bd_autoload_execute_begin_time})) - bd_autoload_execute_total_ms=$(_bd_debug_ms ${bd_autoload_execute_total_time}) - _bd_debug "sourced ${bd_autoload_execute_file} ${bd_autoload_execute_total_ms}" 3 + bd_autoloader_execute_end_time=$(_bd_uptime) + bd_autoloader_execute_total_time=$((${bd_autoloader_execute_end_time}-${bd_autoloader_execute_begin_time})) + bd_autoloader_execute_total_ms=$(_bd_debug_ms ${bd_autoloader_execute_total_time}) + _bd_debug "sourced ${bd_autoloader_execute_file} ${bd_autoloader_execute_total_ms}" 3 fi fi done fi } -export -f _bd_autoload_execute +export -f _bd_autoloader_execute -# call _bd_autoload_execute on an array (of directories) -_bd_autoload_execute_array() { +# call _bd_autoloader_execute on an array (of directories) +_bd_autoloader_execute_array() { _bd_debug "${FUNCNAME}(${@})" 55 [ ${#1} -eq 0 ] && return 1 - local bd_autoload_dir_name bd_autoload_finish bd_autoload_start bd_autoload_total bd_autoload_total_ms + local bd_autoloader_dir_name bd_autoloader_finish bd_autoloader_start bd_autoloader_total bd_autoloader_total_ms - for bd_autoload_dir_name in "${@}"; do - [ ${#BD_DEBUG} -gt 0 ] && bd_autoload_start=$(_bd_uptime) + for bd_autoloader_dir_name in "${@}"; do + [ ${#BD_DEBUG} -gt 0 ] && bd_autoloader_start=$(_bd_uptime) - _bd_autoload_execute "${bd_autoload_dir_name}" + _bd_autoloader_execute "${bd_autoloader_dir_name}" if [ ${#BD_DEBUG} -gt 0 ]; then - bd_autoload_finish=$(_bd_uptime) - bd_autoload_total=$((${bd_autoload_finish}-${bd_autoload_start})) - bd_autoload_total_ms="$(_bd_debug_ms ${bd_autoload_total})" - _bd_debug "_bd_autoload_execute ${bd_autoload_dir_name} ${bd_autoload_total_ms}" + bd_autoloader_finish=$(_bd_uptime) + bd_autoloader_total=$((${bd_autoloader_finish}-${bd_autoloader_start})) + bd_autoloader_total_ms="$(_bd_debug_ms ${bd_autoloader_total})" + _bd_debug "_bd_autoloader_execute ${bd_autoloader_dir_name} ${bd_autoloader_total_ms}" fi done } -export -f _bd_autoload_execute_array +export -f _bd_autoloader_execute_array # prepare bash environment for bd _bd_bootstrap() { @@ -288,7 +288,7 @@ _bd_debug_ms() { export -f _bd_debug_ms # add only unique, existing directories to the BD_AUTOLOADER_DIRS array (& prevent dupes & preserve the given order) -_bd_autoload_dir() { +_bd_autoloader_dir() { _bd_debug "${FUNCNAME}(${@})" 55 local bd_dir_name="${1//\/\//\/}" @@ -309,16 +309,16 @@ _bd_autoload_dir() { [ ${#BD_AUTOLOADER_DIRS} -eq 0 ] && export BD_AUTOLOADER_DIRS=() local bd_dir_exists=0 # false - local bd_autoload_dir + local bd_autoloader_dir - for bd_autoload_dir in ${BD_AUTOLOADER_DIRS[@]}; do + for bd_autoloader_dir in ${BD_AUTOLOADER_DIRS[@]}; do [ ${bd_dir_exists} -eq 1 ] && break - [ "${bd_autoload_dir}" == "${bd_dir_name}" ] && bd_dir_exists=1 + [ "${bd_autoloader_dir}" == "${bd_dir_name}" ] && bd_dir_exists=1 done [ ${bd_dir_exists} -eq 0 ] && BD_AUTOLOADER_DIRS+=("${bd_dir_name}") && _bd_debug "bd_dir_name = ${bd_dir_name}" 2 } -export -f _bd_autoload_dir +export -f _bd_autoloader_dir # load all config files & directories _bd_load_config() { @@ -327,7 +327,7 @@ _bd_load_config() { # ${BD_BITS_DIR} if [ ${#BD_BITS_DIR} -gt 0 ]; then if [ "${1}" != 'preload' ] && [ -d "${BD_BITS_DIR}" ] && [ -r "${BD_BITS_DIR}" ]; then - _bd_autoload_dir "${BD_BITS_DIR}" + _bd_autoloader_dir "${BD_BITS_DIR}" fi fi @@ -336,7 +336,7 @@ _bd_load_config() { [ -f "${BD_DIR}/${BD_CONFIG_FILE}" ] && [ -r "${BD_DIR}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${BD_DIR}/${BD_CONFIG_FILE}" ${1} if [ "${1}" != 'preload' ] && [ -d "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoload_dir "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" + _bd_autoloader_dir "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" _bd_load_config_dir "${BD_DIR}" fi @@ -347,11 +347,11 @@ _bd_load_config() { [ -f "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && [ -r "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && _bd_load_config_file "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ${1} if [ "${1}" != 'preload' ] && [ -d "/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoload_dir "/${BD_AUTOLOADER_SUB_DIR}" + _bd_autoloader_dir "/${BD_AUTOLOADER_SUB_DIR}" # sub-directories for bd_load_config_dir_name in "/${BD_AUTOLOADER_SUB_DIR}"/*; do - [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" + [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done _bd_load_config_dir / @@ -363,11 +363,11 @@ _bd_load_config() { [ -f "${HOME}/${BD_CONFIG_FILE}" ] && [ -r "${HOME}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${HOME}/${BD_CONFIG_FILE}" ${1} if [ "${1}" != 'preload' ] && [ -d "${HOME}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${HOME}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoload_dir "${HOME}/${BD_AUTOLOADER_SUB_DIR}" + _bd_autoloader_dir "${HOME}/${BD_AUTOLOADER_SUB_DIR}" # sub-directories for bd_load_config_dir_name in "${HOME}/${BD_AUTOLOADER_SUB_DIR}"/*; do - [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" + [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done _bd_load_config_dir "${HOME}" @@ -379,11 +379,11 @@ _bd_load_config() { [ -f "${BD_HOME}/${BD_CONFIG_FILE}" ] && [ -r "${BD_HOME}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${BD_HOME}/${BD_CONFIG_FILE}" ${1} if [ "${1}" != 'preload' ] && [ -d "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoload_dir "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" + _bd_autoloader_dir "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" # sub-directories for bd_load_config_dir_name in "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}"/*; do - [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" + [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done _bd_load_config_dir "${BD_HOME}" @@ -395,11 +395,11 @@ _bd_load_config() { [ -f "${PWD}/${BD_CONFIG_FILE}" ] && [ -r "${PWD}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${PWD}/${BD_CONFIG_FILE}" ${1} if [ "${1}" != 'preload' ] && [ -d "${PWD}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${PWD}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoload_dir "${PWD}/${BD_AUTOLOADER_SUB_DIR}" + _bd_autoloader_dir "${PWD}/${BD_AUTOLOADER_SUB_DIR}" # sub-directories for bd_load_config_dir_name in "${PWD}/${BD_AUTOLOADER_SUB_DIR}"/*; do - [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoload_dir "${bd_load_config_dir_name}" + [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done _bd_load_config_dir "${PWD}" @@ -410,7 +410,7 @@ _bd_load_config() { } export -f _bd_load_config -# process BD_AUTOLOADER_CONFIG_DIRS with _bd_autoload_dir(); i.e. look for etc/bash.d in other/specific locations +# process BD_AUTOLOADER_CONFIG_DIRS with _bd_autoloader_dir(); i.e. look for etc/bash.d in other/specific locations _bd_load_config_dir() { _bd_debug "${FUNCNAME}(${@})" 55 @@ -423,10 +423,10 @@ _bd_load_config_dir() { for bd_load_config_dirs in "${BD_AUTOLOADER_CONFIG_DIRS[@]}"; do if [ "${bd_load_config_dirs:0:1}" == "/" ]; then # qualified path - [ -d "${bd_load_config_dirs}" ] && [ -r "${bd_load_config_dirs}" ] && _bd_autoload_dir "${bd_load_config_dirs}" + [ -d "${bd_load_config_dirs}" ] && [ -r "${bd_load_config_dirs}" ] && _bd_autoloader_dir "${bd_load_config_dirs}" else # relative path - [ -d "${bd_load_config_dir_name}/${bd_load_config_dirs}" ] && [ -r "${bd_load_config_dir_name}/${bd_load_config_dirs}" ] && _bd_autoload_dir "${bd_load_config_dir_name}/${bd_load_config_dirs}" + [ -d "${bd_load_config_dir_name}/${bd_load_config_dirs}" ] && [ -r "${bd_load_config_dir_name}/${bd_load_config_dirs}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}/${bd_load_config_dirs}" fi done fi @@ -541,7 +541,7 @@ _bd_main() { _bd_debug "${BD_SOURCE} ${1} pass; invoke autoloader" 10 - _bd_autoload ${@} + _bd_autoloader ${@} ;; esac @@ -731,10 +731,10 @@ _bd_namespace_reset() { if [ "${1}" == 'private' ]; then # private function names - bd_function_names+=(_bd_autoload) - bd_function_names+=(_bd_autoload_dir) - bd_function_names+=(_bd_autoload_execute) - bd_function_names+=(_bd_autoload_execute_array) + bd_function_names+=(_bd_autoloader) + bd_function_names+=(_bd_autoloader_dir) + bd_function_names+=(_bd_autoloader_execute) + bd_function_names+=(_bd_autoloader_execute_array) bd_function_names+=(_bd_bootstrap) bd_function_names+=(_bd_caller) bd_function_names+=(_bd_load_config) diff --git a/doc/bd.md b/doc/bd.md index a86add7..75acc2f 100644 --- a/doc/bd.md +++ b/doc/bd.md @@ -46,7 +46,7 @@ The Bash script, `bd.sh`, implements a sophisticated directory autoloader for ma ### Utility Functions -* `_bd_autoload` - Starts the autoload procedure to predictably source files in the current shell. +* `_bd_autoloader` - Starts the autoloader procedure to predictably source files in the current shell. * `_bd_debug` - Provides consistent, color-coded debug messages for improved readability. * `_bd_os` - Determines the operating system & exports `BD_OS*` values for use in other scripts. * `_bd_realpath` - A portable replacement for `realpath` or `readlink`. diff --git a/etc/bash.d/bd-bits.sh b/etc/bash.d/bd-bits.sh index 8b88a0d..dd9c89f 100644 --- a/etc/bash.d/bd-bits.sh +++ b/etc/bash.d/bd-bits.sh @@ -182,10 +182,10 @@ _bd_bits_hash() { echo "${BD_BITS_DIR}" echo - local bd_autoload_dir bd_autoload_file - for bd_autoload_file in "${BD_BITS_DIR}"/*.{bash,sh}; do - if [ -r "${bd_autoload_file}" ]; then - command md5sum "${bd_autoload_file}" + local bd_autoloader_dir bd_autoloader_file + for bd_autoloader_file in "${BD_BITS_DIR}"/*.{bash,sh}; do + if [ -r "${bd_autoloader_file}" ]; then + command md5sum "${bd_autoloader_file}" fi done echo diff --git a/etc/bash.d/bd-sundry.sh b/etc/bash.d/bd-sundry.sh index ede9e4e..84a2728 100644 --- a/etc/bash.d/bd-sundry.sh +++ b/etc/bash.d/bd-sundry.sh @@ -43,8 +43,8 @@ fi _bd_sundry() { _bd_debug "${FUNCNAME} ${@}" 55 - if [[ "${1}" == "dir"* ]] || [ "${1}" == "autoload_dirs" ]; then - _bd_autoload_dirs ${@} + if [[ "${1}" == "dir"* ]] || [ "${1}" == "autoloader_dirs" ]; then + _bd_autoloader_dirs ${@} fi if [[ "${1}" == "env"* ]]; then @@ -57,24 +57,24 @@ _bd_sundry() { } # info BD_AUTOLOADER_DIRS array -_bd_autoload_dirs() { +_bd_autoloader_dirs() { _bd_debug "${FUNCNAME}(${@})" 55 if [ ${#2} -gt 0 ]; then if [ "${2}" == 'hash' ] || [ "${2}" == 'ls' ]; then - local bd_autoload_dir bd_autoload_file - for bd_autoload_dir in "${BD_AUTOLOADER_DIRS[@]}"; do - if [ -d "${bd_autoload_dir}" ]; then - echo "# ${bd_autoload_dir}" + local bd_autoloader_dir bd_autoloader_file + for bd_autoloader_dir in "${BD_AUTOLOADER_DIRS[@]}"; do + if [ -d "${bd_autoloader_dir}" ]; then + echo "# ${bd_autoloader_dir}" echo - for bd_autoload_file in "${bd_autoload_dir}"/*.{bash,sh}; do - if [ -r "${bd_autoload_file}" ]; then - _bd_debug "bd_autoload_file=${bd_autoload_file}" 18 + for bd_autoloader_file in "${bd_autoloader_dir}"/*.{bash,sh}; do + if [ -r "${bd_autoloader_file}" ]; then + _bd_debug "bd_autoloader_file=${bd_autoloader_file}" 18 if [ "${2}" == 'hash' ]; then - command md5sum "${bd_autoload_file}" + command md5sum "${bd_autoloader_file}" fi if [ "${2}" == 'ls' ]; then - command ls -1d "${bd_autoload_file}" + command ls -1d "${bd_autoloader_file}" fi fi done From f141b360bf988fe3ff2bc4b88dd04f9921cef18b Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Fri, 22 Nov 2024 13:45:39 -0500 Subject: [PATCH 03/11] etc/bash.d/bd-help.sh: removed; moved into bd.sh --- bd.sh | 98 +++++++++++++++++++++++++++++-------------- etc/bash.d/bd-help.sh | 76 --------------------------------- 2 files changed, 67 insertions(+), 107 deletions(-) delete mode 100644 etc/bash.d/bd-help.sh diff --git a/bd.sh b/bd.sh index f059bb8..c597c88 100644 --- a/bd.sh +++ b/bd.sh @@ -92,6 +92,39 @@ _bd_autoloader() { } export -f _bd_autoloader +# add only unique, existing directories to the BD_AUTOLOADER_DIRS array (& prevent dupes & preserve the given order) +_bd_autoloader_dir() { + _bd_debug "${FUNCNAME}(${@})" 55 + + local bd_dir_name="${1//\/\//\/}" + + bd_dir_name="${bd_dir_name//\/\//\/}" + bd_dir_name="${bd_dir_name//\/\//\/}" + + _bd_debug "1 bd_dir_name = ${bd_dir_name}" 6 + + [ ${#bd_dir_name} -eq 0 ] && return 1 + + [ ! -d "${bd_dir_name}" ] && return 1 + + bd_dir_name="$(_bd_realpath "${bd_dir_name}")" + + _bd_debug "2 bd_dir_name = ${bd_dir_name}" 6 + + [ ${#BD_AUTOLOADER_DIRS} -eq 0 ] && export BD_AUTOLOADER_DIRS=() + + local bd_dir_exists=0 # false + local bd_autoloader_dir + + for bd_autoloader_dir in ${BD_AUTOLOADER_DIRS[@]}; do + [ ${bd_dir_exists} -eq 1 ] && break + [ "${bd_autoloader_dir}" == "${bd_dir_name}" ] && bd_dir_exists=1 + done + + [ ${bd_dir_exists} -eq 0 ] && BD_AUTOLOADER_DIRS+=("${bd_dir_name}") && _bd_debug "bd_dir_name = ${bd_dir_name}" 2 +} +export -f _bd_autoloader_dir + # predictably execute commands from every (.bash or .sh) file into the current shell _bd_autoloader_execute() { _bd_debug "${FUNCNAME}(${@})" 55 @@ -287,38 +320,41 @@ _bd_debug_ms() { } export -f _bd_debug_ms -# add only unique, existing directories to the BD_AUTOLOADER_DIRS array (& prevent dupes & preserve the given order) -_bd_autoloader_dir() { - _bd_debug "${FUNCNAME}(${@})" 55 - - local bd_dir_name="${1//\/\//\/}" - - bd_dir_name="${bd_dir_name//\/\//\/}" - bd_dir_name="${bd_dir_name//\/\//\/}" - - _bd_debug "1 bd_dir_name = ${bd_dir_name}" 6 - - [ ${#bd_dir_name} -eq 0 ] && return 1 - - [ ! -d "${bd_dir_name}" ] && return 1 - - bd_dir_name="$(_bd_realpath "${bd_dir_name}")" - - _bd_debug "2 bd_dir_name = ${bd_dir_name}" 6 - - [ ${#BD_AUTOLOADER_DIRS} -eq 0 ] && export BD_AUTOLOADER_DIRS=() - - local bd_dir_exists=0 # false - local bd_autoloader_dir - - for bd_autoloader_dir in ${BD_AUTOLOADER_DIRS[@]}; do - [ ${bd_dir_exists} -eq 1 ] && break - [ "${bd_autoloader_dir}" == "${bd_dir_name}" ] && bd_dir_exists=1 - done - - [ ${bd_dir_exists} -eq 0 ] && BD_AUTOLOADER_DIRS+=("${bd_dir_name}") && _bd_debug "bd_dir_name = ${bd_dir_name}" 2 +# display help +_bd_help() { + local bd_bits_dir="${BD_BITS_DIR:-${BD_DIR}/etc/bash.d/bits}" + local bd_help='' + bd_help+="usage: bd [option]\n" + bd_help+="\n" + bd_help+="options:\n" + bd_help+="\n" + bd_help+=" ['' | *] - (default) invoke autoloader\n" + bd_help+="\n" + bd_help+=" env [BD_* variable] - display BD_* environment variables & values, and optionally the value of a single variable\n" + bd_help+=" dir [hash | ls] - display only BD_AUTOLOADER_DIRS array values, and optionally hash or list them\n" + bd_help+="\n" + bd_help+=" license - display MIT license\n" + bd_help+=" version - display version\n" + bd_help+="\n" + bd_help+=" upgrade - upgrade bd; pull the latest version from " + if [ ${#BD_GIT_URL} -gt 0 ]; then + bd_help+="${BD_GIT_URL}" + else + bd_help+="GitHub" + fi + bd_help+="\n" + bd_help+="\n" + bd_help+=" bits get [name] - get a file from an and put it in ${bd_bits_dir}/[name]\n" + bd_help+=" bits [hash | ls] - display all (.bash & .sh) files in ${bd_bits_dir}\n" + bd_help+=" bits rm - remove bits named from ${bd_bits_dir}\n" + #bd_help+=" bits put - get a file and put/upload it to \n" # WIP + bd_help+="\n" + bd_help+=" functions - export public _bd_ functions but do not invoke autoloader\n" + bd_help+="\n" + bd_help+=" [help | h | --help | -h] - this message\n" + + printf "${bd_help}" } -export -f _bd_autoloader_dir # load all config files & directories _bd_load_config() { diff --git a/etc/bash.d/bd-help.sh b/etc/bash.d/bd-help.sh deleted file mode 100644 index ea11244..0000000 --- a/etc/bash.d/bd-help.sh +++ /dev/null @@ -1,76 +0,0 @@ -# bd-help.sh: display help for bd - -# MIT License -# =========== -# -# Copyright (C) 2018-2024 Joseph Tingiris -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -# https://github.com/bash-d/bd/blob/main/LICENSE.md - -# -# init -# - -# prevent non-sourced execution -if [ "${0}" == "${BASH_SOURCE}" ]; then - printf "\n${BASH_SOURCE} | ERROR | this code is not designed to be executed (instead, 'source ${BASH_SOURCE}')\n\n" - exit 1 -fi - -# -# main -# - -# display help -_bd_help() { - local bd_bits_dir="${BD_BITS_DIR:-${BD_DIR}/etc/bash.d/bits}" - local bd_help='' - bd_help+="usage: bd [option]\n" - bd_help+="\n" - bd_help+="options:\n" - bd_help+="\n" - bd_help+=" ['' | *] - (default) invoke autoloader\n" - bd_help+="\n" - bd_help+=" env [BD_* variable] - display BD_* environment variables & values, and optionally the value of a single variable\n" - bd_help+=" dir [hash | ls] - display only BD_AUTOLOADER_DIRS array values, and optionally hash or list them\n" - bd_help+="\n" - bd_help+=" license - display MIT license\n" - bd_help+=" version - display version\n" - bd_help+="\n" - bd_help+=" upgrade - upgrade bd; pull the latest version from " - if [ ${#BD_GIT_URL} -gt 0 ]; then - bd_help+="${BD_GIT_URL}" - else - bd_help+="GitHub" - fi - bd_help+="\n" - bd_help+="\n" - bd_help+=" bits get [name] - get a file from an and put it in ${bd_bits_dir}/[name]\n" - bd_help+=" bits [hash | ls] - display all (.bash & .sh) files in ${bd_bits_dir}\n" - bd_help+=" bits rm - remove bits named from ${bd_bits_dir}\n" - #bd_help+=" bits put - get a file and put/upload it to \n" # WIP - bd_help+="\n" - bd_help+=" functions - export public _bd_ functions but do not invoke autoloader\n" - bd_help+="\n" - bd_help+=" [help | h | --help | -h] - this message\n" - - printf "${bd_help}" -} From f55d96e790cffa8c0bf6c00be30a33c16b9f1462 Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Fri, 22 Nov 2024 14:10:17 -0500 Subject: [PATCH 04/11] started considering lazy loading, like ksh/zsh autoload --- bd.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bd.sh b/bd.sh index c597c88..12725f2 100644 --- a/bd.sh +++ b/bd.sh @@ -48,6 +48,12 @@ export BD_VERSION=0.46.0 # functions # +# mimic ksh/zsh autoload builtin +autoload() { + _bd_autoload ${@} +} +export -f autoload + # primary functional interfce for this script bd() { [ -r "${BD_SOURCE}" ] && . "${BD_SOURCE}" ${@} @@ -66,6 +72,11 @@ if ! type -t _bd_ansi &> /dev/null; then fi fi +# mimic ksh/zsh function autoload +_bd_autoload() { + '' +} + # start the autoloader procedure _bd_autoloader() { _bd_debug "${FUNCNAME}(${@})" 55 @@ -326,16 +337,21 @@ _bd_help() { local bd_help='' bd_help+="usage: bd [option]\n" bd_help+="\n" + bd_help+="options:\n" bd_help+="\n" + bd_help+=" ['' | *] - (default) invoke autoloader\n" bd_help+="\n" + bd_help+=" env [BD_* variable] - display BD_* environment variables & values, and optionally the value of a single variable\n" bd_help+=" dir [hash | ls] - display only BD_AUTOLOADER_DIRS array values, and optionally hash or list them\n" bd_help+="\n" + bd_help+=" license - display MIT license\n" bd_help+=" version - display version\n" bd_help+="\n" + bd_help+=" upgrade - upgrade bd; pull the latest version from " if [ ${#BD_GIT_URL} -gt 0 ]; then bd_help+="${BD_GIT_URL}" @@ -343,11 +359,13 @@ _bd_help() { bd_help+="GitHub" fi bd_help+="\n" + bd_help+="\n" bd_help+=" bits get [name] - get a file from an and put it in ${bd_bits_dir}/[name]\n" bd_help+=" bits [hash | ls] - display all (.bash & .sh) files in ${bd_bits_dir}\n" bd_help+=" bits rm - remove bits named from ${bd_bits_dir}\n" #bd_help+=" bits put - get a file and put/upload it to \n" # WIP + bd_help+="\n" bd_help+=" functions - export public _bd_ functions but do not invoke autoloader\n" bd_help+="\n" From c73ede6d7b385051d5cedf7a5b2559e0745e51cb Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Fri, 22 Nov 2024 14:11:56 -0500 Subject: [PATCH 05/11] renamed BD_AUTOLOADER_SUB_DIR to BD_SUB_DIR --- bd.sh | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/bd.sh b/bd.sh index 12725f2..da53541 100644 --- a/bd.sh +++ b/bd.sh @@ -62,8 +62,8 @@ export -f bd # stub _bd_ansi() until bd-ansi.sh is fully loaded (needed for embedded _bd_debug) if ! type -t _bd_ansi &> /dev/null; then - if [ -r "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}/bd-ansi.sh" ]; then - . "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}/bd-ansi.sh" + if [ -r "${BD_DIR}/${BD_SUB_DIR}/bd-ansi.sh" ]; then + . "${BD_DIR}/${BD_SUB_DIR}/bd-ansi.sh" else _bd_ansi() { return @@ -225,10 +225,10 @@ export -f _bd_autoloader_execute_array _bd_bootstrap() { _bd_caller || return 1 - export BD_AUTOLOADER_SUB_DIR='etc/bash.d' + export BD_SUB_DIR='etc/bash.d' export BD_CONFIG_FILE='.bd.conf' export BD_DEBUG=${BD_DEBUG:-0} # level >0 enables debugging - export BD_BITS_DIR="${BD_BITS_DIR:-${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}/bits}" + export BD_BITS_DIR="${BD_BITS_DIR:-${BD_DIR}/${BD_SUB_DIR}/bits}" export BD_SOURCE="$(_bd_realpath "${BASH_SOURCE}")" _bd_debug "BD_SOURCE = ${BD_SOURCE} (${FUNCNAME})" 2 @@ -386,25 +386,25 @@ _bd_load_config() { fi # ${BD_DIR} - if [ ${#BD_DIR} -gt 0 ] && [ ${#BD_AUTOLOADER_SUB_DIR} -gt 0 ]; then + if [ ${#BD_DIR} -gt 0 ] && [ ${#BD_SUB_DIR} -gt 0 ]; then [ -f "${BD_DIR}/${BD_CONFIG_FILE}" ] && [ -r "${BD_DIR}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${BD_DIR}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoloader_dir "${BD_DIR}/${BD_AUTOLOADER_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${BD_DIR}/${BD_SUB_DIR}" ] && [ -r "${BD_DIR}/${BD_SUB_DIR}" ]; then + _bd_autoloader_dir "${BD_DIR}/${BD_SUB_DIR}" _bd_load_config_dir "${BD_DIR}" fi fi - # /${BD_AUTOLOADER_SUB_DIR}/.. (/etc) - if [ ${#BD_AUTOLOADER_SUB_DIR} -gt 0 ] && [ "/${BD_AUTOLOADER_SUB_DIR}/.." != "//.." ]; then - [ -f "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && [ -r "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && _bd_load_config_file "/${BD_AUTOLOADER_SUB_DIR}/../${BD_CONFIG_FILE/./}" ${1} + # /${BD_SUB_DIR}/.. (/etc) + if [ ${#BD_SUB_DIR} -gt 0 ] && [ "/${BD_SUB_DIR}/.." != "//.." ]; then + [ -f "/${BD_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && [ -r "/${BD_SUB_DIR}/../${BD_CONFIG_FILE/./}" ] && _bd_load_config_file "/${BD_SUB_DIR}/../${BD_CONFIG_FILE/./}" ${1} - if [ "${1}" != 'preload' ] && [ -d "/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoloader_dir "/${BD_AUTOLOADER_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "/${BD_SUB_DIR}" ] && [ -r "/${BD_SUB_DIR}" ]; then + _bd_autoloader_dir "/${BD_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "/${BD_AUTOLOADER_SUB_DIR}"/*; do + for bd_load_config_dir_name in "/${BD_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done @@ -416,11 +416,11 @@ _bd_load_config() { if [ ${#HOME} -gt 0 ] && [ "${HOME}" != "/" ]; then [ -f "${HOME}/${BD_CONFIG_FILE}" ] && [ -r "${HOME}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${HOME}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${HOME}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${HOME}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoloader_dir "${HOME}/${BD_AUTOLOADER_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${HOME}/${BD_SUB_DIR}" ] && [ -r "${HOME}/${BD_SUB_DIR}" ]; then + _bd_autoloader_dir "${HOME}/${BD_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "${HOME}/${BD_AUTOLOADER_SUB_DIR}"/*; do + for bd_load_config_dir_name in "${HOME}/${BD_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done @@ -432,11 +432,11 @@ _bd_load_config() { if [ ${#BD_HOME} -gt 0 ] && [ "${BD_HOME}" != "/" ] && [ "${BD_HOME}" != "${HOME}" ]; then [ -f "${BD_HOME}/${BD_CONFIG_FILE}" ] && [ -r "${BD_HOME}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${BD_HOME}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoloader_dir "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${BD_HOME}/${BD_SUB_DIR}" ] && [ -r "${BD_HOME}/${BD_SUB_DIR}" ]; then + _bd_autoloader_dir "${BD_HOME}/${BD_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "${BD_HOME}/${BD_AUTOLOADER_SUB_DIR}"/*; do + for bd_load_config_dir_name in "${BD_HOME}/${BD_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done @@ -448,11 +448,11 @@ _bd_load_config() { if [ ${#PWD} -gt 0 ] && [ "${PWD}" != "/etc" ] && [ "${PWD}" != "${BD_HOME}" ] && [ "${PWD}" != "${HOME}" ]; then [ -f "${PWD}/${BD_CONFIG_FILE}" ] && [ -r "${PWD}/${BD_CONFIG_FILE}" ] && _bd_load_config_file "${PWD}/${BD_CONFIG_FILE}" ${1} - if [ "${1}" != 'preload' ] && [ -d "${PWD}/${BD_AUTOLOADER_SUB_DIR}" ] && [ -r "${PWD}/${BD_AUTOLOADER_SUB_DIR}" ]; then - _bd_autoloader_dir "${PWD}/${BD_AUTOLOADER_SUB_DIR}" + if [ "${1}" != 'preload' ] && [ -d "${PWD}/${BD_SUB_DIR}" ] && [ -r "${PWD}/${BD_SUB_DIR}" ]; then + _bd_autoloader_dir "${PWD}/${BD_SUB_DIR}" # sub-directories - for bd_load_config_dir_name in "${PWD}/${BD_AUTOLOADER_SUB_DIR}"/*; do + for bd_load_config_dir_name in "${PWD}/${BD_SUB_DIR}"/*; do [ -d "${bd_load_config_dir_name}" ] && [ -r "${bd_load_config_dir_name}" ] && _bd_autoloader_dir "${bd_load_config_dir_name}" done @@ -866,7 +866,7 @@ _bd_private() { bd_private_variable_names=() - bd_private_variable_names+=('BD_AUTOLOADER_SUB_DIR') + bd_private_variable_names+=('BD_SUB_DIR') bd_private_variable_names+=('BD_CONFIG_FILE') bd_private_variable_names+=('BD_DECLARE') bd_private_variable_names+=('BD_OIFS') From 5c0c7245bbeefde7037589f448d336d309a74b2b Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Fri, 22 Nov 2024 14:15:14 -0500 Subject: [PATCH 06/11] allow setting BD_SUB_DIR --- bd.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bd.sh b/bd.sh index da53541..01a2b1e 100644 --- a/bd.sh +++ b/bd.sh @@ -225,12 +225,13 @@ export -f _bd_autoloader_execute_array _bd_bootstrap() { _bd_caller || return 1 - export BD_SUB_DIR='etc/bash.d' export BD_CONFIG_FILE='.bd.conf' export BD_DEBUG=${BD_DEBUG:-0} # level >0 enables debugging - export BD_BITS_DIR="${BD_BITS_DIR:-${BD_DIR}/${BD_SUB_DIR}/bits}" export BD_SOURCE="$(_bd_realpath "${BASH_SOURCE}")" + export BD_SUB_DIR="${BD_SUB_DIR:-etc/bash.d}" + export BD_BITS_DIR="${BD_BITS_DIR:-${BD_DIR}/${BD_SUB_DIR}/bits}" + _bd_debug "BD_SOURCE = ${BD_SOURCE} (${FUNCNAME})" 2 export BD_DIR="${BD_SOURCE%/*}" From 1469edbcd657b2d3e69162f16b65050cf235de3e Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Sun, 23 Feb 2025 20:07:07 -0500 Subject: [PATCH 07/11] preserve WAYLAND_DISPLAY --- etc/bash.d/bd-root.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/etc/bash.d/bd-root.sh b/etc/bash.d/bd-root.sh index f5ae3d3..e7bd322 100644 --- a/etc/bash.d/bd-root.sh +++ b/etc/bash.d/bd-root.sh @@ -66,10 +66,16 @@ if [ "${USER}" != "root" ]; then BD_ROOT_SUDO_MUST_PRESERVE_ENV="${BD_ROOT_SUDO_MUST_PRESERVE_ENV//,,/,}" - alias bd-root="${BD_ROOT_SUDO_BIN} --preserve-env=${BD_ROOT_SUDO_MUST_PRESERVE_ENV} -u root ${BD_ROOT_BASH_BIN} --init-file ${BD_BASH_INIT_FILE}" - alias bd-root-login="${BD_ROOT_SUDO_BIN} --preserve-env=${BD_ROOT_SUDO_MUST_PRESERVE_ENV} -u root --login" + export BD_ROOT_SUDO_WAYLAND_DISPLAY="" + if [ "${WAYLAND_DISPLAY}" != "" ] && [ "${XDG_RUNTIME_DIR}" != "" ]; then + BD_ROOT_SUDO_WAYLAND_DISPLAY="WAYLAND_DISPLAY=${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY} " + BD_ROOT_SUDO_MUST_PRESERVE_ENV+=",WAYLAND_DISPLAY" + fi + + alias bd-root="${BD_ROOT_SUDO_WAYLAND_DISPLAY}${BD_ROOT_SUDO_BIN} --preserve-env=${BD_ROOT_SUDO_MUST_PRESERVE_ENV} -u root ${BD_ROOT_BASH_BIN} --init-file ${BD_BASH_INIT_FILE}" + alias bd-root-login="${BD_ROOT_SUDO_WAYLAND_DISPLAY}${BD_ROOT_SUDO_BIN} --preserve-env=${BD_ROOT_SUDO_MUST_PRESERVE_ENV} -u root --login" - unset -v BD_ROOT_SUDO_MUST_PRESERVE_ENV + unset -v BD_ROOT_SUDO_MUST_PRESERVE_ENV BD_ROOT_SUDO_WAYLAND_DISPLAY else if [ ${#BD_ROOT_SU_BIN} -gt 0 ] && [ -x "${BD_ROOT_SU_BIN}" ]; then alias bd-root="su --login root -c '${BD_ROOT_BASH_BIN} --init-file ${BD_BASH_INIT_FILE}'" From 88ee138ec831e23a656837ac9fc60a8340516472 Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Sun, 23 Feb 2025 20:07:18 -0500 Subject: [PATCH 08/11] 0.46.1 --- RELEASE-NOTES.md | 11 +++++++++++ bd.sh | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2a2e1b0..b0e83bf 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,14 @@ +# 0.46.1 +- etc/bash.d/bd-root.sh: preserve WAYLAND_DISPLAY + +# 0.46.0 +- bd.sh: allow setting BD_SUB_DIR +- bd.sh: renamed BD_AUTOLOADER_SUB_DIR to BD_SUB_DIR +- bd.sh: started considering lazy loading, like ksh/zsh autoload +- bd.sh: etc/bash.d/bd-help.sh: removed; moved into bd.sh +- bd.sh: renamed bd_autoload* to bd_autoloader* +- all: renamed BD_AUTOLOAD_* to BD_AUTOLAODER_* 0.45.1 + # 0.45.1 - all: renamed 'snippets' to 'bits' diff --git a/bd.sh b/bd.sh index 01a2b1e..bbcf604 100644 --- a/bd.sh +++ b/bd.sh @@ -42,7 +42,7 @@ if [ "${BASH_SOURCE}" == '' ]; then return 1 &> /dev/null fi -export BD_VERSION=0.46.0 +export BD_VERSION=0.46.1 # # functions From f69d867eefc047f17e28af0954c649d94aa49185 Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Sun, 2 Mar 2025 21:23:50 -0500 Subject: [PATCH 09/11] /home/jtingiris/.bd checkpoint source /etc/profile --- RELEASE-NOTES.md | 1 + example/.bashrc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index b0e83bf..d89b871 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,4 +1,5 @@ # 0.46.1 +- example/.bashrc: source /etc/profile - etc/bash.d/bd-root.sh: preserve WAYLAND_DISPLAY # 0.46.0 diff --git a/example/.bashrc b/example/.bashrc index afb833d..cbeeaab 100644 --- a/example/.bashrc +++ b/example/.bashrc @@ -31,10 +31,10 @@ if [ ${#SSH_CONNECTION} -gt 0 ] && [ ${#SSH_TTY} -eq 0 ] && [ ${#STY} -eq 0 ] && fi # -# source system bashrc +# source system profile # -[ -f /etc/bashrc ] && source /etc/bashrc +[ -f /etc/profile ] && source /etc/profile # # bash.d (0.40+) From c43b93aad8bfde6d98dc14444058b591cd8cb8cf Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Wed, 12 Mar 2025 21:15:40 -0400 Subject: [PATCH 10/11] BD_CLIPBOARD --- RELEASE-NOTES.md | 4 +++- bd.sh | 2 +- etc/bash.d/bd-root.sh | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index d89b871..cd1b7d3 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,6 +1,8 @@ # 0.46.1 -- example/.bashrc: source /etc/profile +- bd.sh: don't unset BD_CLIPBOARD - etc/bash.d/bd-root.sh: preserve WAYLAND_DISPLAY +- etc/bash.d/bd-root.sh: preserve BD_CLIPBOARD +- example/.bashrc: source /etc/profile # 0.46.0 - bd.sh: allow setting BD_SUB_DIR diff --git a/bd.sh b/bd.sh index bbcf604..e56bf41 100644 --- a/bd.sh +++ b/bd.sh @@ -758,7 +758,7 @@ _bd_namespace_reset() { _bd_private "${bd_variable_name}" && continue # exclude these, too - [ "${bd_variable_name}" == 'BD_BASH_INIT_FILE' ] && continue + [ "${bd_variable_name}" == 'BD_CLIPBOARD' ] && continue [ "${bd_variable_name}" == 'BD_DEBUG' ] && continue [ "${bd_variable_name}" == 'BD_DIR' ] && continue [ "${bd_variable_name}" == 'BD_HOME' ] && continue diff --git a/etc/bash.d/bd-root.sh b/etc/bash.d/bd-root.sh index e7bd322..4e0f439 100644 --- a/etc/bash.d/bd-root.sh +++ b/etc/bash.d/bd-root.sh @@ -61,6 +61,7 @@ if [ "${USER}" != "root" ]; then fi export BD_ROOT_SUDO_MUST_PRESERVE_ENV="BD_HOME,BD_USER" + [ "${BD_CLIPBOARD}" != "" ] && BD_ROOT_SUDO_MUST_PRESERVE_ENV+=",BD_CLIPBOARD" [ "${BD_ROOT_SUDO_PRESERVE_ENV}" != "" ] && BD_ROOT_SUDO_MUST_PRESERVE_ENV+=",${BD_ROOT_SUDO_PRESERVE_ENV}" [[ "${BD_ROOT_SUDO_MUST_PRESERVE_ENV}" != *",SSH_AUTH_SOCK"* ]] && [ "${SSH_AUTH_SOCK}" != "" ] && BD_ROOT_SUDO_MUST_PRESERVE_ENV+=",SSH_AUTH_SOCK" From a45061efba131556f29c5da6367dca1aeb27ebd4 Mon Sep 17 00:00:00 2001 From: "jtingiris@d0" Date: Tue, 25 Mar 2025 17:53:45 -0400 Subject: [PATCH 11/11] 0.46.1 --- README.md | 10 +++++----- bd.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index afc2776..ed771de 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Autoloader for Bash +# an autoloader for bash [Documentation](https://github.com/bash-d/bd/tree/main/doc) -### Automatic Installation (backup & replace existing .bash_profile/.bashrc) +### Automatic Installation ```sh # main, latest @@ -16,9 +16,9 @@ cd; curl -Ls https://raw.githubusercontent.com/bash-d/bd/main/bd-install.sh | /u [ -r ~/.bd/bd.sh ] && source ~/.bd/bd.sh ${@} ``` +## Example + + ## License [MIT License](https://github.com/bash-d/bd/blob/main/LICENSE.md) - -## Example - diff --git a/bd.sh b/bd.sh index e56bf41..f50dc97 100644 --- a/bd.sh +++ b/bd.sh @@ -1,4 +1,4 @@ -# bd.sh: bash directory (bash.d) autoloader +# bd.sh: an autoloader for bash # https://github.com/bash-d/bd/blob/main/README.md