Last active
December 16, 2015 20:19
-
-
Save jasonmoo/5491260 to your computer and use it in GitHub Desktop.
some bash profile shorties to make golangin easier...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cd() { | |
builtin cd $@ | |
if [[ -e .goenv ]]; then | |
source .goenv | |
fi | |
} | |
function gengo() { | |
local project=${1?:"Usage: gengo <projectname> [<git origin url>]"} | |
[ ! -d "$project" ] && mkdir "$project" && builtin cd "$project" && mkdir -p src bin pkg && | |
# jank to make embedded newlines show up on a mac | |
echo "package main\nimport(\"fmt\")\nconst()\nvar()\nfunc init() {}\n\nfunc main() {\nfmt.Println(\"$project\")\n}" | perl -pe "s/\\\n/\n/g;" > "$project.go" && | |
echo "package main\nimport(\"testing\")\nfunc TestExample(t *testing.T){if false {t.Errorf(\"%s\", \"hi\")}}\nfunc BenchmarkExample(b *testing.B){b.StopTimer()\na, aa := 1, 0\nb.StartTimer()\nfor i := 0; i < b.N; i++ {a, aa = aa, a}}" | perl -pe "s/\\\n/\n/g;" > "${project}_test.go" && | |
go fmt *.go && | |
echo "#$project" > README.md && | |
touch "bin/.gitdir" "pkg/.gitdir" "src/.gitdir" && | |
echo "export ORIG_PATH=\${ORIG_PATH-\$PATH}" > .goenv && | |
echo "export GOPATH=$(pwd)" >> .goenv && | |
echo "export GOBIN=\$GOPATH/bin" >> .goenv && | |
echo "export PATH=\"\$GOBIN:\$ORIG_PATH\"" >> .goenv && | |
git init . && | |
git add . && | |
git commit -m "First" && | |
echo "bin/" >> .gitignore && | |
echo "pkg/" >> .gitignore && | |
echo "$project" >> .gitignore && | |
echo "*.log" >> .gitignore && | |
git add .gitignore && | |
git commit -m "Adding .gitignore" | |
if [[ -n "$2" ]]; then | |
git remote add origin "$2" && | |
git push -u origin master | |
fi | |
cd "$project" 2>/dev/null | |
open -a "Sublime Text 2" . | |
} | |
function benchgo() { | |
go test -bench $1 | tee /dev/stderr | grep Bench | column -t | sort -n -k3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment