dotfiles/.zshrc

145 lines
4.1 KiB
Bash

#!/bin/zsh
## 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
}
## //FIXME: Not working yet, globbing not working
#load_config_files() {
# if [ -n "$(/bin/ls $1)" ]; then
# #GLOB=(${1}/[0-1][0-9]-*)
# for dotfile in $(eval "echo {$1/$2}"); do
# print_dbg "TESTING: $dotfile\n" #//DEBUG
# if [ -r "${dotfile}" ]; then
# source "${dotfile}"
# fi
# done
# unset GLOB
# fi
#}
#### ZSHrc - Setting up the Shell
##
## Almost all actual setup is being done with the help of individual files
## in the .zsh.d/ directory. This file just loads them. They follow a specific order:
##
## 00-09 are bootstrapping the zsh environment, setting aliases and sane
## shell defaults which should need no changes (though you can of course).
## 10-19 allow custom bootstrapping of things that need to be set before any
## zsh plugins are loaded (in my case, theme environment vars, etc)
## 20-29 are run *during* zgen setup and can include plugins to be loaded
## 30-99 are run after plugins are loaded and can be configured
## in whatever way you wish
##
## Most of them are documented, and they try to have sensible naming.
## If you want to supply your own directory of zsh config files you can do so
## by setting the ZSH_CONFIG_DIR environment variable. You can also drop
## configuration files into the config dir without any numbers prepended, they
## will be run after numbered ones (in a random order) if you uncomment the
## corresponding line below.
# 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
# If the user explicitly overrode the path give him an error
if [ ! $ZSH_CONFIG_DIR = "$HOME/.zsh.d" ]; then
printf "\$ZSH_CONFIG_DIR=$ZSH_CONFIG_DIR/ does not exist.\n"
fi
PS1="$HOME $ "
return
fi
# //TODO: Prints error when -no- files are found
# Load bootstrap settings (00-19) before plugin initialization
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
GLOB=($ZSH_CONFIG_DIR/[0-1][0-9]-*)
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
# 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
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 2: $dotfile - Plugin\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
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
GLOB=($ZSH_CONFIG_DIR/[3-9][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
# Uncomment this section to enable execution of arbitrarily named config files
# if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
# GLOB=($ZSH_CONFIG_DIR/[:alpha:]*)
# for dotfile in $GLOB; do
# print_dbg "Phase 4, Alphabetic: $dotfile\n" #//DEBUG
# if [ -r "${dotfile}" ]; then
# source "${dotfile}"
# fi
# done
# unset GLOB
# fi
unset ZSH_CONFIG_DIR
export GOPATH="$HOME/Code/go"
export PATH="$PATH:$GOPATH/bin"