Skip to content

Instantly share code, notes, and snippets.

@colindensem
Forked from caius/gist:128644
Created November 8, 2009 13:34
Show Gist options
  • Save colindensem/229256 to your computer and use it in GitHub Desktop.
Save colindensem/229256 to your computer and use it in GitHub Desktop.
# Runs `git push` before `cap deploy`
# Otherwise just passes through to `cap`
function cap {
CAP="`which cap`"
if [[ "$1" == "deploy" || "$2" == "deploy" ]]; then
git push && $CAP $*
else
$CAP $*
fi
}
## My magical git function ##
# Adds various checks to `git` as detailed below:
# * Makes sure you've run your specs/features before pushing
# * Asks for confirmation before committing on master
function git {
GIT="`which git`"
CONTINUE=true
# git push
# Checks if there are spec/ or features/ folders and
# questions the user if they have been run if they exist.
if [[ "$1" == "push" ]]; then
# Check if spec/ exists
if [[ -e spec ]]; then
CONTINUE=false # fail by default
# Ask the user
echo -n "Have you run your specs? [Y/n]"
read a
if [[ $a == "Y" || $a == "y" || $a == "" ]]; then
CONTINUE=true
fi
fi
# Check if features/ exists
if [[ -e features ]]; then
CONTINUE=false # fail by default
# Ask the user
echo -n "Have you run your features? [Y/n]"
read a
if [[ $a == "Y" || $a == "y" || $a == "" ]]; then
CONTINUE=true
fi
fi
# git commit
# Checks if we're on the master branch and
# double-checks with the user if they are
elif [[ "$1" == "commit" || "$1" == "vi" || "$1" == "via" || "$1" == "viaa" ]]; then
# Check the branch we're on
if [[ `parse_git_branch` == "(master)" ]]; then
CONTINUE=false # fail by default on master
# We're on master! Make sure we want to commit here
echo "= WARNING: Committing on master ="
echo -n "Continue? [y/N]"
read a
if [[ $a == "y" || $a == "Y" || $a == "yes" ]]; then
# They must really want to commit on master
CONTINUE=true
else
echo "Not committing."
fi
fi
fi
# Run the command if we've been told to.
# The default is to run the command so this only
# fires if a check has disabled it.
if [[ $CONTINUE == true ]]; then
$GIT $*
fi
}
# ss # => ./script/server
# ss 3001 # => ./script/server -p 3001
# ss test # => ./script/server -e test
# ss test 3001 # => ./script/server -e test -p 3001
function ss {
if [[ -z "$1" ]]; then
ruby script/server
elif [[ -z "$2" ]]; then
# Is it a port or an env?
if [[ "$1" =~ [0-9]+ ]]; then
# Its a port
ruby script/server -p $1
else # its an env name
ruby script/server -e $1
fi
else
ruby script/server -e $1 -p $2
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment