Last Updated: February 25, 2016
· apaganobeleno

Static Sites for Heroku unix function

One of the common tasks we do on frontend is to create a small static site at heroku to show our progress to our clients, by default we follow the instructions from

But it becomes boring to look fort that link and repeat the same steps every time, so i decided to write a small function on my .zshrc file and i ended with this :


  if [[ -z "$PROJECT_NAME" ]] then
    echo "| You didn't define a name for the site folder, setting it to 'site' by default"

  mkdir -p $PROJECT_NAME/public/{images,js,css}
  touch $PROJECT_NAME/{,public/index.html}

  cd $PROJECT_NAME && touch Gemfile && echo "source \"\"\ngem 'rack'" >> Gemfile

  echo "use Rack::Static, :urls => [\"/images\", \"/js\", \"/css\"],:root => \"public\"\nrun lambda { |env|\n[200, {'Content-Type'  => 'text/html', 'Cache-Control' => 'public, max-age=86400' },'public/index.html', File::RDONLY)]}" >>

  bundle install
  cd ..

it creates the basic files and directories for the application, receives a name for the folder and runs bundle for the gem dependencies.

Hope you like it and waiting for your comments to improve it.