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
Why
The 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
-
How
Edit the
go
file and change the line that declaresGO_SCRIPTS_DIR
:Why
The 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-bash
to.gitignore
-
How
Edit your
.gitignore
file (assuming you're using git) to prevent the go-script-bash framework from being added to your repository.Why
Running 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
Why
./go env
will print out a command to define the go script as a function that you can use from anywhere in your project. Piping that output intobash
runs the command immediately.
Create your first go command script
-
How
Use the
go new
command to create a new script file:Edit the new file (.scripts/serve) to do something useful:
Why
My
serve
command 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 usessed
to parse an IP address from the output ofip
and then passes that on to Jekyll.${_GO_CMD_ARGV}
lets me pass additional arguments, so I can do something likego serve --drafts
to include draft posts when running my website locally.
That was fun. Let's do another one!
-
How
Use the
go new
command to create a new script file:Edit the new file (.scripts/setup) to do something useful:
Why
This 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.