-
Notifications
You must be signed in to change notification settings - Fork 4
/
.zshrc
215 lines (156 loc) · 5.68 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
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
#!/usr/bin/env zsh
# ~/.zshrc
# dotfiles/.zshrc
# http://zsh.sourceforge.net/Intro/intro_3.html
# ---------------------------------------------------------------------------
# Based on:
# https://scriptingosx.com/2019/11/new-book-release-day-moving-to-zsh/
# ---------------------------------------------------------------------------
# Convention(s)
# Enable: setopt
# Disable: unsetopt
### Constants ####
INITIAL_DIR="${HOME}/Documents/Projects"
# $PATH & ENV exports MUST be at the top of .zshrc
# We need all of these to be exported first otherwise some commands will fail or behaviour unexpectedly
# See: b79b7968166df0238df8aa61e975b9bcecbabf06
### $PATH Exports ###
eval "$(/opt/homebrew/bin/brew shellenv)"
# Add Homebrew to PATH
if [ -x "$(command -v /usr/local/opt/ruby/bin/ruby)" ]; then
export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.0.0/bin:$PATH"
# macOS ships with a version of Ruby at /usr/bin/ruby
# /usr/bin also contains versions of gem and bundler
# We need these ruby paths at the front of $PATH to override the default installed ruby bianries
# At some point in the future Apple will remove scripting language runtimes so this will need revised
# https://tidbits.com/2019/06/25/apple-to-deprecate-scripting-languages-in-future-versions-of-macos/
fi
if [[ -x "$(command -v go)" ]]; then
export PATH=$PATH:$GOPATH/bin
fi
if [ -x "$(command -v "$HOME/Library/Python/3.9/bin/virtualenv")" ]; then
# Should the second check be "$HOME/Library/Python/*/bin/virtualenv" this will need manually
# changed when python moves to version 4.x
export PATH=$PATH:$HOME/Library/Python/3.9/bin
# Required for virtualenv as installed by pip
# pip3 show virtualenv
fi
### Enviroment Variable Exports ###
if [ -x "$(command -v /usr/local/bin/brew)" ]; then
export HOMEBREW_BREWFILE=$HOME/Documents/Projects/dotfiles/.extra/Brewfile
# Set location of Brewfile
fi
if [[ -x "$(command -v go)" ]]; then
export GOPATH=$HOME/Documents/Projects/go
fi
if [[ -d "/Applications/Secretive.app" ]]; then
export SSH_AUTH_SOCK=$HOME/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh
fi
export IIOEnableOOP=YES
# Enabled the undocumeted ImageIO sandbox
# Tells ImageIO to parse images our of process in the ImageIOXPCService process instead
# https://rtx.meta.security/mitigation/2023/09/11/Sandboxing-ImageIO-in-macOS.html
### Prompt ###
# shellcheck disable=SC2034
PROMPT=$'%F{blue}% %n%f 🐶 %B%~%b\n%(?.%F{green}√%f.%F{red}%?)%f %(!.#.$) '
# Example
# 0xmachos 🐶 /System/Library/CoreServices
# √ $
# Explanation
# %F{blue}% %n%f
## Print username (%n) in blue
# %B%~%b
## Print pwd relative to $HOME (%~) in bold (%B)
## If last command exit 0 print √ in green else print exit code in red
# %(!.#.$)
# If root print # else print $
# Git Integration
# https://git-scm.com/book/en/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Zsh
# Moving to Zsh p139
setopt prompt_subst
# ENABLE: parameter expansion and command substitution in prompts
autoload -Uz vcs_info
precmd_functions+=(vcs_info)
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git:*' formats '(%b)'
# shellcheck disable=SC2034
RPROMPT=\$vcs_info_msg_0_
### Command/ Path Correction ###
setopt correct
# ENABLE: Command correction
setopt correct_all
# ENABLE: Argument correction
# shellcheck disable=SC2034
SPROMPT="Correct %F{red}%R%f to %F{green}%r%f [nyae]?"
# Correction prompt
### Behaviour ###
setopt autocd
# ENABLE: Changes directory to path without needing cd
setopt glob_complete
# ENABLE: Hitting tab twice lists possible completions
unsetopt case_glob
# DISABLE: Case sensitive globbing
### Completion ###
# Initialise zsh completion system
# https://github.com/zsh-users/zsh-completions
# https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh
# Enables zsh-completions as installed by brew
# If “zsh compinit: insecure directories” run
# chmod -R go-w "$(brew --prefix)/share"
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
# Case insensitive path-completion
zstyle ':completion:*' matcher-list 'm:
{[:lower:][:upper:]}={[:upper:]
[:lower:]}' 'm:{[:lower:][:upper:]}
={[:upper:][:lower:]} l:|=* r:|=*' 'm:
{[:lower:][:upper:]}={[:upper:][:lower:]}
l:|=* r:|=*' 'm:{[:lower:][:upper:]}
={[:upper:][:lower:]} l:|=* r:|=*'
# Partial completion suggestions
zstyle ':completion:*' list-suffixes
zstyle ':completion:*' expand prefix suffix
### Functions ###
FPATH="$HOME/.functions/:$FPATH"
# Add $HOME/.functions/ to FPATH
# shellcheck disable=SC2086,SC2154,SC1087
autoload -Uz $fpath[1]/*(.:t)
# Lazy autoload every file in $HOME/.functions/* as a function
# I've no idea what (.:t) does ¯\_(ツ)_/¯
# https://unix.stackexchange.com/a/526429
### Aliases ###
# shellcheck disable=SC1091
source "$HOME/.aliases"
### History ###
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
# Location of history file
# Use value of $ZDOTDIR if it has a value
# otherwise use value of $HOME
HISTSIZE=50000
# Lines remembered per session
# shellcheck disable=SC2034
SAVEHIST=100000
# Lines stored in history file
setopt EXTENDED_HISTORY
# Save command start time and duration
setopt SHARE_HISTORY
# Use single shared history file for all sessions
## Reducing Clutter
setopt HIST_EXPIRE_DUPS_FIRST
# Expire duplicates first
setopt HIST_IGNORE_DUPS
# Do not store duplications
setopt HIST_FIND_NO_DUPS
# Ignore duplicates when searching
setopt HIST_REDUCE_BLANKS
# Remove blank lines
setopt HIST_IGNORE_SPACE
# Do not store command lines starting with a space
### Change into Inital Directory ###
if [[ -d "${INITIAL_DIR}" ]]; then
# shellcheck disable=SC2164
cd "${INITIAL_DIR}"
fi