Skip to content

Instantly share code, notes, and snippets.

@durango
Created June 27, 2013 15:45
Show Gist options
  • Select an option

  • Save durango/5877571 to your computer and use it in GitHub Desktop.

Select an option

Save durango/5877571 to your computer and use it in GitHub Desktop.
#!/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