diff --git a/README.md b/README.md index 9e73facfd0c..b0f2d8192c5 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,47 @@ There's a few special files in the hierarchy. - **bin/**: Anything in `bin/` will get added to your `$PATH` and be made available everywhere. -- **Brewfile**: This is a list of applications for [Homebrew Cask](https://caskroom.github.io) to install: things like Chrome and 1Password and Adium and stuff. Might want to edit this file before running any initial setup. -- **topic/\*.zsh**: Any files ending in `.zsh` get loaded into your - environment. -- **topic/path.zsh**: Any file named `path.zsh` is loaded first and is - expected to setup `$PATH` or similar. -- **topic/completion.zsh**: Any file named `completion.zsh` is loaded - last and is expected to setup autocomplete. -- **topic/install.sh**: Any file named `install.sh` is executed when you run `script/install`. To avoid being loaded automatically, its extension is `.sh`, not `.zsh`. -- **topic/\*.symlink**: Any file ending in `*.symlink` gets symlinked into - your `$HOME`. This is so you can keep all of those versioned in your dotfiles - but still keep those autoloaded files in your home directory. These get - symlinked in when you run `script/bootstrap`. +- **Brewfile**: This is a list of applications for + [Homebrew Cask](http://caskroom.io) to install: things like Chrome + and 1Password and Adium and stuff. Might want to edit this file + before running any initial setup. +- **topic/\*.zsh**: configuration files + - Environment configuration (i.e., `.zshenv`) + - **topic/path.zsh**: Any `path.zsh` file is loaded first and + is expected to setup `$PATH` or similar. + - **topic/env.zsh**: Any `env.zsh` file is loaded + second and is expected to setup any additional environment + (e.g., shell options). + - Interactive configuration (i.e., `.zshrc`) + - **topic/fpath.zsh**: Any `fpath.zsh` file is loaded for + interactive shells only. They are expected to populate + `$fpath`. + - **topic/\*.zsh**: Any files ending in `.zsh` (except those + specified elsewhere) are loaded for interactive shells only. + Interactive configuration can include aliases, color output, + prompt configuration, or anything else that should only be + loaded when a user is interacting with Zsh. + - **topic/*completion.zsh**: Any `completion.zsh` file is + loaded last for interactive shells only. They are expected + to setup autocomplete. + - Login configuration (i.e., `.zprofile`, `.zlogin`, `.zlogout`) + - **topic/profile.zsh**: Any `profile.zsh` file is loaded for + login shells only. Unlike `.zlogin`, these files are loaded + before the interactive files above are loaded. + - **topic/login.zsh**: Any `login.zsh` file is loaded for login + shells only. Unlike `.zprofile`, they are loaded after your + interactive files are loaded above. This is the ideal place + to put anything you want to see when you start up a new login + shell (e.g., cowsay, date, todo, fortune). + - **topic/logout.zsh**: Any `logout.zsh` file is loaded for + login shells only and only when you exit/logout the shell. +- **topic/install.sh**: Any file named `install.sh` is executed when you + run `script/install`. To avoid being loaded automatically, its + extension is `.sh`, not `.zsh`. +- **topic/\*.symlink**: Any files ending in `*.symlink` get symlinked into + your `$HOME`. This is so you can keep all of those versioned in your + dotfiles but still keep those autoloaded files in your home + directory. These get symlinked in when you run `script/bootstrap`. ## install @@ -59,8 +88,9 @@ script/bootstrap This will symlink the appropriate files in `.dotfiles` to your home directory. Everything is configured and tweaked within `~/.dotfiles`. -The main file you'll want to change right off the bat is `zsh/zshrc.symlink`, -which sets up a few paths that'll be different on your particular machine. +The main file you'll want to change right off the bat is +`zsh/zshenv.symlink`, which sets up a few paths that'll be different on +your particular machine. `dot` is a simple script that installs some dependencies, sets sane macOS defaults, and so on. Tweak this script, and occasionally run `dot` from diff --git a/bin/dot b/bin/dot index 605b0591ec5..2bd020ca16e 100755 --- a/bin/dot +++ b/bin/dot @@ -38,18 +38,18 @@ while test $# -gt 0; do shift done -export ZSH=$HOME/.dotfiles +export DOTFILES=$HOME/.dotfiles # Set macOS defaults -$ZSH/macos/set-defaults.sh +$DOTFILES/macos/set-defaults.sh # Install homebrew -$ZSH/homebrew/install.sh 2>&1 +$DOTFILES/homebrew/install.sh 2>&1 # Upgrade homebrew echo "› brew update" brew update # Install software -echo "› $ZSH/script/install" -$ZSH/script/install +echo "› $DOTFILES/script/install" +$DOTFILES/script/install diff --git a/bin/set-defaults b/bin/set-defaults index 333859619a8..b566e3fd4b3 100755 --- a/bin/set-defaults +++ b/bin/set-defaults @@ -1,5 +1,5 @@ #!/bin/sh # -# Sets macOS defaults by running $ZSH/macos/set-defaults.sh. +# Sets macOS defaults by running $DOTFILES/macos/set-defaults.sh. -exec $ZSH/macos/set-defaults.sh +exec $DOTFILES/macos/set-defaults.sh diff --git a/git/gitconfig.symlink b/git/gitconfig.symlink index c936c2b2cf2..05086ef786d 100644 --- a/git/gitconfig.symlink +++ b/git/gitconfig.symlink @@ -5,9 +5,9 @@ protocol = https [alias] co = checkout - promote = !$ZSH/bin/git-promote - wtf = !$ZSH/bin/git-wtf - rank-contributors = !$ZSH/bin/git-rank-contributors + promote = !$DOTFILES/bin/git-promote + wtf = !$DOTFILES/bin/git-wtf + rank-contributors = !$DOTFILES/bin/git-rank-contributors count = !git shortlog -sn [color] diff = auto diff --git a/system/_path.zsh b/system/path.zsh similarity index 53% rename from system/_path.zsh rename to system/path.zsh index 255c2cfca66..ce76bd3d38e 100644 --- a/system/_path.zsh +++ b/system/path.zsh @@ -1,2 +1,2 @@ -export PATH="./bin:/usr/local/bin:/usr/local/sbin:$ZSH/bin:$PATH" +export PATH="./bin:/usr/local/bin:/usr/local/sbin:$DOTFILES/bin:$PATH" export MANPATH="/usr/local/man:/usr/local/mysql/man:/usr/local/git/man:$MANPATH" diff --git a/zsh/config.zsh b/zsh/config.zsh index 8ca7389e218..243cbf065e4 100644 --- a/zsh/config.zsh +++ b/zsh/config.zsh @@ -1,9 +1,9 @@ export LSCOLORS="exfxcxdxbxegedabagacad" export CLICOLOR=true -fpath=($ZSH/functions $fpath) +fpath=($DOTFILES/functions $fpath) -autoload -U $ZSH/functions/*(:t) +autoload -U $DOTFILES/functions/*(:t) HISTFILE=~/.zsh_history HISTSIZE=10000 diff --git a/zsh/fpath.zsh b/zsh/fpath.zsh index eaff4f41b0b..5254cdbdbac 100644 --- a/zsh/fpath.zsh +++ b/zsh/fpath.zsh @@ -1,2 +1,2 @@ #add each topic folder to fpath so that they can add functions and completion scripts -for topic_folder ($ZSH/*) if [ -d $topic_folder ]; then fpath=($topic_folder $fpath); fi; +for topic_folder ($DOTFILES/*) if [ -d $topic_folder ]; then fpath=($topic_folder $fpath); fi; diff --git a/zsh/prompt.zsh b/zsh/prompt.zsh index fabc959bcb6..2ed66b5d06a 100644 --- a/zsh/prompt.zsh +++ b/zsh/prompt.zsh @@ -57,7 +57,7 @@ directory_name() { battery_status() { if [[ $(sysctl -n hw.model) == *"Book"* ]] then - $ZSH/bin/battery-status + $DOTFILES/bin/battery-status fi } diff --git a/zsh/zlogin.symlink b/zsh/zlogin.symlink new file mode 100644 index 00000000000..33cd01c6a30 --- /dev/null +++ b/zsh/zlogin.symlink @@ -0,0 +1,16 @@ +# NOTE: Not intended to be used with zprofile, but can be. + +# Login configs. +setopt nullglob + +# all of our login zsh files +typeset -U login_files +login_files=($DOTFILES/**/login.zsh) + +# run all login files +for file in ${login_files}; do + source "$file" +done + +unset login_files +unsetopt nullglob diff --git a/zsh/zlogout.symlink b/zsh/zlogout.symlink new file mode 100644 index 00000000000..edf83530f49 --- /dev/null +++ b/zsh/zlogout.symlink @@ -0,0 +1,14 @@ +# Logout configs. +setopt nullglob + +# all of our logout zsh files +typeset -U logout_files +logout_files=($DOTFILES/**/logout.zsh) + +# run all logout files +for file in ${logout_files}; do + source "$file" +done + +unset logout_files +unsetopt nullglob diff --git a/zsh/zprofile.symlink b/zsh/zprofile.symlink new file mode 100644 index 00000000000..99ec29c6dbb --- /dev/null +++ b/zsh/zprofile.symlink @@ -0,0 +1,16 @@ +# NOTE: Not intended to be used with zlogin, but can be. + +# Login profile configs. +setopt nullglob + +# all of our profile zsh files +typeset -U profile_files +profile_files=($DOTFILES/**/profile.zsh) + +# run all profile files +for file in ${profile_files}; do + source "$file" +done + +unset profile_files +unsetopt nullglob diff --git a/zsh/zshenv.symlink b/zsh/zshenv.symlink new file mode 100644 index 00000000000..37e2a352f46 --- /dev/null +++ b/zsh/zshenv.symlink @@ -0,0 +1,26 @@ +# Environment configs. +setopt nullglob extendedglob + +# shortcut to this dotfiles path is $DOTFILES +export DOTFILES="$HOME/.dotfiles" + +# your project folder that we can `c [tab]` to +export PROJECTS="$HOME/Code" + +# path and env zsh files +typeset -U path_files env_files +path_files=($DOTFILES/**/path.zsh~**/fpath.zsh) +env_files=($DOTFILES/**/env.zsh) + +# load the path files +for file in ${path_files}; do + source "$file" +done + +# load the env files +for file in ${env_files}; do + source "$file" +done + +unset path_files env_files +unsetopt nullglob extendedglob diff --git a/zsh/zshrc.symlink b/zsh/zshrc.symlink index 9ce55833097..4981c27dd35 100644 --- a/zsh/zshrc.symlink +++ b/zsh/zshrc.symlink @@ -1,8 +1,5 @@ -# shortcut to this dotfiles path is $ZSH -export ZSH=$HOME/.dotfiles - -# your project folder that we can `c [tab]` to -export PROJECTS=~/Code +# Interactive environment configs. +setopt nullglob extendedglob # Stash your environment variables in ~/.localrc. This means they'll stay out # of your main dotfiles repository (which may be public, like this one), but @@ -12,20 +9,21 @@ then source ~/.localrc fi -# all of our zsh files -typeset -U config_files -config_files=($ZSH/**/*.zsh) +# all of our non-path/env/profile/login/logout zsh files +typeset -U fpath_files interactive_files completion_files +fpath_files=($DOTFILES/**/fpath.zsh) +interactive_files=($DOTFILES/**/*.zsh~**/completion.zsh~**/path.zsh~**/env.zsh~**/profile.zsh~**/fpath.zsh~**/login.zsh~**/logout.zsh) +completion_files=($DOTFILES/**/completion.zsh) -# load the path files -for file in ${(M)config_files:#*/path.zsh} -do - source $file +# load fpath config files +for file in ${fpath_files}; do + source "$file" done -# load everything but the path and completion files -for file in ${${config_files:#*/path.zsh}:#*/completion.zsh} -do - source $file +# load interactive files (everything but the completion, path, env, +# profile, login, and logout files) +for file in ${interactive_files}; do + source "$file" done # initialize autocomplete here, otherwise functions won't be loaded @@ -33,12 +31,12 @@ autoload -U compinit compinit # load every completion after autocomplete loads -for file in ${(M)config_files:#*/completion.zsh} -do - source $file +for file in ${completion_files}; do + source "$file" done -unset config_files +unset fpath_files interactive_files completion_files +unsetopt nullglob extendedglob # Better history # Credits to https://coderwall.com/p/jpj_6q/zsh-better-history-searching-with-arrow-keys @@ -47,4 +45,4 @@ autoload -U down-line-or-beginning-search zle -N up-line-or-beginning-search zle -N down-line-or-beginning-search bindkey "^[[A" up-line-or-beginning-search # Up -bindkey "^[[B" down-line-or-beginning-search # Down \ No newline at end of file +bindkey "^[[B" down-line-or-beginning-search # Down