-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc.tmpl
432 lines (398 loc) · 14.6 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
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
{{- $paths := list }}
{{- range $_, $relPath := list "/usr/local/go/bin" "/opt/homebrew/opt/ruby/bin" "/opt/homebrew/lib/ruby/gems/3.3.0/bin" }}
{{ $path := $relPath }}
{{- if stat $path }}
{{- $paths = mustAppend $paths $path }}
{{- end }}
{{- end }}
{{- $homeDir := .chezmoi.homeDir }}
{{- range $_, $relPath := list "bin" "go/bin" ".cargo/bin" ".local/bin" ".deno/bin" ".rbenv/bin" ".dotnet/tools" }}
{{ $path := joinPath $homeDir $relPath }}
{{- if stat $path }}
{{- $paths = mustAppend $paths $path }}
{{- end }}
{{- end }}
{{- if $paths }}
export PATH={{ toStrings $paths | join ":" }}:$PATH
{{- end }}
export VISUAL=nvim
export EDITOR="$VISUAL"
export ANSIBLE_HOST_KEY_CHECKING=False
export DEBUGINFOD_URLS="https://debuginfod.archlinux.org/"
# Change colors of ls
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*.h=01;30;105:*.hpp=01;30;105:*.c=01;30;46:*.cpp=01;30;46:*.a=01;30;43:*.so=01;30;43:*.gitlab-ci.yml=01;30;47:*Dockerfile=01;46;97:*docker-compose.yml=01;97;105';
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="af-magic"
# ZSH_THEME="cloud"
# ZSH_THEME="half-life"
ZSH_THEME="powerlevel10k/powerlevel10k"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
zsh-autosuggestions
colored-man-pages
zsh-syntax-highlighting
docker
node
python
react-native
zsh-lsd
)
source $ZSH/oh-my-zsh.sh
# Init rbenv
eval "$(rbenv init -)"
# Utils
function slugify {
echo "$1" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z
}
function confirm {
local _response
while true; do
if [ -n "$1" ]; then
echo -n "$1"
else
echo -n "Are you sure"
fi
echo -n " [Y/n] ? "
read -r _response
case "$_response" in
[Yy][Ee][Ss]|[Yy]|"")
return 0
;;
[Nn][Oo]|[Nn])
return 1
;;
*)
echo "Invalid input, Please response Yes or No"
;;
esac
done
}
# Aliases
alias l="ls -hlA"
alias q="exit"
alias c="clear"
alias v="nvim"
alias trouve="grep -rn --exclude-dir=deps --exclude-dir=build"
alias search="grep -rl"
function replace {
if [ "$#" -lt "2" ]; then
echo "Error: You need to give at least two arguments, the searched string, and the string the found elements should be replaced by"
else
files=""
fileChanged=0
find=${1//\//\\\/}
find=${find//\./\\\.}
replace=${2//\//\\\/}
replace=${replace//\./\\\.}
if [ -z "$3" ]; then
files="${files}`find -not -path "." -not -path ".."`"
else
for filter in "${@:3}";
do
files="${files}`find -path $filter -not -path "." -not -path ".."`\n"
done
fi
echo $files
confirm "The previous files may be modified, Continue"
if [ $? -eq 1 ]; then
echo "Aborting..."
return
fi
files="`echo "$files" | tr '\n' ' '`"
setopt shwordsplit
for file in $files;
do
rm -rf /tmp/replacechangelog.txt
sed -i "s/$find/$replace/gw /tmp/replacechangelog.txt" $file
if [ -f /tmp/replacechangelog.txt ]; then
lineChanged=`cat /tmp/replacechangelog.txt | wc -l`
else
lineChanged=0
fi
if [ "$lineChanged" -gt "0" ]; then
echo "$lineChanged line(s) changed in $file"
((fileChanged=fileChanged+1))
fi
done
unsetopt shwordsplit
if [ "$fileChanged" -gt "0" ]; then
echo -e "\n$fileChanged file(s) changed"
else
echo -e "\nNo file changed"
fi
fi
}
alias mkae="make"
alias mkea="make"
alias mkae="make"
alias kmae="make"
alias maek="make"
alias mak="make"
alias mke="make"
alias amek="make"
alias watchc="watch -c -n 0.5"
alias mode="stat -c \"%a %n\""
function dpurge {
confirm "Do you want to stop and remove all docker containers"
if [ $? -eq 0 ]; then
if [ $(docker ps -q | wc -l) -gt "0" ]; then
docker stop $(docker ps -q)
fi
if [ $(docker ps -qa | wc -l) -gt "0" ]; then
docker rm $(docker ps -qa)
fi
fi
confirm "Do you want to remove all docker images"
if [ $? -eq 0 ]; then
if [ $(docker image ls -q | wc -l) -gt "0" ]; then
docker image rm $(docker image ls -q)
fi
fi
confirm "Do you want to remove all docker volumes"
if [ $? -eq 0 ]; then
if [ $(docker volume ls -q | wc -l) -gt "0" ]; then
docker volume rm $(docker volume ls -q)
fi
fi
confirm "Do you want to remove all docker networks"
if [ $? -eq 0 ]; then
if [ $(docker network ls -q | wc -l) -gt "0" ]; then
docker network rm $(docker network ls -q)
fi
fi
}
function notify {
if [ -z "$1" ]; then
echo "Please provide a command to launch"
return 1
fi
eval "$*"
if [ $? -ne 0 ]; then
python3 -c "import playsound;playsound.playsound('/etc/scripts/fail-sound.wav', True);" &
notify-send -u critical -i face-sad "Your command as failed" "$*"
else
python3 -c "import playsound;playsound.playsound('/etc/scripts/success-sound.wav', True);" &
notify-send -u critical -i face-cool "Your command as been successfully runned" "$*"
fi
}
function notifyl {
if [ -z "$1" ]; then
echo "Please provide a command to launch"
return 1
fi
logsFile="$*"
logsFile=`slugify $logsFile`
logsFile=${logsFile//\//-}
logsPath=/tmp/${logsFile}.txt
eval "$*" 2>&1 > $logsPath
if [ $? -ne 0 ]; then
python3 -c "import playsound;playsound.playsound('/etc/scripts/fail-sound.wav', True);" &
response=`notify-send -u critical -i face-sad "Your command as failed" "$*\n$(cat $logsPath)" -A "View logs"`
else
python3 -c "import playsound;playsound.playsound('/etc/scripts/success-sound.wav', True);" &
response=`notify-send -u critical -i face-cool "Your command as been successfully runned" "$*" -A "View logs"`
fi
if [ "$response" = "0" ]; then
terminator -e "$VISUAL $logsPath"
fi
}
function run-command-with-notify-background-impl {
eval "$2" 2>&1 > "$1"
if [ $? -ne 0 ]; then
python3 -c "import playsound;playsound.playsound('/etc/scripts/fail-sound.wav', True);" &
response=`notify-send -u critical -i face-sad "Your command as failed" "$2\n$(cat $1)" -A "View logs"`
else
python3 -c "import playsound;playsound.playsound('/etc/scripts/success-sound.wav', True);" &
response=`notify-send -u critical -i face-cool "Your command as been successfully runned" "$2" -A "View logs"`
fi
if [ "$response" = "0" ]; then
terminator -e "$VISUAL $1"
fi
}
function notifyb {
if [ -z "$1" ]; then
return 1
fi
logsFile="$*"
logsFile=`slugify $logsFile`
logsFile=${logsFile//\//-}
logsPath=/tmp/${logsFile}.txt
run-command-with-notify-background-impl $logsPath "$*" &
disown
}
function update-discord {
tmpPath="/tmp/update-discord"
if [ -z "$1" ]; then
echo "No archive path provided"
return 1
fi
rm -rf $tmpPath
mkdir -p $tmpPath/
cp -r "$1" $tmpPath/
cd $tmpPath/
tar -xvf "$1" Discord/
sudo rm -rf /opt/discord/
sudo cp -r Discord /opt/discord
}
alias zs="source ~/.zshrc"
alias zc="$EDITOR ~/.zshrc"
function merge-cc {
ccfile="compile_commands.json"
oldext=".old"
if [ -f "$ccfile" ]; then
mv $ccfile ${ccfile}${oldext}
fi
jq -s 'map(.[])' $1/**/compile_commands.json > compile_commands.json
}
alias ku=kubectl
# Git
alias gss="git status"
alias ga="git add"
function git-commit {
if [ -n "$1" ] && [ -n "$2" ]; then
git commit -m "$1" -m "$2"
elif [ -n "$1" ]; then
git commit -m $@
else
git commit
fi
}
alias gc="git-commit"
alias gp="git push origin \$(git branch --show-current)"
alias gpl="git pull origin \$(git branch --show-current)"
alias gpla="gpl ; git fetch --all"
alias gs="git switch"
alias gb="git branch"
function git-branch-switch {
if [ -z "$1" ]; then
echo "Please provide a branch name to create"
fi
gpla
git branch "$1"
git switch "$1"
}
alias gbs="git-branch-switch"
alias gbdel="git branch -D"
alias gbdelr="git push origin --delete"
function gbdelall {
if [ -z "$1" ]; then
echo "Please provide a branch to delete"
return 1
fi
git push origin --delete "$1"
git branch -D "$1"
}
alias grest="git restore --staged ."
alias grestu="git restore ."
function gacp {
ga .
if [ -n "$1" ] && [ -n "$2" ]; then
git commit -m "$1" -m "$2"
elif [ -n "$1" ]; then
git commit -m "$1"
else
git commit -m "Update"
fi
gp
}
function gsquash {
git branch --contains "$1"
code=$?
if ! [ $code -eq 0 ]; then
echo "Could not find a commit with the id '$1'"
return 1
fi
git rebase -i ${1}~1
if ! [ $code -eq 0 ]; then
echo "An error occurred while rebasing"
return 1
fi
gp --force
}
function recursive-git-pull-watch-directory {
if [[ -d "$1/.git" ]]; then
echo "Pulling $1"
cd "$1"
gpl
cd -
else
subdircount=$(find $1 -maxdepth 1 -type d | wc -l)
if [[ "$subdircount" -ne 1 ]]; then
for dir in "$1/*/"
do
recursive-git-pull-watch-directory "$dir"
done
fi
fi
}
function rgpl {
setopt dotglob
recursive-git-pull-watch-directory $(pwd)
}
function gprune {
git prune ; git fetch -p ; git branch -vv | awk '/\[.*: gone\]/ || !/\[origin\// {print $1}' | xargs -r -I {} git branch -D {}
}
# Get custom profile
if [ -r $HOME/.zsh_profile ]; then
source $HOME/.zsh_profile
fi
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion