-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.zsh
194 lines (166 loc) · 4.02 KB
/
functions.zsh
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
# functions
edit() { $EDITOR $1 }
snotify() {
local notification_command="display notification \"$2\" with title \"$1\""
osascript -e "$notification_command"
}
alias sys-notify="snotify $1 $2"
watson_status() {
sys-notify Watson "$(watson status)"
}
# wirelab
ssh_wiredev() {
}
# browserstack
browserstack() {
/Users/wirelab/Downloads/BrowserStackLocal --key $BROWSERSTACK_TOKEN
}
# craft cms
craft_apply() {
php craft project-config/apply --force
}
# Resource integrity hash for a file fe: https://code.jquery.com/jquery-2.1.4.min.js
sri_hash() {
curl -s $1 | \
openssl dgst -sha384 -binary | \
openssl base64 -A
}
# commit everything
commit() {
git add --all && git commit -s -S -m "$1"
git pull origin $2
git push origin $2
}
# remove a branch
rm_branch() {
git branch -d $1
git push origin :$1
}
# prune deleted branches
prune_branch() {
git remote prune origin
}
# make branch and push it
mk_branch() {
git checkout -b $1
git push --set-upstream origin $1
}
# ignore a file
gitignore() {
echo $1 >> .gitignore
}
# make github repo from current dir
mk_repo_dir() {
if [ "$1" = "org" ]; then
gh repo create $GITHUB_ORG/$2 --private --source=. --remote=upstream
git remote add origin [email protected]:$GITHUB_ORG/$2.git
else
gh repo create $1 --private --source=. --remote=upstream
git remote add origin [email protected]:$GITHUB_USER/$1.git
fi
git add --all
git branch -M main
git push -u origin main
}
# make github repo from scratch
mk_repo() {
if [ "$1" = "org" ]; then
gh repo create $GITHUB_ORG/$2 --private --clone
cd $2
else
gh repo create $GITHUB_USER/$1 --private --clone
cd $1
fi
}
# make a new sh script
mk_sh() {
echo "#!/bin/sh \n" > $1
chmod +x $1
}
# make a dir and cd into it
mkcd() {
mkdir $1
cd $1
}
# add a new alias
mk_alias() {
echo "alias $1=\"$2\"" >> $DOTFILES/aliases.zsh
}
# open a database
open_db() {
[ ! -f .env ] && { echo "No .env file found."; exit 1; }
DB_CONNECTION=$(grep DB_CONNECTION .env | grep -v -e '^\s*#' | cut -d '=' -f 2-)
DB_HOST=$(grep DB_HOST .env | grep -v -e '^\s*#' | cut -d '=' -f 2-)
DB_PORT=$(grep DB_PORT .env | grep -v -e '^\s*#' | cut -d '=' -f 2-)
DB_DATABASE=$(grep DB_DATABASE .env | grep -v -e '^\s*#' | cut -d '=' -f 2-)
DB_USERNAME=$(grep DB_USERNAME .env | grep -v -e '^\s*#' | cut -d '=' -f 2-)
DB_PASSWORD=$(grep DB_PASSWORD .env | grep -v -e '^\s*#' | cut -d '=' -f 2-)
DB_URL="${DB_CONNECTION}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}"
echo "Opening ${DB_URL}"
open $DB_URL
}
# database access
db() {
if [ "$1" = "refresh" ]; then
mysql -u root -proot -e "drop database $2; create database $2"
elif [ "$1" = "create" ]; then
mysql -u root -proot -e "create database $2"
elif [ "$1" = "drop" ]; then
mysql -u root -proot -e "drop database $2"
elif [ "$1" = "list" ]; then
mysql -u root -proot -e "show databases" | perl -p -e's/\|| *//g'
else
echo "Command: db <argument> <param>"
echo "available arguments:"
echo "- list"
echo "- refresh <database>"
echo "- create <database>"
echo "- drop <database>"
fi
}
# silence output
silent() {
"$@" >& /dev/null
}
# check weather
weather() {
city="$1"
if [ -z "$city" ]; then
city="Enschede"
fi
eval "curl http://wttr.in/${city}"
}
# toogle bluetooth
toggle_bluetooth() {
blueutil -p 0
blueutil -p 1
}
# archive some stuff
archive () {
zip -r "$1".zip -i "$1" ;
}
# symlink to dottools which is in path
symlink() {
filename=$(basename $1)
filedir=$(dirname $1)
sourceFile="$1"
symlink=$DOTFILES/symlinks/$filename
if [ -f $symlink ] ; then
echo "Symbolic link already exists for $filename in $symlink"
else
ln -s $1 $symlink
echo "Symbolic link created in $symlink"
fi
}
# remove the symlink
unsymlink() {
filename=$(basename $1)
symlink="$DOTFILES/symlinks/$filename"
if [ -f $symlink ] ; then
unlink $symlink
echo "Symbolic link removed"
else
echo "No symbolic link found at $symlink"
fi
}