Bash : Drop BASH_MODULE_PATH.
This commit is contained in:
parent
011d46bcfc
commit
0f07aa1e43
|
@ -1,8 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
self=$(realpath ${0})
|
||||
self=$(/usr/bin/env realpath ${0})
|
||||
cd ${self%/*}
|
||||
|
||||
export BASH_PATH="../module/common/bash"
|
||||
|
||||
# Source modules.
|
||||
for file in ${BASH_PATH}/module/*.sh; do
|
||||
source "${file}"
|
||||
done
|
||||
|
||||
IFS=$'\n'
|
||||
file="Bash.md"
|
||||
|
||||
|
@ -25,7 +32,7 @@ echo >> "${file}"
|
|||
# Fill with data.
|
||||
for module in $(find_module); do
|
||||
# Skip if no functions.
|
||||
[[ "$(find_function ${module} | grep -v ^_)" = "" ]] && continue
|
||||
[[ "$(find_function ${module} | /usr/bin/env grep -v ^_)" = "" ]] && continue
|
||||
|
||||
# Print module title.
|
||||
echo "## ${module^}." >> "${file}"
|
||||
|
@ -40,8 +47,8 @@ for module in $(find_module); do
|
|||
[[ "${fun}" =~ ^_.* ]] && continue
|
||||
|
||||
# Parse help info.
|
||||
desc="$(help ${fun} | grep -v Usage\: | tr '\n' ' ')"
|
||||
usage="$(help ${fun} | grep Usage\: | sed -e s\/Usage\:\ \/\/)"
|
||||
desc="$(help ${fun} | /usr/bin/env grep -v Usage\: | /usr/bin/env tr '\n' ' ')"
|
||||
usage="$(help ${fun} | /usr/bin/env grep Usage\: | /usr/bin/env sed -e s\/Usage\:\ \/\/)"
|
||||
|
||||
# Use function name if no usage info available.
|
||||
[[ "${usage}" = "" ]] && usage="${fun}"
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [[ -z ${BASH_PATH} ]]; then
|
||||
echo "BASH_PATH not defined."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source modules.
|
||||
for file in /etc/bash/module/*.sh; do
|
||||
for file in ${BASH_PATH}/module/*.sh; do
|
||||
source "${file}"
|
||||
done
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [[ -z ${BASH_PATH} ]]; then
|
||||
echo "BASH_PATH not defined."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source modules.
|
||||
for file in /etc/bash/module/*.sh; do
|
||||
for file in ${BASH_PATH}/module/*.sh; do
|
||||
source "${file}"
|
||||
done
|
||||
|
||||
|
|
|
@ -49,8 +49,7 @@ in {
|
|||
".ssh/config".source = ./common/ssh/Config;
|
||||
};
|
||||
home.sessionVariables = {
|
||||
BASH_MODULE_PATH = "${homePath}/.bash/module";
|
||||
BASH_PATH = "${homePath}/.bash";
|
||||
BASH_PATH = "${homePath}/.bash";
|
||||
};
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{ environment, lib, ... }: {
|
||||
environment.etc.bash.source = ./bash;
|
||||
environment.shellAliases = lib.mkForce {};
|
||||
environment.variables.BASH_MODULE_PATH = "/etc/bash/module";
|
||||
environment.variables.BASH_PATH = "/etc/bash";
|
||||
programs.bash.interactiveShellInit = "source /etc/bash/Bashrc.sh";
|
||||
environment.etc.bash.source = ./bash;
|
||||
environment.shellAliases = lib.mkForce {};
|
||||
environment.variables.BASH_PATH = "/etc/bash";
|
||||
programs.bash.interactiveShellInit = "source /etc/bash/Bashrc.sh";
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
[[ -f /etc/bashrc ]] && source /etc/bashrc
|
||||
|
||||
# Src custom modules.
|
||||
for module in ${BASH_MODULE_PATH}/*.sh; do
|
||||
for module in ${BASH_PATH}/module/*.sh; do
|
||||
source "${module}"
|
||||
done
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ function find_ext() {
|
|||
|
||||
# Find all modules.
|
||||
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.
|
||||
|
@ -15,7 +15,7 @@ function find_module() {
|
|||
function find_function() {
|
||||
local module="${1}"
|
||||
[[ "${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.
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
function help() {
|
||||
local fun="${1}"
|
||||
|
||||
if [[ "${fun}" = "" ]] || [[ "$(find_function | grep ${fun})" = "" ]]; then
|
||||
if [[ "${fun}" = "" ]] || [[ "$(find_function | /usr/bin/env grep ${fun})" = "" ]]; then
|
||||
help help
|
||||
return 2
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue