dotfiles/zsh/func/makers/mkdjango

59 lines
1.4 KiB
Text
Raw Normal View History

2012-11-15 13:54:16 -08:00
#!/bin/zsh
# Create a Django project using a template in .dotfiles/codetemplates/django
# Eryn Wells <eryn@erynwells.me>
2013-08-07 22:43:53 -07:00
function usage_mkdjango
{
cat <<EOF
Usage: $0 template_name project_name [optional destination directory]"
2012-11-15 13:54:16 -08:00
2013-08-07 22:43:53 -07:00
Create a Django project named [project_name] based on the specified template
[template_name]. If no [destination directory] is given, the project is
created in the current one.
EOF
2012-11-15 13:54:16 -08:00
}
2013-08-07 22:43:53 -07:00
2013-08-09 10:13:34 -07:00
function mkdjango
{
if [[ ${#@} -lt 2 ]]; then
print_error "Need moar arguments" 1>&2
2013-08-07 22:43:53 -07:00
usage_mkdjango $0
2013-08-09 10:13:34 -07:00
return -1
fi
2012-11-15 13:54:16 -08:00
2013-08-07 22:43:53 -07:00
local tname=$1
local tdir="$HOME/.codetemplates/django/$tname"
local pname=$2
local dest=$3
2012-11-15 13:54:16 -08:00
2013-08-07 22:43:53 -07:00
if [[ ! -d "$tdir" ]]; then
print_error "Invalid template name: $tname" 1>&2
2013-08-09 10:13:34 -07:00
return -2
fi
2012-11-15 13:54:16 -08:00
2013-08-07 22:43:53 -07:00
print_info "Making Django project '$pname' with template '$tname'"
if [[ -n "$dest" && ! -d "$dest" ]]; then
print_info_sub "Destination directory given but does not exist; creating $dest"
mkdir -p "$dest"
2013-08-09 10:13:34 -07:00
fi
2012-11-15 13:54:16 -08:00
2013-08-09 10:13:34 -07:00
# Determine what files might not be rendered by django-admin.py
2013-08-07 22:43:53 -07:00
local names=()
for f in `ls -A "$tdir"`; do
# Pick up dotfiles
2013-08-09 10:13:34 -07:00
if [[ -e "$f" && "$f" =~ "^\." ]]; then
2013-08-07 22:43:53 -07:00
names+=("$f")
2013-08-09 10:13:34 -07:00
fi
done
2013-08-07 22:43:53 -07:00
print_info_sub "Calling django-admin.py"
django-admin.py startproject --template="$tdir" --name=${(j.,.)names} "$pname" "$dest"
2013-08-09 10:13:34 -07:00
exitcode=$?
2012-11-15 13:54:16 -08:00
2013-08-09 10:13:34 -07:00
return $exitcode
}
2012-11-15 13:54:16 -08:00
2013-08-09 10:13:34 -07:00
mkdjango $@