-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions
158 lines (135 loc) · 3.64 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
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
function cdw() {
cd ~/workspace/$1;
}
function cdg() {
cd $GOPATH/src/github.com/$1;
}
function daylog() {
git log --format="%s " --since="18 hours ago" --author="Robby Colvin" --no-merges --reverse | xargs -0 ruby -e "puts ARGV.to_s.split(/ \n/).join(' ')"
}
function volume() {
if [[ $1 ]]; then
sudo osascript -e "set Volume $1"
else
echo "Please enter a number from 0 to 10."
fi
}
if [ ! `command -v "pgrep"` ]; then
function pgrep() {
ps -axo pid,command,args | grep -i "$@" | awk '{ print $1 }'
}
fi
if [ ! `command -v "pkill"` ]; then
function pkill() {
kill $(ps ax | awk '$5 ~ /'"$1"'/ { print $1 }')
}
fi
function gc {
git commit -vm "$*"
}
function gca {
git commit -vam "$*"
}
# https://gist.github.com/810859
# $ gh-get https://github.com/defunkt/facebox/blob/master/src/facebox.js
function gh-get {
curl -#O $(echo $1 | sed 's|blob/||' | sed 's|github.com|raw.github.com|')
}
# ghc (GitHub clone)
# http://openmonkey.com/articles/2009/07/fast-github-clone-bash-function
function ghc {
gh_url=${1:-`pbpaste`}
co_dir=${HOME}/code/src/$(echo $gh_url | sed -e 's/^git:\/\/github.com\///; s/\//-/; s/\.git$//')
if [ -d $co_dir ]; then
cd $co_dir && git pull origin master
else
git clone "${gh_url}" "${co_dir}" && cd "${co_dir}"
fi
}
# Show the active network interface.
iface() { route get 0.0.0.0 2>/dev/null | awk '/interface: / {print $2}'; }
# Grep directory listing.
function lg {
ls -la | grep -e "$@";
}
# mkdir, cd into it
# http://onethingwell.org/post/586977440/mkcd-improved
mkcd () {
mkdir -p "$*" && cd "$*"
}
rmdsstore() {
if [ -z "$1" ]; then
find . -name ".DS_Store" -depth -exec rm {} \;
else
find "$1" -name ".DS_Store" -depth -exec rm {} \;
fi
}
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 prezhi() {
highlight -O rtf -t 2 -K 40 -k 'Source Code Pro' --style molokai $1 | pbcopy
}
function updaterepos() {
for dir in $(find . -type d -d 1) ; do
if [ -d $dir/.git ]; then
echo $dir
git --git-dir=$dir/.git --work-tree=$PWD/$dir pull
fi
done
}
function resolvekiip {
HOST=`dig $1 | sed -n 's|.*A.*\(10\..*\)|\1|p'`
echo $HOST
}
function sshkiip {
HOST=`dig $1 | sed -n 's|.*A.*\(10\..*\)|\1|p'`
if [ "$HOST" = "" ]; then
echo "Host $1 not found."
return
fi
ssh -i $HOME/workspace/kiip/.chef/kiip-ssh.pem -l ubuntu $HOST ${@:2}
}
function package_vmware() {
ID=$(ls .vagrant/machines/default/vmware_fusion | grep -v id | grep -v lock | grep -v action_provision)
DIR=".vagrant/machines/default/vmware_fusion/${ID}"
VDISK="$DIR/Virtual Disk.vmdk"
VDISKMANAGER="/Applications/VMware Fusion.app/Contents/Library/vmware-vdiskmanager"
"$VDISKMANAGER" -d "$VDISK"
"$VDISKMANAGER" -k "$VDISK"
pushd $DIR
if [ -f vmware.box ]; then rm vmware.box; fi
tar cvzf vmware.box *
popd
mv "${DIR}/vmware.box" .
echo "Packaged VM to ./vmware.box"
}
function curlsh {
file=$(mktemp -t curlsh) || { echo "Failed creating file"; return; }
curl -s "$1" > $file || { echo "Failed to curl file"; return; }
$EDITOR $file || { echo "Editor quit with error code"; return; }
sh $file;
rm $file;
}
# function echo {
# builtin echo -e '\E[36m'$(basename $0 .sh): '\E[33m'$1;
# }
# vim: set ft=sh: