Skip to content

Instantly share code, notes, and snippets.

@bartkozal
Last active May 6, 2016 19:51
Show Gist options
  • Save bartkozal/959179a8336254eb08196dd8e9f5c6f2 to your computer and use it in GitHub Desktop.
Save bartkozal/959179a8336254eb08196dd8e9f5c6f2 to your computer and use it in GitHub Desktop.
How I run a server or deploy across various projects with a single shell command

I work on various projects and always forget what should I type to run a server, do a deploy etc. So, how I dealt with this problem and have a single shell command for that?

Add to your global .gitignore:

.exec

Add the following function to your .zshrc/.bashrc:

function e {
  $(git rev-parse --show-toplevel)/.exec $1
}

Now for each project, in a root directory, you need to create .exec file with the execute permission (chmod +x ./.exec). I use this template as a starter-kit:

#!/usr/bin/env ruby

def server
  exec('')
end

def deploy
  exec('')
end

case ARGV[0]
when "s", "server" then server
when "d", "deploy" then deploy
end

For example, for Jekyll website it'd look like this:

#!/usr/bin/env ruby

def server
  exec('jekyll serve')
end

def deploy
  exec('git checkout gh-pages && git rebase master && git push && git checkout master')
end

case ARGV[0]
when "s", "server" then server
when "d", "deploy" then deploy
end

For JS project that utilize gulp:

#!/usr/bin/env ruby

def server
  exec('gulp server')
end

def deploy
  exec('gulp publish')
end

case ARGV[0]
when "s", "server" then server
when "d", "deploy" then deploy
end

etc.

That's all. No matter what I'm working on I can just type e s and it always run a local server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment