-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_zshrc
More file actions
257 lines (227 loc) · 7.6 KB
/
Copy pathdot_zshrc
File metadata and controls
257 lines (227 loc) · 7.6 KB
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
# .zshrc --- Processed by interactive shells
# Mike Barker <mike@thebarkers.com>
# Created: November 3rd, 2022
# Updated: November 5th, 2025
## Description:
# This file should contain commands to set up aliases, functions, options, key
# bindings, etc.
#
# Startup files processed order
# /etc/zshenv
# $ZDOTDIR/.zshenv
# If the shell is a login shell:
# /etc/zprofile
# $ZDOTDIR/.zprofile
# If the shell is interactive:
# /etc/zshrc
# $ZDOTDIR/.zshrc
# If the shell is a login shell:
# /etc/zlogin
# $ZDOTDIR/.zlogin
# When a login shell exits:
# $ZDOTDIR/.zlogout
# /etc/zlogout
#
# Startup behaviour can be modified by the RCS and GLOBAL_RCS options. If
# ZDOTDIR is unset, HOME is used instead. See the docs for more info:
# https://zsh.sourceforge.io/Doc/Release/Files.html#Startup_002fShutdown-Files
# Print the sourced file's name
# For example to see the files processed for a login shell use:
# $ DEBUG=1 zsh -l
[[ -n "$DEBUG" ]] && echo "Loading: ${(%):-%1N}..."
# TERM=dumb shell should be as simple as possible
# (no line-editing, no fancy prompts, no completion)
if [[ "$TERM" == "dumb" ]]; then
unsetopt zle
unsetopt prompt_cr
unsetopt prompt_subst
if whence -w precmd >/dev/null; then
unfunction precmd
fi
if whence -w preexec >/dev/null; then
unfunction preexec
fi
PS1='$ '
return
fi
# setup profiling
# zmodload zsh/zprof
# Define the location for oh-my-zsh and custom plugins and themes
ZSH=$HOME/.oh-my-zsh
ZSH_CUSTOM=$ZSH/custom
##
# Clone repositories
# Clone the oh-my-zsh repository
if [[ ! -d $ZSH ]]; then
git clone https://github.com/ohmyzsh/ohmyzsh.git $ZSH
fi
# Clone spaceship-prompt/spaceship-prompt
if [[ ! -d $ZSH_CUSTOM/themes/spaceship-prompt ]]; then
git clone https://github.com/spaceship-prompt/spaceship-prompt.git $ZSH_CUSTOM/themes/spaceship-prompt --depth=1
ln -s $ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme $ZSH_CUSTOM/themes/spaceship.zsh-theme
fi
# Clone z-shell/zsh-eza, if eza is installed
if (( $+commands[eza] )); then
if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-eza" ]]; then
git clone https://github.com/z-shell/zsh-eza.git $ZSH_CUSTOM/plugins/zsh-eza
fi
fi
# Clone zsh-users/zsh-autosuggestions
if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]]; then
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
fi
# Clone zsh-users/zsh-completions
if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-completions" ]]; then
git clone https://github.com/zsh-users/zsh-completions $ZSH_CUSTOM/plugins/zsh-completions
fpath+="$ZSH_CUSTOM/custom/plugins/zsh-completions/src"
fi
# Clone zsh-users/zsh-syntax-highlighting
if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
fi
##
# Configure the prompt
# Use starship if installed and not running in xterm
if (( $+commands[starship] )) && [[ $TERM != xterm ]]; then
# Starship Cross Platform Prompt
# https://starship.rs/
# The ~/.config/starship.toml file is used to configure the prompt.
eval "$(starship init zsh)"
# Otherwise use spaceship theme
else
# Starship zsh prompt theme
# https://denysdovhan.com/spaceship-prompt/
ZSH_THEME="spaceship"
# Disable kubecontext
export SPACESHIP_KUBECTL_CONTEXT_SHOW='false'
fi
##
# Oh-My-Zsh update settings
zstyle ':omz:update' mode auto # update automatically without asking
zstyle ':omz:update' frequency 7
##
# Define oh-my-zsh plugins to load
plugins=()
# Only add plugin if it's associated command is available.
if (( $+commands[brew] )); then
fpath+="$(brew --prefix)/share/zsh/site-functions"
plugins+=(brew)
fi
(( $+commands[chezmoi] )) && plugins+=(chezmoi)
(( $+commands[code] )) && plugins+=(vscode)
(( $+commands[direnv] )) && plugins+=(direnv)
if (( $+commands[eza] )); then
_EZA_PARAMS=(
'--git'
'--icons'
'--group'
'--group-directories-first'
'--time-style=long-iso'
'--color-scale=all'
'--color-scale-mode=fixed')
plugins+=(zsh-eza)
fi
(( $+commands[fzf] )) && plugins+=(fzf)
(( $+commands[git] )) && plugins+=(git)
(( $+commands[nvm] )) && plugins+=(nvm)
(( $+commands[tmux] )) && plugins+=(tmux)
if (( $+commands[zoxide] )); then
ZOXIDE_CMD_OVERRIDE=cd
plugins+=(zoxide)
fi
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
zstyle :omz:plugins:iterm2 shell-integration yes
plugins+=(iterm2)
fi
plugins+=(zsh-autosuggestions)
plugins+=(zsh-syntax-highlighting)
# Initialize oh-my-zsh and plugins
source $ZSH/oh-my-zsh.sh
##
# User environment
# Preferred editor for local and remote sessions
export EDITOR='vim'
##
# Aliases
# Set personal aliases, overriding those provided by oh-my-zsh libs, plugins,
# and themes. Aliases can be placed here, though oh-my-zsh users are encouraged
# to define aliases within the ZSH_CUSTOM folder. For a full list of active
# aliases, run `alias`.
(( $+commands[chezmoi] )) && alias cm=chezmoi
(( $+commands[emacs] )) && alias e=emacs
(( $+commands[emacsclient] )) && alias ec="emacsclient -a=''"
##
# Configure 1Password cli op command completion
if (( $+commands[op] )); then
eval "$(op completion zsh)"; compdef _op op
# 1Password cli `op` third party plugins configuration
op_plugins="$HOME/.config/op/plugins.sh"
if [[ -f "$op_plugins" ]]; then
source "$op_plugins"
fi
fi
##
# Configure 1Password SSH agent.sock
# Export the SSH_AUTH_SOCK
# Handle macos that by default stores the agent socket file in the users Library folder
# by creating a .1password folder and symlinking the agent.soc file to there.
op_agent_sock="$HOME/.1password/agent.sock"
op_agent_sock_macos="$HOME/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
if [[ -e "$op_agent_sock_macos" && ! -e "$op_agent_sock" ]]; then
mkdir -p $HOME/.1password
ln -s "$op_agent_sock_macos" "$op_agent_sock"
fi
[[ -e "$op_agent_sock" ]] && export SSH_AUTH_SOCK="$op_agent_sock"
##
# Configure `atuin` command history manager
if (( $+commands[atuin] )); then
eval "$(atuin init zsh --disable-up-arrow)"
fi
##
# Configure `fzf`
# - but only if 'fzf' *and* 'fd' is installed
if (( $+commands[fzf])) && (( $+commands[fd])); then
# Use 'fd' to find files and directories
export FZF_DEFAULT_COMMAND="fd --hidden --strip-cwd-prefix --exclude .git --exclude .venv"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="fd --type=d --hidden --strip-cwd-prefix --exclude .git --exclude .venv"
# Use 'fd' to list path candidates
_fzf_compgen_path() {
fd --hidden --exclude .git --exclude .venv . "$1"
}
# Use 'fd' to list directory candidates
_fzf_compgen_dir() {
fd --type=d --hidden --exclude .git --exclude .venv . "$1"
}
fi
##
# Configure `mise`
if (( $+commands[mise] )); then
# mise setup
eval "$(mise activate zsh)"
fi
##
# Handle tmux sessions:
# If not in a tmux session and there are tmux sessions running.
# Display active tmux sessions, and ask which session to connect to.
# If a session name was provided, attach to the session
if [[ -z $TMUX ]] && [[ $(tmux ls 2>/dev/null) ]]; then
print -P "%BYou have active tmux sessions:%b"
tmux ls
echo ""
read -r "session?Enter the session name to attach, or enter to continue: "
if [[ -n "$session" ]]; then
tmux attach -t "$session"
fi
fi
##
# chezmoi update and show status
if (( $+commands[chezmoi] )); then
echo "Chezmoi update and status"
chezmoi update -a=false > /dev/null
chezmoi status
fi
## remove duplicates from fpath
typeset -U fpath
# End profiling
# zprof