diff --git a/tools.funcs.zsh b/tools.funcs.zsh new file mode 100644 index 0000000..8e5a29a --- /dev/null +++ b/tools.funcs.zsh @@ -0,0 +1,101 @@ + +function zshlibs_update() +{ + zshlibs_log zlibs_update "preparing self update …" + if [[ -n "$zshlibs_install" ]] + then + zshlibs_log zlibs_update "cd into '$zshlibs_install' …" + pushd $zshlibs_install 2>&1 > /dev/null + zshlibs_log zlibs_update "git pull …" + ( + git pull 2>&1 |zshlibs_log zlibs_update & # > "${HOME}/.log/z_zshlibs_update" & + ) + zshlibs_log zlibs_update "update done" + popd 2>&1 > /dev/null + else + echo "\$zshlibs_install not set!" + return 1 + zlibs_install + fi +} + +function zshlibs_boot() +{ + # ensure log directory + zshlibs_log zbootstrap "ensure directory '${HOME}/.log/'" + zshlibs_ensure -d "${HOME}/.log/" +} + +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 + zconfig_boot + zssh_boot + zshlibs_update +} + +function zbootstrap() +{ + zshlibs_start +} diff --git a/zconfig.funcs.zsh b/zconfig.funcs.zsh new file mode 100644 index 0000000..31f06bd --- /dev/null +++ b/zconfig.funcs.zsh @@ -0,0 +1,80 @@ + +function zconfig_checkload() +{ + typeset -a -g zconfig_loaded + if [[ ! ${zconfig_loaded[(r)${1}]} ]] + then + zshlibs_log zconfig "sourcing config '$1'" + . -- $1 2>&1 >(zshlibs_log zconfig) + zconfig_loaded+=("$1") + zshlibs_log zconfig "end sourcing config '$1'" + else + zshlibs_log zconfig "config '$1' already loaded" + fi +} + +function zconfigs_load() +{ + for configfile in ${*}; do + zconfig_checkload $configfile + done +} + +function zconfigs_local_load() +{ + if [[ ! -a ${zconfig_local_path} ]]; then + zshlibs_log $0 "local config missing, recreating from '${zconfig_shared_path}/zshconfig.example'" + mkdir -p -m 700 ${zconfig_local_path} + cp ${zconfig_shared_path}/zshconfig.example ${zconfig_local_path}/local.config.zsh + fi + if [[ ! -d ${zconfig_local_path} ]]; then + zshlibs_log zconfigs "local config appears to be a file, loading '${zconfig_local_path}'" + zconfig_checkload ${zconfig_local_path} + else + zshlibs_log zconfigs "local config is a directory, loading '${zconfig_local_path}/*.config.zsh'" + zconfigs_load ${zconfig_local_path}/*.config.zsh; + fi +} + +# zconfig bootup + +function zconfig_boot() +{ + zconfig_configure + zconfig_setup + zconfig_setup_interactive +} + +function zconfig_configure() +{ + typeset -a -g zconfig_loaded + typeset -a -g config_extra # user populatable config names in zshlibs location + typeset -g zconfig_shared_path="${zshlibs_install}/config" + typeset -g zconfig_local_path="${HOME}/.config/zsh" +} + +function zbootstrap_noninteractive() +{ + zshlibs_log zconfig "WARNING: legacy function called" + zconfig_configure + zconfig_setup +} + +function zconfig_setup() +{ + zshlibs_log zconfig 'load global config' + zconfig_checkload ${zconfig_shared_path}/global.config.zsh + zshlibs_log zconfig 'load local configs' + zconfigs_local_load + for zconfig in $config_extra; do + zshlibs_log zconfig 'load config extra $zconfig' + zconfig_checkload ${zconfig_shared_path}/${zconfig}.config.zsh + done +} + +function zconfig_setup_interactive() +{ + zshlibs_log zconfig "loading interactive config" + zconfig_checkload ${zconfig_shared_path}/global.style.zsh + zshlibs_log zconfig "done loading interactive config" +}