-
Notifications
You must be signed in to change notification settings - Fork 1
/
zshenv.symlink
419 lines (327 loc) · 14.1 KB
/
zshenv.symlink
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# shellcheck shell=bash disable=SC1090,SC1091,SC2034,SC2206
# _
# _______| |__ ___ _ ____ __
# |_ / __| '_ \ / _ \ '_ \ \ / /
# / /\__ \ | | | __/ | | \ V /
# /___|___/_| |_|\___|_| |_|\_/
# ===============================
#
# Zsh environment configuration file.
#
# Startup Files: https://zsh.sourceforge.io/Intro/intro_3.html
#
# There are five startup files that zsh will read commands from:
# * $ZDOTDIR/.zshenv
# * $ZDOTDIR/.zprofile
# * $ZDOTDIR/.zshrc
# * $ZDOTDIR/.zlogin
# * $ZDOTDIR/.zlogout
#
# If ZDOTDIR is not set, then the value of HOME is used; this is the usual case.
#
# `.zshenv' is sourced on all invocations of the shell, unless -f option is set.
# It should contain commands to set the command search path,
# plus other important environment variables.
# `.zshenv' should not contain commands that produce output
# or assume the shell is attached to a tty.
#
# `.zshrc' is sourced in interactive shells. It should contain commands
# to set up aliases, functions, options, key bindings, etc.
#
# `.zlogin' is sourced in login shells. It should contain commands that
# should be executed only in login shells. `.zlogout' is sourced when
# login shells exit. `.zprofile' is similar to `.zlogin', except that
# it is sourced before `.zshrc'. `.zprofile' is meant as an alternative
# to `.zlogin' for ksh fans; the two are not intended to be used together,
# although this could certainly be done if desired.
#
# `.zlogin' is not the place for alias definitions, options,
# environment variable settings, etc.; as a general rule, it should not
# change the shell environment at all. Rather, it should be used to set
# the terminal type and run a series of external commands (fortune, msgs, etc).
#
# See table below for processing information.
#
# Zsh executes A, then B, then C, etc.
# +----------------+-----------+-----------+------+
# | |Interactive|Interactive|Script|
# | |login |non-login | |
# +----------------+-----------+-----------+------+
# |/etc/zshenv | A | A | A |
# +----------------+-----------+-----------+------+
# | ~/.zshenv | B | B | B | <<< This sets $PATH
# +----------------+-----------+-----------+------+
# |/etc/zprofile | C | | | <<< This overwrites $PATH =(
# +----------------+-----------+-----------+------+
# | ~/.zprofile | D | | |
# +----------------+-----------+-----------+------+
# |/etc/zshrc | E | C | |
# +----------------+-----------+-----------+------+
# | ~/.zshrc | F | D | | <<< This resets $PATH
# +----------------+-----------+-----------+------+
# |/etc/zlogin | G | | |
# +----------------+-----------+-----------+------+
# | ~/.zlogin | H | | |
# +----------------+-----------+-----------+------+
# +----------------+-----------+-----------+------+
# | ~/.zlogout | I | | |
# +----------------+-----------+-----------+------+
# |/etc/zlogout | J | | |
# +----------------+-----------+-----------+------+
#
# Moral: Put stuff in `~/.zshenv`, that should always be executed.
# HOWEVER: Some config may be overwritten by `/etc/zprofile` or `/etc/zshrc`.
# So, you have to put some config in `~/.zshrc` (e.g., prompt config).
#
# Use the Conditional Sections as needed:
# 1. SCRIPT / NON-INTERACTIVE / .zshenv
# 2. INTERACTIVE / PROMPT / .zshrc
# 3. LOGIN / .zprofile / .zlogin
# 4. NON-LOGIN / .zprofile
#
# NOTE: This is different from how Bash is processed (see `~/.bashrc`).
#
# Zsh Reference Card: https://www.bash2zsh.com/zsh_refcard/refcard.pdf
# ZSH-LOVERS(1): https://grml.org/zsh/zsh-lovers.html
_SHELL_TYPE="prompt"
_SHELL_USER="public"
[[ "$SHLVL" -eq 1 && ! -o LOGIN ]] && _SHELL_TYPE="script"
[[ -o LOGIN ]] && _SHELL_TYPE="private"
# [[ "$_SHELL_TYPE" = "prompt" ]] && echo "$SHELL::$_SHELL_TYPE-$_SHELL_USER"
#-------------------------------------------------------------------------------
# Ensure that non-login/non-interactive shell has a defined environment.
#-------------------------------------------------------------------------------
if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then
. "${ZDOTDIR:-$HOME}/.zprofile"
fi
#-------------------------------------------------------------------------------
# HOMEBREW INIT
#-------------------------------------------------------------------------------
# [[ -f "$DOTFILES/brew/init_install.sh" ]] && . "$DOTFILES/brew/init_install.sh" \
# && _init_homebrew
#-------------------------------------------------------------------------------
# Load `.env` a.k.a. `~/.dotfiles/shell/env.symlink`
#-------------------------------------------------------------------------------
# This file should be loaded first in all shell environments,
# in the following files; `~/.bashrc` and `~/.zshenv`.
# It is required in `~/.zshenv` so script-shell-env uses user bin/functions.
# It is required a 2nd time, here in `~/.zshrc`, because `/etc/zprofile`
# overwrites the PATH variable before `~/.zshrc` is executed. =(
[[ -f "${ZDOTDIR:-$HOME}/.env" ]] && . "${ZDOTDIR:-$HOME}/.env"
#-------------------------------------------------------------------------------
# PATHS
#-------------------------------------------------------------------------------
# Set the the list of directories that cd searches.
# cdpath=(
# $cdpath
# )
# Set the list of directories that Zsh searches for programs.
# path=(
# $(brew --prefix)/{bin,sbin}
# $path
# )
# Ensure path arrays do not contain duplicates.
# typeset -gU cdpath fpath mailpath path
################################################################################
################################################################################
##
## GENERAL CONFIGURATION
## (stuff that you always want executed)
##
################################################################################
################################################################################
# autoload every function:
fpath=("$DOTFILES"/functions $fpath)
autoload -U "$DOTFILES"/functions/*(:t)
#-------------------------------------------------------------------------------
# Changing Directories
#-------------------------------------------------------------------------------
# `cd` is run if a valid command is not found
# auto 'cd dir' if you type 'dir'
setopt AUTO_CD
# `cd` pushes the old directory onto the directory stack
# This makes cd=pushd
setopt AUTO_PUSHD
# If arg is not a directory, see if it's a variable, and `cd` to its value
setopt CDABLE_VARS
# this will ignore multiple directories for the stack.
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_MINUS
# `pushd` and `popd` will no longer print the directory name
# No more annoying pushd messages...
# setopt PUSHD_SILENT
# `pushd` with no arguments act like 'pushd $HOME'
setopt PUSHD_TO_HOME
#-------------------------------------------------------------------------------
# Completion
#-------------------------------------------------------------------------------
# don't expand aliases _before_ completion has finished, like; git comm-[tab]
setopt complete_aliases
setopt COMPLETE_IN_WORD
# Immediately cycle through options for tab completion
# setopt MENU_COMPLETE
# Do not beep during listing completions
setopt NO_LIST_BEEP
#-------------------------------------------------------------------------------
# Expansion and Globbing
#-------------------------------------------------------------------------------
# I don't know why I never set this before.
setopt EXTENDED_GLOB
# If we have a glob this will expand it
setopt GLOB_COMPLETE
# Case insensitive globbing
setopt NO_CASE_GLOB
# Be Reasonable!
setopt NUMERIC_GLOB_SORT
# hows about arrays be awesome?
# `foo${cool}foo` has foo surrounding all variables, not just first and last.
setopt RC_EXPAND_PARAM
#-------------------------------------------------------------------------------
# History
#-------------------------------------------------------------------------------
# adds history
setopt APPEND_HISTORY
# Save command timestamps
setopt EXTENDED_HISTORY
# If the internal history needs to be trimmed to add the current command line,
# remove the oldest history event that has a duplicate. You should be sure to
# set the value of HISTSIZE to a larger number than SAVEHIST in order to give
# you some room for the duplicated events, otherwise this option will behave
# just like HIST_IGNORE_ALL_DUPS once the history fills up with unique events.
setopt HIST_EXPIRE_DUPS_FIRST
# When searching for history entries in the line editor,
# do not display duplicates of a line previously found,
# even if the duplicates are not contiguous.
setopt HIST_FIND_NO_DUPS
# If a new command line being added to the history list duplicates
# an older one then the older command is removed from the list.
setopt HIST_IGNORE_ALL_DUPS
# Don't save command if preceded by whitespace
setopt HIST_IGNORE_SPACE
# Trim unnecessary whitespace from commands in history
setopt HIST_REDUCE_BLANKS
# allow functions to have local traps
setopt HIST_VERIFY
# adds history incrementally
setopt INC_APPEND_HISTORY
# Share command history between active shell sessions
setopt SHARE_HISTORY
#-------------------------------------------------------------------------------
# Initialisation
#-------------------------------------------------------------------------------
# Don't globally export environment variables by default
# setopt NO_GLOBAL_EXPORT
#-------------------------------------------------------------------------------
# Input/Output
#-------------------------------------------------------------------------------
# This will use named dirs when possible
setopt AUTO_NAME_DIRS
# Output hex numbers in the familiar C syntax (e.g. '0x2f')
# setopt C_BASES
setopt CORRECT
# don't log out on EOF
setopt IGNORE_EOF
# Allow comments, even in an the interactive shell
# setopt INTERACTIVE_COMMENTS
# allow functions to have local options
setopt LOCAL_OPTIONS
# allow functions to have local traps
setopt LOCAL_TRAPS
# Keep echo "station" > station from clobbering station
# don't overwrite files unless forced
setopt NO_CLOBBER
# Output octal numbers in the familiar C syntax (e.g. '077')
# setopt OCTAL_ZEROES
# 10 second wait if you do something that will delete everything.
setopt RM_STAR_WAIT
# Print the exit value of programs with non-zero exit status
# setopt PRINT_EXIT_VALUE
#-------------------------------------------------------------------------------
# Job Control
#-------------------------------------------------------------------------------
# When disowning a process, send a SIGCONT
# setopt AUTO_CONTINUE
# Single letter commands call `fg`
# setopt AUTO_RESUME
# List jobs in a verbose format
# setopt LONG_LIST_JOBS
# zsh sends SIGHUP to running background jobs.
# setopt NO_HUP config only sends SIGHUP in certain situations.
setopt NO_HUP
# don't nice background tasks
setopt NO_BG_NICE
# If I could disable Ctrl-s completely I would!
setopt NO_FLOW_CONTROL
#-------------------------------------------------------------------------------
# Prompt
#-------------------------------------------------------------------------------
# Enable prompt substitution
setopt PROMPT_SUBST
# Clear right-side prompt upon submission of command
# setopt TRANSIENT_RPROMPT
#-------------------------------------------------------------------------------
# Scripts and Functions
#-------------------------------------------------------------------------------
# Pipe to multiple outputs
setopt MULTIOS
#-------------------------------------------------------------------------------
# Shell Emulation
#-------------------------------------------------------------------------------
# Use a version of `echo` compatible with bash
# setopt BSD_ECHO
#-------------------------------------------------------------------------------
# Zle
#-------------------------------------------------------------------------------
# use magic (this is default, but it can't hurt!)
# ! DISABLED: can't change option: ZLE
# setopt ZLE
zle -N newtab
#-------------------------------------------------------------------------------
# In the line editor, the number of matches to list without asking first.
# If the value is negative, the list will be shown if it spans at most as many
# lines as given by the absolute value. If set to zero, the shell asks only if
# the top of the listing would scroll off the screen.
# typeset -gx LISTMAX=0
# Duration to wait for further input during a key-sequence
# (in hundredths of a second)
# typeset -gx KEYTIMEOUT=20
#-------------------------------------------------------------------------------
# Who doesn't want home and end to work?
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
# Incremental search is elite!
bindkey -M vicmd "/" history-incremental-search-backward
bindkey -M vicmd "?" history-incremental-search-forward
# Search based on what you typed in already
bindkey -M vicmd "//" history-beginning-search-backward
bindkey -M vicmd "??" history-beginning-search-forward
bindkey "\eOP" run-help
# oh wow! This is killer... try it!
bindkey -M vicmd "q" push-line
# it's like, space AND completion. Gnarlbot.
bindkey -M viins ' ' magic-space
bindkey '^[^[[D' backward-word
bindkey '^[^[[C' forward-word
bindkey '^[[5D' beginning-of-line
bindkey '^[[5C' end-of-line
bindkey '^[[3~' delete-char
bindkey '^[^N' newtab
bindkey '^?' backward-delete-char
#-------------------------------------------------------------------------------
# History Settings
#-------------------------------------------------------------------------------
export HISTFILE="${ZDOTDIR:-$HOME}/.zsh_history"
export HISTSIZE=10000
export SAVEHIST=10000
#-------------------------------------------------------------------------------
# Temporary Files
#-------------------------------------------------------------------------------
if [[ ! -d "${TMPDIR:-}" ]]; then
export TMPDIR="/tmp/${LOGNAME:-}"
# shellcheck disable=SC2174
mkdir -p -m 700 "$TMPDIR"
fi
export TMPPREFIX="${TMPDIR%/}/zsh"
################################################################################
## THE END: GENERAL CONFIGURATION
################################################################################