-
Notifications
You must be signed in to change notification settings - Fork 8
/
zshrc
151 lines (125 loc) Β· 6.05 KB
/
zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# This zshrc sources files in $DOTFILES/zsh & any `.zsh` files in the directory
# specified by "$DOTFILES" (set to `$HOME/.files` in `./zshenv`)
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# <<<< guards >>>>
[[ -v DOTFILES ]] || {
echo '$DOTFILES not defined, `.zshenv` must not have run. Bailing on `.zshrc`'
return 1
}
# << zsh history >>
# cannot be set in `zshenv` as the default `/etc/zshrc` overrides these values
HISTSIZE=100000 # number of lines of history kept by the shell
SAVEHIST=$HISTSIZE # number of lines saved to $HISTFILE
# $PATH configuration
# perform early so that executables are available for enabled check and future
# config files
source "$DOTFILES/zsh/path.zsh"
"$DOTFILES/infra/scripts/component_enabled.sh" 'zsh' || return 0
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block, everything else may go below.
# ref - https://github.com/romkatv/powerlevel10k#what-is-instant-prompt
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# <<<< files without dependencies >>>>
# store tokens/keys in `secrets.zsh`, gitignored to avoid checking in
[ -f "$DOTFILES/zsh/secrets.zsh" ] && source "$DOTFILES/zsh/secrets.zsh"
source "$DOTFILES/zsh/completion.zsh"
source "$DOTFILES/zsh/keymap.zsh"
source "$DOTFILES/zsh/manydots.zsh"
# <<<< files with dependencies >>>>
# these files depend either on executables made accessible via $PATH or code
# defined in earlier config files.
#
# note: some files here also define dependencies for later files so the ordering
# in this section matters (unlike in the previous two sections)
source "$DOTFILES/zsh/dynamic_env_vars.zsh"
source "$DOTFILES/zsh/functions.zsh"
# source after $DOTFILES/zsh/functions.zsh to allow aliasing those functions
source "$DOTFILES/zsh/alias.zsh"
# <<<< plugins >>>>
# managed via `zinit` - https://github.com/zdharma/zinit
# see more details in $DOTFILES/zsh/plugins.zsh
# below installer hunk added to this file (instead of internal to
# $DOTFILES/zsh/plugins.zsh) so that `zinit` avoids redundantly appending it
### Added by Zinit's installer
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
print -P "%F{33}βββ %F{220}Installing DHARMA Initiative Plugin Manager (zdharma/zinit)β¦%f"
command mkdir -p $HOME/.zinit
command git clone https://github.com/zdharma/zinit $HOME/.zinit/bin && \
print -P "%F{33}βββ %F{34}Installation successful.%F" || \
print -P "%F{160}βββ The clone has failed.%F"
fi
source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
### End of Zinit installer's chunk
# load and configure plugins
source "$DOTFILES/zsh/plugins.zsh"
# <<<< end of plugins >>>>
# run `p10k configure` or edit $DOTFILES/zsh/prompt.zsh to customize prompt
# prefer `~/.p10k.zsh` if it exists (likely from `p10k configure`)
if [[ -f $HOME/.p10k.zsh ]]; then
source "$HOME/.p10k.zsh"
else
# otherwise source default config
source "$DOTFILES/zsh/prompt.zsh"
fi
# all *.zsh files throughout this repo exluding the $DOTFILES/zsh directory
# (technically excludes $DOTFILES/**/zsh)
#
# x~y matches anything that matches the pattern x but does not match y
# ref - http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators
# (search "x~y" to find documentation for the above described behavior)
# define variable to store list of files to source
# note: -U ensures uniqueness
typeset -U config_files
setopt extended_glob
config_files=($DOTFILES/**/*.zsh~*/zsh/*)
for config_file in $config_files; do source "$config_file"; done
unset config_files config_file
setopt no_extended_glob
# source asdf to give it final say on package versions
source "$DOTFILES/zsh/asdf.zsh"
# apply options, overriding any set for script purposes
#
# ref - http://zsh.sourceforge.net/Doc/Release/Options.html
#
# - `auto_cd` - type a bare path to perform `cd <path>`
# - `$ ~/.files<Enter>` will `cd` to `~/.files`
# - `$ ..<Enter>` will `cd` up a directory
# - `extended_glob` - expansion & globbing
# - `interactive_comments` - allow comments at the command line (zle)
# - `local_options` - reset any options on script return
# - history
# - `hist_ignore_space` - don't save commands starting w/ ' ' to history
# - useful if you want to run a command with secrets
# - ref - https://superuser.com/a/352858
# - `hist_ignore_all_dups` - treat '#', '~' & '^' as glob patterns
# - `hist_reduce_blanks` - dedupe & remove lines differing only in whitespace
# - `share_history` - sync history between simultaneous shells on prompt load
setopt auto_cd extended_glob interactive_comments local_options
setopt hist_ignore_space hist_ignore_all_dups hist_reduce_blanks share_history
# any last local overrides, gitignored to avoid checking in
[ -f "$DOTFILES/zsh/local.zsh" ] && source "$DOTFILES/zsh/local.zsh"
# initialize `nix`
# this code should be added to the corresponding `etc` file for your shell, e.g.
# `/etc/bashrc` or `/etc/zshrc`. For some reason it seems like `macOS` may
# overwrite these changes on a system update. For that reason add it here as
# well (duplicate sourcing isn't an issue as the script bails immediately if run
# previously)
# ref - https://discourse.nixos.org/t/post-macos-install-env-var-settings-for-zsh/4597/7
# TODO: make sure this is the best way to handle this
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# make `home-manager` available for use
# ref - https://github.com/rycee/home-manager#installation
# TODO: remove if this becomes unnecessary
# tracking issue - https://github.com/NixOS/nix/issues/2033
export NIX_PATH=$HOME/.nix-defexpr/channels${NIX_PATH:+:}$NIX_PATH
# initialize direnv
# ref - https://direnv.net/docs/hook.html#zsh
eval "$(direnv hook zsh)"