-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
237 lines (185 loc) · 6.77 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# BASIC SETUP #########################################################
typeset -U PATH
autoload colors; colors;
# HOMEBREW ############################################################
# $(brew --prefix) is slow, check existing env variable instead
if [ "$CPUTYPE" = "arm64" ]; then
HOMEBREW_PREFIX=/opt/homebrew
else
HOMEBREW_PREFIX=/usr/local
fi
PATH=$HOMEBREW_PREFIX/bin:$HOMEBREW_PREFIX/sbin:$PATH
# HISTORY ############################################################
HISTFILE=$HOME/.zsh_history
HISTSIZE=50000
SAVEHIST=50000
setopt INC_APPEND_HISTORY # Immediately append to history file.
setopt EXTENDED_HISTORY # Record timestamp in history.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS # Dont record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Dont record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Dont write duplicate entries in the history file.
setopt SHARE_HISTORY # Share history between all sessions.
unsetopt HIST_VERIFY # Execute commands using history (e.g.: using !$) immediately
# COMPLETION ############################################################
# Add completions installed through Homebrew packages
# See: https://docs.brew.sh/Shell-Completion
if type brew &>/dev/null; then
FPATH="${HOMEBREW_PREFIX}/share/zsh/site-functions:${FPATH}"
fi
# Speed up completion init, see: https://gist.github.com/ctechols/ca1035271ad134841284
autoload -Uz compinit
for dump in ~/.zcompdump(N.mh+24); do
compinit
done
compinit -C
# unsetopt menucomplete
unsetopt flowcontrol
setopt auto_menu
setopt complete_in_word
setopt always_to_end
setopt auto_pushd
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
# PROMPT ############################################################
setopt prompt_subst
# left prompt is just a > that is colored red if there are background jobs
local promptnormal="> %{$reset_color%}"
local promptjobs="%{$fg_bold[red]%}> %{$reset_color%}"
PROMPT='%(1j.$promptjobs.$promptnormal)'
# static prompt above where the cursor is
git_status_short() {
if [[ ! -z $(git status --porcelain 2> /dev/null | tail -n1) ]]; then
echo "%{$fg_bold[red]%} ✘%{$reset_color%}"
else
echo "%{$fg_bold[green]%} ✔%{$reset_color%}"
fi
}
git_prompt_info() {
# get the branch name if we're in a git repo, otherwise return
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
# we're in a git repo, emit the branch name and 1 character status
echo " %{$fg_bold[green]%}${ref#refs/heads/}$(git_status_short)%{$reset_color%}"
}
local timestamp="%{$fg[blue]%}%D{%H:%M:%S}%{$reset_color%}"
local working_directory=" %{$fg_bold[yellow]%}%(5~|%-2~/.../%2~|%4~)%{$reset_color%}"
local exit_code="%(?.. [%{$fg_bold[red]%}%?%{$reset_color%}])"
# create a line above the prompt to with info
precmd() {
print -rP '${timestamp}${working_directory}$(git_prompt_info)${exit_code}'
}
# ALIASES/FUNCTIONS ############################################################
case $OSTYPE in
darwin*)
local aliasfile="${HOME}/.zsh.d/aliases.Darwin.sh"
[[ -e ${aliasfile} ]] && source ${aliasfile}
;;
esac
alias gs='git status --short'
alias grh="git reset --hard"
alias grs="git reset --soft"
alias gd="git diff"
alias gds="git diff --stat"
alias gdh1="git diff HEAD~1"
alias dh='dirs -v' # directory history
alias spwd='pwd | pbcopy' # copy the current working directory to the clipboard
alias agrep='alias | grep -i'
# builtins don't have their own man page
alias manbi='man zshbuiltins'
# directory usage recursive
alias duc='du -sh *(/)'
# starts a server on port 8000 that makes the current directory browsable with a webbrowser
alias webshare='python -m SimpleHTTPServer'
alias ws='windsurf'
function drma() {
## docker remove all containers
[[ -z $(docker ps -aq) ]] || docker rm -f $(docker ps -aq)
}
function epochToDate() {
if [ -z $1 ] ; then
echo "USAGE: epochToDate 1509821064514"
return 1
fi
date -j -r $(($1 / 1000))
}
# ENV #################################################################
case $OSTYPE in
darwin*)
local envfile="${HOME}/.zsh.d/env.Darwin.sh"
[[ -e ${envfile} ]] && source ${envfile}
;;
esac
export EDITOR=code
export WORDS=/usr/share/dict/words
# direnv
if type direnv &> /dev/null; then
eval "$(direnv hook zsh)"
else
echo "missing direnv, install with:"
echo "brew install direnv"
fi
# atuin
if type atuin &> /dev/null; then
eval "$(atuin init zsh)"
else
echo "missing atuin, install with:"
echo "brew install atuin"
fi
# fzf
if type fzf &> /dev/null; then
local fzf_shell="/opt/homebrew/opt/fzf/shell"
if [[ -d "${fzf_shell}" ]]; then
export FZF_CTRL_R_OPTS="--min-height=20 --exact --preview 'echo {}' --preview-window down:3:wrap"
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,build}/*" 2> /dev/null'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS=$'--min-height=20 --preview \'[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file ||
(bat --style=numbers --color=always {} ||
cat {}) 2> /dev/null | head -500
\''
export FZF_DEFAULT_OPTS="
--layout=reverse
--info=inline
--height=80%
--bind '?:toggle-preview'
"
source "${fzf_shell}/completion.zsh" 2> /dev/null
source "${fzf_shell}/key-bindings.zsh"
else
echo "fzf shell scripts not found, check installation"
fi
else
echo "missing fzf, install with:"
echo "brew install fzf"
fi
# PATH ################################################################
if [[ -d "$HOME/.cargo/bin" ]]; then
export PATH="$HOME/.cargo/bin:$PATH"
fi
if [[ -d "$HOME/.local/bin" ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
if [[ -d "$HOME/bin" ]]; then
export PATH="$HOME/bin:$PATH"
fi
if [[ -d "$HOME/.codeium/windsurf/bin" ]]; then
export PATH="$HOME/.codeium/windsurf/bin:$PATH"
fi
# PRIVATE / HOST SPECIFIC ############################################
# Include private stuff that's not supposed to show up in the dotfiles repo
local private="${HOME}/.zsh.d/private.sh"
if [ -e ${private} ]; then
. ${private}
fi
# Include host specific settings that likely won't apply to other machines
# HOST sometimes has .local on the end for some reason, this seems more consistent
local SIMPLE_HOST=$(hostname -s)
local this_host="${HOME}/.zsh.d/${SIMPLE_HOST}.sh"
if [ -e ${this_host} ]; then
. ${this_host}
else
echo "no host specific settings for ${SIMPLE_HOST}" >&2
fi
# Added by Windsurf
export PATH="/Users/tednaleid/.codeium/windsurf/bin:$PATH"