2019-02-18 16:55:05 +00:00
|
|
|
#!/bin/zsh
|
2019-02-18 17:41:50 +00:00
|
|
|
|
2019-02-24 10:06:50 +00:00
|
|
|
### DEFAULT DIRECTORY STRUCTURE
|
2019-02-18 17:41:50 +00:00
|
|
|
#
|
2019-02-24 10:06:50 +00:00
|
|
|
# ~/
|
|
|
|
# - .zshrc > Initial setup, should not need to be changed
|
|
|
|
# - .bashrc > Bash setup (empty for my dotfiles)
|
|
|
|
# - .Xresources > Initial Xresources setup, redirects to .config/.Xresources.d/
|
|
|
|
# - .tmux > Tmux setup (would love to put this into .config/ )
|
|
|
|
# - .config/ > all other (program) configuration should go in this dir
|
|
|
|
# --------- .zshrc.d/ > The actual zsh setup files, see their configuration below
|
|
|
|
# --------- .Xresources.d/ > The actual Xresources setup files
|
|
|
|
# --------- .zgen/ > The zsh plugin manager
|
|
|
|
# - .dotfiles/ > the version control of dotfiles
|
|
|
|
#
|
|
|
|
####
|
|
|
|
|
|
|
|
## Show debug information
|
2019-02-18 17:41:50 +00:00
|
|
|
#
|
2019-02-24 10:06:50 +00:00
|
|
|
# ZSH_SETUP_SHOW_DEBUG="true"
|
2019-02-18 17:41:50 +00:00
|
|
|
# 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
|
2019-02-24 10:06:50 +00:00
|
|
|
ZGEN_PARENT_DIR=${${XDG_CONFIG_DIR}:="$HOME/.config/"}
|
|
|
|
ZGEN_DIR="$ZGEN_PARENT_DIR/zgen"
|
2019-02-18 17:41:50 +00:00
|
|
|
fi
|
2019-02-24 10:06:50 +00:00
|
|
|
if [[ ! -f $ZGEN_DIR/zgen.zsh ]]; then
|
2019-02-18 17:41:50 +00:00
|
|
|
if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then
|
|
|
|
mkdir -p "$ZGEN_PARENT_DIR"
|
|
|
|
fi
|
|
|
|
pushd $ZGEN_PARENT_DIR
|
2019-02-24 10:06:50 +00:00
|
|
|
git clone https://github.com/tarjoilija/zgen.git $ZGEN_DIR
|
2019-02-18 17:41:50 +00:00
|
|
|
popd
|
|
|
|
fi
|
2019-02-24 10:06:50 +00:00
|
|
|
source $ZGEN_DIR/zgen.zsh
|
2019-02-18 17:41:50 +00:00
|
|
|
unset ZGEN_PARENT_DIR
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:36:24 +00:00
|
|
|
## //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
|
|
|
|
#}
|
|
|
|
|
2019-02-18 17:41:50 +00:00
|
|
|
#### ZSHrc - Setting up the Shell
|
2019-02-18 16:55:05 +00:00
|
|
|
##
|
|
|
|
## Almost all actual setup is being done with the help of individual files
|
2019-02-21 18:36:24 +00:00
|
|
|
## in the .zsh.d/ directory. This file just loads them. They follow a specific order:
|
2019-02-18 16:55:05 +00:00
|
|
|
##
|
|
|
|
## 00-09 are bootstrapping the zsh environment, setting aliases and sane
|
2019-02-21 18:36:24 +00:00
|
|
|
## shell defaults which should need no changes (though you can of course).
|
2019-02-18 16:55:05 +00:00
|
|
|
## 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.
|
|
|
|
|
2019-02-24 11:04:32 +00:00
|
|
|
# Set ZSH_CONFIG_DIR to default to ~/.config/zsh, or let user override
|
2019-02-18 16:55:05 +00:00
|
|
|
# Exit early if no configuration directory has been found
|
2019-02-24 10:06:50 +00:00
|
|
|
if [ ! -d ${ZSH_CONFIG_DIR:="${XDG_CONFIG_DIR:-$HOME/.config}/zsh"} ]; then
|
2019-02-18 16:55:05 +00:00
|
|
|
# If the user explicitly overrode the path give him an error
|
2019-02-24 10:06:50 +00:00
|
|
|
if [ ! $ZSH_CONFIG_DIR = "${XDG_CONFIG_DIR:-$HOME/.config/}/zsh" ]; then
|
2019-02-18 16:55:05 +00:00
|
|
|
printf "\$ZSH_CONFIG_DIR=$ZSH_CONFIG_DIR/ does not exist.\n"
|
2019-02-04 02:32:45 +00:00
|
|
|
fi
|
2019-02-18 16:55:05 +00:00
|
|
|
PS1="$HOME $ "
|
|
|
|
return
|
2019-02-04 02:32:45 +00:00
|
|
|
fi
|
2018-12-19 11:38:19 +00:00
|
|
|
|
2019-02-18 16:55:05 +00:00
|
|
|
# //TODO: Prints error when -no- files are found
|
|
|
|
# Load bootstrap settings (00-19) before plugin initialization
|
2019-02-24 11:04:32 +00:00
|
|
|
print_dbg "Starting bootstrap (00-19)...\n"
|
|
|
|
load_config_files $ZSH_CONFIG_DIR 01
|
2018-12-19 11:38:19 +00:00
|
|
|
|
2019-02-18 16:55:05 +00:00
|
|
|
# set up zgen - load external zsh plugins
|
2019-02-18 17:41:50 +00:00
|
|
|
# If you need to reload your plugins use 'zgen reset' and restart
|
|
|
|
# your shell
|
|
|
|
if [ -n "$(/bin/ls $ZSH_CONFIG_DIR/)" ]; then
|
2019-02-24 11:04:32 +00:00
|
|
|
print_dbg "Starting plugin system...\n" #//DEBUG
|
2019-02-18 17:41:50 +00:00
|
|
|
|
|
|
|
check_zgen_installation
|
|
|
|
|
|
|
|
if ! zgen saved; then
|
2019-02-24 11:04:32 +00:00
|
|
|
print_dbg "Applying plugins (20-29)...\n"
|
|
|
|
load_config_files $ZSH_CONFIG_DIR 2
|
2019-02-18 17:41:50 +00:00
|
|
|
|
|
|
|
# Save it all to init script.
|
|
|
|
zgen save
|
2019-02-24 11:04:32 +00:00
|
|
|
else
|
|
|
|
print_dbg "Plugins already applied. If you want to re-apply run 'zgen reset' and open new terminal.\n"
|
|
|
|
fi
|
2019-02-18 16:55:05 +00:00
|
|
|
fi
|
2018-12-19 11:38:19 +00:00
|
|
|
|
2019-02-18 16:55:05 +00:00
|
|
|
# Load additional settings (30-99) after plugin initialization
|
2019-02-24 11:04:32 +00:00
|
|
|
print_dbg "Setting up remaining scripts (30-99)\n"
|
|
|
|
load_config_files $ZSH_CONFIG_DIR 3456789
|
2019-02-04 02:32:45 +00:00
|
|
|
|
2019-02-18 16:55:05 +00:00
|
|
|
# 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
|
2019-02-04 02:32:45 +00:00
|
|
|
# fi
|
2018-12-19 11:38:19 +00:00
|
|
|
|
2019-02-18 16:55:05 +00:00
|
|
|
unset ZSH_CONFIG_DIR
|
2019-02-24 11:09:43 +00:00
|
|
|
# unset ZGEN_DIR -- Needs to remain set for some plugins to function
|
2019-02-24 11:04:32 +00:00
|
|
|
unset ZGEN_PARENT_DIR
|
|
|
|
unset ZSH_SETUP_SHOW_DEBUG
|
|
|
|
unfunction print_dbg
|
|
|
|
unfunction load_config_files
|
|
|
|
unfunction check_zgen_installation
|
2019-02-04 02:32:45 +00:00
|
|
|
|
2019-02-24 11:04:32 +00:00
|
|
|
# //FIXME this needs to get the hell out of here -> put it in an env loading file
|
2019-02-04 02:32:45 +00:00
|
|
|
export GOPATH="$HOME/Code/go"
|
|
|
|
export PATH="$PATH:$GOPATH/bin"
|