-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshrc
428 lines (347 loc) · 8.48 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
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
#!/bin/sh
###############################################################################
# Basic config
###############################################################################
# Start new terminals with tmux and add pywal color scheme
if ! { [ "$TERM" = "screen" ] && [ -n "$TMUX" ]; } then
# Prevent lose color scheme for new tmux sessions
wal -R -e -q
tmux
else
# Add wal color schema to the main terminal
cat ~/.cache/wal/sequences
fi
# Custom programs path
source ~/Programs/.programsrc
# zsh config
export ZSH=~/.oh-my-zsh
export ZSH_THEME=custom
export plugins=(git virtualenv shrink-path)
source $ZSH/oh-my-zsh.sh
# ranger config
export RANGER_LOAD_DEFAULT_RC=false
# ls alias
alias ls="ls -F -h --color=always -a"
###############################################################################
# Weird zone
###############################################################################
function bk {
# Change background and color scheme, and run neo function
#
# The color scheme is set using the selected background
#
# Args:
# $1 (optional): wallpaper path
#
# Without args:
# Select a random wallpaper
sh change-background >> /dev/null "$1"
clear
neo
}
function desc {
# Print the description of the Astronomic Picture of the Day
cat ~/.config/wal/image-description.txt
}
desc # run at start
function fav {
# Set preferred color schema
# Good themes:
# - base16-materia
# - sexy-theme2
wal -q --theme base16-materia
}
function lolban {
# Print a rainbow message with special ASCII font
#
# Args:
# $1: message
if [ -z "$1" ]; then
echo Miss message
return 1
fi
# Cool fonts list:
# - ~/.local/share/figlet-fonts/3d.flf
figlet "$@" -f ~/.local/share/figlet-fonts/3d.flf | lolcat
}
function cow {
# Invoke a psychedelic cow that tells your fortune
fortune | cowsay -w -f three-eyes | lolcat
}
function neo {
# Run a custom neofetch config
# If Ctrl+C is pressed, we clear the screen
trap clear INT
neofetch
# Return as a success after press Ctrl+C
return 0
}
###############################################################################
# Productivity
###############################################################################
# Alias for open the default UI editor
alias ed=code
function open {
# Open a link in the default browser
#
# Args:
# $1: link
if [ -z "$1" ]; then
echo Miss link
return 1
fi
$BROWSER "$1"
}
function cud {
# Interact with the current datetime
#
# You can change the datetime using UTC timezone, passing, in the following order, year, month, days, hours, and/or
# minutes.
# All of these args are optional, and you can pass a year without passing month using the next format: "cud 2020".
# This set the actual year to 2020, keeping all other values.
# Also, you can pass month ignoring year using a dot (.). E.g. "cud . 12". This set the month to December,
# keeping all other values.
# Another example: "cud . . . 15 12" set the time to UTC 3:12 p.m. maintaining the year, month and day.
# If no arguments are passed, the time is set automatically.
#
# Args:
# $1 (optional): year
# $2 (optional): month
# $3 (optional): day
# $4 (optional): hour
# $5 (optional): minute
#
# Without Args:
# Set the time to auto
if [ -z "$1" ]; then
timedatectl set-ntp true
echo RESTORED: "$(date +"%Y-%m-%d %H:%M:%S")"
return 0
fi
if [[ $(timedatectl show --value --property NTPSynchronized) == "no" ]]; then
timedatectl set-ntp false
fi
local year month day hour minute
if [[ $1 && "$1" != "." ]]; then
year=$1
else
year=$(date +%Y)
fi
if [[ $2 && "$2" != "." ]]; then
month=$2
else
month=$(date +%m)
fi
if [[ $3 && "$3" != "." ]]; then
day=$3
else
day=$(date +%d)
fi
if [[ $4 && "$4" != "." ]]; then
# Fix UTC differences
local timezone diff
timezone=$(date +%Z)
# - Get the absolute value of the difference
diff=$(grep -Po "(?<=\+|-)[0-9]+" <<< "$timezone")
# - When it's positive
if grep -Pq "[+](?<=[0-9])*" <<< "$timezone"; then
hour=$(($4 + $diff))
# - When it's negative
elif grep -Pq "[-](?<=[0-9])*" <<< "$timezone"; then
hour=$(($4 - $diff))
# - Whatever
else
hour=$4
fi
else
hour=$(date +%H)
fi
if [[ $5 && "$5" != "." ]]; then
minute=$5
else
minute=$(date +%M)
fi
echo BEFORE: "$(date +"%Y-%m-%d %H:%M:%S")"
sudo date -s "$year-$month-$day $hour:$minute:$(date +%S)" >> /dev/null
echo AFTER: "$(date +"%Y-%m-%d %H:%M:%S")"
}
function pk {
# Terminate all processes related to a port
#
# Args:
# $1: port
if [ -z "$1" ]; then
echo Miss port
return 1
fi
local processes
processes=$(lsof -t -i:"$1")
if [ -n "$processes" ]; then
echo -e "$processes" | while read -r pid; do
kill -9 "$pid"
done
else
return 1
fi
}
###############################################################################
# Python
###############################################################################
export PIPENV_VERBOSITY=-1
export WORKON_HOME=~/.Envs/Python
source ~/.local/bin/virtualenvwrapper.sh
function __check_py_virtual_env {
if [[ $(python -c "import os; print(1 if os.getenv('VIRTUAL_ENV') else 0)") == "1" ]]; then
return 0
else
return 1
fi
}
function pyc {
# Create a Python environment
#
# Args:
# $1: Python interpreter
# $2: env name
if __check_py_virtual_env; then
echo Deactivate the actual Python environment first
fi
if [ -z "$1" ]; then
echo Miss Python interpreter and env name
return 1
fi
if [ -z "$2" ]; then
echo Miss env name
return 1
fi
mkvirtualenv -p "$1" "$2"
pip install virtualenvwrapper
pyd
}
function pya {
# Activate a Python environment
#
# Args:
# $1: env name
if [ -z "$1" ]; then
echo Miss env name
return 1
fi
source $WORKON_HOME/"$1"/bin/activate
}
function pyl {
# List all Python environments
lsvirtualenv
}
function pyr {
# Remove a Python environment
#
# Args:
# $1: env name
if [ -z "$1" ]; then
echo Miss env name
return 1
fi
rmvirtualenv "$1"
}
function pyd {
# Deactivate the present Python environment if any
if __check_py_virtual_env; then
deactivate
fi
}
###############################################################################
# Deno and NodeJS
###############################################################################
source /usr/share/nvm/init-nvm.sh
function dd {
# Use default Deno version
dvm use v1.3.0
}
function nd {
# Use the default NodeJS version
nvm use node
}
###############################################################################
# Workspaces
###############################################################################
export WORKSPACE_H=~/Workspaces/H
export WORKSPACE_J=~/Workspaces/J
source ~/Workspaces/.hrc
source ~/Workspaces/.jrc
source ~/Workspaces/.crc
function __goto_clone {
# Change to a clone of a repo
#
# Args:
# $1: repo base folder
# $2: repo name
# $3: clone number
if [ -z "$3" ]; then
return 1
fi
local clone head_path
head_path="$1"/"$2"
clone="$head_path"/"$3"/"$2"
if [ -d "$clone" ]; then
cd "$clone" || return
else
echo Making clone number "$3" using clone number 1
mkdir "$head_path"/"$3"
cp -r "$head_path"/1/"$2" "$clone"
cd "$clone" || return
fi
}
function clean {
# Clean all workspaces envs
#
# It's mean all env vars and virtual envs set by the workspaces are removed
__wh_cleanall
__wj_cleanall
pyd
nd >> /dev/null
}
function wgc {
# Clone git repository in the appropriated workspace
#
# Args:
# $1: "h" | "j": Clone for H or J workspace
# $2: repo user
# $3: repo name
# $4 (optional): base folder
#
# Example:
# wgc h jackfrued Python-100-Days learn
if [ -z "$1" ]; then
echo Miss the definition of workspace "( \"h\" | \"j\" )", repo user and repo name
return 1
fi
if [ "$1" != h ] && [ "$1" != j ]; then
echo Bad workspace
return 1
fi
if [ -z "$2" ]; then
echo Miss repo user and repo name
return 1
fi
if [ -z "$3" ]; then
echo Miss repo name
return 1
fi
local workspace folder
case $1 in
h)
workspace=H
;;
j)
workspace=J
;;
esac
if [ -n "$4" ]; then
folder=~/Workspaces/"$workspace"/"$4"/"$3"/1
else
folder=~/Workspaces/"$workspace"/"$3"/1
fi
mkdir -p "$folder"
git -C "$folder" clone [email protected]:"$2"/"$3".git
}