22# -*- mode: sh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
33# vim: ft=sh sw=2 ts=2 et
44
5- trap ' rm -rf "$WORKDIR"' EXIT INT
6- WORKDIR=" $( mktemp -d) "
5+ set -eu
6+
7+ WORKDIR=" $( mktemp -d) " || exit 1
8+ trap ' rm -rf "${WORKDIR:?}"' EXIT INT TERM
79ZOPT=" "
810AOPT=" "
911BOPT=" main"
@@ -43,21 +45,21 @@ if [ "${AOPT}" = loader ]; then
4345 command wget -qO " ${ZI_CONFIG_DIR} /init.zsh" https://raw.githubusercontent.com/z-shell/zi-src/main/lib/zsh/init.zsh
4446 fi
4547 command chmod go-w " ${ZI_CONFIG_DIR} " && command chmod a+x " ${ZI_CONFIG_DIR} /init.zsh"
46- command sed -i " s/branch=\" main\" /branch=\" ${BOPT} \" /g" " ${ZI_CONFIG_DIR} /init.zsh"
48+ # shellcheck disable=SC2016
49+ command sed -i ' s|: ${ZI\[STREAM\]:="main"}|: ${ZI[STREAM]:="' " ${BOPT} " ' "}|' " ${ZI_CONFIG_DIR} /init.zsh"
4750fi
4851
49- if [ -z " ${ZI_HOME} " ]; then
50- ZI_HOME=" ${ZDOTDIR :- ${HOME} } /. zi"
52+ if [ -z " ${ZI_HOME- } " ]; then
53+ ZI_HOME=" ${XDG_DATA_HOME :- ${HOME} / .local / share} / zi"
5154fi
5255
53- if [ -z " ${ZI_BIN_DIR_NAME} " ]; then
56+ if [ -z " ${ZI_BIN_DIR_NAME- } " ]; then
5457 ZI_BIN_DIR_NAME=" bin"
5558fi
5659
5760if ! test -d " ${ZI_HOME} " ; then
5861 command mkdir " ${ZI_HOME} "
5962 command chmod go-w " ${ZI_HOME} "
60- command chmod go-w " ${ZI_HOME} /${ZI_BIN_DIR_NAME} "
6163fi
6264
6365if ! command -v git > /dev/null 2>&1 ; then
6870# Get the download-progress bar tool
6971if command -v curl > /dev/null 2>&1 ; then
7072 command mkdir -p /tmp/zi
71- cd /tmp/zi || return
73+ cd /tmp/zi || exit 1
7274 command curl -fsSLO https://raw.githubusercontent.com/z-shell/zi/main/lib/zsh/git-process-output.zsh &&
7375 command chmod a+x /tmp/zi/git-process-output.zsh
7476elif command -v wget > /dev/null 2>&1 ; then
7577 command mkdir -p /tmp/zi
76- cd /tmp/zi || return
78+ cd /tmp/zi || exit 1
7779 command wget -q https://raw.githubusercontent.com/z-shell/zi/main/lib/zsh/git-process-output.zsh &&
7880 command chmod a+x /tmp/zi/git-process-output.zsh
7981fi
8082
8183if test -d " ${ZI_HOME} /${ZI_BIN_DIR_NAME} /.git" ; then
82- cd " ${ZI_HOME} /${ZI_BIN_DIR_NAME} " || return
84+ cd " ${ZI_HOME} /${ZI_BIN_DIR_NAME} " || exit 1
8385 printf ' %s\n' " [1;34m▓▒░[0m Updating [1;36m(z-shell/zi)[1;33m plugin manager[0m at [1;35m${ZI_HOME} /${ZI_BIN_DIR_NAME} [0m"
8486 command git clean -d -f -f
8587 command git reset --hard HEAD
86- command git pull -q origin HEAD
88+ command git pull -q origin " ${BOPT} "
8789else
88- cd " ${ZI_HOME} " || return
90+ cd " ${ZI_HOME} " || exit 1
8991 printf ' %s\n' " [1;34m▓▒░[0m Installing [1;36m(z-shell/zi)[1;33m plugin manager[0m at [1;35m${ZI_HOME} /${ZI_BIN_DIR_NAME} [0m"
9092 { git clone --progress --depth=1 --branch " ${BOPT} " https://github.com/z-shell/zi.git " ${ZI_BIN_DIR_NAME} " \
9193 2>&1 | { /tmp/zi/git-process-output.zsh || cat; }; } 2> /dev/null
92- if [ -d " ${ZI_BIN_DIR_NAME} " ]; then
94+ if [ -d " ${ZI_HOME} / ${ ZI_BIN_DIR_NAME}" ]; then
9395 printf ' %s\n' " [1;34m▓▒░[0m Successfully installed at [1;32m${ZI_HOME} /${ZI_BIN_DIR_NAME} [0m" .
9496 else
9597 printf ' %s\n' " [1;31m▓▒░[0m Something went wrong, couldn't install ZI at [1;33m${ZI_HOME} /${ZI_BIN_DIR_NAME} [0m"
98+ exit 1
9699 fi
97100fi
98101
@@ -106,7 +109,7 @@ MAIN_PROFILE() {
106109 printf ' %s\n' " [34m▓▒░[34m Seems that .zshrc already has content or setup skipped - no changes will be made."
107110 ZOPT=' skip'
108111 fi
109- if [ " ${ZOPT} " != skip ]; then
112+ if [ " ${ZOPT} " != skip ] && [ " ${AOPT} " != loader ] ; then
110113 printf ' %s\n' " [34m▓▒░[0m Updating ${THE_ZDOTDIR} /.zshrc"
111114 ZI_HOME=" $( echo " ${ZI_HOME} " | sed " s|${HOME} |\$ HOME|" ) "
112115 command cat << -EOF >>"${THE_ZDOTDIR} /.zshrc"
126129 printf ' %s\n' " [34m▓▒░[0m[1;36m Minimal configuration[0m"
127130 fi
128131 if [ " ${AOPT} " = loader ] && [ " ${ZOPT} " != skip ]; then
129- command rm -rf " ${THE_ZDOTDIR} /.zshrc"
130132 command cat << -EOF >>"${THE_ZDOTDIR} /.zshrc"
131- if [[ -r "${XDG_CONFIG_HOME:- ${HOME} / .config} /zi/init.zsh" ]]; then
132- source "${XDG_CONFIG_HOME:- ${HOME} / .config} /zi/init.zsh" && zzinit
133+ if [[ -r "\ $ {XDG_CONFIG_HOME:-\ $ {HOME}/.config}/zi/init.zsh" ]]; then
134+ source "\ $ {XDG_CONFIG_HOME:-\ $ {HOME}/.config}/zi/init.zsh" && zzinit
133135fi
134136EOF
135137 printf ' %s\n' " [34m▓▒░[0m[1;36m Loader added[0m"
@@ -164,86 +166,38 @@ EOF
164166 fi
165167}
166168
167- SETUP_ZPMOD () {
168- if ! test -d " ${ZI_HOME} /${MOD_HOME} " ; then
169- command mkdir -p " ${ZI_HOME} /${MOD_HOME} "
170- command chmod go-w " ${ZI_HOME} /${MOD_HOME} "
171- fi
169+ ZPMOD_PROFILE () {
170+ _zpmod_sh=" "
171+ case " $0 " in
172+ * /* )
173+ _script_dir=" $( cd " $( dirname " $0 " ) " 2> /dev/null && pwd) " || _script_dir=" "
174+ ;;
175+ * )
176+ _script_dir=" "
177+ ;;
178+ esac
172179
173- printf ' %s\n' " ${col_pname} == Downloading ZPMOD module to ${ZI_HOME} /${MOD_HOME} "
174- if test -d " ${ZI_HOME} /${MOD_HOME} /.git" ; then
175- cd " ${ZI_HOME} /${MOD_HOME} " || return
176- git pull -q origin main
180+ if [ -n " ${_script_dir} " ] && [ -f " ${_script_dir} /install_zpmod.sh" ]; then
181+ _zpmod_sh=" ${_script_dir} /install_zpmod.sh"
177182 else
178- cd " ${ZI_HOME} " || return
179- git clone -q https://github.com/z-shell/zpmod.git " ${MOD_HOME} "
180- fi
181- printf ' %s\n' " ${col_pname} == Done"
182- }
183-
184- BUILD_ZPMOD () {
185- if command -v zsh > /dev/null; then
186- printf ' %s\n' " ${col_info2} -- Checkig version --${col_rst} "
187- ZSH_CURRENT=$( zsh --version < /dev/null | head -n1 | cut -d" " -f2,6- | tr -d ' -' )
188- ZSH_REQUIRED=" 5.8.1"
189- if expr " ${ZSH_CURRENT} " \< " ${ZSH_REQUIRED} " > /dev/null; then
190- printf ' %s\n' " ${col_error} -- Zsh version 5.8.1 and above required --${col_rst} "
191- exit 1
183+ _zpmod_sh=" ${WORKDIR} /install_zpmod.sh"
184+ _zpmod_url=" https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install_zpmod.sh"
185+ if command -v curl > /dev/null 2>&1 ; then
186+ command curl -fsSL " ${_zpmod_url} " -o " ${_zpmod_sh} "
187+ elif command -v wget > /dev/null 2>&1 ; then
188+ command wget -qO " ${_zpmod_sh} " " ${_zpmod_url} "
192189 else
193- printf ' %s\n' " ${col_info2} -- Zsh version ${ZSH_CURRENT} --${col_rst} "
194- cd " ${ZI_HOME} /${MOD_HOME} " || return
195- printf ' %s\n' " ${col_pname} == Building module ZPMOD, running: a make clean, then ./configure and then make ==${col_rst} "
196- printf ' %s\n' " ${col_pname} == The module sources are located at: ${ZI_HOME} /${MOD_HOME} ==${col_rst} "
197- if test -f Makefile; then
198- if [ " $1 " = " --clean" ]; then
199- printf ' %s\n' " ${col_info2} -- make distclean --${col_rst} "
200- make -s distclean
201- true
202- else
203- printf ' %s\n' " ${col_info2} -- make clean (pass --clean to invoke \` make distclean') --${col_rst} "
204- make -s clean
205- fi
206- fi
207- printf ' %s\n' " ${col_info2} -- Configuring --${col_rst} "
208- if CPPFLAGS=-I/usr/local/include CFLAGS=" -g -Wall -O3" LDFLAGS=-L/usr/local/lib ./configure --disable-gdbm --without-tcsetpgrp; then
209- printf ' %s\n' " ${col_info2} -- Running make --${col_rst} "
210- if make -s; then
211- command cat << -EOF
212- [38;5;219m▓▒░[0m [38;5;220mModule [38;5;177mhas been built correctly.
213- [38;5;219m▓▒░[0m [38;5;220mTo [38;5;160mload the module, add following [38;5;220m2 lines to [38;5;172m.zshrc, at top:
214- [0m [38;5;51m module_path+=( "${ZI_HOME} /${MOD_HOME} /Src" )
215- [0m [38;5;51m zmodload zi/zpmod
216- [38;5;219m▓▒░[0m [38;5;220mSee 'zpmod -h' for more information.
217- [38;5;219m▓▒░[0m [38;5;220mRun 'zpmod source-study' to see profile data,
218- [38;5;219m▓▒░[0m [38;5;177mGuaranteed, automatic compilation of any sourced script.
219- EOF
220- else
221- printf ' %s\n' " ${col_error} Module didn't build.${col_rst} . You can copy the error messages and submit"
222- printf ' %s\n' " error-report at: https://github.com/z-shell/zpmod/issues"
223- fi
224- fi
190+ printf ' %s\n' " -- ERROR -- curl or wget is required to download install_zpmod.sh" >&2
191+ exit 1
225192 fi
226- else
227- printf ' %s\n' " ${col_error} Zsh is not installed. Please install zsh and try again.${col_rst} "
193+ if [ ! -s " ${_zpmod_sh} " ]; then
194+ printf ' %s\n' " -- ERROR -- failed to download install_zpmod.sh" >&2
195+ exit 1
196+ fi
197+ command chmod a+x " ${_zpmod_sh} "
228198 fi
229- }
230199
231- ZPMOD_PROFILE () {
232- col_pname=" [33m"
233- col_error=" [31m"
234- col_info=" [32m"
235- col_info2=" [32m"
236- col_rst=" [0m"
237-
238- ZI_HOME=" ${ZI_HOME:- ${ZDOTDIR:- ${HOME} } / .zi} "
239- MOD_HOME=" ${MOD_HOME:- zmodules} /zpmod"
240-
241- printf ' %s\n' " ${col_info} Re-run this script to update (from Github) and rebuild the module.${col_rst} "
242- printf ' %s\n' " ${col_info2} Press any key to continue, or Ctrl-C to exit.${col_rst} "
243- read -r
244-
245- SETUP_ZPMOD
246- BUILD_ZPMOD " $@ "
200+ exec sh " ${_zpmod_sh} " " $@ "
247201}
248202
249203CLOSE_PROFILE () {
273227 exit 0
274228}
275229
276- while true ; do
277- MAIN " ${@ } "
278- done
230+ MAIN " ${@ } "
0 commit comments