Refactor: Extract zsh config file loading to function

This commit is contained in:
Marty Oehme 2019-02-24 12:04:32 +01:00
parent 54b756a0f6
commit ff874c4c79

52
.zshrc
View file

@ -78,7 +78,7 @@ check_zgen_installation() {
## will be run after numbered ones (in a random order) if you uncomment the ## will be run after numbered ones (in a random order) if you uncomment the
## corresponding line below. ## corresponding line below.
# Set ZSH_CONFIG_DIR to default to ~/.zsh.d, or let user override # Set ZSH_CONFIG_DIR to default to ~/.config/zsh, or let user override
# Exit early if no configuration directory has been found # Exit early if no configuration directory has been found
if [ ! -d ${ZSH_CONFIG_DIR:="${XDG_CONFIG_DIR:-$HOME/.config}/zsh"} ]; then if [ ! -d ${ZSH_CONFIG_DIR:="${XDG_CONFIG_DIR:-$HOME/.config}/zsh"} ]; then
# If the user explicitly overrode the path give him an error # If the user explicitly overrode the path give him an error
@ -91,55 +91,31 @@ fi
# //TODO: Prints error when -no- files are found # //TODO: Prints error when -no- files are found
# Load bootstrap settings (00-19) before plugin initialization # Load bootstrap settings (00-19) before plugin initialization
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then print_dbg "Starting bootstrap (00-19)...\n"
GLOB=($ZSH_CONFIG_DIR/[0-1][0-9]-*) load_config_files $ZSH_CONFIG_DIR 01
for dotfile in $GLOB; do
print_dbg "Phase 1: $dotfile\n" #//DEBUG
if [ -r "${dotfile}" ]; then
source "${dotfile}"
fi
done
unset GLOB
fi
# set up zgen - load external zsh plugins # set up zgen - load external zsh plugins
# If you need to reload your plugins use 'zgen reset' and restart # If you need to reload your plugins use 'zgen reset' and restart
# your shell # your shell
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
print_dbg "Phase 2: Setting up ZGEN\n" #//DEBUG print_dbg "Starting plugin system...\n" #//DEBUG
check_zgen_installation check_zgen_installation
if ! zgen saved; then if ! zgen saved; then
print_dbg "Applying plugins (20-29)...\n"
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then load_config_files $ZSH_CONFIG_DIR 2
GLOB=($ZSH_CONFIG_DIR/2[0-9]-*)
for dotfile in $GLOB; do
print_dbg "Phase 2: $dotfile - Plugin\n" #//DEBUG
if [ -r "${dotfile}" ]; then
source "${dotfile}"
fi
done
unset GLOB
fi
# Save it all to init script. # Save it all to init script.
zgen save zgen save
else
print_dbg "Plugins already applied. If you want to re-apply run 'zgen reset' and open new terminal.\n"
fi fi
fi fi
# Load additional settings (30-99) after plugin initialization # Load additional settings (30-99) after plugin initialization
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then print_dbg "Setting up remaining scripts (30-99)\n"
GLOB=($ZSH_CONFIG_DIR/[3-9][0-9]-*) load_config_files $ZSH_CONFIG_DIR 3456789
for dotfile in $GLOB; do
print_dbg "Phase 3: $dotfile\n" #//DEBUG
if [ -r "${dotfile}" ]; then
source "${dotfile}"
fi
done
unset GLOB
fi
# Uncomment this section to enable execution of arbitrarily named config files # Uncomment this section to enable execution of arbitrarily named config files
# if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then # if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
@ -154,7 +130,13 @@ fi
# fi # fi
unset ZSH_CONFIG_DIR unset ZSH_CONFIG_DIR
unset ZGEN_DIR
unset ZGEN_PARENT_DIR
unset ZSH_SETUP_SHOW_DEBUG
unfunction print_dbg
unfunction load_config_files
unfunction check_zgen_installation
# //FIXME this needs to get the hell out of here -> put it in an env loading file
export GOPATH="$HOME/Code/go" export GOPATH="$HOME/Code/go"
export PATH="$PATH:$GOPATH/bin" export PATH="$PATH:$GOPATH/bin"