zshlibs/global.funcs.zsh

178 lines
4.3 KiB
Bash
Raw Normal View History

2021-12-20 14:08:22 +00:00
typeset -g globaldots_path="${HOME}/.global"
if [[ -a $(realpath -m $(dirname $0)/../../.globaldir ) ]]
then
typeset -g globaldots_path=$(realpath -m $(dirname $0)/../../)
fi
if [[ -n ${GLOBALDOTS_PATH} ]]
then
typeset -g globaldots_path=${GLOBALDOTS_PATH}
fi
2021-11-10 14:41:19 +00:00
if [[ -z $globaldots_path ]]; then
echo 'functions require $globaldots_path to be set!'
fi
2021-12-20 14:08:22 +00:00
#### BASIC ZSHLIBS TOOLS
function zlibs_update()
{
zbootstrap_message zlibs_update "preparing self update …"
if [[ -n "$zshlibs_install" ]]
then
zbootstrap_message zlibs_update "cd into '$zshlibs_install' …"
pushd $zshlibs_install
zbootstrap_message zlibs_update "git pull …"
2021-12-20 14:20:33 +00:00
git pull &
2021-12-20 14:08:22 +00:00
zbootstrap_message zlibs_update "update done"
popd
else
echo "\$zshlibs_install not set!"
return 1
zlibs_install
fi
}
function ztools_ensure()
{
target=${2}
typ=${1}
if ! test -e ${target}
then
zbootstrap_message ztools_ensure "creating '${target}' ($typ) …"
case $typ in
-d)
mkdir -p ${target} \
|| zbootstrap_message ztools_ensure "unable to create directory '${target}'" \
&& return 2
;;
-f)
touch ${target} \
|| zbootstrap_message ztools_ensure "unable to create file '${target}'" \
&& return 2
esac
zbootstrap_message ztools_ensure "target '${target}' created"
elif test ${typ} ${target}
then
zbootstrap_message ztools_ensure "target '${target}' ($typ) present"
return 0
else
zbootstrap_message ztools_ensure "target '${target}' already exists and it is not a directory"
return 1
fi
}
##### CONFIGURATION LIBRARIES
function zlibs_path_expand()
{
}
2021-11-10 14:41:19 +00:00
function global_path_expand()
{
local bin_base=${globaldots_path}/bin
for pathnew in ${*}; do
if [[ ! ${path[(r)${pathnew}]} ]] ; then
path+=(${bin_base}/${pathnew});
fi
done;
}
function global_fpath_expand()
{
local bin_base=${globaldots_path}/bin
for pathnew in ${*}; do
if [[ ! ${fpath[(r)${pathnew}]} ]] ; then
fpath+=${bin_base}/${pathnew}
fi
done;
}
2021-12-04 21:34:16 +00:00
2021-11-10 14:41:19 +00:00
function zconfig_checkload()
{
2021-12-20 14:08:22 +00:00
typeset -a -g zconfig_loaded
if [[ ! ${zconfig_loaded[(r)${1}]} ]]
2021-11-10 14:41:19 +00:00
then
zbootstrap_message zbootstrap "sourcing config '$1'"
source -- $1 2>&1 >> "${HOME}/.log/z_zbootstrap.log"
2021-12-20 14:08:22 +00:00
zconfig_loaded+=("$1")
2021-11-10 14:41:19 +00:00
zbootstrap_message zbootstrap "end sourcing config '$1'"
else
zbootstrap_message zbootstrap "config '$1' already loaded"
fi
}
function zconfigs_load()
{
for configfile in ${*}; do
zconfig_checkload $configfile
done
}
function zconfigs_local_load()
{
if [[ ! -a ${HOME}/.config/zsh ]]; then
mkdir -p -m 700 ${HOME}/.config/zsh
cp ${globaldots_path}/config/zsh/zshconfig.example ${HOME}/.config/zsh/local.config.zsh
fi
if [[ ! -d ${HOME}/.config/zsh ]]; then
zconfig_checkload ${HOME}/.config/zsh
else
zconfigs_load ${HOME}/.config/zsh/*.config.zsh;
fi
}
function zbootstrap_message()
{
local facility=$1
shift
echo "$(date -Ins) ${@}" >> "${HOME}/.log/z_$facility.log"
}
2021-12-20 14:08:22 +00:00
function zshlibs_boot()
2021-11-10 14:41:19 +00:00
{
# ensure log directory
zbootstrap_message zbootstrap "ensure directory '${HOME}/.log/'"
ztools_ensure -d "${HOME}/.log/"
# loading configs
2021-12-20 14:08:22 +00:00
typeset -a -g zconfig_loaded
2021-11-10 14:41:19 +00:00
typeset -a -g path_extra
typeset -a -g config_extra
2021-12-20 14:08:22 +00:00
typeset -g zconfig_shared_path="${zshlibs_install}/config"
typeset -g zconfig_local_path="${HOME}/.config/zsh"
}
function zbootstrap_noninteractive()
{
2021-11-10 14:41:19 +00:00
zbootstrap_message zbootstrap 'load global config'
zconfig_checkload ${globaldots_path}/config/zsh/global.config.zsh
zbootstrap_message zbootstrap 'load local configs'
zconfigs_local_load
for zconfig in $config_extra; do
zbootstrap_message zbootstrap 'load config extra $zconfig'
zconfig_checkload ${globaldots_path}/config/zsh/${zconfig}.config.zsh
done
# expanding settings
zbootstrap_message zbootstrap "expanding path with '$path_extra'"
global_path_expand $path_extra
zbootstrap_message zbootstrap "expanding fpath with '$fpath_extra'"
global_fpath_expand vanilla
zbootstrap_message zbootstrap "done loading noninteractive config"
}
function zbootstrap ()
{
2021-12-20 14:08:22 +00:00
zshlibs_boot
2021-11-10 14:41:19 +00:00
zbootstrap_noninteractive
zconfig_checkload ${globaldots_path}/config/zsh/global.style.zsh
2021-12-20 14:20:33 +00:00
zshlibs_update
2021-11-10 14:41:19 +00:00
zbootstrap_message zbootstrap "done loading interactive config"
}