-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
320 lines (276 loc) · 7.7 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
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
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC1091
# NOTE: SC1090, SC1091 because we dont need to check linked shellscripts
# imports
source "$HOME/.profile"
if [ ! -d "$HOME/.local" ]; then mkdir "$HOME/.local"; fi
# --- Cross platform management ---
# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR="vim"
else
export ALTERNATE_EDITOR=''
# @TODO: Need to fix first file loading using emacsclient E.G git commit
# export EDITOR="emacsclient -t"
export EDITOR="nvim"
export VISUAL="$EDITOR"
fi
# Imports bash utils
source "$DOTFILES_PATH/install-scripts/functions-utils.bash"
# --- Rebinds ---
function vim() {
if test_command nvim; then
nvim "$@"
else
vim "$@"
fi
}
# upgrade
# function sudo() {
# # NOTE: Use full path to support user utils
# local cmd
# cmd="$(which "$1")"
# fullcmd="$cmd ${@:2}"
#
# if echo "$cmd" | grep -q "not found"; then
# >&2 echo "Error command $1 not found"
# return 1
# fi
#
# if echo "$cmd" | grep -Pq ".*?\s?\(\)\s?\{"; then
# fullcmd="bash -c '$cmd; $1 ${@:2}'"
# fi
#
# # Because linked in functions-utils.bash
# # shellcheck disable=SC2154
# printf "${c_bold}sudo${c_reset} ${c_red}%s %s${c_reset}\n" "$fullcmd"
# if [[ "$cmd" == "rm" ]]; then
# REPLY=$(bash -c 'read -p "Are you sure? [y/n] " -n 1 -r; echo $REPLY')
# echo
# if [[ ! $REPLY =~ ^[Yy]$ ]]
# then
# return 1
# fi
# fi
#
# eval "sudo $fullcmd"
# }
# shortcuts
# shellcheck disable=SC2139
alias sz="source $HOME/.zshrc"
# TODO: do not work
function fgl() {
>&2 echo "NOT IMPLEMENTED"
# sk --ansi --header='[find:git-commit]' \
# --cmd 'git log --oneline --graph --color' \
# --preview "echo git show --stat $(echo '{}' sed -E \"s/^[ *|]* [a-z0-9]{7} (.*)/\1/g\")"
}
function start-patch-number() {
local patch_folder
local patch_number
patch_folder=$(if [ "$#" -eq 1 ]; then echo "$1"; else echo "patches"; fi)
patch_number=0001
if [ -d "$patch_folder" ]; then
# shellcheck disable=SC2012
patch_number=$(echo "1 + $(ls "$patch_folder" | sed -E 's/([0-9]*)-.*/\1/' | sort --numeric-sort --reverse | head -n1)" | bc | xargs printf "%04d")
fi
echo "$patch_number"
}
function new-patch() {
local patch_folder
local patch_name
local patch_number
patch_folder=$(if [ "$#" -eq 2 ]; then echo "$1"; else echo "patches"; fi)
patch_name=$(if [ "$#" -eq 2 ]; then echo "$2"; else echo "$1"; fi)
patch_number=$(start-patch-number "$patch_folder")
# TODO: try ${variable//search/replace} instead.
# shellcheck disable=SC2001
echo "$patch_folder/$patch_number-$(echo "$patch_name" | sed 's/ /-/g').patch"
}
# SSH fix
alias ssh="env SHELL=/bin/sh TERM=xterm-256color ssh"
alias tailscale-ssh="env SHELL=/bin/sh TERM=xterm-256color tailscale ssh"
# CPE
function gccpe() { gcc "$1" -o "$2" -Wall -Wextra -g; }
# ls
# shellcheck disable=SC2139
alias ls="${CUSTOM_LS:-$(if command -v lsd >/dev/null; then echo lsd; else echo ls; fi)}"
alias ll="ls -l"
alias la="ls -al"
alias lh="ls -alh"
alias l="ls"
# Emacs
alias ec="emacsclient"
alias ecw="emacsclient -t"
alias ecc="emacsclient -c"
alias eccw="emacsclient -c -t"
# Nvim
alias nv-purge-swap="rm ~/.local/share/nvim/swap/*"
# git
alias ga="git add"
alias gu="git restore --staged"
alias gc="git commit"
alias gcm="gc -m"
alias gk="git checkout"
alias gkk="git branch | sk | xargs git checkout"
alias gm="git merge"
alias gb="git branch"
alias gf="git fetch"
alias gp="git pull"
alias gPu="git-push-upstream"
alias gBu="git-branch-set-upstream"
alias gst="git status"
alias gsh="git show"
alias gl="git log"
alias gd="git diff --minimal -B -M -C --color-moved=zebra"
alias gsl="git stash list"
alias gsa="git-stash-apply"
alias gs="git stash"
# --- Colored LESS E.G for man ---
export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;4;31m'
# --- Kitty (https://github.com/kovidgoyal/kitty/issues/610) ---
function set-title-precmd() {
printf "\e]2;%s\a" "${PWD/#$HOME/~}"
}
function set-title-preexec() {
printf "\e]2;%s\a" "$1"
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd set-title-precmd
add-zsh-hook preexec set-title-preexec
# REVIEW: Clean completion cache
rm -f ~/.zcompdump >/dev/null 2>&1
fpath+=~/.local/share/zfunc
# Support bash completions
autoload bashcompinit
bashcompinit
# ZSH Completions
autoload -Uz compinit
compinit
# --- Tools sourcing ---
if test_command broot; then
source "$HOME/.config/broot/launcher/bash/br"
fi
if test_command zoxide; then
eval "$(zoxide init zsh)"
fi
if test_command kubectl; then
eval "$(kubectl completion zsh)"
fi
if test_command k3s; then
eval "$(k3s completion zsh)"
fi
# Load ASDF
ASDF_PATH="$HOME/.asdf/asdf.sh"
if [ -f "$ASDF_PATH" ]; then
source "$ASDF_PATH"
# shellcheck disable=SC2206
fpath+=(${ASDF_DIR}/completions $fpath)
export PATH="$PATH:$ASDF_USER_SHIMS"
elif [ -f "/opt/asdf-vm/asdf.sh" ]; then
. /opt/asdf-vm/asdf.sh
fi
## Load JAVA_HOME
set_java_home_file=~/.asdf/plugins/java/set-java-home.zsh
if [ -f $set_java_home_file ]; then
source $set_java_home_file
fi
## Load Rebar3
if [ -d "$HOME/.cache/rebar3/bin" ]; then
export PATH="$PATH:$HOME/.cache/rebar3/bin"
fi
## Load fly.io's flyctl
if [ -d "$HOME/.fly" ]; then
export FLYCTL_INSTALL="$HOME/.fly"
export PATH="$PATH:$FLYCTL_INSTALL/bin"
fi
## Pulumi
if [ -d "$HOME/.pulumi" ]; then
# add Pulumi to the PATH
export PATH="$PATH:$HOME/.pulumi/bin"
fi
## Proto
if [ -d "$HOME/.proto" ]; then
export PROTO_HOME="$HOME/.proto"
export PATH="$PROTO_HOME/shims:$PROTO_HOME/bin:$PATH"
fi
# Load Nix
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
# --- Antigen ---
ANTIGEN_PATH="$HOME/.local/antigen.zsh"
if [ ! -f "$ANTIGEN_PATH" ]; then
curl -L git.io/antigen -o "$ANTIGEN_PATH"
fi
source "$ANTIGEN_PATH"
# plugins
antigen bundle MichaelAquilina/zsh-you-should-use
antigen bundle hlissner/zsh-autopair
antigen bundle Aloxaf/fzf-tab
# zsh-users
antigen bundle zsh-users/zsh-completions
# Last one !important
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-history-substring-search
antigen bundle zsh-users/zsh-autosuggestions
antigen apply
# --- Sources ---
if test_command starship; then
eval "$(starship init zsh)"
fi
# --- Key rebind ---
# del
bindkey "^[[3~" delete-char
# os-left
bindkey "^[[1;9D" beginning-of-line
bindkey "^[[H" beginning-of-line
# os-right
bindkey "^[[1;9C" end-of-line
bindkey "^[[F" end-of-line
# ctrl-left
bindkey "^[[1;5D" emacs-backward-word
# ctrl-right
bindkey "^[[1;5C" emacs-forward-word
# ctrl-c
bindkey "^C" kill-whole-line
# ctrl-backspace
bindkey "^H" backward-delete-word
# fish search up
bindkey "^[[A" history-substring-search-up
# fish search down
bindkey "^[[B" history-substring-search-down
# search histoty
bindkey '^R' history-incremental-search-backward
# --- ZSH ---
# Default: *?_-.[]~=/&;!#$%^(){}<>
export WORDCHARS="*?_.~&;!#$%^"
# History
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=10000
export SAVEHIST=10000
setopt inc_append_history
setopt histignorespace
# Highlights
export ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor root line)
export ZSH_HIGHLIGHT_PATTERNS=('rm *\*' 'fg=white,bold,bg=red')
# DISABLE_AUTO_UPDATE="true"
export DISABLE_UPDATE_PROMPT="true"
export ENABLE_CORRECTION="true"
export DISABLE_UNTRACKED_FILES_DIRTY="true"
#bashcompinit
#autoload -Uz compinit && compinit &&
if test_command moon; then
eval "$(moon completions)"
fi
# bun completions
[ -s "/home/johan/.bun/_bun" ] && source "/home/johan/.bun/_bun"
# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"