Skip to content

Commit

Permalink
feat(zsh): Break up Zsh configuration files
Browse files Browse the repository at this point in the history
 1. zshenv: path.zsh, env.zsh
 2. zprofile: profile.zsh
 3. zshrc: *.zsh, completion.zsh
 4. zlogin: login.zsh
 5. zlogout: logout.zsh

WIP: #10
  • Loading branch information
Derek Michael Frank committed Dec 11, 2016
1 parent 9066533 commit aede5ea
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 24 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,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
Expand Down
16 changes: 16 additions & 0 deletions zsh/zlogin.symlink
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions zsh/zlogout.symlink
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions zsh/zprofile.symlink
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions zsh/zshenv.symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Environment configs.
setopt nullglob

# 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)
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
36 changes: 14 additions & 22 deletions zsh/zshrc.symlink
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# shortcut to this dotfiles path is $DOTFILES
export DOTFILES=$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
Expand All @@ -12,30 +9,25 @@ then
source ~/.localrc
fi

# all of our zsh files
typeset -U config_files
config_files=($DOTFILES/**/*.zsh)

# load the path files
for file in ${(M)config_files:#*/path.zsh}
do
source $file
done
# all of our non-path/env/profile/login/logout zsh files
typeset -U interactive_files completion_files
interactive_files=($DOTFILES/**/*.zsh~**/completion.zsh~**/path.zsh~**/env.zsh~**/profile.zsh~**/login.zsh~**/logout.zsh)
completion_file=($DOTFILES/**/completion.zsh)

# 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
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 interactive_files completion_files
unsetopt nullglob extendedglob

0 comments on commit aede5ea

Please sign in to comment.