-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
84 lines (70 loc) · 1.66 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
#!/usr/bin/env bash
# TODO add these functions to the readme
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
# 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;
}
# Use Git’s colored diff when available
hash git &>/dev/null;
if [ $? -eq 0 ]; then
function diff() {
git diff --no-index --color-words "$@";
}
fi;
# Create a data URL from a file
function dataurl() {
local mimeType=$(file -b --mime-type "$1");
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8";
fi
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
}
# TODO make variables configurable or something
DB_USER="root"
DB_PASS="root"
function mdbc() {
DB_NAME=$1
if [ -z $DB_NAME ];then
echo "No database name given"
return
fi
mysql -u$DB_USER -p$DB_PASS -e "
CREATE DATABASE IF NOT EXISTS ${DB_NAME};
CREATE USER IF NOT EXISTS $DB_USER@localhost IDENTIFIED BY '$DB_PASS';
GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '$DB_USER'@'localhost';
FLUSH PRIVILEGES;
"
code=$?
if [ 0 -ne $code ];then
echo "Couldn't create database";
exit $code;
fi
}
function mdbd() {
DB_NAME=$1
if [ -z $DB_NAME ];then
echo "No database name given"
return
fi
mysql -u$DB_USER -p$DB_PASS -e "
DROP DATABASE ${DB_NAME};
"
code=$?
if [ 0 -ne $code ];then
echo "Couldn't drop database";
exit $code;
fi
}