-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeveloper-tools.sh
100 lines (83 loc) · 2.19 KB
/
developer-tools.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
#!/usr/bin/env sh
# --- aliases ---
alias ll="ls -la"
# k8s
alias k=kubectl
alias k8s=kubectl
# --- aliases ---
# --- git ---
function clone() {
PARENT_REGEX="^git@.*:(.*)\/.*.git"
PARENT=
if [[ "$1" =~ $PARENT_REGEX ]]
then
PARENT="$HOME/git/${match[1]}"
else
echo "Invalid git repo url! are you sure you used ssh?"
return 1
fi
FOLDER_REGEX="^git@.*:.*\/(.*).git"
FOLDER=
if [[ "$1" =~ $FOLDER_REGEX ]]
then
FOLDER="${match[1]}"
else
echo "Invalid git repo url! are you sure you used ssh?"
return 1
fi
echo "$PARENT/$FOLDER"
git clone $1 "$PARENT/$FOLDER"
}
function master() {
if [ -d "$PWD/.git" ]; then
git checkout master
return 0
fi
for directory in */; do
if [ -d "$directory/.git" ]; then
git -C $directory checkout master
fi
done
}
function cleanup_git_branches() {
if [ -d "$PWD/.git" ]; then
_cleanup_git_branches $PWD
return 0
fi
for directory in */; do
if [ -d "$directory/.git" ]; then
_cleanup_git_branches $directory
fi
done
}
function _cleanup_git_branches() {
REPO=$1
echo "Cleaning up already merged branches in $REPO ..."
git -C $REPO branch --merged | egrep -v "(^\*|master|dev)" | xargs git -C $REPO branch -D
}
# --- git ---
# --- helpers ---
function foreach_file_of_type_in_directory() {
read "TYPE?Type(default is *): "
read "DIRECTORY?Directory(default is \$PWD): "
read "COMMAND?Foreach file: \$FILE -> "
# the .N prevents errors if no matches were found
for FILE in $(find "${DIRECTORY:-$PWD}" -iname "*.${TYPE:-*}" -maxdepth 1).N; do
[ -f "$FILE" ] || continue
eval $COMMAND;
done
}
# Usage: for_each_folder "$HOME/git" | while read -r; do echo "Working in $REPLY"; cd "$REPLY"; pre-commit install; done
function for_each_folder() {
for directory in $(find $1 -not -path '*/.*' -mindepth 1 -maxdepth 1 -type d); do
echo $directory
done
}
function kill_process_by_port() {
PORT=$1
kill $(lsof -t -i:$PORT)
}
function jwt() {
jq -R 'split(".") | .[1] | @base64d | fromjson' <<< $1
}
# --- helpers ---