-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot.functions
More file actions
184 lines (157 loc) · 4.82 KB
/
dot.functions
File metadata and controls
184 lines (157 loc) · 4.82 KB
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
#!/bin/bash
BREW=$(brew --prefix)
function cmd_exists() {
command -v "$1" &> /dev/null
}
# set a JDK default.
function setjdk() {
if [ ! -f /usr/libexec/java_home ]; then
return
fi
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath "$JAVA_HOME"
fi
# shellcheck disable=SC2068,SC2155
export JAVA_HOME=$(/usr/libexec/java_home -v $@)
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
# shellcheck disable=SC2155
export PATH=$(echo "$PATH" | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
function composer() {
phar=$BREW/bin/composer
if [ -e composer.phar ]; then
phar=composer.phar
fi
php -d memory_limit=-1 $phar "$@"
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
# Run `dig` and display the most useful info
function digga() {
dig +nocmd "$1" any +multiline +noall +answer;
}
# whois a domain or a URL
function whois() {
local domain=$(echo "$1" | awk -F/ '{print $3}') # get domain from URL
if [ -z $domain ] ; then
domain=$1
fi
echo "Getting whois record for: $domain …"
/usr/bin/whois -h whois.internic.net $domain | sed '/NOTICE:/q'
}
# who is using the laptop's iSight camera?
camerausedby() {
echo "Checking to see who is using the iSight camera… 📷"
usedby=$(lsof | grep -w "AppleCamera\|USBVDC\|iSight" | awk '{printf $2"\n"}' | xargs ps)
echo -e "Recent camera uses:\n$usedby"
}
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
# the `.git` directory, listing directories first. The output gets piped into
# `less` with options to preserve color and line numbers, unless the output is
# small enough for one screen.
function tre() {
tree -aC -I '.git' --dirsfirst "$@" | less -FRNX;
}
# Create a .sql.bz2 file for each (non-system) database in mysql.
function backupdbs () {
MY_DUMPOPT=(--opt --dump-date --skip-extended-insert --order-by-primary)
DATE=$(date "+%Y-%m-%d");
databases=$(mysql -e 'show databases;' --skip-column-names -B | grep -vE 'sys|_schema|mysql')
for db in $databases; do
filename="$db-$DATE.sql"
rm -f "$filename" "${filename}.bz2"
echo -n "copying $db to $filename"
mysqldump "${MY_DUMPOPT[@]}" -r "$filename" "$db"
echo -n " compressing"
bzip2 -9 "$filename"
echo " done."
done
}
function rdb () {
if [[ $# -lt 1 ]]; then
echo "usage: $FUNC_NAME db [sql]"
return 1
fi
local name="$1"
shift
mysql -e "DROP DATABASE IF EXISTS $name"
mysql -e "CREATE DATABASE $name"
mysql -e "DROP USER IF EXISTS $name@localhost"
mysql -e "CREATE USER $name@localhost IDENTIFIED BY 'abc123'"
mysql -e "GRANT ALL ON $name.* TO $name@localhost"
while (( "$#" )); do
local file="$1"
shift
if [[ -r $file ]]; then
pv "$file" | mysql "$name"
else
echo "Cannot read $file."
return 1
fi
done
}
function recrud() {
for entity in "$@"; do
if [[ $entity =~ "\\" ]]; then
./bin/console make:entity --regenerate "$entity"
else
./bin/console make:entity --regenerate App\\Entity\\"$entity"
fi
./bin/console nines:make:repo "$entity"
./bin/console nines:make:fixture "$entity"
./bin/console nines:make:crud "$entity"
./bin/console nines:make:test "$entity"
done
if [ -e .php_cs.dist ] || [ -e .php_cs ] || [ -e .php-cs-fixer.dist.php ]; then
php-cs-fixer --quiet fix
fi
}
# Start a PHP server from a directory, optionally specifying the port
# (Requires PHP 5.4.0+.)
function phpserver() {
local port="${1:-4000}";
local ip
ip=$(ipconfig getifaddr en1);
sleep 1 && open "http://${ip}:${port}/" &
php -S "${ip}:${port}";
}
function symlint() {
symfony security:check --quiet
php-cs-fixer --quiet fix --diff --dry-run
./bin/console lint:yaml --quiet config --parse-tags
./bin/console lint:twig --quiet templates
./bin/console lint:container --quiet
./bin/console doctrine:schema:validate --quiet --skip-sync -vvv --no-interaction
composer --quiet validate
composer show -Do
yarn -q outdated
echo "Complete."
}
function symuser() {
user="$1"
name="$2"
inst="$3"
./bin/console nines:user:create "$user" "$name" "$inst"
./bin/console nines:user:activate "$user"
./bin/console nines:user:password "$user" abc123
./bin/console nines:user:promote "$user" ROLE_ADMIN
}
function wbc() {
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"
}