4c14cb0f73
This is a major change, where Zsh modules/plugins are not git submodules in the Zim repo anymore, but customized and installed separately as individual repositories. The discussion about this started more than 2 years ago in #88. Closes #299. This will allow contributors' modules to live in their own repositories. Closes #33, closes #138, closes #262, closes #277, closes #281. Some discussion topics that I think are worth considering before merging this: - [ ] Reduce the Zim "core" to a single file? - [ ] Simplify installation? With an installation script? (See #182) - [ ] Put the configuration into `.zshrc` instead of a separate `.zimrc`? (See #288) - [ ] Rerun the Eriner/zsh-framework-benchmark? I suggest we create individual GitHub issues/PRs to start the separate discussions. The current code has what, up to this point, I considered to be the best balance between simplicity, execution speed and number of files. One measured decision was to make the initialization of modules depend only on the `':zim' modules` style, keeping it as fast as possible. The `':zim:module' module` style is used to install, update and clean the modules, all operations that happen after the user got his as-blazing-fast-possible shell prompt. Even though I didn't care much about making install or update fast, `xargs` has a nice feature of allowing commands to be executed in parallel with `-P`. I took advantage of that. I've also worked on making the `zimfw` utility give the user some nice (while still minimalistic) output. Also I'm suggesting this as the new name for the `zmanage` tool, since `zimfw` does not shadow the `zim` wiki tool. I strongly recommend you install this from scratch in a separate directory, instead of checking out `develop` in your current Zim installation repo.
58 lines
1.7 KiB
Bash
58 lines
1.7 KiB
Bash
# This runs in a new shell
|
|
URL=${1}
|
|
DIR=${2}
|
|
TYPE=${3}
|
|
REV=${4}
|
|
OPT=${5}
|
|
MODULE=${DIR:t}
|
|
if ! cd ${DIR} 2>/dev/null; then
|
|
print -P "%F{red}✗ ${MODULE}: Not installed%f"
|
|
return 1
|
|
fi
|
|
if ! command git rev-parse --is-inside-work-tree &>/dev/null; then
|
|
# Not a git repository. Will not try to update.
|
|
return 0
|
|
fi
|
|
if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then
|
|
print -P "%F{red}✗ ${MODULE}: URL does not match. Expected ${URL}. Will not try to update.%f"
|
|
return 1
|
|
fi
|
|
if [[ ${TYPE} == 'tag' ]]; then
|
|
if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then
|
|
[[ ${OPT} != -q ]] && print -P "%F{green}✓%f ${MODULE}: Already up to date"
|
|
return 0
|
|
fi
|
|
fi
|
|
if ! ERR=$(command git fetch -pq origin ${REV} 2>&1); then
|
|
print -P "%F{red}✗ ${MODULE}: Error (1)%f\n${ERR}"
|
|
return 1
|
|
fi
|
|
if [[ ${TYPE} == 'branch' ]]; then
|
|
LOG_REV="${REV}@{u}"
|
|
else
|
|
LOG_REV=${REV}
|
|
fi
|
|
LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} 2>/dev/null)
|
|
if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then
|
|
print -P "%F{red}✗ ${MODULE}: Error (2)%f\n${ERR}"
|
|
return 1
|
|
fi
|
|
if [[ ${TYPE} == 'branch' ]]; then
|
|
if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then
|
|
print -P "%F{red}✗ ${MODULE}: Error (3)%f\n${OUT}"
|
|
return 1
|
|
fi
|
|
# keep just first line of OUT
|
|
OUT=${OUT%%($'\n'|$'\r')*}
|
|
else
|
|
OUT="Updating to ${TYPE} ${REV}"
|
|
fi
|
|
[[ -n ${LOG} ]] && OUT="${OUT}\n${LOG}"
|
|
if ERR=$(command git submodule update --init --recursive -q 2>&1); then
|
|
if [[ ${OPT} != -q ]]; then
|
|
print -P "%F{green}✓%f ${MODULE}: ${OUT}"
|
|
fi
|
|
else
|
|
print -P "%F{red}✗ ${MODULE}: Error (4)%f\n${ERR}"
|
|
return 1
|
|
fi
|