-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.zsh
127 lines (111 loc) · 3.32 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
joinpdf(){
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf $@ ;
}
function extract {
echo Extracting $1 ...
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
function pg_start {
if is_linux; then
/usr/local/bin/pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
elif is_macosx; then
open -a Postgres93.app
fi
}
function pg_stop {
/usr/local/bin/pg_ctl -D /usr/local/var/postgres stop -s -m fast
}
function es_start {
elasticsearch -Xms7g -Xmx7g --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
}
function es_stop {
curl -XPOST 'http://localhost:9200/_shutdown'
}
function mysql_start {
mysql.server start
}
function mysql_stop {
mysql.server stop
}
function ss {
if [ -e script/server ]; then
script/server $@
else
script/rails server $@
fi
}
function sc {
if [ -e script/rails ]; then
script/rails console $@
else
script/console $@
fi
}
# -------------------------------------------------------------------
# display a neatly formatted path
# -------------------------------------------------------------------
path() {
echo $PATH | tr ":" "\n" | \
awk "{ sub(\"/usr\", \"$fg_no_bold[green]/usr$reset_color\"); \
sub(\"/bin\", \"$fg_no_bold[blue]/bin$reset_color\"); \
sub(\"/opt\", \"$fg_no_bold[cyan]/opt$reset_color\"); \
sub(\"/sbin\", \"$fg_no_bold[magenta]/sbin$reset_color\"); \
sub(\"/local\", \"$fg_no_bold[yellow]/local$reset_color\"); \
print }"
}
# -------------------------------------------------------------------
# any function from http://onethingwell.org/post/14669173541/any
# search for running processes
# -------------------------------------------------------------------
any() {
emulate -L zsh
unsetopt KSH_ARRAYS
if [[ -z "$1" ]] ; then
echo "any - grep for process(es) by keyword" >&2
echo "Usage: any " >&2 ; return 1
else
ps xauwww | grep -i --color=auto "[${1[1]}]${1[2,-1]}"
fi
}
# -------------------------------------------------------------------
# kill any process containing $1
# -------------------------------------------------------------------
kill9() {
kill -9 `any $1 | awk '{ print $2 }'`
}
pngcrushdir() {
ls *.png | while read line; do pngcrush -brute $line compressed/$line; done
}
# -------------------------------------------------------------------
# Reset a cordova plugin by removing it, and then re-adding it.
# $1 - plugin ID
# $2 - path to plugin project
# -------------------------------------------------------------------
cpreset() {
cordova plugin remove $1
cordova plugin add $2
}
# -------------------------------------------------------------------
# mimic mac's open path in Finder cmd
# because i cant spell nautilus
# -------------------------------------------------------------------
#open() {
#nautilus $1
#}