title: Modularizing and distributing bash script via Homebrew
body: <h2>Context</h2>
  
  <p>I have some functions defined in my <code>~/.bashrc</code> which I'd like to turn into a Homebrew package. Currently, these functions act as custom commands on my command line:</p>
  
  <pre class="lang-sh prettyprint-override"><code># .bashrc
  function foo() {
      # do something interesting
  }
  
  # at terminal
  $ foo
  # =&gt; does the interesting thing
  </code></pre>
  
  <h2>Approach</h2>
  
  <p>I've created a homebrew formula using <code>brew create</code>. My current approach is as follows:</p>
  
  <ol>
  <li>Move the function definitions into a separate file, <code>script</code>, within a directory, <code>brew-script</code></li>
  <li>Make <code>brew-script</code> downloadable as a tarball, <code>brew-script.tar.gz</code></li>
  <li>Have my brew formula append text to the end of <code>~/.bash_profile</code> to include <code>script</code> when terminal session starts</li>
  </ol>
  
  <h2>Concerns</h2>
  
  <ol>
  <li><p>Is modifying <code>.bash_profile</code> in a brew formula bad practice? (eg. when uninstalling with <code>brew uninstall script</code>, brew should somehow remove the text that was appended to <code>.bash_profile</code>... Parsing <code>.bash_profile</code> doesn't seem very fun.)</p></li>
  <li><p>Is there a convention already established for including functions in bash scripts so that they are available from the command line?</p></li>
  <li><p>Is it common to simply ask the user to add some text to their <code>.bash_profile</code> or <code>.bashrc</code>?</p></li>
  </ol>
  
  <h2>Desired result</h2>
  
  <p>Should be able to install cleanly with brew and then run <code>foo</code> as a command:</p>
  
  <pre><code>$ brew install script
  $ foo
  # =&gt; does the interesting thing
  </code></pre>
  
  <p>(Assume the brew formula is already installed locally. I'll worry about auditing and pushing the formula to homebrew later)</p>