Last active
March 3, 2017 08:17
-
-
Save inz/d1742e33a9066e3150b90206ab2b723d to your computer and use it in GitHub Desktop.
Prevent wercker cli from polluting project directories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prevent wercker from polluting repositories | |
# | |
# Usage: | |
# Add this to your .bashrc or .zshrc | |
function wercker() { | |
# To prevent collisions between projects (i.e., directories) with the same | |
# name in different locations in your file system, we append a SHA of the | |
# project path to the project name. | |
project_name=$(basename $(pwd))-$(shasum <(pwd)|awk '{print $1}') | |
wercker_dir=~/.wercker/projects/$project_name | |
# Capture global options. | |
global_opts=() | |
# Use environment from `.env` file if it exists | |
if [ -f .env ]; then | |
global_opts+=(--environment <(sed -e '/^[ ]*#/d' -e '/^[:space:]*$/d' -e 's/^[ ]*export \(.*\)$/export X_\1/g' .env)) | |
fi | |
while [[ "$1" =~ '^--' ]]; do | |
if [[ "$1" = "--environment" ]]; then | |
global_opts+=($1) | |
shift | |
fi | |
global_opts+=($1) | |
shift | |
done | |
if [[ "$#" -ge 1 ]]; then | |
command=$1 | |
shift | |
fi | |
# Write wercker artifacts to `$wercker_dir`. | |
command_opts=() | |
if [[ "$command" =~ '^(b|build|dev|d|deploy|check-config)$' ]]; then | |
command_opts+=(--working-dir $wercker_dir) | |
fi | |
command wercker $global_opts $command $command_opts $@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment