-
Notifications
You must be signed in to change notification settings - Fork 0
/
oh-my-custom-zsh.zsh
303 lines (268 loc) · 7.86 KB
/
oh-my-custom-zsh.zsh
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
# PW - Custom password generator function
# Usage:
# - pw 20 (genrate random password, without special characters)
# - pw 20 char (genrate random password, with special characters)
# Required pwgen, install with: brew install pwgen
# For further help: pwgen -h
pw() {
if [[ $2 == "char" ]]; then
pwgen -Bcnsvy -r \<\>\=\+\'\"\?\^\(\)\`\:\~\;\:\[\]\{\}\.\,\\\/\| $1 1 | tr -d "\n" | pbcopy;
else
pwgen -Bcnsv $1 1 | tr -d "\n" | pbcopy;
fi
echo -e "$(pbpaste)\nCopied to clipboard!"
}
# PW bcrypt - Custom bcrypt password generator function
# Usage:
# - pwbcrypt newPassword (generate bcrypt hash)
# - pwbcrypt 20 (genrate random bcrypt hash and password, without special characters)
# - pwbcrypt 20 char (genrate random bcrypt hash and password, with special characters)
# Required pwgen, install with: brew install pwgen
# For further help: pwgen -h
pwbcrypt() {
if [[ $1 =~ '^[0-9]+$' ]]; then
if [[ $3 == "char" ]]; then
PASSWORD=$(pwgen -Bcnsvy -r \<\>\=\+\'\"\?\^\(\)\`\:\~\;\:\[\]\{\}\.\,\\\/\| $1 1 | tr -d "\n");
else
PASSWORD=$(pwgen -Bcnsv $1 1 | tr -d "\n");
fi
else
PASSWORD=$1
fi
if [[ $2 =~ '^[0-9]+$' ]]; then
ROUNDS=$2
else
ROUNDS=10
fi
BCRYPT_HASH=$(htpasswd -nbBC $ROUNDS user $PASSWORD | awk -F 'user:' '{print $2}')
echo -e "Password: $PASSWORD"
echo $BCRYPT_HASH | tr -d "\n" | pbcopy
echo -e "Bcrypt hash with $ROUNDS rounds (copied to clipboard): $BCRYPT_HASH"
}
# macOS
alias ll="ls -alhF"
alias rm="${aliases[rm]:-rm} -vi"
alias mv="${aliases[mv]:-mv} -vi"
alias cp="${aliases[cp]:-cp} -v"
alias grep="${aliases[grep]:-grep} --color=auto -n"
alias rmds="find . -name '*.DS_Store' -type f -delete"
alias hosts="vsa /etc/hosts"
alias exports="vsa /etc/exports"
alias knownhosts="vsa ~/.ssh/known_hosts"
alias sshconfig="vsa ~/.ssh/config"
alias resetls="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -seed -r -f -v -domain local -domain user -domain system"
alias flushdns="sudo killall -HUP mDNSResponder"
alias clearkext="sudo kextcache --clear-staging"
alias myip="dig +short txt ch whoami.cloudflare @1.0.0.1"
alias qrscan="zbarimg"
alias weight="tree -a --du -sh"
# Git
alias gcs="git checkout staging"
# ssh-agent
alias sshls="ssh-add -L"
alias sshdl="ssh-add -D"
alias sshad="ssh-add --apple-use-keychain ~/.ssh/id_rsa ~/.ssh/id_ed25519 ~/.ssh/id_ed25519_personal"
# Oh My Zsh and Oh My Custom Zsh
alias ohmyzsh="cd ~/.oh-my-zsh"
alias ohmycustomzsh="cd ~/.oh-my-custom-zsh"
# Vagrant
alias vau="vagrant up"
alias vah="vagrant halt"
alias vas="vagrant status"
alias var="vagrant reload"
alias vap="vagrant provision"
alias vaup="vagrant up --provision"
alias vass="vagrant ssh"
alias vabu="vagrant box update"
# Visual Studio Code
alias vsls="code --list-extensions"
# Sail
alias sail='bash ./vendor/bin/sail'
# BeDo CLI
alias bedo="./bedo.sh"
# Print plist file to stdout (XML format)
catplist() {
plutil -convert xml1 -o - $1
}
# PHP Version Manager
pvm() {
NEW_VERSION=$1
OLD_VERSION=$(php --version | awk '/^PHP/{print $2}' | cut -d'.' -f1,2)
if [ "NEW_VERSION" != "$OLD_VERSION" ]; then
brew unlink php@$OLD_VERSION && brew link --force php@$NEW_VERSION
else
cd "It's the same version!"
fi
return
}
# Go to projets
works() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - GitLab CE"
PROJ=$1
if [ ! -d "$WORKSPACE_PATH/$PROJ" ] && [ "$WORKSPACE_PATH/$PROJ" != "" ]; then
echo "'$PROJ' is not a directory project or not exists!"
else
if [ "$PROJ" = "" ]; then
cd "$WORKSPACE_PATH"
else
cd "$WORKSPACE_PATH/$PROJ"
fi
fi
return
}
glab() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - GitLab.com"
PROJ=$1
if [ ! -d "$WORKSPACE_PATH/$PROJ" ] && [ "$WORKSPACE_PATH/$PROJ" != "" ]; then
echo "'$PROJ' is not a directory project or not exists!"
else
if [ "$PROJ" = "" ]; then
cd "$WORKSPACE_PATH"
else
cd "$WORKSPACE_PATH/$PROJ"
fi
fi
return
}
ghub() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - GitHub.com"
PROJ=$1
if [ ! -d "$WORKSPACE_PATH/$PROJ" ] && [ "$WORKSPACE_PATH/$PROJ" != "" ]; then
echo "'$PROJ' is not a directory project or not exists!"
else
if [ "$PROJ" = "" ]; then
cd "$WORKSPACE_PATH"
else
cd "$WORKSPACE_PATH/$PROJ"
fi
fi
return
}
ghubp() {
WORKSPACE_PATH="$HOME/Workspace/Personal - GitHub.com"
PROJ=$1
if [ ! -d "$WORKSPACE_PATH/$PROJ" ] && [ "$WORKSPACE_PATH/$PROJ" != "" ]; then
echo "'$PROJ' is not a directory project or not exists!"
else
if [ "$PROJ" = "" ]; then
cd "$WORKSPACE_PATH"
else
cd "$WORKSPACE_PATH/$PROJ"
fi
fi
return
}
ado() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - Azure DevOps"
PROJ=$1
if [ ! -d "$WORKSPACE_PATH/$PROJ" ] && [ "$WORKSPACE_PATH/$PROJ" != "" ]; then
echo "'$PROJ' is not a directory project or not exists!"
else
if [ "$PROJ" = "" ]; then
cd "$WORKSPACE_PATH"
else
cd "$WORKSPACE_PATH/$PROJ"
fi
fi
return
}
aquest() {
WORKSPACE_PATH="$HOME/Workspace/AQuest - GitLab CE"
PROJ=$1
if [ ! -d "$WORKSPACE_PATH/$PROJ" ] && [ "$WORKSPACE_PATH/$PROJ" != "" ]; then
echo "'$PROJ' is not a directory project or not exists!"
else
if [ "$PROJ" = "" ]; then
cd "$WORKSPACE_PATH"
else
cd "$WORKSPACE_PATH/$PROJ"
fi
fi
return
}
timenet() {
WORKSPACE_PATH="$HOME/Workspace/Timenet - GitLab CE"
PROJ=$1
if [ ! -d "$WORKSPACE_PATH/$PROJ" ] && [ "$WORKSPACE_PATH/$PROJ" != "" ]; then
echo "'$PROJ' is not a directory project or not exists!"
else
if [ "$PROJ" = "" ]; then
cd "$WORKSPACE_PATH"
else
cd "$WORKSPACE_PATH/$PROJ"
fi
fi
return
}
# Auto completions for go to projects
_works() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - GitLab CE"
DIRS=(`ls -d "$WORKSPACE_PATH"/*/ | tr -d ' ' | xargs basename | tr '\n' ' '`)
compadd -X "Select a 'Beliven - GitLab CE' project:" $DIRS
}
compdef _works works
_glab() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - GitLab.com"
DIRS=(`ls -d "$WORKSPACE_PATH"/*/ | tr -d ' ' | xargs basename | tr '\n' ' '`)
compadd -X "Select a 'Beliven - GitLab.com' project:" $DIRS
}
compdef _glab glab
_ghub() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - GitHub.com"
DIRS=(`ls -d "$WORKSPACE_PATH"/*/ | tr -d ' ' | xargs basename | tr '\n' ' '`)
compadd -X "Select a 'Beliven - GitHub.com' project:" $DIRS
}
compdef _ghub ghub
_ghubp() {
WORKSPACE_PATH="$HOME/Workspace/Personal - GitHub.com"
DIRS=(`ls -d "$WORKSPACE_PATH"/*/ | tr -d ' ' | xargs basename | tr '\n' ' '`)
compadd -X "Select a 'Personal - GitHub.com' project:" $DIRS
}
compdef _ghubp ghubp
_ado() {
WORKSPACE_PATH="$HOME/Workspace/Beliven - Azure DevOps"
DIRS=(`ls -d "$WORKSPACE_PATH"/*/ | tr -d ' ' | xargs basename | tr '\n' ' '`)
compadd -X "Select a 'Beliven - Azure DevOps' project:" $DIRS
}
compdef _ado ado
_aquest() {
WORKSPACE_PATH="$HOME/Workspace/AQuest - GitLab CE"
DIRS=(`ls -d "$WORKSPACE_PATH"/*/ | tr -d ' ' | xargs basename | tr '\n' ' '`)
compadd -X "Select a 'AQuest - GitLab CE' project:" $DIRS
}
compdef _aquest aquest
_timenet() {
WORKSPACE_PATH="$HOME/Workspace/Timenet - GitLab CE"
DIRS=(`ls -d "$WORKSPACE_PATH"/*/ | tr -d ' ' | xargs basename | tr '\n' ' '`)
compadd -X "Select a 'Timenet - GitLab CE' project:" $DIRS
}
compdef _timenet timenet
# Benchmark shell load time
zshbench() {
shell=${1-$SHELL}
for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}
# Quick jump into WordPress theme folder
theme() {
if [ -d "website/web/app/themes/$1" ]; then
cd website/web/app/themes/$1
return
fi
if [ -d "web/app/themes/$1" ]; then
cd web/app/themes/$1
return
fi
if [ -d "wp-content/themes/$1" ]; then
cd wp-content/themes/$1
return
fi
if [ -d "themes/$1" ]; then
cd themes/$1
return
fi
if [ -d "$1" ]; then
cd $1
return
fi
echo "Theme folder doesn't exist!"
}