split tools

This commit is contained in:
Aleksey 2024-01-18 19:21:01 +04:00
parent b19268d02d
commit d5faffd04c
Signed by: tea
GPG Key ID: D9C68D34A3CAE37A
10 changed files with 88 additions and 91 deletions

View File

@ -1,90 +0,0 @@
function zshlibs_boot()
{
typeset -g zshlibs_bootlevel
if [[ $zshlibs_bootlevel -gt 1 ]]
then
echo "You are likely doing double bootstrap"
fi
zshlibs_bootlevel=0
zshlibs_log zbootstrap "ensure directory '${HOME}/.log/'"
zshlibs_ensure -d "${HOME}/.log/"
zshlibs_bootlevel=2
}
function zshlibs_ensure()
{
target="${2}"
typ="${1}"
if ! test -e "${target}"
then
zshlibs_log zshlibs_ensure "creating '${target}' ($typ) …"
case $typ in
-d)
mkdir -p "${target}" \
|| zshlibs_log $0 "unable to create directory '${target}'" \
&& return 2
;;
-f)
touch "${target}" \
|| zshlibs_log $0 "unable to create file '${target}'" \
&& return 2
esac
zshlibs_log zshlibs_ensure "target '${target}' created"
elif test "${typ}" "${target}"
then
zshlibs_log zshlibs_ensure "target '${target}' ($typ) present"
return 0
else
zshlibs_log zshlibs_ensure "target '${target}' already exists and it is not a directory"
return 1
fi
}
function zshlibs_log()
{
local facility=$1
shift
if [[ -n "${@}" ]]
then
echo "$(date -Ins) ${@}" >> "${HOME}/.log/z_$facility.log"
else
echo "$(date -Ins) $(cat)" >> "${HOME}/.log/z_$facility.log"
fi
}
function zshlibs_path_add()
{
local pathtoadd="${1}"
zshlibs_log $0 "adding path '$pathtoadd' to \$PATH"
if [[ ! ${path[(r)${pathtoadd}]} ]]
then
path+=(${pathtoadd})
fi
}
function zshlibs_fpath_add()
{
local fpathtoadd="${1}"
zshlibs_log $0 "adding fpath '$fpathtoadd' to \$fpath"
if [[ ! ${fpath[(r)${fpathtoadd}]} ]]
then
path+=(${fpathtoadd})
fi
}
function zshlibs_start()
{
zshlibs_boot
zshlibs_update
zconfig_boot
global_boot
zssh_boot
zshlibs_log zbootstrap "zshlibs booted up
==========================================="
}
function zbootstrap()
{
zshlibs_start
}

6
tools.zsh Normal file
View File

@ -0,0 +1,6 @@
function zbootstrap()
{
autoload zshlibs_boot zshlibs_log zshlibs_ensure zshlibs_fpath_add \
zshlibs_path_add zshlibs_start zshlibs_update
zshlibs_start
}

12
tools/zshlibs_boot Normal file
View File

@ -0,0 +1,12 @@
function zshlibs_boot()
{
typeset -g zshlibs_bootlevel
if [[ $zshlibs_bootlevel -gt 1 ]]
then
echo "You are likely doing double bootstrap"
fi
zshlibs_bootlevel=0
zshlibs_log zbootstrap "ensure directory '${HOME}/.log/'"
zshlibs_ensure -d "${HOME}/.log/"
zshlibs_bootlevel=2
}

28
tools/zshlibs_ensure Normal file
View File

@ -0,0 +1,28 @@
function zshlibs_ensure()
{
target="${2}"
typ="${1}"
if ! test -e "${target}"
then
zshlibs_log zshlibs_ensure "creating '${target}' ($typ) …"
case $typ in
-d)
mkdir -p "${target}" \
|| zshlibs_log $0 "unable to create directory '${target}'" \
&& return 2
;;
-f)
touch "${target}" \
|| zshlibs_log $0 "unable to create file '${target}'" \
&& return 2
esac
zshlibs_log zshlibs_ensure "target '${target}' created"
elif test "${typ}" "${target}"
then
zshlibs_log zshlibs_ensure "target '${target}' ($typ) present"
return 0
else
zshlibs_log zshlibs_ensure "target '${target}' already exists and it is not a directory"
return 1
fi
}

9
tools/zshlibs_fpath_add Normal file
View File

@ -0,0 +1,9 @@
function zshlibs_fpath_add()
{
local fpathtoadd="${1}"
zshlibs_log $0 "adding fpath '$fpathtoadd' to \$fpath"
if [[ ! ${fpath[(r)${fpathtoadd}]} ]]
then
path+=(${fpathtoadd})
fi
}

11
tools/zshlibs_log Normal file
View File

@ -0,0 +1,11 @@
function zshlibs_log()
{
local facility=$1
shift
if [[ -n "${@}" ]]
then
echo "$(date -Ins) ${@}" >> "${HOME}/.log/z_$facility.log"
else
echo "$(date -Ins) $(cat)" >> "${HOME}/.log/z_$facility.log"
fi
}

10
tools/zshlibs_path_add Normal file
View File

@ -0,0 +1,10 @@
function zshlibs_path_add()
{
local pathtoadd="${1}"
zshlibs_log $0 "adding path '$pathtoadd' to \$PATH"
if [[ ! ${path[(r)${pathtoadd}]} ]]
then
path+=(${pathtoadd})
fi
}

10
tools/zshlibs_start Normal file
View File

@ -0,0 +1,10 @@
function zshlibs_start()
{
zshlibs_boot
zshlibs_update
zconfig_boot
global_boot
zssh_boot
zshlibs_log zbootstrap "zshlibs booted up
==========================================="
}

View File

@ -1,5 +1,6 @@
function zshlibs_update()
{
autoload zshlibs_log
zshlibs_log zlibs_update "preparing self update …"
if [[ -n "$zshlibs_install" ]]
then

View File

@ -16,7 +16,7 @@ else
fi
source ${zshlibs_install}/tools.funcs.zsh
source ${zshlibs_install}/tools.zsh
source ${zshlibs_install}/zconfig.funcs.zsh
source ${zshlibs_install}/global.funcs.zsh
source ${zshlibs_install}/zssh.zsh