-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_aliases.orig
568 lines (466 loc) · 15.6 KB
/
.bash_aliases.orig
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
################################################################################
# golang
################################################################################
alias gi='goimports -w -v .'
alias gb='go build'
alias gr='go run'
alias gins='go install'
alias gtest='go test'
alias gvet='go vet'
alias gf='go fmt'
alias gdoc='godoc -http=:6060'
alias gmodtidy='go mod tidy'
alias gmodvendor='go mod vendor'
alias gclean='go clean -cache -modcache -i -r'
alias gg='go get -u'
alias ggv='go get'
alias gmodu='go get -u ./... && go mod tidy'
alias gstatic='staticcheck ./...'
alias gdocs='godoc -http=:6060'
alias glint='golangci-lint run'
alias ggen='go generate ./...'
alias gtestv='go test -v ./...'
alias gmodinit='go mod init $(basename $(pwd))'
benchmark() {
go test -bench=. $@
}
function gocover() {
t=$(tempfile)
go test $COVERFLAGS -coverprofile=$t $@ && go tool cover -func=$t && unlink $t
}
function coverweb() {
t=$(tempfile)
go test $COVERFLAGS -coverprofile=$t $@ && go tool cover -html=$t && unlink $t
}
################################################################################
# SonarQube
################################################################################
# mount current working directory as a volume at /usr/src where sonar-scanner
# is looking for source code.
alias sonar-scanner='docker run --rm -v "$(pwd):/usr/src" sonar-scanner-cli'
################################################################################
# git
################################################################################
alias ga='git add'
alias gaa='git add -A'
alias gba='git branch --all'
alias gbd='git branch -d'
alias gbD='git branch -D'
alias gbn='git checkout -b'
alias gca='git-cz --amend'
alias gcan='git-cz --amend --no-edit'
alias gcann='git commit --amend --no-edit --no-verify'
alias gcl='git clone'
alias gcm='git commit -m'
alias gco='git checkout'
alias gc='git-cz'
alias gcr='git-cz --retry'
alias gd='git diff'
alias gdc='git diff --cached'
alias gfa='git fetch --all'
alias gl='git log --branches --remotes --tags --graph --oneline --decorate'
alias gp='git push'
alias gpf='git push -f'
alias gpsuo='git push --set-upstream origin'
alias gpu='git pull'
alias gpuff='git pull --ff-only'
alias gpur='git pull --rebase --autostash'
alias gpurm='git fetch --all && git pull --rebase --autostash origin master'
alias gpurmi='git fetch --all && git rebase --interactive --autostash origin/master'
alias gmm='git fetch --all && git merge origin/master'
alias gras='git rebase --autostash'
alias gri='git rebase --interactive'
alias gra='git rebase --abort'
alias grc='git rebase --continue'
alias grs='git rebase --skip'
alias grv='git remote -v'
alias greh='git reset --hard'
alias grsh='git reset --hard'
alias gs='git status'
alias gstl='git stash list'
alias gst='git stash'
alias gsts='git stash show'
alias gstp='git stash pop'
alias gstpi='git stash pop --index'
alias gsta='git stash apply'
alias gcp='git cherry-pick'
alias gcpc='git cherry-pick --continue'
alias gcpa='git cherry-pick --abort'
function gln() {
n=${1:-1}
git log "-$n"
}
function gbDm() {
for branch in $(gba | grep $1 | grep -v origin); do
gbD $branch
done
}
function pushAll() {
echo What is your message?
read commit_message
gaa && gcm "$commit_message" && gp
}
################################################################################
# bash
################################################################################
alias cdr='cd $(git rev-parse --show-toplevel)'
alias changelang='setxkbmap -layout de,ch,us -option grp:alt_shift_toggle'
alias dfh='df -h'
alias freem='free -m'
alias gh='history | grep'
alias left='ls -t -1'
alias ll='ls -lA'
alias la='ls -aF'
alias lt='ll --human-readable --size -1 -S --classify'
alias sbr='source ~/.bashrc'
function completeAlias() {
echo "complete -F _complete_alias ${1}" >>~/.bash_completion
}
################################################################################
# openvpn
################################################################################
startvpn() {
echo "Select a VPN location:"
echo "1) Bordeaux"
echo "2) Marseille"
echo "3) Paris"
echo "4) Zurich"
read -p "Enter your choice (1-4): " choice
case $choice in
1) config="NCVPN-FR-Bordeaux-UDP.ovpn" ;;
2) config="NCVPN-FR-Marseille-UDP.ovpn" ;;
3) config="NCVPN-FR-Paris-UDP.ovpn" ;;
4) config="NCVPN-CH-Zurich-UDP.ovpn" ;;
*) echo "Invalid choice"; return ;;
esac
sudo openvpn --config "/etc/openvpn/udp/$config" --daemon
# Wait for a short duration to allow the VPN connection to establish.
sleep 10
# Check for tun or tap interface
if ip link show | grep -qE 'tun|tap'; then
echo "VPN connection seems to be established successfully."
else
echo "VPN connection failed or took too long to establish."
fi
}
################################################################################
# MY SIMPLE CUSTOM IMPLEMENTATION TO TRACK DOTFILES WITHOUT OVERTHINKING
################################################################################
function trackAliases() {
echo Going to home directory where dot files are kept
cd $HOME
pwd
echo Where do you keep your dot files?
read -e dotfiles_directory
DIR="$HOME/$dotfiles_directory/"
echo Which dot file do you want to track?
read -e dotfile_to_track
if [[ -d "$DIR" && ! -f "$DIR/$dotfile_to_track" ]]; then
cp $HOME/$dotfile_to_track $DIR
echo $dotfile_to_track has successfully been copied to selected directory.
fi
if [[ -d "$DIR" && -f "$DIR/$dotfile_to_track" ]]; then
echo A file with the same already exists. Are you sure you want to overwrite it? y/n
read is_user_sure
if [[ $is_user_sure == "y" ]]; then
cp $HOME/$dotfile_to_track $DIR
echo $dotfile_to_track has successfully been copied to selected directory.
else
echo Operation aborted.
#exit 1
fi
fi
if [ ! -d "$DIR" ]; then
mkdir $DIR
cp $HOME/$dotfile_to_track $DIR
fi
echo ""
echo Go to directory? y/n
echo Necessary if you want to add, commit and push the files.
read gotodir
if [[ $gotodir == "y" ]]; then
cd $DIR
pwd
fi
if [[ -d "$DIR/.git/" && pwd == "$DIR" ]]; then
echo 'Would you like to add, commit and push the updated file(s)? y/n'
read push_or_not
if [[ $push_or_not == "y" ]]; then
pushAll
fi
fi
if [[ ! -d "$DIR/.git/" ]]; then
echo Would you like to initiate a git repository?
read init_git
if [[ $init_git == "y" ]]; then
git init
fi
fi
}
function checkGit() {
for d in */; do
cd "$d"
git status &>/dev/null
if [ "$?" -ne 0 ]; then
pwd
echo "not a git repo"
fi
cd ..
done
}
################################################################################
# Arch Linux
################################################################################
alias aur-list='pacman -Qqm'
function isRebootRequired() {
RED='\033[0;31m'
GREEN='\033[0;32m'
NOCOLOR='\033[0m'
echo "CHECKING IF A REBOOT IS REQUIRED"
echo "BEGINNING OF COMPARISON OF uname -r and file /boot/vmlinuz"
NEXTLINE=0
FIND=""
for L in `file /boot/vmlinuz*`; do
if [ ${NEXTLINE} -eq 1 ]; then
FIND="${L}"
NEXTLINE=0
else
if [ "${L}" = "version" ]; then NEXTLINE=1; fi
fi
done
if [ ! "${FIND}" = "" ]; then
CURRENT_KERNEL=`uname -r`
if [ ! "${CURRENT_KERNEL}" = "${FIND}" ]; then
echo -e "${RED}REBOOT YOUR COMPUTER NOW!! ${NOCOLOR}\n"
else
echo -e "${GREEN}No reboot required. ${NOCOLOR}\n"
fi
fi
}
# Purpose: This function is used to update any package from the Arch User
# Repository (AUR) on an Arch Linux system in a way that works for me.
# It first navigates to the home directory, then checks if a local repository
# of the given package exists.
# If it does, it pulls the latest changes from the remote repository and makes
# the package or just exits if no new changes are detected.
# If it doesn't, it clones the repository and makes the package.
# After the update is finished, it returns the user back to the Downloads directory.
function updateAur() {
# Check if package name is provided
if [ -z "$1" ]; then
echo "Error: No package name provided. Usage: updateAur <package_name>"
return 1
fi
# Define the package name
local PACKAGE="$1"
# Print a message to the user
echo "Navigating to the home directory..."
# Go to home directory
cd $HOME
# Define the download directory path
local DL="$HOME/Downloads"
# Define the Arch User Repository (AUR) URL
local AUR="https://aur.archlinux.org"
# Check if a local repository of the given package exists in the download
# directory
if [ -d "$DL/$PACKAGE" ]; then
echo "Existing repository found, pulling latest changes..."
# If it does, navigate to the repository
cd "$DL/$PACKAGE"
# Pull the latest changes
git_output=$(git pull)
# Check if there are any new updates
if [[ $git_output == *"Already up to date."* ]]; then
echo "Nothing to update for $PACKAGE. Going back to the Downloads directory..."
cd $DL
return 0
fi
# Build and install the package from the updated sources
makepkg -si
else
# If it doesn't, print a message
echo "No existing repository found, cloning..."
# Clone the repository from the AUR
git clone "$AUR/$PACKAGE.git" "$DL/$PACKAGE"
# Navigate to the new repository
cd "$DL/$PACKAGE"
# Make the package
makepkg -si
fi
# After the update is finished, print a message to the user
echo "Update of $PACKAGE finished. Going back to the Downloads directory..."
# Navigate back to the Downloads directory
cd $DL
}
# Purpose: This function is used to update Google Chrome from the AUR on an
# Arch Linux system.
# It first navigates to the home directory, then checks if a local repository
# of Google Chrome exists.
# If it does, it pulls the latest changes from the remote repository.
# If it doesn't, it clones the repository and makes the package.
function updateChrome() {
echo "Navigating to the home directory..."
cd $HOME
local DL="$HOME/Downloads"
local AUR="https://aur.archlinux.org"
# Define the name of the Google Chrome repository
local GC="google-chrome"
# Check if a local repository of Google Chrome exists in the download
# directory
if [ -d "$DL/$GC" ]; then
echo "Existing repository found, pulling latest changes..."
# If it does, navigate to the repository
cd "$DL/$GC"
# Pull the latest changes
git pull
makepkg -si
else
echo "No existing repository found, cloning..."
# Clone the repository from the AUR
git clone "$AUR/$GC.git" "$DL/$GC"
# Navigate to the new repository
cd "$DL/$GC"
# Make the package
makepkg -si
fi
echo "Update finished. Going back to the Downloads directory..."
cd $DL
}
function updateVscode() {
echo "Going to the home directory"
echo ""
cd $HOME
DL="$HOME/Downloads"
if [ ! -d $DL ]; then
mkdir $DL
fi
cd $DL
AUR="https://aur.archlinux.org/"
VSCODE="visual-studio-code-bin"
echo "Starting to clone VSCODE-BIN AUR git"
git clone "$AUR/$VSCODE.git"
cd $VSCODE/
makepkg -si
cd ..
echo ""
echo "Removing now useless directory..."
rm -rf "$VSCODE/"
}
function updateSlack() {
echo "Going to the home directory"
echo ""
cd $HOME
DL="$HOME/Downloads"
if [ ! -d $DL ]; then
mkdir $DL
fi
cd $DL
AUR="https://aur.archlinux.org/"
SLACK="slack-desktop"
echo "Starting to clone Slack AUR git"
git clone "$AUR/$SLACK.git"
cd $SLACK/
makepkg -si
cd ..
echo ""
echo "Removing now useless directory..."
rm -rf "$SLACK/"
}
################################################################################
# nvim
################################################################################
alias vimdiff='nvim -d'
################################################################################
# gradle
################################################################################
function gw() {
DIR=$(pwd)
cd $(git rev-parse --show-toplevel)
./gradlew "$@"
cd "$DIR"
}
################################################################################
# docker
################################################################################
alias d='docker'
alias dp='docker ps'
alias dpa='docker ps -a'
alias di='docker images'
alias dspa='docker system prune -a'
alias dsa='docker stop $(docker ps -q)'
alias dsta='docker start $(docker ps -qa)'
alias dra='docker stop $(docker ps -q); docker rm $(docker ps -qa)'
alias dei='docker exec -ti'
dockersize() {
if ! docker_output=$(docker manifest inspect -v "$1" 2>/dev/null); then
echo "Error: Failed to fetch manifest for image '$1'. Please check if the image name is correct."
return 1
fi
if ! jq_output=$(echo "$docker_output" | jq -c 'if type == "array" then .[] else . end' 2>/dev/null); then
echo "Error: Failed to process JSON output. Ensure jq is correctly processing the manifest."
return 1
fi
if ! size_output=$(echo "$jq_output" | jq -r '
[
( .Descriptor.platform | [ .os, .architecture, .variant, ."os.version" ] | del(..|nulls) | join("/") ),
( [ .SchemaV2Manifest.layers[].size ] | add )
] | join(" ")' 2>/dev/null); then
echo "Error: Failed to extract and process sizes from manifest. Check the structure of the manifest."
return 1
fi
if ! formatted_output=$(echo "$size_output" | numfmt --to iec --format '%.2f' --field 2 2>/dev/null); then
echo "Error: Failed to format sizes into human-readable format."
return 1
fi
echo "$formatted_output" | sort | column -t
}
################################################################################
# docker-compose
################################################################################
alias dcu='docker-compose up -d'
alias dcd='docker-compose down'
function dcuf() {
FILE=$1
shift
docker-compose -f $FILE up -d $@
}
function dcdf() {
FILE=$1
shift
docker-compose -f $FILE down $@
}
################################################################################
# npm and npx
################################################################################
alias nc='npm-check'
alias npxts='npx tsc --init'
################################################################################
# yarn
################################################################################
alias y='yarn'
alias yadts='yarn add typescript @types/node @types/react @types/react-dom @types/jest'
alias yt='y && y test'
alias ytw='y && yarn test --watch'
alias yw='y && yarn watch'
alias ys='yarn && yarn start'
alias ysb='y && yarn start-storybook'
alias ytl='y && yarn test && yarn lint'
alias yc='yarn-check'
alias ycu='yarn-check -u'
alias ycz='yarn commit'
################################################################################
# tmux
################################################################################
alias t='tmux'
alias tn='tmux new -s'
alias ta='tmux attach -t'
alias tl='tmux ls'
alias tk='tmux kill-session -t'
################################################################################
# erlang / elixir
################################################################################
alias iex='iex --erl "-kernel shell_history enabled"'
################################################################################
# code
################################################################################
alias co='code $(git rev-parse --show-toplevel)'