Created
June 27, 2013 15:45
-
-
Save durango/5877571 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| if [ $# -lt 2 ] | |
| then | |
| echo "Usage: hat [hat directory] [hat] [output directory]" | |
| exit 1 | |
| fi | |
| if [ $# -lt 3 ] | |
| then | |
| dir=$HOME/.hat/ | |
| else | |
| dir=$1 | |
| shift | |
| fi | |
| # Trailing / | |
| dir=$(echo $dir | sed 's/\/$//')/ | |
| hat=$1 | |
| compressed=$(echo $hat | sed -e 's/[^[:alnum:]|-]//g') | |
| echo $compressed | |
| # Check to see if the project exists | |
| if [ -z "$1" -o ! -d "$dir$hat" -o "$compressed" != "$hat" ] | |
| then | |
| echo "Invalid project name." | |
| fi | |
| shift | |
| output=$1 | |
| if [ -z "$output" ] | |
| then | |
| output=./ | |
| fi | |
| output=$(echo $output | sed 's/\/$//')/ | |
| if [ ! -d "$output" ] | |
| then | |
| mkdir "$output" | |
| fi | |
| echo "Copying from $dir$hat to $output..." | |
| cp -r $dir$hat/* $output | |
| # Copy from project to the directory that we want | |
| echo "Done" | |
| echo | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment