-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions.sh
executable file
Β·297 lines (244 loc) Β· 7.1 KB
/
.functions.sh
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
# parses output from git grep and opens files on sublime
function gosub(){
awk '{print $1}' | sed 's/:$//' | xargs subl
}
function ban_ip() {
iptables -A INPUT -s $1 -j DROP
}
function dup() {
docker-compose up -d $@
}
function of() {
selected=$(ps axc | awk 'NR > 1' | awk '{print substr($0,index($0,$5))}' | sort -u | fzf)
if [ ! -z $1 ]; then
lsof -r 2 -c "$selected"
else
lsof -c "$selected"
fi
}
function dc() {
if docker ps >/dev/null 2>&1; then
container=$(docker ps | awk '{if (NR!=1) print $1 ": " $(NF)}' | fzf --height 40%)
if [[ -n $container ]]; then
container_id=$(echo $container | awk -F ': ' '{print $1}')
docker exec -it $container_id /bin/bash || docker exec -it $container_id /bin/sh
else
echo "You haven't selected any container! ΰΌΌγ€β_βΰΌ½γ€"
fi
else
echo "Docker daemon is not running! (ΰ² _ΰ² )"
fi
}
progress-bar() {
local duration=${1}
already_done() { for ((done=0; done<$elapsed; done++)); do printf "β"; done }
remaining() { for ((remain=$elapsed; remain<$duration; remain++)); do printf " "; done }
percentage() { printf "| %s%%" $(( (($elapsed)*100)/($duration)*100/100 )); }
clean_line() { printf "\r"; }
for (( elapsed=1; elapsed<=$duration; elapsed++ )); do
already_done; remaining; percentage
sleep 1
clean_line
done
clean_line
}
function edit() {
nano $(find . -maxdepth 1 -type f | fzf)
}
function lsip() {
nmcli -g ip4.address device show $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF | fzf)
}
function zsh-stats() {
fc -l 1 | awk '{CMD[$2]++;count++;} END { for (a in CMD) print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n25;
}
function gitconfig() {
echo "+===================================+"
echo "| π Github Account |"
echo "+===================================+"
echo "Introduce your name: "
read NAME
echo "Introduce your email: "
read EMAIL
echo "Key-Type: 1
Key-Length: 4096
Subkey-Type: 1
Subkey-Length: 4096
Name-Real: ${NAME}
Name-Email: ${EMAIL}
Expire-Date: 0" >! ~/.gen-key-script
echo "====================================="
echo "β»οΈ Erasing the old GPG keys if exists"
echo "====================================="
gpg --delete-key "${NAME}"
gpg --delete-secret-key "${NAME}"
echo "====================================="
echo "π Generating GPG keys"
echo "====================================="
gpg --batch --gen-key ~/.gen-key-script
ID=$(gpg --list-secret-keys --with-colons \
2> /dev/null \
| grep '^sec:' | cut --delimiter ':' --fields 5)
echo "
[user]
name = ${NAME}
email = ${EMAIL}
username = ${USERNAME}
signingkey=${ID}
[commit]
gpgsign = true
" >! ~/.gitconfig_local
echo "π The OUTPUT of the ~/.gitconfig_local file is:"
cat ~/.gitconfig_local
gpg --armor --export ${ID} >! ~/.gpg_github_key
echo "π The OUTPUT of the ~/.gpg_github_key will be copy to your clipboard and the content would be:"
cat ~/.gpg_github_key | xclip -selection clipboard
cat ~/.gpg_github_key
echo "======================="
echo "1 - Editar"
echo "2 - Continuar"
echo "========================"
echo -n "Selecione una opcion:"
read opcion
case $opcion in
1) nano ~/.gitconfig_local
;;
2) ;;
*) echo "Opcion erronea";
esac
echo "======================="
echo "1 - Crear SSH key"
echo "2 - Salir"
echo "========================"
echo -n "Selecione una opcion:"
read opcion
case $opcion in
1) echo "+====================================+"
echo "|π Generating SSH key for that email|"
echo "+====================================+"
ssh-keygen -t rsa -b 4096 -C "${EMAIL}"
;;
2) exit;;
*) echo "Opcion erronea";
esac
}
# update node to latest lts version
function nvm::update() {
local -r current_node_version=$(nvm current)
local -r next_node_version=$(nvm version-remote --lts)
if [ "$current_node_version" != "$next_node_version" ]; then
local -r previous_node_version=$current_node_version
nvm install --lts
nvm reinstall-packages "$previous_node_version"
nvm uninstall "$previous_node_version"
nvm cache clear
fi
}
function docker::stop-all() {
docker stop $(docker ps -a -q)
}
function monday() {
#terminals
cd ~/projects/nailted-api && tilix -a session-add-right -w ~/projects/nailted-survey-webapp && tilix -a session-add-down -w ~/projects/nailted-webapp && tilix -a app-new-session -w ~/projects/nailted-api && tilix -a session-add-right -w ~/projects/nailted-survey-webapp && tilix -a session-add-down -w ~/projects/nailted-webapp && tilix -a app-new-session -w ~/projects/nailted-api;
#slack
slack > /dev/null 2>&1 &
#tandem
tandem > /dev/null 2>&1 &
#tandem
dbeaver > /dev/null 2>&1 &
# google chrome
google-chrome https://mail.google.com/ https://www.notion.so/ https://github.com/nailted > /dev/null 2>&1 &
}
function nailted-api() {
npm run dev:start-postgres && npm run dev && npm run dev:stop-postgres
}
clone_git_repo() {
repo_url=$(curl -s -H "Authorization: token $GITHUB_TOKEN_PULL" "https://api.github.com/user/repos?per_page=200" | jq --raw-output ".[].ssh_url" | fzf)
git clone "$repo_url"
echo "$repo_url"
}
open_project() {
ls ${PROJECTS} | rofi -show -dmenu -i -normal-window | xargs -I_ echo ${PROJECTS}/_ | xargs -L 1 bash -c 'code -n $0'
}
core_setup() {
sdk install java 11.0.17-ms
sdk install gradle 6.8.1
sdk install kotlin 1.4.20
sdk install maven 3.8.2
sdk use java 11.0.17-ms
sdk use gradle 6.8.1
sdk use kotlin 1.4.20
sdk use maven 3.8.2
}
core_up() {
cd ${PROJECTS}/scentmate/core
core_setup
docker-compose up -d
./gradlew bootRun
}
core_down() {
cd ${PROJECTS}/scentmate/core
docker-compose down
cd -
}
front_up() {
cd ${PROJECTS}/scentmate/frontend
nvm use
npm run dev
}
admin_up() {
cd ${PROJECTS}/scentmate/admin
nvm use
npm run dev
}
clean_apt_update() {
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
}
function lg () {
export LAZYGIT_NEW_DIR_FILE=~/.lazygit/newdir
lazygit "$@"
if [ -f $LAZYGIT_NEW_DIR_FILE ]; then
cd "$(cat $LAZYGIT_NEW_DIR_FILE)"
rm -f $LAZYGIT_NEW_DIR_FILE > /dev/null
fi
}
declare -A pomo_options
pomo_options["work"]="25"
pomo_options["break"]="5"
function pomodoro () {
if [ -n "$1" -a -n "${pomo_options["$1"]}" ]; then
val=$1
echo $val | lolcat
sleep ${pomo_options["$val"]}m
notify-send "'$val' session done" --icon=dialog-information
spd-say -r -25 "'$val' session done"
fi
}
function cycle_work(){
for i in $(seq $1); do
pomodoro 'work'
pomodoro 'break'
done
}
function zsh_preformance() {
repeat 10 { time zsh -i -c exit }
}
function cheat.sh() {
curl cheat.sh/$1
}
function resetvpn() {
cd ~/Descargas/PanGPLinux-6.0.4-c25/
./install.sh
cd -
}
function wttr() {
curl wttr.in/$1
}
function pdfCipher() {
# $1 input, $2 output, $3 password
pdftk $1 output $2 userpw $3
}
function ram () {
ps -eo pid,comm | grep -E -i -w 'chrome|slack|zoom' | awk '{print $1}' | xargs sudo renice -n 19 -p
}