/
.shellhook
94 lines (81 loc) · 2.04 KB
/
.shellhook
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
#!/usr/bin/env bash
export WD=$PWD
export GOPATH="$WD/server"
export JSPATH="$WD/client"
export HTML_TIDY="$JSPATH/.tidyrc"
export PORT="8080"
export RACE=false
export HOST
if [ "$(uname -s)" = "Darwin" ]; then
alias ls="ls --color=auto"
alias ll="ls -l"
HOST=$(ipconfig getifaddr en0 || ipconfig getifaddr en1)
else
alias open="xdg-open"
HOST=$(ip route get 1.2.3.4 | awk '{print $7}')
fi
if [ ! -d "$GOPATH/bin" ]; then
mkdir "$GOPATH/bin"
fi
if [ ! -f "$WD/.goinit" ]; then
go get -v golang.org/x/lint/golint
go get -v github.com/gorilla/websocket
touch "$WD/.goinit"
fi
gofmts() {
if gofmt -w -s -e "$1"; then
awk '{ gsub(/\t/, " "); print }' < "$1" > tmp
cat tmp > "$1"
rm tmp
fi
}
golint() {
"$GOPATH/bin/golint" "$1" \
| sed -n -e '/exported .* should have comment.* or be unexported/!p' \
| sed -n -e '/struct field Id should be ID/!p' \
| sed -n -e "/don't use ALL_CAPS in Go names; use CamelCase/!p"
}
goall() {
wd=$(pwd)
cd "$GOPATH" || exit
find . -type f -name '*.go' \
-not -path "*github.com*" \
-not -path "*golang.org*" \
-exec bash -c 'echo "$0"; golint "$0"; gofmts "$0"' {} \;
cd "$wd" || exit
}
govets() {
wd=$(pwd)
cd "$GOPATH/src" || exit
src=$(
find -- * -prune -type d \
-not -name "*github.com*" \
-not -name "*golang.org*" \
| tr '\r\n' ' '
)
eval "go vet -v $src"
cd "$wd" || exit
}
export -f gofmts
export -f golint
export -f goall
export -f govets
if [ ! -f "$WD/.jsinit" ]; then
cd "$JSPATH" || exit
npm install --no-save jshint
touch "$WD/.jsinit"
cd "$WD" || exit
fi
jsall () {
wd=$(pwd)
cd "$JSPATH" || exit
tidy -q -m "$JSPATH/src/index.html"
sed -i 's/[ \t]\+$//' "$JSPATH/src/index.html"
for x in "$JSPATH"/src/js/*.js; do
echo "$x"
"$JSPATH/node_modules/jshint/bin/jshint" -c "$JSPATH/.jshintrc" "$x"
clang-format -i "$x"
done
cd "$wd" || exit
}
export -f jsall