#!/usr/bin/env sh setup_environment() { if [ -z "${ZI_HOME}" ]; then if [ -d "${HOME}"/.zi ]; then ZI_HOME="${HOME}/.zi" elif [ -d "${ZDOTDIR}"/.zi ]; then ZI_HOME="${ZDOTDIR}/.zi" elif [ -d "${XDG_DATA_HOME}"/.zi ]; then ZI_HOME="${XDG_DATA_HOME}/.zi" else ZI_HOME="${HOME}/.zi" fi fi if [ -z "${MOD_HOME}" ]; then MOD_HOME="${ZI_HOME}/zmodules/zpmod" fi if ! test -d "${MOD_HOME}"; then mkdir -p "${MOD_HOME}" chmod g-rwX "${MOD_HOME}" fi if [ ! -d "${MOD_HOME}" ]; then printf '%s\n' "${col_error}== Error: Failed to setup module directory ==${col_rst}" exit 255 fi } setup_zpmod_repository() { printf '%s\n' "${col_pname}== Downloading ZPMOD module to ${MOD_HOME}" if test -d "${MOD_HOME}/.git"; then cd "${MOD_HOME}" || exit 255 git pull -q origin main else git clone --depth 10 -q https://github.com/z-shell/zpmod.git "${MOD_HOME}" fi } build_zpmod_module() { if command -v zsh >/dev/null; then printf '%s\n' "${col_info2}-- Checking version --${col_rst}" ZSH_CURRENT=$(zsh --version /dev/null; then printf '%s\n' "${col_error}-- Zsh version 5.8.1 and above required --${col_rst}" exit 1 else ( printf '%s\n' "${col_info2}-- Zsh version ${ZSH_CURRENT} --${col_rst}" cd "${MOD_HOME}" || exit 255 printf '%s\n' "${col_pname}== Building module ZPMOD, running: a make clean, then ./configure and then make ==${col_rst}" printf '%s\n' "${col_pname}== The module sources are located at: ${MOD_HOME} ==${col_rst}" if test -f Makefile; then if [ "$1" = "--clean" ]; then printf '%s\n' "${col_info2}-- make distclean --${col_rst}" make distclean true else printf '%s\n' "${col_info2}-- make clean (pass --clean to invoke \`make distclean') --${col_rst}" make clean fi fi INSTALL_PATH="/usr/local" export PATH="${INSTALL_PATH}"/bin:"${PATH}" export LD_LIBRARY_PATH="${INSTALL_PATH}"/lib:"${LD_LIBRARY_PATH}" export CFLAGS=-I"${INSTALL_PATH}"/include export CPPFLAGS="-I${INSTALL_PATH}/include" LDFLAGS="-L${INSTALL_PATH}/lib" CFLAGS="-g -Wall -O3" ./configure --disable-gdbm --without-tcsetpgrp --quiet printf '%s\n' "${col_info2}-- Running make --${col_rst}" if make -j 4 >/dev/null && [ -f Src/zi/zpmod.so ]; then cp -vf Src/zi/zpmod.so Src/zi/zpmod.bundle command cat <<-EOF â–“â–’â–‘ Module has been built correctly. â–“â–’â–‘ To load the module, add following 2 lines to .zshrc, at top:   module_path+=( "${MOD_HOME}/Src" )   zmodload zi/zpmod â–“â–’â–‘ See 'zpmod -h' for more information. â–“â–’â–‘ Run 'zpmod source-study' to see profile data, â–“â–’â–‘ Guaranteed, automatic compilation of any sourced script. EOF else printf '%s\n' "${col_error}Module didn't build.${col_rst}. You can copy the error messages and submit" printf '%s\n' "error-report at: https://github.com/z-shell/zpmod/issues" exit 255 fi ) fi else printf '%s\n' "${col_error} Zsh is not installed. Please install zsh and try again.${col_rst}" exit 255 fi } MAIN() { col_pname="" col_error="" col_info2="" col_rst="" setup_environment "$@" setup_zpmod_repository "$@" build_zpmod_module "$@" exit 0 } while true; do MAIN "${@}" done