Run Cacher snippet contents through bash commands

Rui Jiang
Rui Jiang
Jul 9, 2018 · 2 min read

A question that often comes up is whether you can run snippet file contents in a shell (like bash or zsh). The answer is yes and here is how.

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:

Image for post
Image for post
Turn on the public URL for the snippet 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:

\curl -sSL https://api.cacher.io/raw/d87125a90faaf53b24bf/8f84e8dce35880bd3bbc/setup.sh | bash

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.

Cacher is a code snippet organizer for pro developers. Try it at cacher.io.

Cacher App

The code snippet organizer for professional developers

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store