Refactor Plugin loading to be modular

This commit is contained in:
Marty Oehme 2019-02-18 18:41:50 +01:00
parent 415d335262
commit da31bc3959
5 changed files with 156 additions and 218 deletions

69
.zshrc
View file

@ -1,5 +1,35 @@
#!/bin/zsh
#### ZSHRC - Setting up the Shell
## DEBUG INFORMATION
#
# ZSH_SETUP_SHOW_DEBUG="true"
#
# Uncomment the above line to get debug information during the script setup.
print_dbg() {
if [ -z $ZSH_SETUP_SHOW_DEBUG ]; then
return
fi
printf $@
}
# Clone zgen if you haven't already
check_zgen_installation() {
if [[ -z "$ZGEN_PARENT_DIR" ]]; then
ZGEN_PARENT_DIR=$HOME
fi
if [[ ! -f $ZGEN_PARENT_DIR/.zgen/zgen.zsh ]]; then
if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then
mkdir -p "$ZGEN_PARENT_DIR"
fi
pushd $ZGEN_PARENT_DIR
git clone https://github.com/tarjoilija/zgen.git ./.zgen
popd
fi
source $ZGEN_PARENT_DIR/.zgen/zgen.zsh
unset ZGEN_PARENT_DIR
}
#### ZSHrc - Setting up the Shell
##
## Almost all actual setup is being done with the help of individual files
## in the .zsh.d/ directory. They follow a specific order:
@ -19,18 +49,6 @@
## will be run after numbered ones (in a random order) if you uncomment the
## corresponding line below.
## DEBUG INFORMATION
#
# ZSH_SETUP_SHOW_DEBUG="true"
#
# Uncomment the above line to get debug information during the script setup.
print_dbg() {
if [ -z $ZSH_SETUP_SHOW_DEBUG ]; then
return
fi
printf $@
}
# Set ZSH_CONFIG_DIR to default to ~/.zsh.d, or let user override
# Exit early if no configuration directory has been found
if [ ! -d ${ZSH_CONFIG_DIR:="$HOME/.zsh.d"} ]; then
@ -56,9 +74,30 @@ if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
fi
# set up zgen - load external zsh plugins
if [ -f ~/.zgenrc ]; then
# If you need to reload your plugins use 'zgen reset' and restart
# your shell
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
print_dbg "Phase 2: Setting up ZGEN\n" #//DEBUG
source ~/.zgenrc
check_zgen_installation
if ! zgen saved; then
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
GLOB=($ZSH_CONFIG_DIR/2[0-9]-*)
for dotfile in $GLOB; do
print_dbg "Phase 3: $dotfile\n" #//DEBUG
if [ -r "${dotfile}" ]; then
source "${dotfile}"
fi
done
unset GLOB
fi
# Save it all to init script.
zgen save
fi
fi
# Load additional settings (30-99) after plugin initialization