mkdjango
This commit is contained in:
parent
0cbeea2103
commit
b2a9ecfa7c
1 changed files with 51 additions and 0 deletions
51
zsh/func/makers/mkdjango
Normal file
51
zsh/func/makers/mkdjango
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
# Create a Django project using a template in .dotfiles/codetemplates/django
|
||||||
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
|
|
||||||
|
local funcname=$0
|
||||||
|
|
||||||
|
|
||||||
|
_usage() {
|
||||||
|
print_info "Usage: $funcname template_name project_name [optional destination directory]"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ ${#@} -lt 2 ]]; then
|
||||||
|
print_error "Need moar arguments" 1>&2
|
||||||
|
_usage
|
||||||
|
return -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
local tname=$1
|
||||||
|
local tdir="$HOME/.codetemplates/django/$tname"
|
||||||
|
local pname=$2
|
||||||
|
local dest=$3
|
||||||
|
|
||||||
|
if [[ ! -d "$tdir" ]]; then
|
||||||
|
print_error "Invalid template name: $tname" 1>&2
|
||||||
|
return -2
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
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"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Determine what files might not be rendered by django-admin.py
|
||||||
|
local names=()
|
||||||
|
for f in `find "$tdir"`; do
|
||||||
|
# Pick up all dotfiles
|
||||||
|
if [[ -e "$f" && "`basename $f`" =~ "^\." ]]; then
|
||||||
|
names+=($f)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
print_info_sub "Calling django-admin.py"
|
||||||
|
django-admin.py startproject --template="$tdir" --name=${(j.,.)names} $pname $dest
|
||||||
|
exitcode=$?
|
||||||
|
|
||||||
|
unfunction _usage
|
||||||
|
return $exitcode
|
Loading…
Add table
Add a link
Reference in a new issue