Isaac.Truett.info
How to Get Started with go-script-bash
- easy
- repeatable
- self-documenting
This guide will show you how to add go-bash-script to your project. Mike's documentation is already a great place to start. Hopefully this example is a useful addition.
Open all sections
- Copy the go-template into your project root
-  How$ curl https://raw.githubusercontent.com/mbland/go-script-bash/master/go-template >./go $ chmod ugo+rx ./goWhyThe curl command lets us quickly copy a single file out of GitHub, and the chmod command sets the write and execute permissions so we can run the script. 
- Edit the template to set a location for our scripts
-  HowEdit the gofile and change the line that declaresGO_SCRIPTS_DIR:declare GO_SCRIPTS_DIR=.scriptsWhyThe scripts feel like configuration/metadata for my project, so I wanted to tuck them into a directory named with a leading dot. 
- Add- /.scripts/go-script-bashto- .gitignore
-  HowEdit your .gitignorefile (assuming you're using git) to prevent the go-script-bash framework from being added to your repository./.scripts/go-script-bashWhyRunning the go command for the first time will download the go-script-bash framework from GitHub. You could check that in along with your code, or add it as a submodule as Mike explains in his documentation. I chose to let it download once every time I set up my project on a new computer. I feel that option keeps my repository the cleanest. 
- Define "go" as a function
-  How$ ./go env | bashWhy./go envwill print out a command to define the go script as a function that you can use from anywhere in your project. Piping that output intobashruns the command immediately.
- Create your first go command script
-  HowUse the go newcommand to create a new script file:$ go new --command serveEdit the new file (.scripts/serve) to do something useful: #! /usr/bin/env bash # # Starts the built-in Jekyll development server _serve() { local IP=$(ip -f inet addr show eth0 | sed -n -e 's/^ inet \(.*\)\/.*$/\1/p') bundle exec jekyll serve --host=$IP ${_GO_CMD_ARGV} } _serve "$@"WhyMy servecommand was getting a little unwieldly after I had to start specifying the IP address to bind to (I'll address that more when I get to writing about my experience with developing on a Pixelbook). This command usessedto parse an IP address from the output ofipand then passes that on to Jekyll.${_GO_CMD_ARGV}lets me pass additional arguments, so I can do something likego serve --draftsto include draft posts when running my website locally.
- That was fun. Let's do another one!
-  HowUse the go newcommand to create a new script file:$ go new --command setupEdit the new file (.scripts/setup) to do something useful: #! /usr/bin/env bash # # Installs ruby, jekyll, bundler, and their dependencies. _setup() { sudo apt-get install ruby ruby-all-dev zlib1g-dev sudo gem install jekyll bundler bundle install } _setup "$@"WhyThis command should come in handy the next time I have to set up a new workspace for this project. It will install ruby, jekyll, bundler, and all the other dependencies needed to run my website.