-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.functions
129 lines (113 loc) · 2.95 KB
/
.functions
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
#!/usr/bin/env zsh
# Create a new directory and enter it
function mkd {
mkdir -p "$@" && cd "$_" || return 1;
}
# Change working directory to project root
function pr {
local dir="$PWD"
until [[ -z "$dir" ]]; do
if [ -d ./.git ]; then
break
else
cd ..
fi
dir="${dir%/*}"
done
}
# Start an HTTP server from a directory, optionally specifying the port
function server {
local port="${1:-8000}"
echo "python3 -m http.server $port"
sleep 1 && open "http://localhost:${port}/" &
python3 -m http.server "$port"
}
# Show the response headers for a given url
function http_headers {
if [ -n "$1" ]; then
curl "$1" -I -L
else
echo "Usage: http_headers <url>"
fi
}
# Show the timing details for a given url
function http_debug {
if [ -n "$1" ]; then
local format="dns_resolution: %{time_namelookup}, tcp_established: %{time_connect}, ssl_handshake_done: %{time_appconnect}, TTFB: %{time_starttransfer}\n"
curl "$1" -o /dev/null -s -w "$format"
else
echo "Usage: http_debug <url>"
fi
}
# Check the compression for a given url
function http_compression {
if [ -n "$1" ]; then
local accept_encoding="accept-encoding: gzip, deflate, br"
curl "$1" -o /dev/null -s -w "Size (uncompressed) = %{size_download}\n"
curl "$1" -o /dev/null -s -H "$accept_encoding" -w "Size (compressed) = %{size_download}\n"
curl "$1" -s -I -H "$accept_encoding" | grep -i "content-encoding"
else
echo "Usage: http_compression <url>"
fi
}
# Checkout master
function master {
if [ -d ./.git ]; then
git checkout master
else
echo "Not a git directory"
fi
}
# Checkout main
function main {
if [ -d ./.git ]; then
git checkout main
else
echo "Not a git directory"
fi
}
# Checkout develop
function develop {
if [ -d ./.git ]; then
git checkout develop
else
echo "Not a git directory"
fi
}
function squash {
if [ -n "$1" ]; then
git reset --soft HEAD~$1 && git commit
else
echo "Usage: squash <number of commits>"
fi
}
# Pull down and log changes, optionally specifying the branch
function pull {
local branch="${1:-$(git rev-parse --abbrev-ref HEAD)}"
if [ -d ./.git ]; then
echo "git pull origin $branch"
git pull origin "$branch"
if [ "$(git rev-list --count ORIG_HEAD..HEAD)" -gt 0 ]; then
echo "git log ORIG_HEAD..HEAD"
git log ORIG_HEAD..HEAD --oneline
fi
else
echo "Not a git directory"
fi
}
# Push up changes, optionally specifying the branch or `f` for force pushing
function push {
local branch="${1:-$(git rev-parse --abbrev-ref HEAD)}"
if [[ -d ./.git ]]; then
if [[ "$1" == "f" ]]; then
branch=$(git rev-parse --abbrev-ref HEAD)
echo "git push origin ${branch}:${branch} --force-with-lease"
git push origin "${branch}:${branch}" --force-with-lease
else
echo "git push origin ${branch}:${branch}"
git push origin "${branch}:${branch}"
fi
else
echo "Not a git directory"
fi
}