-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdot_zshrc_main.tmpl
More file actions
324 lines (260 loc) · 9.35 KB
/
Copy pathdot_zshrc_main.tmpl
File metadata and controls
324 lines (260 loc) · 9.35 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
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
# Activate mise if installed
export PATH="$HOME/.local/bin:$PATH"
if (( $+commands[mise] )); then
eval "$(mise activate zsh)"
# Try to switch to nushell if
# - mise is available with nushell installed
# - we are at shell level 1
if [[ $- == *i* && $SHLVL < 2 ]] && mise which nu &> /dev/null; then
exec mise x -- nu -il
fi
fi
#---------------------------------------------------------------------
# Configure plugins and load with antigen
#---------------------------------------------------------------------
# Add custom functions to path
export fpath=( $HOME/.config/zsh/functions $fpath )
#---------------------------------------------------------------------
# Configure plugins and load with antigen
#---------------------------------------------------------------------
# Minimum recommend version
min_zsh_version='4.3.10'
if ! autoload -Uz is-at-least || ! is-at-least $min_zsh_version; then
print "zshrc: old shell detected, minimum required:\
$min_zsh_version" >&2
else
export ZPLUG_HOME=$HOME/.zplug
# Make sure we have zplug first
if [ ! -d $ZPLUG_HOME ] && ! which git &> /dev/null; then
echo "ERROR: zplug not found and we don't have git. Plugins\
and themes will not be loaded."
else
if ! [ -d $ZPLUG_HOME ]; then
echo "[33mNo ~/.zplug directory found. Installing zplug.[m"
rm -rf $ZPLUG_HOME &> /dev/null
git clone https://github.com/zplug/zplug $ZPLUG_HOME
fi
# Load zplug
source $ZPLUG_HOME/init.zsh
# Set case-sensitivity for completion, history lookup, etc.
zstyle ':prezto:*:*' case-sensitive 'no'
# Color output (auto set to 'no' on dumb terminals).
zstyle ':prezto:*:*' color 'yes'
# Set the Zsh modules to load (man zshmodules).
# zstyle ':prezto:load' zmodule 'attr' 'stat'
# Set the Zsh functions to load (man zshcontrib).
zstyle ':prezto:load' zfunction 'zargs' 'zmv'
# Don't alias normal commands to interactive versions
zstyle ':prezto:module:utility' safe-ops 'no'
# Set the Prezto modules to load (browse modules).
# The order matters.
zstyle ':prezto:load' pmodule \
'osx' \
'environment' \
'terminal' \
'editor' \
'history' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'python' \
'archive' \
'ruby' \
'node' \
'git'
# Set the key mapping style to 'emacs' or 'vi'.
zstyle ':prezto:module:editor' keymap 'vi'
# Auto convert .... to ../..
# zstyle ':prezto:module:editor' dot-expansion 'yes'
# Indicate when waiting on completions
zstyle ':prezto:module:editor:info:completing' format '[1;31m...[m'
# Ignore submodules when they are 'dirty', 'untracked', 'all', or 'none'.
# zstyle ':prezto:module:git:status:ignore' submodules 'all'
# Set the command prefix on non-GNU systems.
# zstyle ':prezto:module:gnu-utility' prefix 'g'
# Set the Pacman frontend.
# zstyle ':prezto:module:pacman' frontend 'yaourt'
# Set the prompt theme to load.
# Setting it to 'random' loads a random theme.
# Auto set to 'off' on dumb terminals.
# zstyle ':prezto:module:prompt' theme 'jmatth'
# Auto start a session when Zsh is launched.
# zstyle ':prezto:module:screen' auto-start 'yes'
# Set the SSH identities to load into the agent.
# zstyle ':prezto:module:ssh:load' identities 'id_rsa'
# Auto set the tab and window titles.
zstyle ':prezto:module:terminal' auto-title 'no'
# Auto start a session when Zsh is launched.
zstyle ':prezto:module:tmux:auto-start' remote 'yes'
# Override some git formatting
zstyle ':prezto:module:git:log:medium' format '%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%C(bold)PGP:%C(reset) %C(magenta)%G? %GK %GS%C(reset)%n%+B'
# Set virtualenv location
export WORKON_HOME="$HOME/.virtualenvs"
# Install and source my fork of prezto
zplug sorin-ionescu/prezto
# extra plugins
# antigen-bundle zsh-users/zsh-syntax-highlighting
zplug zsh-users/zsh-completions
zplug rupa/z, use:"z.sh"
# zplug jeffreytse/zsh-vi-mode
zplug load
zplug check || echo 'zsh plugins missing, run zplug install'
fi
fi
unset min_zsh_version
#---------------------------------------------------------------------
# Set zsh options
#---------------------------------------------------------------------
# Expand expressions in prompt variables
setopt promptsubst
#---------------------------------------------------------------------
# Exports
#---------------------------------------------------------------------
# Add extra executables to the path
export PATH=$PATH:$HOME/.local/bin:$HOME/projects/go/bin:$HOME/.cabal/bin:$HOME/.dotfiles/bin
# Add extra libraries
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.local/lib
# Fix UTF-8 characters breaking the prompt
export LANG="en_US.utf-8"
# Set editor
export EDITOR="nvim"
# Report runtime stats if something runs for more than 30 seconds
export REPORTTIME=30
# Better paging
export MANPAGER='nvim +Man!'
export LESSKEYIN=$HOME/.config/lesskey
#---------------------------------------------------------------------
# Key bindings
#---------------------------------------------------------------------
# Same custom keybinding as in vim
KEYTIMEOUT=1
bindkey "" vi-cmd-mode
bindkey "" history-incremental-search-backward
# Clear all escape-prefixed bindings
# bindkey -rpM viins '^['; bindkey -rp '^['
#---------------------------------------------------------------------
# Aliases
#---------------------------------------------------------------------
# Config mangement
alias zmod="$EDITOR ~/.zshrc_main"
alias lzmod="$EDITOR ~/.zshrc"
alias zsave="source ~/.zshrc"
alias vmod="$EDITOR $HOME/.config/nvim/init.lua"
alias smod="$EDITOR $HOME/.ssh/config"
alias hosts="$EDITOR /etc/hosts"
# sudo
alias sudo="sudo -E"
# ls
alias la="ls -AlhF"
alias lsa="ls -A"
# grep
alias grepc="grep --color=always"
alias grepi="grep -i"
alias grepp="ps aux | grep "
# git
alias gwt='cd ${$(git rev-parse --show-cdup):-.}'
# unalias gws || true
alias gws="git status"
alias gw="git switch"
alias gwc="git switch"
# Directory navigation
alias ..="cd .."
# zmv
alias zmv="zmv -wM"
alias zcp="zmv -wC"
alias zln="zmv -wL"
alias vim=nvim
alias vimdiff='nvim -d'
alias code=codium
#---------------------------------------------------------------------
# More aliases, but specifically for coreutils replacements
#---------------------------------------------------------------------
if (( $+commands[eza] )); then
alias ls="eza"
alias sl="eza"
alias la="eza -alF"
alias ll="eza -lF"
alias l="eza -1a"
alias tree="eza -T"
fi
if (( $+commands[bat] )); then
compdef _gnu_generic bat
alias cat="bat"
fi
#---------------------------------------------------------------------
# Shell functions.
#---------------------------------------------------------------------
# Move up n directories
function up () {
if [[ $# > 1 || $# == 1 && $1 != <-> ]]; then
echo "Usage: up [int]"
return 2
else
cd $(builtin printf "../"%.0s {1..${1:-1}})
fi
}
function mkcd () {
mkdir -p $1 && cd $1
}
# Shorthand clone from github
function hclone () {
local url
if [[ "$1" == "-p" ]]; then
url="git@github.com:$2.git"
shift
else
url="git://github.com/$1.git"
fi
git clone "$url" $2
}
{{ if eq .chezmoi.os "darwin" }}
#---------------------------------------------------------------------
# macOS specific
#---------------------------------------------------------------------
# Set up homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"
# change the mac version of ls to match my solarized dircolors
export LSCOLORS=gxfxfeaeBxdehebxbxgxgx
# tmux color black magic
if [[ `tput colors` -ge 256 ]]; then
alias tmux="TERM=screen-256color-bce tmux"
elif [[ `tput colors` -ge 16 ]]; then
alias tmux="TERM=screen-16color-bce tmux"
fi
# Fix weird behaviors
alias file="file -h"
# Can remove if Apple ever fixes their version of less
if test -f /usr/local/bin/less; then
export PAGER="/usr/local/bin/less -is"
fi
notify() {
osascript -e "display notification \"$1\" with title \"$2\" subtitle \"$3\""
}
{{ end }}
#---------------------------------------------------------------------
# Fix variables
#---------------------------------------------------------------------
# Eliminate duplicates in PATH and fpath
typeset -aU path
typeset -aU fpath
#---------------------------------------------------------------------
# Misc
#---------------------------------------------------------------------
# Change the colorscheme if using a vconsole
if [[ "$TERM" == "linux" ]] && which vconsole-color &> /dev/null; then
vconsole-color
fi
# Use GPG as SSH agent
unset SSH_AGENT_PID
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
export GPG_TTY="$(tty)"
# Use starship prompt if available
if (( $+commands[starship] )); then
eval "$(starship init zsh)"
fi
# Activate cargo/rustup if installed
if test -e "$HOME/.cargo/env"; then
source "$HOME/.cargo/env"
fi
# vi: ft=zsh