-
Notifications
You must be signed in to change notification settings - Fork 0
/
.myzsh
124 lines (101 loc) · 2.66 KB
/
.myzsh
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
# custom zsh config and bash helper functions
tabs -4
logstat () {
git log --graph --stat --pretty=short --decorate --color
}
# uses lib 'lf', and cd's into selected directory
lfcd () {
tmp="$(mktemp)"
lf -last-dir-path="$tmp" "$@"
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
rm -f "$tmp"
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
fi
}
run_new_tab () {
osascript \
-e 'tell application "iTerm2" to tell current window to set newWindow to (create tab with default profile)'\
-e "tell application \"iTerm2\" to tell current session of newWindow to write text \"${@}\""
}
greps () {
ps aux | grep -v grep | grep $1
}
is_port_in_use () {
local PORT=${1?Error: include a port, silly!}
lsof -i :$PORT
}
kill_my_process () {
local SIGNATURE="kill_my_process [-f | --force (optional)] [PID]";
if [[ $# -eq 0 ]]; then
echo $SIGNATURE;
return;
fi
if [[ $# -eq 1 ]]; then
if [[ $1 -eq '-f' ]]; then
echo $SIGNATURE;
return;
fi
fi
if [[ $# -gt 1 ]]; then
if [ $1 == "-f" | $1 == "--force" ]; then
COMMAND=-9;
shift;
fi
else
COMMAND=-15;
fi
echo "killing process $1"
kill $COMMAND $1
}
kill_my_port () {
local PORT=${1?Error: include a port, silly!};
if [[ $(is_port_in_use $PORT) ]]; then
PROCESS=$(is_port_in_use $PORT | awk '{ print $2 }');
PID=${PROCESS[(w)2]};
is_port_in_use $PORT;
echo "Port $PORT | Process $PID";
kill_my_process $PID;
else
echo "Port $PORT is not in use"
fi
}
mongobg () {
echo "[Mongo] Running in background";
mongod --config /usr/local/etc/mongod.conf --fork
}
mongo_check () {
echo "grep mongod..."
greps mongod
}
# Backs up a mongo db to local
# from https://docs.mongodb.com/manual/reference/program/mongodump/
# $1 = uri string
# $2 = db name
# $3 = [OPTIONAL] rename db
backupDb () {
echo "$@"
if [[ $# -lt 2 ]] ; then
echo "not enough arguments supplied"
return
elif [[ $# -eq 2 ]] ; then
temp="$2"
else
temp="$3"
fi
mongodump --archive --uri="$1" | mongorestore --archive --nsFrom="$2.*" --nsTo="$temp.*"
}
# Restores a mongo db collection to local
# from https://docs.mongodb.com/manual/reference/program/mongodump/
# $1 = uri string
# $2 = collection name
backupCollection () {
echo "$@"
if [[ $# -lt 2 ]] ; then
echo "not enough arguments supplied"
return
fi
mongodump --archive --uri="$1" --collection="$2" \
| mongorestore --archive --nsFrom="$2" --nsTo="$2"
}
echo ".myzsh loaded";