-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc.tmpl
240 lines (206 loc) · 9.47 KB
/
dot_zshrc.tmpl
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
#
# SPDX-FileCopyrightText: (c) 2024 Rowan Gillson <[email protected]>
# SPDX-License-Identifier: MIT
#
# Documentation: https://github.com/romkatv/zsh4humans/blob/v5/README.md.
#
{{- if lookPath "zellij" }}
# Enable Zellij auto-attach if we are in a remote terminal.
if [ -n "${SSH_TTY}" ] && [ "${0##*/}" = "-zsh" ]; then
export ZELLIJ_AUTO_ATTACH=true
# Handle SSH_AUTH_SOCK forwarding for Zellij sessions.
if [ -z "${ZELLIJ}" ] && [ "${TERM}" != 'dumb' ] && ( echo "$-" | grep "i" >/dev/null ) && command -v zellij >/dev/null; then
if [ -S "${SSH_AUTH_SOCK}" ] && [ -w "/run/user/$(id -u)/" ] && ! [ -S "/run/user/$(id -u)/ssh_auth.sock" ]; then
rm -f /run/user/$(id -u)/ssh_auth.sock
ln -s "${SSH_AUTH_SOCK}" "/run/user/$(id -u)/ssh_auth.sock"
fi
eval "$(zellij setup --generate-auto-start zsh)"
fi
if [ -S "/run/user/$(id -u)/ssh_auth.sock" ]; then
export SSH_AUTH_SOCK="/run/user/$(id -u)/ssh_auth.sock"
fi
fi
{{- end }}
# Personal Zsh configuration file. It is strongly recommended to keep all
# shell customization and configuration (including exported environment
# variables such as PATH) in this file or in files sourced from it.
# Periodic auto-update on Zsh startup: 'ask' or 'no'.
# You can manually run `z4h update` to update everything.
zstyle ':z4h:' auto-update 'yes'
# Ask whether to auto-update this often; has no effect if auto-update is 'no'.
zstyle ':z4h:' auto-update-days '7'
# Keyboard type: 'mac' or 'pc'.
{{/* Support multiple keyboard layout options depending on target */}}
{{- if .target.wsl }}
zstyle ':z4h:bindkey' keyboard 'pc'
{{- else }}
zstyle ':z4h:bindkey' keyboard 'mac'
{{- end }}
# Don't automatically start tmux - we use Zellij for terminal multiplexing.
zstyle ':z4h:' start-tmux no
# Mark up shell's output with semantic information.
zstyle ':z4h:' term-shell-integration 'yes'
zstyle ':z4h:' propagate-cwd 'yes'
# Right-arrow key accepts one character ('partial-accept') from
# command autosuggestions or the whole thing ('accept')?
zstyle ':z4h:autosuggestions' forward-char 'accept'
# Use fzf to select directories from the directory history.
zstyle ':z4h:fzf-dir-history' fzf-bindings tab:repeat
zstyle ':z4h:cd-down' fzf-bindings tab:repeat
# Recursively traverse directories when TAB-completing files.
zstyle ':z4h:fzf-complete' recurse-dirs 'no'
# Enable direnv to automatically source .envrc files.
zstyle ':z4h:direnv' enable 'no'
# Show "loading" and "unloading" notifications from direnv.
# zstyle ':z4h:direnv:success' notify 'yes'
# Enable ('yes') or disable ('no') automatic teleportation of z4h over
# SSH when connecting to these hosts.
# zstyle ':z4h:ssh:example-hostname1' enable 'yes'
# zstyle ':z4h:ssh:*.example-hostname2' enable 'no'
# The default value if none of the overrides above match the hostname.
zstyle ':z4h:ssh:*' enable 'no'
# Send these files over to the remote host when connecting over SSH to the
# enabled hosts.
zstyle ':z4h:ssh:*' send-extra-files '~/.config/zsh/.exports.sh' '~/.config/zsh/.aliases.sh' '~/.config/zsh-abbr/user-abbreviations'
# Enable SSH config hostname completion.
zstyle ':completion:*:ssh:argument-1:' tag-order hosts users
zstyle ':completion:*:scp:argument-rest:' tag-order hosts files users
zstyle ':completion:*:(ssh|scp|rdp):*:hosts' hosts
# Clone additional Git repositories from GitHub.
#
# This doesn't do anything apart from cloning the repository and keeping it
# up-to-date. Cloned files can be used after `z4h init`. This is just an
# example. If you don't plan to use Oh My Zsh, delete this line.
z4h install ohmyzsh/ohmyzsh || return
z4h install mroth/evalcache || return
z4h install djui/alias-tips || return
# Install or update core components (fzf, zsh-autosuggestions, etc.) and
# initialize Zsh. After this point console I/O is unavailable until Zsh
# is fully initialized. Everything that requires user interaction or can
# perform network I/O must be done above. Everything else is best done below.
z4h init || return
# Extend PATH.
typeset -U PATH path
{{/* Define paths conditionally */}}
{{- if and (.target.darwin) (env "BREW_PATH") -}}
path=(
# The Homebrew versions of Gnu tools.
"${HOMEBREW_PREFIX}/opt/coreutils/libexec/gnubin"
"${HOMEBREW_PREFIX}/opt/gnu-sed/libexec/gnubin"
"${HOMEBREW_PREFIX}/opt/gnu-tar/libexec/gnubin"
"${HOMEBREW_PREFIX}/opt/grep/libexec/gnubin"
"${HOMEBREW_PREFIX}/bin"
"${HOME}/.local/bin"
${path}
)
{{- else if and (or .target.ubuntu .target.wsl) (env "BREW_PATH") -}}
path=(
"${HOMEBREW_PREFIX}/bin"
"${HOME}/.local/bin"
${path}
)
{{- else -}}
path+=(
"${HOME}/.local/bin"
${path}
)
{{- end }}
# Add additional directories to $fpath.
fpath=(
$ZDOTDIR/completions
$fpath
)
# Source additional local files if they exist.
z4h source "${ZDOTDIR:-$HOME/.config/zsh}/.exports.sh"
z4h source "${ZDOTDIR:-$HOME/.config/zsh}/.aliases.sh"
z4h source "${ZDOTDIR:-$HOME/.config/zsh}/.functions.sh"
{{/* Source GRC only on targets where it is already available */}}
{{- if lookPath "grc" -}}
z4h source "${HOMEBREW_PREFIX}/etc/grc.zsh" <$TTY
{{- end }}
{{/* Source Zsh-abbr only on targets where it is installed */}}
{{- if env "BREW_PATH" -}}
if [[ -L "${HOMEBREW_PREFIX}/share/zsh-abbr/zsh-abbr.zsh" ]]; then
z4h source "${HOMEBREW_PREFIX}/share/zsh-abbr/zsh-abbr.zsh"
fpath+=("${HOMEBREW_PREFIX}/share/zsh-abbr")
fi
{{- end }}
# Use additional Git repositories pulled in with `z4h install`.
#
# This is just an example that you should delete. It does nothing useful.
# z4h source ohmyzsh/ohmyzsh/lib/diagnostics.zsh # source an individual file
# z4h load ohmyzsh/ohmyzsh/plugins/emoji-clock # load a plugin
z4h load mroth/evalcache
z4h load djui/alias-tips
z4h load ohmyzsh/ohmyzsh/plugins/encode64
z4h load ohmyzsh/ohmyzsh/plugins/sudo
z4h load ohmyzsh/ohmyzsh/plugins/gitignore
{{/* Source systemd Zsh plugin only for Ubuntu servers */}}
{{- if .target.ubuntu -}}
z4h load ohmyzsh/ohmyzsh/plugins/systemd
{{- end -}}
{{/* Source Poetry-env plugin only when Poetry is installed */}}
{{- if lookPath "poetry" -}}
z4h load ohmyzsh/ohmyzsh/plugins/poetry-env
{{- end }}
# Define key bindings.
z4h bindkey undo Ctrl+/ Shift+Tab # undo the last command line change
z4h bindkey redo Option+/ # redo the last undone command line change
z4h bindkey z4h-cd-back Shift+Left # cd into the previous directory
z4h bindkey z4h-cd-forward Shift+Right # cd into the next directory
z4h bindkey z4h-cd-up Shift+Up # cd into the parent directory
z4h bindkey z4h-cd-down Shift+Down # cd into a child directory
# Autoload functions.
autoload -Uz zmv
# Define functions and completions.
function md() { [[ $# == 1 ]] && mkdir -p -- "$1" && cd -- "$1" }
compdef _directories md
# Define named directories: ~w <=> Windows home directory on WSL.
[[ -z $z4h_win_home ]] || hash -d w=$z4h_win_home
# Define aliases.
# alias tree='tree -a -I .git'
# Add flags to existing aliases.
# alias ls="${aliases[ls]:-ls} -A"
# Set shell options: http://zsh.sourceforge.net/Doc/Release/Options.html.
setopt glob_dots # no special treatment for file names with a leading dot
setopt no_auto_menu # require an extra TAB press to open the completion menu
# History options
HISTSIZE=50000
SAVEHIST=50000
HISTORY_IGNORE="(:|cd(| *)|l[adls](| *)|lsd(| *)|clear|pwd|exit|man *|*--help|*--version|[bf]g(| *)|jobs|z(| *)|history|less *|*shutdown*|*reboot*)"
HISTFILE="${ZDOTDIR:-$HOME/.config/zsh}/.zsh_history"
setopt APPEND_HISTORY # Append history to the history file.
setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt COMBINING_CHARS # Recognize certain non-English character combinations as special.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
# Cache unpackaged completions and functions
(( ${+commands[chezmoi]} )) && _evalcache chezmoi completion zsh
(( ${+commands[op]} )) && _evalcache op completion zsh && compdef _op op
(( ${+commands[thefuck]} )) && _evalcache thefuck --alias
(( ${+commands[wezterm]} )) && _evalcache wezterm shell-completion --shell zsh
# Test for Bat themes cache file in .cache/bat/themes.bin, if not present, run bat command to cache user themes
if [ ! -f "${XDG_CACHE_HOME}/bat/themes.bin" ]; then
(( ${+commands[bat]} )) && bat cache --build
fi
{{ if .target.wsl -}}
# Check for SSH_AUTH_SOCK env variable and load ssh-agent and SSH private key for Git commit signing
if [ -z "$SSH_AUTH_SOCK" ]; then
RUNNING_AGENT_COUNT=$(pgrep -cfx 'ssh-agent -s')
if [ "RUNNING_AGENT_COUNT" -eq 0 ]; then
ssh-agent -s > "${HOME}/.ssh/agent.env"
fi
eval $(cat "${HOME}/.ssh/agent.env") > /dev/null
ssh-add "${HOME}/.ssh/keys.d/id_ed25519.sign.work" > /dev/null 2>&1
fi
{{- end }}
# Remove slow command not found handler
[[ ! -v functions[command_not_found_handler] ]] || unfunction command_not_found_handler