Bash : Drop BASH_MODULE_PATH.

This commit is contained in:
Dmitry Voronin 2024-03-08 22:40:38 +03:00
parent 011d46bcfc
commit 0f07aa1e43
9 changed files with 34 additions and 19 deletions

View file

@ -1,8 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
self=$(realpath ${0}) self=$(/usr/bin/env realpath ${0})
cd ${self%/*} cd ${self%/*}
export BASH_PATH="../module/common/bash"
# Source modules.
for file in ${BASH_PATH}/module/*.sh; do
source "${file}"
done
IFS=$'\n' IFS=$'\n'
file="Bash.md" file="Bash.md"
@ -25,7 +32,7 @@ echo >> "${file}"
# Fill with data. # Fill with data.
for module in $(find_module); do for module in $(find_module); do
# Skip if no functions. # Skip if no functions.
[[ "$(find_function ${module} | grep -v ^_)" = "" ]] && continue [[ "$(find_function ${module} | /usr/bin/env grep -v ^_)" = "" ]] && continue
# Print module title. # Print module title.
echo "## ${module^}." >> "${file}" echo "## ${module^}." >> "${file}"
@ -40,8 +47,8 @@ for module in $(find_module); do
[[ "${fun}" =~ ^_.* ]] && continue [[ "${fun}" =~ ^_.* ]] && continue
# Parse help info. # Parse help info.
desc="$(help ${fun} | grep -v Usage\: | tr '\n' ' ')" desc="$(help ${fun} | /usr/bin/env grep -v Usage\: | /usr/bin/env tr '\n' ' ')"
usage="$(help ${fun} | grep Usage\: | sed -e s\/Usage\:\ \/\/)" usage="$(help ${fun} | /usr/bin/env grep Usage\: | /usr/bin/env sed -e s\/Usage\:\ \/\/)"
# Use function name if no usage info available. # Use function name if no usage info available.
[[ "${usage}" = "" ]] && usage="${fun}" [[ "${usage}" = "" ]] && usage="${fun}"

View file

@ -1,3 +1,3 @@
.PHONY: doc .PHONY: doc
doc: doc:
@.doc/Generate.sh @env -i .doc/Generate.sh

View file

@ -1,7 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [[ -z ${BASH_PATH} ]]; then
echo "BASH_PATH not defined."
exit 1
fi
# Source modules. # Source modules.
for file in /etc/bash/module/*.sh; do for file in ${BASH_PATH}/module/*.sh; do
source "${file}" source "${file}"
done done

View file

@ -1,7 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [[ -z ${BASH_PATH} ]]; then
echo "BASH_PATH not defined."
exit 1
fi
# Source modules. # Source modules.
for file in /etc/bash/module/*.sh; do for file in ${BASH_PATH}/module/*.sh; do
source "${file}" source "${file}"
done done

View file

@ -49,7 +49,6 @@ in {
".ssh/config".source = ./common/ssh/Config; ".ssh/config".source = ./common/ssh/Config;
}; };
home.sessionVariables = { home.sessionVariables = {
BASH_MODULE_PATH = "${homePath}/.bash/module";
BASH_PATH = "${homePath}/.bash"; BASH_PATH = "${homePath}/.bash";
}; };
programs.bash = { programs.bash = {

View file

@ -1,7 +1,6 @@
{ environment, lib, ... }: { { environment, lib, ... }: {
environment.etc.bash.source = ./bash; environment.etc.bash.source = ./bash;
environment.shellAliases = lib.mkForce {}; environment.shellAliases = lib.mkForce {};
environment.variables.BASH_MODULE_PATH = "/etc/bash/module";
environment.variables.BASH_PATH = "/etc/bash"; environment.variables.BASH_PATH = "/etc/bash";
programs.bash.interactiveShellInit = "source /etc/bash/Bashrc.sh"; programs.bash.interactiveShellInit = "source /etc/bash/Bashrc.sh";
} }

View file

@ -5,7 +5,7 @@
[[ -f /etc/bashrc ]] && source /etc/bashrc [[ -f /etc/bashrc ]] && source /etc/bashrc
# Src custom modules. # Src custom modules.
for module in ${BASH_MODULE_PATH}/*.sh; do for module in ${BASH_PATH}/module/*.sh; do
source "${module}" source "${module}"
done done

View file

@ -6,7 +6,7 @@ function find_ext() {
# Find all modules. # Find all modules.
function find_module() { function find_module() {
ls "${BASH_MODULE_PATH}" | sed -e "s/.sh$//" /usr/bin/env ls "${BASH_PATH}/module" | /usr/bin/env sed -e "s/.sh$//"
} }
# Find all module functions. # Find all module functions.
@ -15,7 +15,7 @@ function find_module() {
function find_function() { function find_function() {
local module="${1}" local module="${1}"
[[ "${module}" = "" ]] && module="*" [[ "${module}" = "" ]] && module="*"
cat "${BASH_MODULE_PATH}"/${module}.sh | grep "^function.*()" | sed -e "s/^function //" -e "s/().*//" /usr/bin/env cat "${BASH_PATH}/module"/${module}.sh | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//"
} }
# Autocomplete with module. # Autocomplete with module.

View file

@ -3,12 +3,12 @@
function help() { function help() {
local fun="${1}" local fun="${1}"
if [[ "${fun}" = "" ]] || [[ "$(find_function | grep ${fun})" = "" ]]; then if [[ "${fun}" = "" ]] || [[ "$(find_function | /usr/bin/env grep ${fun})" = "" ]]; then
help help help help
return 2 return 2
fi fi
sed -e '$s/$/\n/' -s "${BASH_MODULE_PATH}"/* | sed -n -e "/function ${fun}()/q;p" | tac | sed -n -e "/^$/q;p" | tac | sed -e "s/^# \+//" -e "\$i \ " /usr/bin/env sed -e '$s/$/\n/' -s "${BASH_PATH}/module"/* | /usr/bin/env sed -n -e "/function ${fun}()/q;p" | /usr/bin/env tac | /usr/bin/env sed -n -e "/^$/q;p" | /usr/bin/env tac | /usr/bin/env sed -e "s/^# \+//" -e "\$i \ "
} }
# Short for help. # Short for help.