TLDR: Check out the snippet.
For example, suppose that you have a set of commands you need to run on the machine of every new engineer. These commands install Homebrew and wget. You could write a snippet with the following as the file’s content:
echo "Running setup commands ..."echo "Installing Homebrew ..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"echo "Installing wget ..."
brew install wget
Save it as either a private or public snippet.
If you saved a private snippet, click on Share for the file, then toggle on the Public URL for the file:
Otherwise, if the snippet is public, click on the View Raw link in the file’s header to open a browser tab to the URL.
Then, simply curl the file contents into
bash to run the commands:
Obviously, you’re not limited to to executing shell commands. You could use any HTTP client written in any language to retrieve snippet file contents. You could say, write a RSS feed that gets consumed by Feedparser… or write a portable config file that gets used by CI builds.
Do you have any cool uses for Cacher snippets? Let us know in the comments.
Want to remember this technique? Save the snippet for this blog post to your Cacher library.