-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_functions.tmpl
137 lines (124 loc) · 3.49 KB
/
dot_functions.tmpl
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
#!/bin/bash
# values pulled from .netrc file for hub
GITHUB_USER=$(awk '/github.com/{getline; print $3}' ~/.config/hub)
GITHUB_TOKEN=$(awk '/github.com/{getline; getline; print $2}' ~/.config/hub)
alias-help() {
awk -v RS='# ' -v IGNORECASE=1 '/'"$1"'/ {print "# "$0}' ~/.aliases
}
function colormap() {
for i in {0..255}; do print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'}; done
}
function dev-restart() {
sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
}
# create a new dev app alias
function dev-init() {
sudo -v
if [ $# -lt 2 ]
then
echo "Error! App alias and port required."
else
local name=$(echo $1 | awk '{print tolower($0)}')
tee /usr/local/etc/nginx/servers/$name.conf > /dev/null << EOF
server {
listen 80;
server_name $name.test;
location / {
proxy_pass http://127.0.0.1:$2;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
dev-restart
fi
}
# delete a dev app alias
function dev-rm() {
if [ $# -lt 1 ]
then
echo "Error! App name required."
else
local name=$(echo $1 | awk '{print tolower($0)}')
rm /usr/local/etc/nginx/servers/$name.conf
fi
}
# list current dev app aliases
function dev-ls() {
echo "\nAvailable Environments:\n"
for f in /usr/local/etc/nginx/servers/*.conf; do
local name=$(basename $f)
printf '* %s\n' "${name%.conf}"
done
}
# exports a git repo to a new project folder
function git-export() {
if [ $# -lt 2 ]
then
echo "Error! Repo and project name required."
else
git clone --quiet --depth=1 $1 $2
rm -rf $2/.git*
fi
}
# clean merged git branches
function gb-clean() {
git branch -d $(git branch --merged=master | grep -v master)
git branch -d $(git branch --merged=main | grep -v main)
git fetch --prune
}
# Repeat Command
function repeat() {
if [ $# -lt 2 ]
then
echo "Error! Count and command required."
else
for i in {1..$0}; do $#; done
fi
}
# DNS Records
function dighost() {
host $(dig $1 | grep ANSWER -C 1 | tail -n 1 | awk '{ print $5 }')
}
# Add reminder to Reminders.app (OS X 10.8+)
function remind() {
local text
if [ -t 0 ]; then
text="$1" # argument
else
text=$(cat) # pipe
fi
osascript >/dev/null <<EOF
tell application "Reminders"
tell list "Personal" of default account
make new reminder with properties {name:"$text"}
end tell
end tell
EOF
}
# Helper to extract an archvie
# credit: http://nparikh.org/notes/zshrc.txt
extract () {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar -jxvf $1 ;;
*.tar.gz) tar -zxvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.dmg) hdiutil mount $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar -xvf $1 ;;
*.tbz2) tar -jxvf $1 ;;
*.tgz) tar -zxvf $1 ;;
*.zip) unzip $1 ;;
*.ZIP) unzip $1 ;;
*.pax) cat $1 | pax -r ;;
*.pax.Z) uncompress $1 --stdout | pax -r ;;
*.Z) uncompress $1 ;;
*) echo "'$1' cannot be extracted/mounted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}